Skip to content

Commit 1079b4e

Browse files
committed
Add ViewTargets support for MATERIALIZED VIEW with TO clause
- Add hasStorageChild check for counting ViewTargets as a child - Output ViewTargets when MATERIALIZED VIEW has TO clause but no storage - This matches ClickHouse's EXPLAIN AST format for MATERIALIZED VIEW
1 parent 063e557 commit 1079b4e

69 files changed

Lines changed: 67 additions & 247 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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,14 @@ func explainCreateQuery(sb *strings.Builder, n *ast.CreateQuery, indent string,
140140
if len(n.Columns) > 0 || len(n.Indexes) > 0 || len(n.Projections) > 0 || len(n.Constraints) > 0 {
141141
children++
142142
}
143-
if n.Engine != nil || len(n.OrderBy) > 0 || len(n.PrimaryKey) > 0 || n.PartitionBy != nil {
143+
hasStorageChild := n.Engine != nil || len(n.OrderBy) > 0 || len(n.PrimaryKey) > 0 || n.PartitionBy != nil || n.SampleBy != nil || n.TTL != nil || len(n.Settings) > 0
144+
if hasStorageChild {
144145
children++
145146
}
147+
// For materialized views with TO clause but no storage, count ViewTargets as a child
148+
if n.Materialized && n.To != "" && !hasStorageChild {
149+
children++ // ViewTargets
150+
}
146151
if n.AsSelect != nil {
147152
children++
148153
}
@@ -381,6 +386,10 @@ func explainCreateQuery(sb *strings.Builder, n *ast.CreateQuery, indent string,
381386
if len(n.Settings) > 0 {
382387
fmt.Fprintf(sb, "%s Set\n", storageIndent)
383388
}
389+
} else if n.Materialized && n.To != "" {
390+
// For materialized views with TO clause but no storage definition,
391+
// output just ViewTargets without children
392+
fmt.Fprintf(sb, "%s ViewTargets\n", indent)
384393
}
385394
// For non-materialized views, output AsSelect after storage
386395
if n.AsSelect != nil && !n.Materialized {
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt3": true
4-
}
5-
}
1+
{}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
{"explain_todo":{"stmt10":true,"stmt7":true}}
1+
{
2+
"explain_todo": {
3+
"stmt10": true
4+
}
5+
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
{
2-
"explain_todo": {
3-
"stmt7": true
4-
}
5-
}
1+
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"explain_todo":{"stmt6":true}}
1+
{}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"explain_todo":{"stmt7":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-
"stmt6": true,
43
"stmt9": 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-
"stmt7": true
4-
}
5-
}
1+
{}
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"explain_todo": {
3-
"stmt12": true,
43
"stmt6": true
54
}
65
}

parser/testdata/01064_incremental_streaming_from_2_src_with_feedback/metadata.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
22
"explain_todo": {
3-
"stmt14": true,
4-
"stmt16": true,
53
"stmt17": true,
64
"stmt18": true,
75
"stmt19": true

0 commit comments

Comments
 (0)