Skip to content

Commit e2c0f3a

Browse files
committed
Fix window function explain for named window references
When a window function uses a named window reference (like `OVER w`), the WindowDefinition should not be included as a child of the function in the EXPLAIN output. Only inline window specs (like `OVER ()` or `OVER (ORDER BY x)`) should include the WindowDefinition as a child. This fixes test 03210_lag_lead_inframe_types.
1 parent 2abbe5e commit e2c0f3a

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

internal/explain/functions.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ func explainFunctionCallWithAlias(sb *strings.Builder, n *ast.FunctionCall, alia
1616
if len(n.Parameters) > 0 {
1717
children++ // parameters ExpressionList
1818
}
19-
if n.Over != nil {
19+
// Only count WindowDefinition as a child for inline window specs (not named references)
20+
// When it's just a reference like "OVER w", it's shown in the SELECT's WINDOW clause instead
21+
// Inline specs include OVER () - empty window, and OVER (ORDER BY x) - window with spec
22+
// Named refs have n.Over.Name set and no inline definition
23+
hasInlineWindowSpec := n.Over != nil && n.Over.Name == ""
24+
if hasInlineWindowSpec {
2025
children++ // WindowDefinition for OVER clause
2126
}
2227
// Normalize function name
@@ -65,9 +70,10 @@ func explainFunctionCallWithAlias(sb *strings.Builder, n *ast.FunctionCall, alia
6570
Node(sb, p, depth+2)
6671
}
6772
}
68-
// Window definition (for window functions with OVER clause)
73+
// Window definition (for window functions with inline OVER clause)
6974
// WindowDefinition is a sibling to ExpressionList, so use the same indent
70-
if n.Over != nil {
75+
// Only output for inline specs, not named references like "OVER w"
76+
if hasInlineWindowSpec {
7177
explainWindowSpec(sb, n.Over, indent+" ", depth+1)
7278
}
7379
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"todo":true,"todo_format":true}
1+
{"todo_format":true}

0 commit comments

Comments
 (0)