@@ -482,6 +482,38 @@ func explainShowQuery(sb *strings.Builder, n *ast.ShowQuery, indent string) {
482482 return
483483 }
484484
485+ // SHOW CREATE DICTIONARY has special output format
486+ if n .ShowType == ast .ShowCreateDictionary && (n .Database != "" || n .From != "" ) {
487+ if n .Database != "" && n .From != "" {
488+ fmt .Fprintf (sb , "%sShowCreateDictionaryQuery %s %s (children 2)\n " , indent , n .Database , n .From )
489+ fmt .Fprintf (sb , "%s Identifier %s\n " , indent , n .Database )
490+ fmt .Fprintf (sb , "%s Identifier %s\n " , indent , n .From )
491+ } else if n .From != "" {
492+ fmt .Fprintf (sb , "%sShowCreateDictionaryQuery %s (children 1)\n " , indent , n .From )
493+ fmt .Fprintf (sb , "%s Identifier %s\n " , indent , n .From )
494+ } else if n .Database != "" {
495+ fmt .Fprintf (sb , "%sShowCreateDictionaryQuery %s (children 1)\n " , indent , n .Database )
496+ fmt .Fprintf (sb , "%s Identifier %s\n " , indent , n .Database )
497+ }
498+ return
499+ }
500+
501+ // SHOW CREATE VIEW has special output format
502+ if n .ShowType == ast .ShowCreateView && (n .Database != "" || n .From != "" ) {
503+ if n .Database != "" && n .From != "" {
504+ fmt .Fprintf (sb , "%sShowCreateViewQuery %s %s (children 2)\n " , indent , n .Database , n .From )
505+ fmt .Fprintf (sb , "%s Identifier %s\n " , indent , n .Database )
506+ fmt .Fprintf (sb , "%s Identifier %s\n " , indent , n .From )
507+ } else if n .From != "" {
508+ fmt .Fprintf (sb , "%sShowCreateViewQuery %s (children 1)\n " , indent , n .From )
509+ fmt .Fprintf (sb , "%s Identifier %s\n " , indent , n .From )
510+ } else if n .Database != "" {
511+ fmt .Fprintf (sb , "%sShowCreateViewQuery %s (children 1)\n " , indent , n .Database )
512+ fmt .Fprintf (sb , "%s Identifier %s\n " , indent , n .Database )
513+ }
514+ return
515+ }
516+
485517 // SHOW CREATE TABLE has special output format with database and table identifiers
486518 if n .ShowType == ast .ShowCreate && (n .Database != "" || n .From != "" ) {
487519 // Format: ShowCreateTableQuery database table (children 2)
@@ -550,12 +582,33 @@ func explainDescribeQuery(sb *strings.Builder, n *ast.DescribeQuery, indent stri
550582}
551583
552584func explainExistsTableQuery (sb * strings.Builder , n * ast.ExistsQuery , indent string ) {
553- // EXISTS TABLE/DATABASE/DICTIONARY query
585+ // Determine query type name based on ExistsType
586+ queryType := "ExistsTableQuery"
587+ switch n .ExistsType {
588+ case ast .ExistsDictionary :
589+ queryType = "ExistsDictionaryQuery"
590+ case ast .ExistsDatabase :
591+ queryType = "ExistsDatabaseQuery"
592+ case ast .ExistsView :
593+ queryType = "ExistsViewQuery"
594+ }
595+
596+ // EXISTS DATABASE has only one child (the database name stored in Table)
597+ if n .ExistsType == ast .ExistsDatabase {
598+ name := n .Table
599+ fmt .Fprintf (sb , "%s%s %s (children %d)\n " , indent , queryType , name , 1 )
600+ fmt .Fprintf (sb , "%s Identifier %s\n " , indent , n .Table )
601+ return
602+ }
603+
604+ // For TABLE/DICTIONARY/VIEW, show database and object name
554605 name := n .Table
606+ children := 1
555607 if n .Database != "" {
556608 name = n .Database + " " + n .Table
609+ children = 2
557610 }
558- fmt .Fprintf (sb , "%sExistsTableQuery %s (children %d)\n " , indent , name , 2 )
611+ fmt .Fprintf (sb , "%s%s %s (children %d)\n " , indent , queryType , name , children )
559612 if n .Database != "" {
560613 fmt .Fprintf (sb , "%s Identifier %s\n " , indent , n .Database )
561614 }
0 commit comments