Document limitation: cannot flatten OR/AND chains in EXPLAIN output#92
Merged
kyleconroy merged 2 commits intomainfrom Dec 30, 2025
Merged
Document limitation: cannot flatten OR/AND chains in EXPLAIN output#92kyleconroy merged 2 commits intomainfrom
kyleconroy merged 2 commits intomainfrom
Conversation
The 02711_trim_aliases test expects OR chains like "a OR b OR c" to be flattened to or(a, b, c) with 3 children. However, tests like 01661_join_complex expect "(a OR b) OR c" to remain nested as or(or(a,b), c) with 2 children. Both SQL patterns produce identical parse trees due to left-associative parsing. Our parser doesn't track explicit parenthesization, but ClickHouse's EXPLAIN output distinguishes between them based on the original SQL syntax. Since we cannot tell implicit grouping apart from explicit parentheses at the AST level, any fix for 02711 would break 01661 (and vice versa). The 02711_trim_aliases test remains in explain_todo as this is a fundamental limitation of our parser architecture.
…ization Add a Parenthesized field to BinaryExpr in the AST to track when an expression was wrapped in explicit parentheses. This allows the EXPLAIN output to correctly distinguish between: - "a OR b OR c" → or(a, b, c) [flattened, no explicit parens] - "(a OR b) OR c" → or(or(a,b), c) [nested, explicit parens preserved] Changes: - ast/ast.go: Add Parenthesized field to BinaryExpr - parser/expression.go: Set Parenthesized=true when parsing grouped expressions - internal/explain/expressions.go: Add collectLogicalOperands() that respects the Parenthesized flag when flattening OR/AND chains This fixes the 02711_trim_aliases test and many other tests that were previously in explain_todo due to incorrect OR/AND chain handling.
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.
The 02711_trim_aliases test expects OR chains like "a OR b OR c" to be
flattened to or(a, b, c) with 3 children. However, tests like 01661_join_complex
expect "(a OR b) OR c" to remain nested as or(or(a,b), c) with 2 children.
Both SQL patterns produce identical parse trees due to left-associative parsing.
Our parser doesn't track explicit parenthesization, but ClickHouse's EXPLAIN
output distinguishes between them based on the original SQL syntax.
Since we cannot tell implicit grouping apart from explicit parentheses at the
AST level, any fix for 02711 would break 01661 (and vice versa).
The 02711_trim_aliases test remains in explain_todo as this is a fundamental
limitation of our parser architecture.