Improve JOIN execution, FK enforcement and table alias support - #52
Open
efremropelato wants to merge 3 commits into
Open
Improve JOIN execution, FK enforcement and table alias support#52efremropelato wants to merge 3 commits into
efremropelato wants to merge 3 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
1. Foreign Key — Critical Crash and Missing Enforcement
Files:
src/core/xdb_fkey.c,src/core/xdb_fkey.h,src/core/xdb_crud.cxdb_create_fkeywas writing through anxdb_filter_t*pointer that was never allocated (NULL), causing an immediate SIGSEGV on anyCREATE TABLE ... FOREIGN KEY. Added real storage (fkey_filters[]) in thexdb_fkeym_tstruct.>>8instead of>>3) in the field bitmap computation, which left memory uninitialized.#if 0):XDB_E_CONSTRAINTif the FK value does not exist in the referenced table.fkeyref_objm, which was registered on the wrong table).2. Multi-Table JOIN — From Completely Non-Functional to Working
Files:
src/parser/xdb_parser_dml.c,src/core/xdb_crud.cJOIN was dead code (
#if 0) that was never completed. Distinct bugs fixed:ONclause parser was disabled → restored with multi-column support.xdb_sql_join, wrong row indexing (pRowPtrs[level]instead oflevel-1).3. Table Alias and Self-Join
File:
src/parser/xdb_parser_dml.cFROM tbl AS aliasandJOIN tbl AS alias(theas_namefield already existed inxdb_reftbl_tbut was never populated).xdb_stmt_find_tablefixed to resolve by alias — necessary to disambiguate a self-join (same table twice).4. WHERE/ORDER BY Consistency on Joined Tables
Files:
src/parser/xdb_parser_dml.c,src/core/xdb_crud.c,src/parser/xdb_stmt.hxdb_sql_joinonly consideredONconditions).tbl.col) — it failed even on simple JOINs.reftbl_countconsecutive pointers; sorting/truncation shuffled single pointers instead of whole batches, producing rows with columns mismatched across different tables. Fixed with the correct stride and a neworder_reftbl_idfield (constraint: all ORDER BY columns must belong to the same joined table).pRefTbl[i]instead ofpStmt->ref_tbl[i]) that broke multi-table resolution after the first table switch.5. Tests Added
Files:
test/xdb_smoke_ddl.c,test/xdb_smoke_dml.c18 new test cases (139 → 147 counting the double fixture instances), including: FK crash, FK enforcement (insert-check + RESTRICT), 2/3-table join, join with index, non-chained join rejected, combined join + WHERE + ORDER BY + LIMIT, ambiguous column, table alias, self-join. Full suite verified with no regressions under ASan.