SQL summary: isolate select state, fix bugs#16017
Merged
trask merged 3 commits intoopen-telemetry:mainfrom Jan 30, 2026
Merged
Conversation
trask
commented
Jan 27, 2026
Comment on lines
+742
to
+747
| Arguments.of( | ||
| "SELECT * FROM a, (SELECT * FROM b), c", | ||
| expect("SELECT", null, "SELECT a SELECT b c")), | ||
| Arguments.of( | ||
| "SELECT * FROM (SELECT * FROM inner1), (SELECT * FROM inner2), outer_table", | ||
| expect("SELECT", null, "SELECT SELECT inner1 SELECT inner2 outer_table"))); |
Member
Author
There was a problem hiding this comment.
these didn't work previously
24a8e75 to
3cda0ec
Compare
54 tasks
laurit
reviewed
Jan 28, 2026
| private void pushOperation() { | ||
| operationStack.push(operation); | ||
| subqueryStartLevels.push(parenLevel); | ||
| operation = none; |
Contributor
There was a problem hiding this comment.
what if you have SELECT * FROM (TABLE)
Member
Author
There was a problem hiding this comment.
I don't think this is valid SQL?
Contributor
There was a problem hiding this comment.
you can try it our in https://www.db-fiddle.com/ it works on mysql but doesn't on postgres
e08b74b to
0eba6fd
Compare
laurit
reviewed
Jan 30, 2026
|
|
||
| /** Called when an identifier is seen - cancels pending subquery (it's a parenthesized table name). */ | ||
| private void cancelPendingSubqueryIfNeeded() { | ||
| pendingSubqueryPush = false; |
Contributor
There was a problem hiding this comment.
commenting this line out doesn't seem to make any tests fail
laurit
approved these changes
Jan 30, 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.
Follow-up to @laurit's #15986 (comment)
Problem
Subqueries were sharing state with their outer queries, causing several bugs:
SELECT * FROM a, (SELECT * FROM b), cwould miss "c" because the subquery's completion interfered with the outer FROM clause stateUNION/INTERSECT/EXCEPThandling was settingoperation = none, which broke the outer query's operation trackingINSERT INTO t SELECT * FROM (VALUES (1))would incorrectly append "VALUES" to the summarySolution
Introduced an operation stack to properly isolate subquery state:
operationStack(ArrayDeque): Pushes current operation when entering a subquery, pops when exitingsubqueryStartLevels(ArrayDeque): Tracks paren levels where subqueries beginWhen a subquery completes, the outer query's state is restored and updated to account for the subquery as one "table reference" in the FROM clause.
Additional cleanup
Simplified the
Selectclass state from 12 fields to 6:mainTableSetAlreadyidentifierCount > 0inImplicitJoinidentifiersAfterCommaidentifierCountexpectingSubqueryOrTablecaptureTableList || captureSingleTableinColumnAliasListcolumnAliasListParenLevel >= 0identifiersAfterJoinidentifierCountRenamed fields for clarity:
expectingTableName→captureTableList(FROM clause mode)expectingJoinTableName→captureSingleTable(JOIN clause mode)Testing
Added test cases for subquery state isolation:
SELECT * FROM a, (SELECT * FROM b), c→"SELECT a b c"SELECT * FROM (SELECT * FROM inner1), (SELECT * FROM inner2), outer_table→ captures all tables