EXPLAIN QUERY PLAN: fix incorrect join order, add missing annotations, convert some snapshot tests to EQP-only#5511
Merged
jussisaurio merged 10 commits intomainfrom Feb 21, 2026
Merged
Conversation
EXPLAIN QUERY PLAN was iterating joined_tables() in original SQL order instead of the optimizer's join_order. This made EQP output misleading when the optimizer reordered joins. Now builds visit_order from join_order first, then appends hash-join build tables. Also fixes the left join ordering fuzz test to account for the LEFT-to-INNER join simplification optimization that was added after the test was written. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds a new 'snapshot-eqp' directive that captures only the EXPLAIN QUERY PLAN output without bytecode. Useful for tests that verify join ordering and access method selection where bytecode details are noise. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ggregates - Emit "USE SORTER FOR GROUP BY" when GROUP BY uses a sorter - Emit "USE SORTER FOR ORDER BY" / "USE TEMP B-TREE FOR ORDER BY" depending on whether sorter or heap sort is used - Emit "SCALAR SUBQUERY N" / "CORRELATED SCALAR SUBQUERY N" for scalar subqueries - Emit "LIST SUBQUERY N" / "CORRELATED LIST SUBQUERY N" for IN subqueries - Emit "USE HASH TABLE FOR func(DISTINCT)" for distinct aggregates Annotations reflect actual data structures used (sorter, hash table) rather than copying SQLite's "TEMP B-TREE" phrasing. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Bytecode snapshots now include USE SORTER FOR GROUP BY/ORDER BY, USE HASH TABLE FOR count(DISTINCT), and SCALAR SUBQUERY annotations. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… annotations Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
817ff39 to
3e13ff5
Compare
PThorpe92
approved these changes
Feb 21, 2026
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.
EXPLAIN QUERY PLAN didn't show correct join order
EXPLAIN QUERY PLAN was missing stuff that SQLite has
USE TEMP B-TREE FOR ORDER BYannotation because we never use temp b-tree for sorting, so instead printUSE SORTER FOR ORDER BY. Also add turso-custom prints likeUSE HASH TABLE FOR count(DISTINCT)(sqlite doesn't have hash table)Add new snapshot format that only prints EQP instead of full bytecode, in cases where we don't much care about the full bytecode
snapshot-eqpsnapshot test format that just prints the EQP, not the bytecodesnapshot-eqp(for example, most TPC-H tests; in many of them we just care about the join order and maybe order by elimination)