Skip to content

fix(convert): keep set-operator chains flat and slice non-ASCII source once - #280

Closed
kvlonge wants to merge 1 commit into
mainfrom
perf/convert-slow-path
Closed

kvlonge wants to merge 1 commit into
mainfrom
perf/convert-slow-path

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Why

Converting a long chain of one set operator (a UNION ALL b UNION ALL c ..., typical of inline test fixtures) produced one nested, parenthesised level per branch, so later passes, the layout above all, did work proportional to branches times statement length. Separately, the Snowflake parser re-walked the whole text on every slice once it held a non-ASCII character.

Changes

  • A left operand continuing the chain with the same operator and quantifier, and no clauses of its own, prints without brackets; the chain stays one level deep.
  • The parser builds character-to-byte offsets once per parse.
  • Synthetic tests (crates/sqlquack/tests/cli/test_set_chains.rs): nesting depth is constant at 4 and 64 branches; a work-count guard asserts each extra branch adds the same laid-out output; converted chains (mixed UNION / UNION ALL, EXCEPT, non-ASCII text) return the right rows on DuckDB.
  • Baselines re-recorded: strict-parsing instructions -2.6%; SQL sizes: 5,225 cases smaller, none larger.

Verification

  • make check-ci and make test-crate CRATE=sqlquack pass.
  • The full local gate passed every step except the wall-clock sql-benchmark, which fails identically on main on the same machine (decimal_divide ~81x vs a recorded 37.4x); CI runs it on its own runners.
  • On a corpus of 787 real test statements (release builds): p90 statement 770 ms -> 701 ms, largest 1,540 ms -> 1,283 ms; every statement converts as before, and changed outputs parse to the same DuckDB tree.

…e once

A chain of one set operator converted to one nested, parenthesised level per
branch, so every later pass over the output (above all the layout) did work
proportional to the number of branches times the statement's length. A left
operand that continues the chain with the same operator and needs no cast now
prints without its parentheses, which DuckDB reads left to right as the
nesting did, so the chain stays one level deep and each further branch adds
the same laid-out output.

The Snowflake parser sliced its source by character offsets by walking the
whole text from the start on every call once the text held any non-ASCII
character. It now builds the character-to-byte offsets once per parse, which
also takes 2.6% off the strict-parsing instruction count; the baseline
records the gain. Converted SQL loses the brackets, so the SQL size baseline
records 5225 smaller cases and none larger.
@kvlonge
kvlonge added this pull request to the merge queue Nov 25, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 25, 2026
@kvlonge

kvlonge commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Superseded: the flat chain printing landed with #279, and the parser change is carried, with two more conversion speed fixes, in a follow-up PR from feat/convert-bind-opt-out.

@kvlonge kvlonge closed this Nov 25, 2026
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.

1 participant