Skip to content

Commit 08b61d3

Browse files
committed
Fix EXPLAIN type handling in viewExplain for subqueries
- Only show explicit EXPLAIN type when it's not AST or PLAN (default) - EXPLAIN SYNTAX correctly outputs 'EXPLAIN SYNTAX' - EXPLAIN or EXPLAIN PLAN outputs just 'EXPLAIN' Fixes many tests with EXPLAIN subqueries (comma_join, window functions, etc.)
1 parent ed21805 commit 08b61d3

14 files changed

Lines changed: 19 additions & 87 deletions

File tree

internal/explain/tables.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,13 @@ func explainViewExplain(sb *strings.Builder, n *ast.ExplainQuery, alias string,
149149
// Now output the viewExplain function
150150
fmt.Fprintf(sb, "%s Function viewExplain (children %d)\n", indent, 1)
151151
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, 3)
152-
// First argument: 'EXPLAIN' literal
153-
fmt.Fprintf(sb, "%s Literal \\'EXPLAIN\\'\n", indent)
152+
// First argument: 'EXPLAIN' or 'EXPLAIN SYNTAX' etc.
153+
// PLAN is the default and never shown; only show non-default types like SYNTAX
154+
explainTypeStr := "EXPLAIN"
155+
if n.ExplicitType && n.ExplainType != "" && n.ExplainType != ast.ExplainAST && n.ExplainType != ast.ExplainPlan {
156+
explainTypeStr = "EXPLAIN " + string(n.ExplainType)
157+
}
158+
fmt.Fprintf(sb, "%s Literal \\'%s\\'\n", indent, explainTypeStr)
154159
// Second argument: options string (e.g., "actions = 1")
155160
options := n.OptionsString
156161
fmt.Fprintf(sb, "%s Literal \\'%s\\'\n", indent, options)
Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt13": true,
4-
"stmt14": true,
5-
"stmt15": true,
6-
"stmt16": true,
7-
"stmt17": true,
8-
"stmt18": true,
9-
"stmt19": true,
10-
"stmt20": true,
11-
"stmt21": true,
12-
"stmt22": true,
13-
"stmt23": true,
14-
"stmt24": true,
15-
"stmt25": true,
16-
"stmt26": true,
17-
"stmt27": true,
18-
"stmt28": true,
19-
"stmt29": true,
20-
"stmt30": true,
21-
"stmt31": true,
22-
"stmt32": true,
23-
"stmt33": true,
24-
"stmt34": true,
25-
"stmt35": true,
26-
"stmt36": true,
27-
"stmt37": true,
28-
"stmt38": true,
29-
"stmt39": true,
30-
"stmt40": true,
31-
"stmt41": true,
32-
"stmt42": true
33-
}
34-
}
1+
{}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt16": true,
4-
"stmt17": true
5-
}
6-
}
1+
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"explain_todo":{"stmt10":true,"stmt12":true,"stmt14":true,"stmt17":true,"stmt19":true,"stmt8":true}}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt6": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"explain_todo":{"stmt4":true,"stmt6":true,"stmt8":true}}
1+
{}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"explain_todo": {
3-
"stmt10": true,
43
"stmt4": true
54
}
65
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt6": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt2": true
4-
}
5-
}
1+
{}

parser/testdata/02911_join_on_nullsafe_optimization/metadata.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
"stmt18": true,
77
"stmt19": true,
88
"stmt20": true,
9-
"stmt30": true,
10-
"stmt31": true,
119
"stmt32": true,
12-
"stmt33": true,
13-
"stmt34": true
10+
"stmt33": true
1411
}
1512
}

0 commit comments

Comments
 (0)