Skip to content

sqlparser: accept left-associated comparison chains - #504

Closed
sciyoshi wants to merge 1 commit into
dolthub:mainfrom
sciyoshi:fix/chained-comparisons
Closed

sciyoshi wants to merge 1 commit into
dolthub:mainfrom
sciyoshi:fix/chained-comparisons

Conversation

@sciyoshi

@sciyoshi sciyoshi commented Nov 4, 2026

Copy link
Copy Markdown

SELECT 1 < 2 = 1 and SELECT (1,2) < (1,3) = 1 currently fail to parse, although grouping the first comparison works. Introduce a left-recursive comparison tier so each scalar comparison can consume the preceding comparison's result. The right operand remains a value expression, preserving left associativity and keeping logical operators outside the comparison operands. Regenerate sql.go and add 22 AST and parse-format-parse cases covering scalar/row chains, mixed comparison operators, explicit grouping, arithmetic, logical operators, NULL, predicates and subqueries.

Fixes dolthub/dolt#12345.

Validation:

  • New chain regressions fail against the original generated parser; GOWORK=off go test ./go/vt/sqlparser -count=1 passes with the fix.
  • Baseline and changed grammars both report zero shift/reduce and reduce/reduce conflicts; regeneration is reproducible.
  • GMS TestQueriesSimple, an external 34-case execution regression, and Dolt TestQueries pass with this checkout selected through an external Go workspace.
  • Rebuilt Dolt passes the same 34 scalar/row cases, incompatible-row-width rejection, table filtering, persisted view reopening and updates.
  • Temporarily combining the grammar and tests from sqlparser: accept boolean expressions in generated columns #503 also passes the full parser package with zero conflicts. This branch is based directly on main and does not include or require sqlparser: accept boolean expressions in generated columns #503; generated parser tables should be regenerated when combining grammar changes.

No dependency version bumps or local module overrides are included. Downstream execution checks remain external until consumers adopt the parser. Validation does not include the full Vitess/MySQL-server suite or a fresh live MySQL comparison.

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.

Chained comparisons fail to parse unless the first comparison is parenthesized

1 participant