@@ -122,7 +122,7 @@ func explainCreateQuery(sb *strings.Builder, n *ast.CreateQuery, indent string,
122122 }
123123 // Count children: name + columns + engine/storage
124124 children := 1 // name identifier
125- if len (n .Columns ) > 0 {
125+ if len (n .Columns ) > 0 || len ( n . Indexes ) > 0 || len ( n . Constraints ) > 0 {
126126 children ++
127127 }
128128 if n .Engine != nil || len (n .OrderBy ) > 0 || len (n .PrimaryKey ) > 0 || n .PartitionBy != nil {
@@ -141,14 +141,17 @@ func explainCreateQuery(sb *strings.Builder, n *ast.CreateQuery, indent string,
141141 fmt .Fprintf (sb , "%sCreateQuery %s (children %d)\n " , indent , name , children )
142142 }
143143 fmt .Fprintf (sb , "%s Identifier %s\n " , indent , name )
144- if len (n .Columns ) > 0 || len (n .Indexes ) > 0 {
144+ if len (n .Columns ) > 0 || len (n .Indexes ) > 0 || len ( n . Constraints ) > 0 {
145145 childrenCount := 0
146146 if len (n .Columns ) > 0 {
147147 childrenCount ++
148148 }
149149 if len (n .Indexes ) > 0 {
150150 childrenCount ++
151151 }
152+ if len (n .Constraints ) > 0 {
153+ childrenCount ++
154+ }
152155 // Check for PRIMARY KEY constraints in column declarations
153156 var primaryKeyColumns []string
154157 for _ , col := range n .Columns {
@@ -172,6 +175,14 @@ func explainCreateQuery(sb *strings.Builder, n *ast.CreateQuery, indent string,
172175 Index (sb , idx , depth + 3 )
173176 }
174177 }
178+ // Output constraints wrapped in Constraint nodes
179+ if len (n .Constraints ) > 0 {
180+ fmt .Fprintf (sb , "%s ExpressionList (children %d)\n " , indent , len (n .Constraints ))
181+ for _ , constraint := range n .Constraints {
182+ fmt .Fprintf (sb , "%s Constraint (children 1)\n " , indent )
183+ Node (sb , constraint .Expression , depth + 4 )
184+ }
185+ }
175186 // Output PRIMARY KEY columns as Function tuple
176187 if len (primaryKeyColumns ) > 0 {
177188 fmt .Fprintf (sb , "%s Function tuple (children %d)\n " , indent , 1 )
@@ -181,7 +192,7 @@ func explainCreateQuery(sb *strings.Builder, n *ast.CreateQuery, indent string,
181192 }
182193 }
183194 }
184- if n .Engine != nil || len (n .OrderBy ) > 0 || len (n .PrimaryKey ) > 0 || n .PartitionBy != nil || n .SampleBy != nil || len (n .Settings ) > 0 {
195+ if n .Engine != nil || len (n .OrderBy ) > 0 || len (n .PrimaryKey ) > 0 || n .PartitionBy != nil || n .SampleBy != nil || n . TTL != nil || len (n .Settings ) > 0 {
185196 storageChildren := 0
186197 if n .Engine != nil {
187198 storageChildren ++
@@ -214,6 +225,9 @@ func explainCreateQuery(sb *strings.Builder, n *ast.CreateQuery, indent string,
214225 }
215226 }
216227 }
228+ if n .TTL != nil {
229+ storageChildren ++
230+ }
217231 if len (n .Settings ) > 0 {
218232 storageChildren ++
219233 }
@@ -313,6 +327,11 @@ func explainCreateQuery(sb *strings.Builder, n *ast.CreateQuery, indent string,
313327 }
314328 }
315329 }
330+ if n .TTL != nil {
331+ fmt .Fprintf (sb , "%s ExpressionList (children 1)\n " , indent )
332+ fmt .Fprintf (sb , "%s TTLElement (children 1)\n " , indent )
333+ Node (sb , n .TTL .Expression , depth + 4 )
334+ }
316335 if len (n .Settings ) > 0 {
317336 fmt .Fprintf (sb , "%s Set\n " , indent )
318337 }
@@ -681,7 +700,8 @@ func explainAlterCommand(sb *strings.Builder, cmd *ast.AlterCommand, indent stri
681700 case ast .AlterDropPartition , ast .AlterDetachPartition , ast .AlterAttachPartition ,
682701 ast .AlterReplacePartition , ast .AlterFreezePartition :
683702 if cmd .Partition != nil {
684- Node (sb , cmd .Partition , depth + 1 )
703+ fmt .Fprintf (sb , "%s Partition (children 1)\n " , indent )
704+ Node (sb , cmd .Partition , depth + 2 )
685705 }
686706 case ast .AlterFreeze :
687707 // No children
@@ -690,18 +710,16 @@ func explainAlterCommand(sb *strings.Builder, cmd *ast.AlterCommand, indent stri
690710 Node (sb , cmd .Where , depth + 1 )
691711 }
692712 case ast .AlterUpdate :
713+ if cmd .Where != nil {
714+ Node (sb , cmd .Where , depth + 1 )
715+ }
693716 if len (cmd .Assignments ) > 0 {
694717 fmt .Fprintf (sb , "%s ExpressionList (children %d)\n " , indent , len (cmd .Assignments ))
695718 for _ , assign := range cmd .Assignments {
696- fmt .Fprintf (sb , "%s Function equals (children 1)\n " , indent )
697- fmt .Fprintf (sb , "%s ExpressionList (children 2)\n " , indent )
698- fmt .Fprintf (sb , "%s Identifier %s\n " , indent , assign .Column )
699- Node (sb , assign .Value , depth + 4 )
719+ fmt .Fprintf (sb , "%s Assignment %s (children 1)\n " , indent , assign .Column )
720+ Node (sb , assign .Value , depth + 3 )
700721 }
701722 }
702- if cmd .Where != nil {
703- Node (sb , cmd .Where , depth + 1 )
704- }
705723 case ast .AlterAddProjection :
706724 if cmd .Projection != nil {
707725 explainProjection (sb , cmd .Projection , indent , depth + 1 )
@@ -866,3 +884,26 @@ func explainTruncateQuery(sb *strings.Builder, n *ast.TruncateQuery, indent stri
866884 fmt .Fprintf (sb , "%sTruncateQuery %s (children %d)\n " , indent , name , 1 )
867885 fmt .Fprintf (sb , "%s Identifier %s\n " , indent , name )
868886}
887+
888+ func explainCheckQuery (sb * strings.Builder , n * ast.CheckQuery , indent string ) {
889+ if n == nil {
890+ fmt .Fprintf (sb , "%s*ast.CheckQuery\n " , indent )
891+ return
892+ }
893+
894+ name := n .Table
895+ if n .Database != "" {
896+ name = n .Database + "." + n .Table
897+ }
898+
899+ children := 1 // identifier
900+ if len (n .Settings ) > 0 {
901+ children ++
902+ }
903+
904+ fmt .Fprintf (sb , "%sCheckQuery %s (children %d)\n " , indent , name , children )
905+ fmt .Fprintf (sb , "%s Identifier %s\n " , indent , name )
906+ if len (n .Settings ) > 0 {
907+ fmt .Fprintf (sb , "%s Set\n " , indent )
908+ }
909+ }
0 commit comments