Skip to content

Commit 1e10e2e

Browse files
kyleconroyclaude
andcommitted
Output WINDOW clause before QUALIFY in SelectQuery EXPLAIN
ClickHouse outputs WINDOW definitions before QUALIFY in the EXPLAIN AST. Fixed the ordering in both explainSelectQuery and explainSelectQueryWithInheritedWith. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 18a6990 commit 1e10e2e

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

internal/explain/select.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,17 @@ func explainSelectQueryWithInheritedWith(sb *strings.Builder, stmt ast.Statement
110110
if sq.Having != nil {
111111
Node(sb, sq.Having, depth+1)
112112
}
113-
// QUALIFY
114-
if sq.Qualify != nil {
115-
Node(sb, sq.Qualify, depth+1)
116-
}
117-
// WINDOW clause
113+
// WINDOW clause - output before QUALIFY
118114
if len(sq.Window) > 0 {
119115
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, len(sq.Window))
120116
for range sq.Window {
121117
fmt.Fprintf(sb, "%s WindowListElement\n", indent)
122118
}
123119
}
120+
// QUALIFY
121+
if sq.Qualify != nil {
122+
Node(sb, sq.Qualify, depth+1)
123+
}
124124
// ORDER BY
125125
if len(sq.OrderBy) > 0 {
126126
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, len(sq.OrderBy))
@@ -430,17 +430,17 @@ func explainSelectQuery(sb *strings.Builder, n *ast.SelectQuery, indent string,
430430
if n.Having != nil {
431431
Node(sb, n.Having, depth+1)
432432
}
433-
// QUALIFY
434-
if n.Qualify != nil {
435-
Node(sb, n.Qualify, depth+1)
436-
}
437-
// WINDOW clause (named window definitions)
433+
// WINDOW clause (named window definitions) - output before QUALIFY
438434
if len(n.Window) > 0 {
439435
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, len(n.Window))
440436
for range n.Window {
441437
fmt.Fprintf(sb, "%s WindowListElement\n", indent)
442438
}
443439
}
440+
// QUALIFY
441+
if n.Qualify != nil {
442+
Node(sb, n.Qualify, depth+1)
443+
}
444444
// ORDER BY
445445
if len(n.OrderBy) > 0 {
446446
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, len(n.OrderBy))
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt4": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)