Skip to content

Commit 1bd0d12

Browse files
committed
Revert "Flatten OR/AND operators in EXPLAIN AST output"
This reverts commit 5f5d3a9.
1 parent 5f5d3a9 commit 1bd0d12

420 files changed

Lines changed: 1784 additions & 414 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

internal/explain/expressions.go

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

267-
// For OR and AND operators, flatten chained expressions
268-
opLower := strings.ToLower(n.Op)
269-
if opLower == "or" || opLower == "and" {
270-
operands := collectBooleanOperands(n, opLower)
271-
fmt.Fprintf(sb, "%sFunction %s (children %d)\n", indent, fnName, 1)
272-
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, len(operands))
273-
for _, op := range operands {
274-
Node(sb, op, depth+2)
275-
}
276-
return
277-
}
278-
279267
fmt.Fprintf(sb, "%sFunction %s (children %d)\n", indent, fnName, 1)
280268
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, 2)
281269
Node(sb, n.Left, depth+2)
@@ -303,27 +291,6 @@ func collectConcatOperands(n *ast.BinaryExpr) []ast.Expression {
303291
return operands
304292
}
305293

306-
// collectBooleanOperands flattens chained OR/AND operations into a list of operands
307-
func collectBooleanOperands(n *ast.BinaryExpr, op string) []ast.Expression {
308-
var operands []ast.Expression
309-
310-
// Recursively collect from left side if it's also the same operator
311-
if left, ok := n.Left.(*ast.BinaryExpr); ok && strings.ToLower(left.Op) == op {
312-
operands = append(operands, collectBooleanOperands(left, op)...)
313-
} else {
314-
operands = append(operands, n.Left)
315-
}
316-
317-
// Recursively collect from right side if it's also the same operator
318-
if right, ok := n.Right.(*ast.BinaryExpr); ok && strings.ToLower(right.Op) == op {
319-
operands = append(operands, collectBooleanOperands(right, op)...)
320-
} else {
321-
operands = append(operands, n.Right)
322-
}
323-
324-
return operands
325-
}
326-
327294
func explainUnaryExpr(sb *strings.Builder, n *ast.UnaryExpr, indent string, depth int) {
328295
// Handle negate of literal numbers - output as negative literal instead of function
329296
if n.Op == "-" {
@@ -443,14 +410,6 @@ func explainAliasedExpr(sb *strings.Builder, n *ast.AliasedExpr, depth int) {
443410
for _, op := range operands {
444411
Node(sb, op, depth+2)
445412
}
446-
} else if opLower := strings.ToLower(e.Op); opLower == "or" || opLower == "and" {
447-
// For OR and AND operators, flatten chained expressions
448-
operands := collectBooleanOperands(e, opLower)
449-
fmt.Fprintf(sb, "%sFunction %s (alias %s) (children %d)\n", indent, fnName, escapeAlias(n.Alias), 1)
450-
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, len(operands))
451-
for _, op := range operands {
452-
Node(sb, op, depth+2)
453-
}
454413
} else {
455414
fmt.Fprintf(sb, "%sFunction %s (alias %s) (children %d)\n", indent, fnName, escapeAlias(n.Alias), 1)
456415
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, 2)
@@ -626,18 +585,6 @@ func explainWithElement(sb *strings.Builder, n *ast.WithElement, indent string,
626585
for _, op := range operands {
627586
Node(sb, op, depth+2)
628587
}
629-
} else if opLower := strings.ToLower(e.Op); opLower == "or" || opLower == "and" {
630-
// For OR and AND operators, flatten chained expressions
631-
operands := collectBooleanOperands(e, opLower)
632-
if n.Name != "" {
633-
fmt.Fprintf(sb, "%sFunction %s (alias %s) (children %d)\n", indent, fnName, n.Name, 1)
634-
} else {
635-
fmt.Fprintf(sb, "%sFunction %s (children %d)\n", indent, fnName, 1)
636-
}
637-
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, len(operands))
638-
for _, op := range operands {
639-
Node(sb, op, depth+2)
640-
}
641588
} else {
642589
if n.Name != "" {
643590
fmt.Fprintf(sb, "%sFunction %s (alias %s) (children %d)\n", indent, fnName, n.Name, 1)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
{"explain_todo":{"stmt11":true,"stmt12":true,"stmt5":true,"stmt6":true,"stmt7":true}}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
{}
1+
{
2+
"explain_todo": {
3+
"stmt2": true
4+
}
5+
}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
{}
1+
{
2+
"explain_todo": {
3+
"stmt6": true,
4+
"stmt7": true,
5+
"stmt8": true
6+
}
7+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
{"explain_todo":{"stmt4":true}}
Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1-
{}
1+
{
2+
"explain_todo": {
3+
"stmt28": true,
4+
"stmt42": true,
5+
"stmt43": true,
6+
"stmt44": true,
7+
"stmt45": true,
8+
"stmt46": true,
9+
"stmt47": true,
10+
"stmt48": true
11+
}
12+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
{"explain_todo":{"stmt3":true,"stmt4":true}}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
{}
1+
{
2+
"explain_todo": {
3+
"stmt20": true,
4+
"stmt21": true
5+
}
6+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{}
1+
{"explain_todo":{"stmt3":true}}
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
{}
1+
{
2+
"explain_todo": {
3+
"stmt1": true,
4+
"stmt2": true,
5+
"stmt3": true
6+
}
7+
}

0 commit comments

Comments
 (0)