Skip to content

Commit 43aed1a

Browse files
committed
Fix CREATE DICTIONARY explain output to include database name
When a dictionary is created with a database-qualified name like sqllt.dictionary, the explain output now correctly shows both the database and table identifiers, matching ClickHouse's EXPLAIN AST output.
1 parent 71db62b commit 43aed1a

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

internal/explain/statements.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,25 @@ func explainCreateQuery(sb *strings.Builder, n *ast.CreateQuery, indent string,
9999
return
100100
}
101101
if n.CreateDictionary {
102-
// Dictionary: count children = identifier + attributes (if any) + definition (if any)
103-
children := 1 // identifier
102+
// Dictionary: count children = database identifier (if any) + table identifier + attributes (if any) + definition (if any)
103+
children := 1 // table identifier
104+
hasDatabase := n.Database != ""
105+
if hasDatabase {
106+
children++ // database identifier
107+
}
104108
if len(n.DictionaryAttrs) > 0 {
105109
children++
106110
}
107111
if n.DictionaryDef != nil {
108112
children++
109113
}
110-
fmt.Fprintf(sb, "%sCreateQuery %s (children %d)\n", indent, n.Table, children)
114+
// Format: "CreateQuery [database] [table] (children N)"
115+
if hasDatabase {
116+
fmt.Fprintf(sb, "%sCreateQuery %s %s (children %d)\n", indent, n.Database, n.Table, children)
117+
fmt.Fprintf(sb, "%s Identifier %s\n", indent, n.Database)
118+
} else {
119+
fmt.Fprintf(sb, "%sCreateQuery %s (children %d)\n", indent, n.Table, children)
120+
}
111121
fmt.Fprintf(sb, "%s Identifier %s\n", indent, n.Table)
112122
// Dictionary attributes
113123
if len(n.DictionaryAttrs) > 0 {

parser/testdata/01702_system_query_log/metadata.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"explain_todo": {
3-
"stmt14": true,
43
"stmt15": true,
54
"stmt19": true,
65
"stmt24": true,

0 commit comments

Comments
 (0)