Skip to content

fix(e6): SUBQUERY_TREE runs every query through the tree; skip JOIN ON/USING in LiteParser - #337

Merged
tkaunlaky-e6 merged 1 commit into
mainfrom
fix/subtree-all-queries
Nov 17, 2026
Merged

tkaunlaky-e6 merged 1 commit into
mainfrom
fix/subtree-all-queries

Conversation

@tkaunlaky-e6

@tkaunlaky-e6 tkaunlaky-e6 commented Nov 17, 2026 •

Copy link
Copy Markdown

What

  1. SUBQUERY_TREE=true now sends every query through the subquery tree, whether or not the planner sends the MULTIDIALECT feature flag. The planner doesn't need to know if a query is single or multi-dialect: a single-dialect query is just a tree whose regions all parse the same way. With SUBQUERY_TREE off, nothing changes.
  2. LiteParser no longer parses a JOIN's ON condition or USING list. It already skipped the SELECT list and WHERE etc.; ON/USING were the last value expressions it parsed with the generic tokenizer. A backtick there broke it:
    • JOIN u ON CAST(u.`x` AS INT) = t.id failed with Expected AS after CAST.
    • A top-level backtick in ON ended the parse early, so a subquery joined after it was silently missed.

Evidence (nov_4th medium dump, pure Databricks, 13,397 unique queries)

Subtree (no MULTIDIALECT flag) vs plain from_sql=databricks:

  • Before this fix: 9 queries failed only in the subtree, all from the backtick-in-ON bug.
  • After: 0 fail only in the subtree; the 9 now give the same output as plain. No other output changed.
  • The only differences left (58 queries) are CAST(x AS DATE) vs DATE(x), which give the same result on e6.
  • Queries failing in both modes are truncated sources or SHOW/DESCRIBE.

Tests

  • tests/test_subquery_tree.py:
    • backtick in ON, COALESCE in ON, USING (...), LEFT(...) as a function, and a subquery joined after them;
    • the trigger test now checks that SUBQUERY_TREE alone triggers the tree;
    • an API test comparing against the plain path. These tests fail without the fix.
  • make test (1063 OK), make test-rs (1063 OK), make test-multidialect (Samsung / Condé Nast / OneTrust): OK.
  • ruff and ruff-format pass. The only mypy error is the missing generated sqlglot/_version.py, unrelated to this change.

Notes

  • With SUBQUERY_TREE=true the multidialect branch also takes POWERBI_SF_TO_DBR requests, since it is checked first.
  • The fallback dialect is still INNER_DIALECT (default databricks). If the planner stops sending flags, non-Databricks deployments would need that default to come from from_sql.

Timing (sequential, one process, all 14,840 rows of the dump)

Each row is sent once in each mode, alternating; from_sql=databricks, no MULTIDIALECT flag, logging off.

Total Mean p50 p90 p99 Max
Plain Databricks 210.3 s 14.2 ms 11.2 ms 27.0 ms 50.8 ms 244.7 ms
SUBQUERY_TREE 253.6 s 17.1 ms 13.0 ms 34.1 ms 61.9 ms 192.7 ms

That is +2.9 ms per query on average (median +1.7 ms), about 20% more in total. The gap grows with query size: +0.7 ms under 2k chars, +14 ms over 50k chars.

…N/USING in LiteParser

- SUBQUERY_TREE=true now sends every /convert-query request through the subquery
  tree, whether or not the planner sends the MULTIDIALECT feature flag.
- LiteParser no longer parses a JOIN's ON condition or USING list. A backtick
  there (e.g. CAST(u.`x` AS INT)) failed the lite parse with "Expected AS after
  CAST", or ended it early so later JOIN subqueries were missed.
@tkaunlaky-e6
tkaunlaky-e6 merged commit 4c65134 into main Nov 17, 2026
6 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