fix(sql): a two-table comma-join accepts a composite key - #161
Merged
FiveTechSoft merged 1 commit intoAug 5, 2026
Merged
Conversation
`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)
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.
SELECT ... FROM a, b WHERE a.k1 = b.k1 AND a.k2 = b.k2rejected the secondequality: 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 withINNER JOINalready worked— only the comma spelling was affected.
The fix does not lower a composite comma-join into the single-pair
JoinClause; it leavesinner_joinunset and lets the N-way executor take itfrom
from_tablesplus the WHERE equalities, which is the route three or moretables already take.
Tests
sql_parser_testextended with the composite comma-join form.Full suite green on this branch (1291 cases).