Skip to content

fix(sql): a two-table comma-join accepts a composite key - #161

Merged
FiveTechSoft merged 1 commit into
FiveTechSoft:mainfrom
russimicro:fix/sql-comma-join-composite-key
Aug 5, 2026
Merged

fix(sql): a two-table comma-join accepts a composite key#161
FiveTechSoft merged 1 commit into
FiveTechSoft:mainfrom
russimicro:fix/sql-comma-join-composite-key

Conversation

@russimicro

Copy link
Copy Markdown
Collaborator

SELECT ... FROM a, b WHERE a.k1 = b.k1 AND a.k2 = b.k2 rejected the second
equality: the comma-join path only ever recognised a single-column join key, so
a composite key fell through as unsupported.

xBase applications join on composite keys routinely (ours does it on
document + line), and the same query written with INNER JOIN already worked
— only the comma spelling was affected.

The fix does not lower a composite comma-join into the single-pair
JoinClause; it leaves inner_join unset and lets the N-way executor take it
from from_tables plus the WHERE equalities, which is the route three or more
tables already take.

Tests

sql_parser_test extended with the composite comma-join form.
Full suite green on this branch (1291 cases).

`FROM a, b WHERE a.k1 = b.k1 AND a.k2 = b.k2` was rejected with "comma-join
supports a single equality join key; use INNER JOIN ... ON for composite
keys", while the identical predicate across THREE tables worked. The limit
was never about composite keys -- it was about which executor ran:

  2 tables  -> the equality is lowered into stmt.inner_join, a JoinClause
               that holds exactly one left/right column pair
  3+ tables -> the N-way executor, which reads the join equalities straight
               from the WHERE and handles any number of them

So a two-table query hit a wall that a three-table one did not.

Do not lower a composite key and do not reject it: leave inner_join unset,
keep every equality in the WHERE, and let the N-way executor take the
statement. The gate that selected it moves from `>= 3 tables` to `>= 3
tables, or 2 tables with no inner_join`. A two-table join with a single key
still takes the simpler path, unchanged.

Reported from an ERP whose historical movement query joins moviminv and
conseinv on (ccodigocon, cdocumetra). Same failure on DBF/CDX and on
ADT/ADI -- it is a parser limit, independent of storage format.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
(cherry picked from commit 7346b95)
@FiveTechSoft
FiveTechSoft merged commit b6470b7 into FiveTechSoft:main Aug 5, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants