Skip to content

Commit ac43df1

Browse files
committed
Document limitation: cannot flatten OR/AND chains in EXPLAIN output
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.
1 parent 56cb4de commit ac43df1

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

internal/explain/expressions.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ func explainBinaryExpr(sb *strings.Builder, n *ast.BinaryExpr, indent string, de
264264
return
265265
}
266266

267+
// Note: OR and AND chains are NOT flattened because we cannot distinguish
268+
// implicit left-associativity from explicit parenthesization in the AST.
269+
// For example: "a OR b OR c" and "(a OR b) OR c" produce identical parse trees
270+
// but ClickHouse EXPLAIN outputs different structures for them.
271+
267272
fmt.Fprintf(sb, "%sFunction %s (children %d)\n", indent, fnName, 1)
268273
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, 2)
269274
Node(sb, n.Left, depth+2)

0 commit comments

Comments
 (0)