Skip to content

Commit befdafd

Browse files
kyleconroyclaude
andcommitted
Handle alias on IS NULL expressions in explain output
Add explainIsNullExprWithAlias to properly show aliases on IS NULL expressions when wrapped in AliasedExpr. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent e72bb31 commit befdafd

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

internal/explain/expressions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,9 @@ func explainAliasedExpr(sb *strings.Builder, n *ast.AliasedExpr, depth int) {
808808
case *ast.ExistsExpr:
809809
// EXISTS expressions with alias
810810
explainExistsExprWithAlias(sb, e, n.Alias, indent, depth)
811+
case *ast.IsNullExpr:
812+
// IS NULL expressions with alias
813+
explainIsNullExprWithAlias(sb, e, n.Alias, indent, depth)
811814
case *ast.Parameter:
812815
// QueryParameter with alias
813816
if e.Name != "" {

internal/explain/functions.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1544,12 +1544,20 @@ func explainBetweenExprWithAlias(sb *strings.Builder, n *ast.BetweenExpr, alias
15441544
}
15451545

15461546
func explainIsNullExpr(sb *strings.Builder, n *ast.IsNullExpr, indent string, depth int) {
1547+
explainIsNullExprWithAlias(sb, n, "", indent, depth)
1548+
}
1549+
1550+
func explainIsNullExprWithAlias(sb *strings.Builder, n *ast.IsNullExpr, alias string, indent string, depth int) {
15471551
// IS NULL is represented as Function isNull
15481552
fnName := "isNull"
15491553
if n.Not {
15501554
fnName = "isNotNull"
15511555
}
1552-
fmt.Fprintf(sb, "%sFunction %s (children %d)\n", indent, fnName, 1)
1556+
if alias != "" {
1557+
fmt.Fprintf(sb, "%sFunction %s (alias %s) (children %d)\n", indent, fnName, alias, 1)
1558+
} else {
1559+
fmt.Fprintf(sb, "%sFunction %s (children %d)\n", indent, fnName, 1)
1560+
}
15531561
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, 1)
15541562
Node(sb, n.Expr, depth+2)
15551563
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt8": true
4-
}
5-
}
1+
{}

0 commit comments

Comments
 (0)