feat(sql): JOIN ... USING / NATURAL / CROSS (SQLR-5)#158
Merged
Conversation
PR #99 shipped INNER/LEFT/RIGHT/FULL OUTER JOIN ... ON; the three related shapes SQLite supports were still rejected as NotImplemented. This wires all three through the existing nested-loop join driver. Parser (src/sql/parser/select.rs): - JoinClause.on: Expr → constraint: JoinConstraintKind (On/Using/Natural). - USING (cols) is narrowed to a list of column names; NATURAL is carried as-is (it needs schemas the parser doesn't have); CROSS JOIN is rewritten to ON true at parse time. Executor (src/sql/executor.rs): - resolve_join_constraint lowers USING/NATURAL into the synthesized `left.col = right.col [AND …]` predicate, schema-aware: the left qualifier is picked per column so join chains resolve correctly, and NATURAL auto-discovers the shared column names (none ⇒ cross product, matching SQLite). - SELECT * de-duplicates USING/NATURAL columns per the SQLite convention — the joined-on column shows once, taking the left copy. Tests: 8 new executor tests (USING≡ON rows, SELECT* dedup for USING and NATURAL, NATURAL multi-column AND, NATURAL-without-common-cols cross product, CROSS cartesian product, LEFT OUTER USING, USING unknown-column error), replacing the old "returns NotImplemented" test. Docs updated (supported-sql, sql-engine, roadmap, README, web docs). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Merged
joaoh82
added a commit
that referenced
this pull request
Jun 2, 2026
Bump every product manifest 0.11.0 → 0.12.0 and refresh Cargo.lock. Headline change since 0.11.0: JOIN ... USING / NATURAL / CROSS support (SQLR-5, #158). Backward-compatible for embedders — the public Connection/Statement/Rows/Value API is unchanged. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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
Completes the SQLR-5 JOIN surface. PR #99 shipped
INNER/LEFT/RIGHT/FULL OUTER JOIN ... ON ...; this adds the three related shapes SQLite supports, all riding the existing nested-loop driver:JOIN ... USING (col[, col…])— lowered toleft.col = right.colAND-chained per column. The joined-on column shows once inSELECT *(left copy kept), matching SQLite.NATURAL JOIN— auto-discovers the shared column names, then behaves exactly likeUSING (<shared>). No shared columns ⇒ a cross product (SQLite behavior). Combines with flavors (NATURAL LEFT JOIN).CROSS JOIN— the cross product; rewritten toINNER JOIN ... ON trueat parse time.How
JoinClause.on: Expr→constraint: JoinConstraintKind(On/Using/Natural).USING/NATURALno longer error;CROSSis rewritten toON true.resolve_join_constraintsynthesizes the equality predicate against live schemas (left qualifier picked per column so join chains resolve correctly), andSELECT *de-duplicatesUSING/NATURALcolumns.The synthesized predicates flow through the same
eval_predicate_scopepath asON, so NULL/truthiness semantics and outer-join NULL-padding are inherited unchanged.Tests
8 new executor tests (replacing the old
using_or_natural_join_returns_not_implemented):join_using_matches_same_rows_as_on,select_star_using_dedups_joined_columnnatural_join_matches_on_all_shared_columns,select_star_natural_dedups_shared_columnsnatural_join_without_common_columns_is_cross_productcross_join_produces_cartesian_product,left_outer_join_using_preserves_unmatched_leftusing_unknown_column_errorsVerification
cargo build/cargo test(CI exclude set) — 611 lib + all integration tests passcargo fmt --all --check,cargo clippy(no new warnings),cargo doc— cleanUSING(id shown once),NATURAL(k1,k2 once, matched on both),CROSS(full product) — all correctsupported-sql.md,sql-engine.md,roadmap.md,README.md, web docs🤖 Generated with Claude Code