Repository navigation
Fix inconsistent AST formatting for EXPLAIN with UNION and trailing SETTINGS - #99485
Merged
alexey-milovidov merged 3 commits intoMar 16, 2026
Merged
Conversation
…ETTINGS When an `EXPLAIN` query wraps a `SelectWithUnionQuery` and has output-level `SETTINGS` (from `ASTQueryWithOutput`), the SETTINGS clause was formatted after the UNION chain without parenthesizing the last SELECT. During re-parsing, `ParserSelectQuery` eagerly consumed SETTINGS as part of the last SELECT, causing the SETTINGS to migrate from the `EXPLAIN` node to the last `SelectQuery` - an inconsistent AST round-trip. The fix propagates a `parent_has_trailing_settings` flag through `FormatStateStacked`, set in `ASTQueryWithOutput::formatImpl` when `settings_ast` is present without preceding `out_file` or `format_ast`. `ASTSelectWithUnionQuery::formatQueryImpl` checks this flag (alongside its existing check for its own `settings_ast`) and wraps individual SELECTs in parentheses, preventing the parser from consuming the trailing SETTINGS. https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=8e9faf48d7ba8b442a2fe7973454c4d6b1e1844f&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_debug%29 Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Contributor
|
Workflow [PR], commit [26625b2] Summary: ✅ AI ReviewSummaryThis PR fixes AST formatting round-trip for queries where ClickHouse Rules
Final Verdict
|
… SETTINGS `ASTCreateQuery` already wraps the AS-select in parentheses when `settings_ast` is present, which prevents `ParserSelectQuery` from consuming the trailing SETTINGS. Clear `parent_has_trailing_settings` before formatting the inner select to avoid `ASTSelectWithUnionQuery` adding redundant parentheses around individual SELECTs. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
Contributor
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 100.00% (15/15, 0 noise lines excluded) |
alexey-milovidov
added a commit
that referenced
this pull request
Mar 17, 2026
…`parent_has_trailing_settings` The merge from master brought PR #99485 which renamed the field. Also rename test files to avoid index collision with tests added on master. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
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.
Summary
EXPLAINwraps aSelectWithUnionQueryand has output-levelSETTINGS.ParserSelectQueryto consume SETTINGS during re-parse, moving it from theEXPLAINnode to the lastSelectQuery.parent_has_trailing_settingsflag throughFormatStateStackedsoASTSelectWithUnionQueryparenthesizes individual SELECTs when a parent will append SETTINGS.CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=8e9faf48d7ba8b442a2fe7973454c4d6b1e1844f&name_0=MasterCI&name_1=AST%20fuzzer%20%28amd_debug%29
Test plan
04039_explain_union_settings_formatting_roundtriptest verifyingformatQuerySingleLineoutput has parenthesized SELECTsChangelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
🤖 Generated with Claude Code
Version info
26.3.1.703