Skip to content

Commit fc9aa6f

Browse files
committed
Add column list output to InsertQuery EXPLAIN
When INSERT has a column list (e.g., INSERT INTO t (col1, col2) SELECT ...), the columns are now output as an ExpressionList child node.
1 parent 46b7a23 commit fc9aa6f

90 files changed

Lines changed: 118 additions & 381 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/statements.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ func explainInsertQuery(sb *strings.Builder, n *ast.InsertQuery, indent string,
2121
} else if n.Table != "" {
2222
children++ // Table identifier
2323
}
24+
if len(n.Columns) > 0 {
25+
children++ // Column list
26+
}
2427
if n.Select != nil {
2528
children++
2629
}
@@ -49,6 +52,14 @@ func explainInsertQuery(sb *strings.Builder, n *ast.InsertQuery, indent string,
4952
fmt.Fprintf(sb, "%s Identifier %s\n", indent, name)
5053
}
5154

55+
// Column list
56+
if len(n.Columns) > 0 {
57+
fmt.Fprintf(sb, "%s ExpressionList (children %d)\n", indent, len(n.Columns))
58+
for _, col := range n.Columns {
59+
fmt.Fprintf(sb, "%s Identifier %s\n", indent, col.Parts[len(col.Parts)-1])
60+
}
61+
}
62+
5263
if n.Select != nil {
5364
Node(sb, n.Select, depth+1)
5465
}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt6": true,
4-
"stmt7": true
5-
}
6-
}
1+
{}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt13": true,
4-
"stmt7": true
5-
}
6-
}
1+
{}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt4": true,
4-
"stmt5": true
5-
}
6-
}
1+
{}
Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt16": true,
4-
"stmt19": true,
5-
"stmt27": true,
6-
"stmt30": true,
7-
"stmt33": true
8-
}
9-
}
1+
{}

parser/testdata/00276_sample/metadata.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
"stmt32": true,
1616
"stmt33": true,
1717
"stmt34": true,
18-
"stmt38": true,
1918
"stmt39": true,
20-
"stmt6": true,
2119
"stmt9": true
2220
}
2321
}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt4": true,
4-
"stmt8": true
5-
}
6-
}
1+
{}
Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt11": true,
4-
"stmt12": true,
5-
"stmt18": true,
6-
"stmt19": true,
7-
"stmt25": true,
8-
"stmt26": true,
9-
"stmt27": true,
10-
"stmt33": true,
11-
"stmt34": true,
12-
"stmt35": true,
13-
"stmt39": true,
14-
"stmt43": true,
15-
"stmt52": true,
16-
"stmt53": true,
17-
"stmt59": true,
18-
"stmt60": true
19-
}
20-
}
1+
{}
Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt8": true,
4-
"stmt9": true
5-
}
6-
}
1+
{}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"explain_todo": {
3-
"stmt43": true,
43
"stmt80": true
54
}
65
}

0 commit comments

Comments
 (0)