github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/sql/sem/tree/show.go (about) 1 // Copyright 2012, Google Inc. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in licenses/BSD-vitess.txt. 4 5 // Portions of this file are additionally subject to the following 6 // license and copyright. 7 // 8 // Copyright 2015 The Cockroach Authors. 9 // 10 // Use of this software is governed by the Business Source License 11 // included in the file licenses/BSL.txt. 12 // 13 // As of the Change Date specified in that file, in accordance with 14 // the Business Source License, use of this software will be governed 15 // by the Apache License, Version 2.0, included in the file 16 // licenses/APL.txt. 17 18 // This code was derived from https://github.com/youtube/vitess. 19 20 package tree 21 22 import ( 23 "fmt" 24 "strings" 25 26 "github.com/cockroachdb/cockroachdb-parser/pkg/sql/lexbase" 27 "github.com/cockroachdb/errors" 28 "github.com/google/go-cmp/cmp" 29 ) 30 31 // ShowVar represents a SHOW statement. 32 type ShowVar struct { 33 Name string 34 } 35 36 // Format implements the NodeFormatter interface. 37 func (node *ShowVar) Format(ctx *FmtCtx) { 38 ctx.WriteString("SHOW ") 39 // Session var names never contain PII and should be distinguished 40 // for feature tracking purposes. 41 ctx.WithFlags(ctx.flags & ^FmtAnonymize & ^FmtMarkRedactionNode, func() { 42 ctx.FormatNameP(&node.Name) 43 }) 44 } 45 46 // ShowClusterSetting represents a SHOW CLUSTER SETTING statement. 47 type ShowClusterSetting struct { 48 Name string 49 } 50 51 // Format implements the NodeFormatter interface. 52 func (node *ShowClusterSetting) Format(ctx *FmtCtx) { 53 ctx.WriteString("SHOW CLUSTER SETTING ") 54 // Cluster setting names never contain PII and should be distinguished 55 // for feature tracking purposes. 56 ctx.WithFlags(ctx.flags & ^FmtAnonymize & ^FmtMarkRedactionNode, func() { 57 ctx.FormatNameP(&node.Name) 58 }) 59 } 60 61 // ShowClusterSettingList represents a SHOW [ALL|PUBLIC] CLUSTER SETTINGS statement. 62 type ShowClusterSettingList struct { 63 // All indicates whether to include non-public settings in the output. 64 All bool 65 } 66 67 // Format implements the NodeFormatter interface. 68 func (node *ShowClusterSettingList) Format(ctx *FmtCtx) { 69 ctx.WriteString("SHOW ") 70 qual := "PUBLIC" 71 if node.All { 72 qual = "ALL" 73 } 74 ctx.WriteString(qual) 75 ctx.WriteString(" CLUSTER SETTINGS") 76 } 77 78 // ShowBackupDetails represents the type of details to display for a SHOW BACKUP 79 // statement. 80 type ShowBackupDetails int 81 82 const ( 83 // BackupDefaultDetails identifies a bare SHOW BACKUP statement. 84 BackupDefaultDetails ShowBackupDetails = iota 85 // BackupRangeDetails identifies a SHOW BACKUP RANGES statement. 86 BackupRangeDetails 87 // BackupFileDetails identifies a SHOW BACKUP FILES statement. 88 BackupFileDetails 89 // BackupSchemaDetails identifies a SHOW BACKUP SCHEMAS statement. 90 BackupSchemaDetails 91 // BackupValidateDetails identifies a SHOW BACKUP VALIDATION 92 // statement. 93 BackupValidateDetails 94 // BackupConnectionTest identifies a SHOW BACKUP CONNECTION statement 95 BackupConnectionTest 96 ) 97 98 // TODO (msbutler): 22.2 after removing old style show backup syntax, rename 99 // Path to Subdir and InCollection to Dest. 100 101 // ShowBackup represents a SHOW BACKUP statement. 102 // 103 // TODO(msbutler): implement a walkableStmt for ShowBackup. 104 type ShowBackup struct { 105 Path Expr 106 InCollection StringOrPlaceholderOptList 107 From bool 108 Details ShowBackupDetails 109 Options ShowBackupOptions 110 } 111 112 // Format implements the NodeFormatter interface. 113 func (node *ShowBackup) Format(ctx *FmtCtx) { 114 if node.InCollection != nil && node.Path == nil { 115 ctx.WriteString("SHOW BACKUPS IN ") 116 ctx.FormatNode(&node.InCollection) 117 return 118 } 119 ctx.WriteString("SHOW BACKUP ") 120 121 switch node.Details { 122 case BackupRangeDetails: 123 ctx.WriteString("RANGES ") 124 case BackupFileDetails: 125 ctx.WriteString("FILES ") 126 case BackupSchemaDetails: 127 ctx.WriteString("SCHEMAS ") 128 case BackupConnectionTest: 129 ctx.WriteString("CONNECTION ") 130 } 131 132 if node.From { 133 ctx.WriteString("FROM ") 134 } 135 136 ctx.FormatNode(node.Path) 137 if node.InCollection != nil { 138 ctx.WriteString(" IN ") 139 ctx.FormatNode(&node.InCollection) 140 } 141 if !node.Options.IsDefault() { 142 ctx.WriteString(" WITH OPTIONS (") 143 ctx.FormatNode(&node.Options) 144 ctx.WriteString(")") 145 } 146 } 147 148 type ShowBackupOptions struct { 149 AsJson bool 150 CheckFiles bool 151 DebugIDs bool 152 IncrementalStorage StringOrPlaceholderOptList 153 DecryptionKMSURI StringOrPlaceholderOptList 154 EncryptionPassphrase Expr 155 Privileges bool 156 SkipSize bool 157 158 // EncryptionInfoDir is a hidden option used when the user wants to run the deprecated 159 // 160 // SHOW BACKUP <incremental_dir> 161 // 162 // on an encrypted incremental backup will need to pass their full backup's 163 // directory to the encryption_info_dir parameter because the 164 // `ENCRYPTION-INFO` file necessary to decode the incremental backup lives in 165 // the full backup dir. 166 EncryptionInfoDir Expr 167 DebugMetadataSST bool 168 169 CheckConnectionTransferSize Expr 170 CheckConnectionDuration Expr 171 CheckConnectionConcurrency Expr 172 } 173 174 var _ NodeFormatter = &ShowBackupOptions{} 175 176 func (o *ShowBackupOptions) Format(ctx *FmtCtx) { 177 var addSep bool 178 maybeAddSep := func() { 179 if addSep { 180 ctx.WriteString(", ") 181 } 182 addSep = true 183 } 184 if o.AsJson { 185 ctx.WriteString("as_json") 186 addSep = true 187 } 188 if o.CheckFiles { 189 maybeAddSep() 190 ctx.WriteString("check_files") 191 } 192 if o.DebugIDs { 193 maybeAddSep() 194 ctx.WriteString("debug_ids") 195 } 196 if o.EncryptionPassphrase != nil { 197 maybeAddSep() 198 ctx.WriteString("encryption_passphrase = ") 199 if ctx.flags.HasFlags(FmtShowPasswords) { 200 ctx.FormatNode(o.EncryptionPassphrase) 201 } else { 202 ctx.WriteString(PasswordSubstitution) 203 } 204 } 205 if o.IncrementalStorage != nil { 206 maybeAddSep() 207 ctx.WriteString("incremental_location = ") 208 ctx.FormatNode(&o.IncrementalStorage) 209 } 210 211 if o.Privileges { 212 maybeAddSep() 213 ctx.WriteString("privileges") 214 } 215 216 if o.EncryptionInfoDir != nil { 217 maybeAddSep() 218 ctx.WriteString("encryption_info_dir = ") 219 ctx.FormatNode(o.EncryptionInfoDir) 220 } 221 if o.DecryptionKMSURI != nil { 222 maybeAddSep() 223 ctx.WriteString("kms = ") 224 ctx.FormatNode(&o.DecryptionKMSURI) 225 } 226 if o.SkipSize { 227 maybeAddSep() 228 ctx.WriteString("skip size") 229 } 230 if o.DebugMetadataSST { 231 maybeAddSep() 232 ctx.WriteString("debug_dump_metadata_sst") 233 } 234 235 // The following are only used in connection-check SHOW. 236 if o.CheckConnectionConcurrency != nil { 237 maybeAddSep() 238 ctx.WriteString("CONCURRENTLY = ") 239 ctx.FormatNode(o.CheckConnectionConcurrency) 240 } 241 if o.CheckConnectionTransferSize != nil { 242 maybeAddSep() 243 ctx.WriteString("TRANSFER = ") 244 ctx.FormatNode(o.CheckConnectionTransferSize) 245 } 246 if o.CheckConnectionDuration != nil { 247 maybeAddSep() 248 ctx.WriteString("TIME = ") 249 ctx.FormatNode(o.CheckConnectionDuration) 250 } 251 } 252 253 func (o ShowBackupOptions) IsDefault() bool { 254 options := ShowBackupOptions{} 255 return o.AsJson == options.AsJson && 256 o.CheckFiles == options.CheckFiles && 257 o.DebugIDs == options.DebugIDs && 258 cmp.Equal(o.IncrementalStorage, options.IncrementalStorage) && 259 cmp.Equal(o.DecryptionKMSURI, options.DecryptionKMSURI) && 260 o.EncryptionPassphrase == options.EncryptionPassphrase && 261 o.Privileges == options.Privileges && 262 o.SkipSize == options.SkipSize && 263 o.DebugMetadataSST == options.DebugMetadataSST && 264 o.EncryptionInfoDir == options.EncryptionInfoDir && 265 o.CheckConnectionTransferSize == options.CheckConnectionTransferSize && 266 o.CheckConnectionDuration == options.CheckConnectionDuration && 267 o.CheckConnectionConcurrency == options.CheckConnectionConcurrency 268 } 269 270 func combineBools(v1 bool, v2 bool, label string) (bool, error) { 271 if v2 && v1 { 272 return false, errors.Newf("% option specified multiple times", label) 273 } 274 return v2 || v1, nil 275 } 276 func combineExpr(v1 Expr, v2 Expr, label string) (Expr, error) { 277 if v1 != nil { 278 if v2 != nil { 279 return v1, errors.Newf("% option specified multiple times", label) 280 } 281 return v1, nil 282 } 283 return v2, nil 284 } 285 func combineStringOrPlaceholderOptList( 286 v1 StringOrPlaceholderOptList, v2 StringOrPlaceholderOptList, label string, 287 ) (StringOrPlaceholderOptList, error) { 288 if v1 != nil { 289 if v2 != nil { 290 return v1, errors.Newf("% option specified multiple times", label) 291 } 292 return v1, nil 293 } 294 return v2, nil 295 } 296 297 // CombineWith merges other backup options into this backup options struct. 298 // An error is returned if the same option merged multiple times. 299 func (o *ShowBackupOptions) CombineWith(other *ShowBackupOptions) error { 300 var err error 301 o.AsJson, err = combineBools(o.AsJson, other.AsJson, "as_json") 302 if err != nil { 303 return err 304 } 305 o.CheckFiles, err = combineBools(o.CheckFiles, other.CheckFiles, "check_files") 306 if err != nil { 307 return err 308 } 309 o.DebugIDs, err = combineBools(o.DebugIDs, other.DebugIDs, "debug_ids") 310 if err != nil { 311 return err 312 } 313 o.EncryptionPassphrase, err = combineExpr(o.EncryptionPassphrase, other.EncryptionPassphrase, 314 "encryption_passphrase") 315 if err != nil { 316 return err 317 } 318 o.IncrementalStorage, err = combineStringOrPlaceholderOptList(o.IncrementalStorage, 319 other.IncrementalStorage, "incremental_location") 320 if err != nil { 321 return err 322 } 323 o.DecryptionKMSURI, err = combineStringOrPlaceholderOptList(o.DecryptionKMSURI, 324 other.DecryptionKMSURI, "kms") 325 if err != nil { 326 return err 327 } 328 o.Privileges, err = combineBools(o.Privileges, other.Privileges, "privileges") 329 if err != nil { 330 return err 331 } 332 o.SkipSize, err = combineBools(o.SkipSize, other.SkipSize, "skip size") 333 if err != nil { 334 return err 335 } 336 o.DebugMetadataSST, err = combineBools(o.DebugMetadataSST, other.DebugMetadataSST, 337 "debug_dump_metadata_sst") 338 if err != nil { 339 return err 340 } 341 o.EncryptionInfoDir, err = combineExpr(o.EncryptionInfoDir, other.EncryptionInfoDir, 342 "encryption_info_dir") 343 if err != nil { 344 return err 345 } 346 347 o.CheckConnectionTransferSize, err = combineExpr(o.CheckConnectionTransferSize, other.CheckConnectionTransferSize, 348 "transfer") 349 if err != nil { 350 return err 351 } 352 353 o.CheckConnectionDuration, err = combineExpr(o.CheckConnectionDuration, other.CheckConnectionDuration, 354 "time") 355 if err != nil { 356 return err 357 } 358 359 o.CheckConnectionConcurrency, err = combineExpr(o.CheckConnectionConcurrency, other.CheckConnectionConcurrency, 360 "concurrently") 361 if err != nil { 362 return err 363 } 364 365 return nil 366 } 367 368 // ShowColumns represents a SHOW COLUMNS statement. 369 type ShowColumns struct { 370 Table *UnresolvedObjectName 371 WithComment bool 372 } 373 374 // Format implements the NodeFormatter interface. 375 func (node *ShowColumns) Format(ctx *FmtCtx) { 376 ctx.WriteString("SHOW COLUMNS FROM ") 377 ctx.FormatNode(node.Table) 378 379 if node.WithComment { 380 ctx.WriteString(" WITH COMMENT") 381 } 382 } 383 384 // ShowDatabases represents a SHOW DATABASES statement. 385 type ShowDatabases struct { 386 WithComment bool 387 } 388 389 // Format implements the NodeFormatter interface. 390 func (node *ShowDatabases) Format(ctx *FmtCtx) { 391 ctx.WriteString("SHOW DATABASES") 392 393 if node.WithComment { 394 ctx.WriteString(" WITH COMMENT") 395 } 396 } 397 398 // ShowEnums represents a SHOW ENUMS statement. 399 type ShowEnums struct { 400 ObjectNamePrefix 401 } 402 403 // Format implements the NodeFormatter interface. 404 func (node *ShowEnums) Format(ctx *FmtCtx) { 405 ctx.WriteString("SHOW ENUMS") 406 } 407 408 // ShowTypes represents a SHOW TYPES statement. 409 type ShowTypes struct{} 410 411 // Format implements the NodeFormatter interface. 412 func (node *ShowTypes) Format(ctx *FmtCtx) { 413 ctx.WriteString("SHOW TYPES") 414 } 415 416 // ShowTraceType is an enum of SHOW TRACE variants. 417 type ShowTraceType string 418 419 // A list of the SHOW TRACE variants. 420 const ( 421 ShowTraceRaw ShowTraceType = "TRACE" 422 ShowTraceKV ShowTraceType = "KV TRACE" 423 ShowTraceReplica ShowTraceType = "EXPERIMENTAL_REPLICA TRACE" 424 ) 425 426 // ShowTraceForSession represents a SHOW TRACE FOR SESSION statement. 427 type ShowTraceForSession struct { 428 TraceType ShowTraceType 429 Compact bool 430 } 431 432 // Format implements the NodeFormatter interface. 433 func (node *ShowTraceForSession) Format(ctx *FmtCtx) { 434 ctx.WriteString("SHOW ") 435 if node.Compact { 436 ctx.WriteString("COMPACT ") 437 } 438 ctx.WriteString(string(node.TraceType)) 439 ctx.WriteString(" FOR SESSION") 440 } 441 442 // ShowIndexes represents a SHOW INDEX statement. 443 type ShowIndexes struct { 444 Table *UnresolvedObjectName 445 WithComment bool 446 } 447 448 // Format implements the NodeFormatter interface. 449 func (node *ShowIndexes) Format(ctx *FmtCtx) { 450 ctx.WriteString("SHOW INDEXES FROM ") 451 ctx.FormatNode(node.Table) 452 453 if node.WithComment { 454 ctx.WriteString(" WITH COMMENT") 455 } 456 } 457 458 // ShowDatabaseIndexes represents a SHOW INDEXES FROM DATABASE statement. 459 type ShowDatabaseIndexes struct { 460 Database Name 461 WithComment bool 462 } 463 464 // Format implements the NodeFormatter interface. 465 func (node *ShowDatabaseIndexes) Format(ctx *FmtCtx) { 466 ctx.WriteString("SHOW INDEXES FROM DATABASE ") 467 ctx.FormatNode(&node.Database) 468 469 if node.WithComment { 470 ctx.WriteString(" WITH COMMENT") 471 } 472 } 473 474 // ShowQueries represents a SHOW STATEMENTS statement. 475 type ShowQueries struct { 476 All bool 477 Cluster bool 478 } 479 480 // Format implements the NodeFormatter interface. 481 func (node *ShowQueries) Format(ctx *FmtCtx) { 482 ctx.WriteString("SHOW ") 483 if node.All { 484 ctx.WriteString("ALL ") 485 } 486 if node.Cluster { 487 ctx.WriteString("CLUSTER STATEMENTS") 488 } else { 489 ctx.WriteString("LOCAL STATEMENTS") 490 } 491 } 492 493 // ShowJobs represents a SHOW JOBS statement 494 type ShowJobs struct { 495 // If non-nil, a select statement that provides the job ids to be shown. 496 Jobs *Select 497 498 // If Automatic is true, show only automatically-generated jobs such 499 // as automatic CREATE STATISTICS jobs. If Automatic is false, show 500 // only non-automatically-generated jobs. 501 Automatic bool 502 503 // Whether to block and wait for completion of all running jobs to be displayed. 504 Block bool 505 506 // If non-nil, only display jobs started by the specified 507 // schedules. 508 Schedules *Select 509 510 // Options contain any options that were specified in the `SHOW JOB` query. 511 Options *ShowJobOptions 512 } 513 514 // Format implements the NodeFormatter interface. 515 func (node *ShowJobs) Format(ctx *FmtCtx) { 516 ctx.WriteString("SHOW ") 517 if node.Automatic { 518 ctx.WriteString("AUTOMATIC ") 519 } 520 ctx.WriteString("JOBS") 521 if node.Block { 522 ctx.WriteString(" WHEN COMPLETE") 523 } 524 if node.Jobs != nil { 525 ctx.WriteString(" ") 526 ctx.FormatNode(node.Jobs) 527 } 528 if node.Schedules != nil { 529 ctx.WriteString(" FOR SCHEDULES ") 530 ctx.FormatNode(node.Schedules) 531 } 532 if node.Options != nil { 533 ctx.WriteString(" WITH") 534 ctx.FormatNode(node.Options) 535 } 536 } 537 538 // ShowJobOptions describes options for the SHOW JOB execution. 539 type ShowJobOptions struct { 540 // ExecutionDetails, if true, will render job specific details about the job's 541 // execution. These details will provide improved observability into the 542 // execution of the job. 543 ExecutionDetails bool 544 } 545 546 func (s *ShowJobOptions) Format(ctx *FmtCtx) { 547 if s.ExecutionDetails { 548 ctx.WriteString(" EXECUTION DETAILS") 549 } 550 } 551 552 func (s *ShowJobOptions) CombineWith(other *ShowJobOptions) error { 553 s.ExecutionDetails = other.ExecutionDetails 554 return nil 555 } 556 557 var _ NodeFormatter = &ShowJobOptions{} 558 559 // ShowChangefeedJobs represents a SHOW CHANGEFEED JOBS statement 560 type ShowChangefeedJobs struct { 561 // If non-nil, a select statement that provides the job ids to be shown. 562 Jobs *Select 563 } 564 565 // Format implements the NodeFormatter interface. 566 func (node *ShowChangefeedJobs) Format(ctx *FmtCtx) { 567 ctx.WriteString("SHOW CHANGEFEED JOBS") 568 if node.Jobs != nil { 569 ctx.WriteString(" ") 570 ctx.FormatNode(node.Jobs) 571 } 572 } 573 574 // ShowSurvivalGoal represents a SHOW SURVIVAL GOAL statement 575 type ShowSurvivalGoal struct { 576 DatabaseName Name 577 } 578 579 // Format implements the NodeFormatter interface. 580 func (node *ShowSurvivalGoal) Format(ctx *FmtCtx) { 581 ctx.WriteString("SHOW SURVIVAL GOAL FROM DATABASE") 582 if node.DatabaseName != "" { 583 ctx.WriteString(" ") 584 ctx.FormatNode(&node.DatabaseName) 585 } 586 } 587 588 // ShowRegionsFrom denotes what kind of SHOW REGIONS command is being used. 589 type ShowRegionsFrom int 590 591 const ( 592 // ShowRegionsFromCluster represents SHOW REGIONS FROM CLUSTER. 593 ShowRegionsFromCluster ShowRegionsFrom = iota 594 // ShowRegionsFromDatabase represents SHOW REGIONS FROM DATABASE. 595 ShowRegionsFromDatabase 596 // ShowRegionsFromAllDatabases represents SHOW REGIONS FROM ALL DATABASES. 597 ShowRegionsFromAllDatabases 598 // ShowRegionsFromDefault represents SHOW REGIONS. 599 ShowRegionsFromDefault 600 // ShowSuperRegionsFromDatabase represents SHOW SUPER REGIONS FROM DATABASE. 601 ShowSuperRegionsFromDatabase 602 ) 603 604 // ShowRegions represents a SHOW REGIONS statement 605 type ShowRegions struct { 606 ShowRegionsFrom ShowRegionsFrom 607 DatabaseName Name 608 } 609 610 // Format implements the NodeFormatter interface. 611 func (node *ShowRegions) Format(ctx *FmtCtx) { 612 if node.ShowRegionsFrom == ShowSuperRegionsFromDatabase { 613 ctx.WriteString("SHOW SUPER REGIONS") 614 } else { 615 ctx.WriteString("SHOW REGIONS") 616 } 617 switch node.ShowRegionsFrom { 618 case ShowRegionsFromDefault: 619 case ShowRegionsFromAllDatabases: 620 ctx.WriteString(" FROM ALL DATABASES") 621 case ShowRegionsFromDatabase, ShowSuperRegionsFromDatabase: 622 ctx.WriteString(" FROM DATABASE") 623 if node.DatabaseName != "" { 624 ctx.WriteString(" ") 625 ctx.FormatNode(&node.DatabaseName) 626 } 627 case ShowRegionsFromCluster: 628 ctx.WriteString(" FROM CLUSTER") 629 default: 630 panic(fmt.Sprintf("unknown ShowRegionsFrom: %v", node.ShowRegionsFrom)) 631 } 632 } 633 634 // ShowSessions represents a SHOW SESSIONS statement 635 type ShowSessions struct { 636 All bool 637 Cluster bool 638 } 639 640 // Format implements the NodeFormatter interface. 641 func (node *ShowSessions) Format(ctx *FmtCtx) { 642 ctx.WriteString("SHOW ") 643 if node.All { 644 ctx.WriteString("ALL ") 645 } 646 if node.Cluster { 647 ctx.WriteString("CLUSTER SESSIONS") 648 } else { 649 ctx.WriteString("LOCAL SESSIONS") 650 } 651 } 652 653 // ShowSchemas represents a SHOW SCHEMAS statement. 654 type ShowSchemas struct { 655 Database Name 656 } 657 658 // Format implements the NodeFormatter interface. 659 func (node *ShowSchemas) Format(ctx *FmtCtx) { 660 ctx.WriteString("SHOW SCHEMAS") 661 if node.Database != "" { 662 ctx.WriteString(" FROM ") 663 ctx.FormatNode(&node.Database) 664 } 665 } 666 667 // ShowSequences represents a SHOW SEQUENCES statement. 668 type ShowSequences struct { 669 Database Name 670 } 671 672 // Format implements the NodeFormatter interface. 673 func (node *ShowSequences) Format(ctx *FmtCtx) { 674 ctx.WriteString("SHOW SEQUENCES") 675 if node.Database != "" { 676 ctx.WriteString(" FROM ") 677 ctx.FormatNode(&node.Database) 678 } 679 } 680 681 // ShowTables represents a SHOW TABLES statement. 682 type ShowTables struct { 683 ObjectNamePrefix 684 WithComment bool 685 } 686 687 // Format implements the NodeFormatter interface. 688 func (node *ShowTables) Format(ctx *FmtCtx) { 689 ctx.WriteString("SHOW TABLES") 690 if node.ExplicitSchema { 691 ctx.WriteString(" FROM ") 692 ctx.FormatNode(&node.ObjectNamePrefix) 693 } 694 695 if node.WithComment { 696 ctx.WriteString(" WITH COMMENT") 697 } 698 } 699 700 // ShowRoutines represents a SHOW FUNCTIONS or SHOW PROCEDURES statement. 701 type ShowRoutines struct { 702 ObjectNamePrefix 703 Procedure bool 704 } 705 706 // Format implements the NodeFormatter interface. 707 func (node *ShowRoutines) Format(ctx *FmtCtx) { 708 if node.Procedure { 709 ctx.WriteString("SHOW PROCEDURES") 710 } else { 711 ctx.WriteString("SHOW FUNCTIONS") 712 } 713 if node.ExplicitSchema { 714 ctx.WriteString(" FROM ") 715 ctx.FormatNode(&node.ObjectNamePrefix) 716 } 717 } 718 719 // ShowTransactions represents a SHOW TRANSACTIONS statement 720 type ShowTransactions struct { 721 All bool 722 Cluster bool 723 } 724 725 // Format implements the NodeFormatter interface. 726 func (node *ShowTransactions) Format(ctx *FmtCtx) { 727 ctx.WriteString("SHOW ") 728 if node.All { 729 ctx.WriteString("ALL ") 730 } 731 if node.Cluster { 732 ctx.WriteString("CLUSTER TRANSACTIONS") 733 } else { 734 ctx.WriteString("LOCAL TRANSACTIONS") 735 } 736 } 737 738 // ShowConstraints represents a SHOW CONSTRAINTS statement. 739 type ShowConstraints struct { 740 Table *UnresolvedObjectName 741 WithComment bool 742 } 743 744 // Format implements the NodeFormatter interface. 745 func (node *ShowConstraints) Format(ctx *FmtCtx) { 746 ctx.WriteString("SHOW CONSTRAINTS FROM ") 747 ctx.FormatNode(node.Table) 748 749 if node.WithComment { 750 ctx.WriteString(" WITH COMMENT") 751 } 752 } 753 754 // ShowGrants represents a SHOW GRANTS statement. 755 // GrantTargetList is defined in grant.go. 756 type ShowGrants struct { 757 Targets *GrantTargetList 758 Grantees RoleSpecList 759 } 760 761 // Format implements the NodeFormatter interface. 762 func (node *ShowGrants) Format(ctx *FmtCtx) { 763 ctx.WriteString("SHOW ") 764 if node.Targets != nil && node.Targets.System { 765 ctx.WriteString("SYSTEM ") 766 } 767 ctx.WriteString("GRANTS") 768 if node.Targets != nil { 769 if !node.Targets.System { 770 ctx.WriteString(" ON ") 771 ctx.FormatNode(node.Targets) 772 } 773 } 774 if node.Grantees != nil { 775 ctx.WriteString(" FOR ") 776 ctx.FormatNode(&node.Grantees) 777 } 778 } 779 780 // ShowRoleGrants represents a SHOW GRANTS ON ROLE statement. 781 type ShowRoleGrants struct { 782 Roles RoleSpecList 783 Grantees RoleSpecList 784 } 785 786 // Format implements the NodeFormatter interface. 787 func (node *ShowRoleGrants) Format(ctx *FmtCtx) { 788 ctx.WriteString("SHOW GRANTS ON ROLE") 789 if node.Roles != nil { 790 ctx.WriteString(" ") 791 ctx.FormatNode(&node.Roles) 792 } 793 if node.Grantees != nil { 794 ctx.WriteString(" FOR ") 795 ctx.FormatNode(&node.Grantees) 796 } 797 } 798 799 // ShowCreateMode denotes what kind of SHOW CREATE should be used 800 type ShowCreateMode int 801 802 const ( 803 // ShowCreateModeTable represents SHOW CREATE TABLE 804 ShowCreateModeTable ShowCreateMode = iota 805 // ShowCreateModeView represents SHOW CREATE VIEW 806 ShowCreateModeView 807 // ShowCreateModeSequence represents SHOW CREATE SEQUENCE 808 ShowCreateModeSequence 809 // ShowCreateModeDatabase represents SHOW CREATE DATABASE 810 ShowCreateModeDatabase 811 // ShowCreateModeIndexes represents SHOW CREATE INDEXES FROM 812 ShowCreateModeIndexes 813 // ShowCreateModeSecondaryIndexes represents SHOW CREATE SECONDARY INDEXES FROM 814 ShowCreateModeSecondaryIndexes 815 ) 816 817 type ShowCreateFormatOption int 818 819 const ( 820 ShowCreateFormatOptionNone ShowCreateFormatOption = iota 821 ShowCreateFormatOptionRedactedValues 822 ) 823 824 // ShowCreate represents a SHOW CREATE statement. 825 type ShowCreate struct { 826 Mode ShowCreateMode 827 Name *UnresolvedObjectName 828 FmtOpt ShowCreateFormatOption 829 } 830 831 // Format implements the NodeFormatter interface. 832 func (node *ShowCreate) Format(ctx *FmtCtx) { 833 ctx.WriteString("SHOW CREATE ") 834 835 switch node.Mode { 836 case ShowCreateModeDatabase: 837 ctx.WriteString("DATABASE ") 838 case ShowCreateModeIndexes: 839 ctx.WriteString("INDEXES FROM ") 840 case ShowCreateModeSecondaryIndexes: 841 ctx.WriteString("SECONDARY INDEXES FROM ") 842 } 843 ctx.FormatNode(node.Name) 844 845 switch node.FmtOpt { 846 case ShowCreateFormatOptionRedactedValues: 847 ctx.WriteString(" WITH REDACT") 848 } 849 } 850 851 // ShowCreateAllSchemas represents a SHOW CREATE ALL SCHEMAS statement. 852 type ShowCreateAllSchemas struct{} 853 854 // Format implements the NodeFormatter interface. 855 func (node *ShowCreateAllSchemas) Format(ctx *FmtCtx) { 856 ctx.WriteString("SHOW CREATE ALL SCHEMAS") 857 } 858 859 // ShowCreateAllTables represents a SHOW CREATE ALL TABLES statement. 860 type ShowCreateAllTables struct{} 861 862 // Format implements the NodeFormatter interface. 863 func (node *ShowCreateAllTables) Format(ctx *FmtCtx) { 864 ctx.WriteString("SHOW CREATE ALL TABLES") 865 } 866 867 // ShowCreateAllTypes represents a SHOW CREATE ALL TYPES statement. 868 type ShowCreateAllTypes struct{} 869 870 // Format implements the NodeFormatter interface. 871 func (node *ShowCreateAllTypes) Format(ctx *FmtCtx) { 872 ctx.WriteString("SHOW CREATE ALL TYPES") 873 } 874 875 // ShowCreateSchedules represents a SHOW CREATE SCHEDULE statement. 876 type ShowCreateSchedules struct { 877 ScheduleID Expr 878 } 879 880 // Format implements the NodeFormatter interface. 881 func (node *ShowCreateSchedules) Format(ctx *FmtCtx) { 882 if node.ScheduleID != nil { 883 ctx.WriteString("SHOW CREATE SCHEDULE ") 884 ctx.FormatNode(node.ScheduleID) 885 return 886 } 887 ctx.Printf("SHOW CREATE ALL SCHEDULES") 888 } 889 890 // ShowSyntax represents a SHOW SYNTAX statement. 891 // This the most lightweight thing that can be done on a statement 892 // server-side: just report the statement that was entered without 893 // any processing. Meant for use for syntax checking on clients, 894 // when the client version might differ from the server. 895 type ShowSyntax struct { 896 Statement string 897 } 898 899 // Format implements the NodeFormatter interface. 900 func (node *ShowSyntax) Format(ctx *FmtCtx) { 901 ctx.WriteString("SHOW SYNTAX ") 902 if ctx.flags.HasFlags(FmtAnonymize) || ctx.flags.HasFlags(FmtHideConstants) { 903 ctx.WriteString("'_'") 904 } else { 905 ctx.WriteString(lexbase.EscapeSQLString(node.Statement)) 906 } 907 } 908 909 // ShowTransactionStatus represents a SHOW TRANSACTION STATUS statement. 910 type ShowTransactionStatus struct { 911 } 912 913 // Format implements the NodeFormatter interface. 914 func (node *ShowTransactionStatus) Format(ctx *FmtCtx) { 915 ctx.WriteString("SHOW TRANSACTION STATUS") 916 } 917 918 // ShowLastQueryStatistics represents a SHOW LAST QUERY STATS statement. 919 type ShowLastQueryStatistics struct { 920 Columns NameList 921 } 922 923 // ShowLastQueryStatisticsDefaultColumns is the default list of columns 924 // when the USING clause is not specified. 925 // Note: the form that does not specify the USING clause is deprecated. 926 // Remove it when there are no more clients using it (22.1 or later). 927 var ShowLastQueryStatisticsDefaultColumns = NameList([]Name{ 928 "parse_latency", 929 "plan_latency", 930 "exec_latency", 931 "service_latency", 932 "post_commit_jobs_latency", 933 }) 934 935 // Format implements the NodeFormatter interface. 936 func (node *ShowLastQueryStatistics) Format(ctx *FmtCtx) { 937 ctx.WriteString("SHOW LAST QUERY STATISTICS RETURNING ") 938 // The column names for this statement never contain PII and should 939 // be distinguished for feature tracking purposes. 940 ctx.WithFlags(ctx.flags & ^FmtAnonymize & ^FmtMarkRedactionNode, func() { 941 ctx.FormatNode(&node.Columns) 942 }) 943 } 944 945 // ShowFullTableScans represents a SHOW FULL TABLE SCANS statement. 946 type ShowFullTableScans struct { 947 } 948 949 // Format implements the NodeFormatter interface. 950 func (node *ShowFullTableScans) Format(ctx *FmtCtx) { 951 ctx.WriteString("SHOW FULL TABLE SCANS") 952 } 953 954 // ShowSavepointStatus represents a SHOW SAVEPOINT STATUS statement. 955 type ShowSavepointStatus struct { 956 } 957 958 // Format implements the NodeFormatter interface. 959 func (node *ShowSavepointStatus) Format(ctx *FmtCtx) { 960 ctx.WriteString("SHOW SAVEPOINT STATUS") 961 } 962 963 // ShowUsers represents a SHOW USERS statement. 964 type ShowUsers struct { 965 } 966 967 // Format implements the NodeFormatter interface. 968 func (node *ShowUsers) Format(ctx *FmtCtx) { 969 ctx.WriteString("SHOW USERS") 970 } 971 972 // ShowRoles represents a SHOW ROLES statement. 973 type ShowRoles struct { 974 } 975 976 // Format implements the NodeFormatter interface. 977 func (node *ShowRoles) Format(ctx *FmtCtx) { 978 ctx.WriteString("SHOW ROLES") 979 } 980 981 // ShowRanges represents a SHOW RANGES statement. 982 type ShowRanges struct { 983 DatabaseName Name 984 TableOrIndex TableIndexName 985 Options *ShowRangesOptions 986 Source ShowRangesSource 987 } 988 989 // ShowRangesSource represents the source of a SHOW RANGES statement. 990 type ShowRangesSource int8 991 992 const ( 993 // SHOW RANGES FROM CURRENT_CATALOG 994 ShowRangesCurrentDatabase ShowRangesSource = iota 995 // SHOW RANGES FROM DATABASE 996 ShowRangesDatabase 997 // SHOW RANGES FROM TABLE 998 ShowRangesTable 999 // SHOW RANGES FROM INDEX 1000 ShowRangesIndex 1001 // SHOW CLUSTER RANGES 1002 ShowRangesCluster 1003 ) 1004 1005 // ShowRangesOptions represents the WITH clause in SHOW RANGES. 1006 type ShowRangesOptions struct { 1007 Details bool 1008 Explain bool 1009 Keys bool 1010 Mode ShowRangesMode 1011 } 1012 1013 // ShowRangesMode represents the WITH clause in SHOW RANGES. 1014 type ShowRangesMode int8 1015 1016 const ( 1017 // UniqueRanges tells to use just 1 row per range in the output. 1018 // 1019 // Note: The UniqueRanges constant must have value 0; otherwise, 1020 // the parsing logic would become incorrect. 1021 UniqueRanges ShowRangesMode = iota 1022 // ExpandTables requests one row per table in the output. 1023 ExpandTables 1024 // ExpandIndexes requests one row per index in the output. 1025 ExpandIndexes 1026 ) 1027 1028 // Format implements the NodeFormatter interface. 1029 func (node *ShowRanges) Format(ctx *FmtCtx) { 1030 ctx.WriteString("SHOW ") 1031 if node.Source == ShowRangesCluster { 1032 ctx.WriteString("CLUSTER ") 1033 } 1034 ctx.WriteString("RANGES") 1035 if node.Source != ShowRangesCluster { 1036 ctx.WriteString(" FROM ") 1037 switch node.Source { 1038 case ShowRangesCurrentDatabase: 1039 ctx.WriteString("CURRENT_CATALOG") 1040 case ShowRangesDatabase: 1041 ctx.WriteString("DATABASE ") 1042 ctx.FormatNode(&node.DatabaseName) 1043 case ShowRangesIndex: 1044 ctx.WriteString("INDEX ") 1045 ctx.FormatNode(&node.TableOrIndex) 1046 case ShowRangesTable: 1047 ctx.WriteString("TABLE ") 1048 ctx.FormatNode(&node.TableOrIndex) 1049 } 1050 } 1051 ctx.FormatNode(node.Options) 1052 } 1053 1054 // Format implements the NodeFormatter interface. 1055 func (node *ShowRangesOptions) Format(ctx *FmtCtx) { 1056 noOpts := ShowRangesOptions{} 1057 if *node == noOpts { 1058 return 1059 } 1060 ctx.WriteString(" WITH ") 1061 comma := "" 1062 if node.Details { 1063 ctx.WriteString("DETAILS") 1064 comma = ", " 1065 } 1066 if node.Keys { 1067 ctx.WriteString(comma) 1068 ctx.WriteString("KEYS") 1069 comma = ", " 1070 } 1071 if node.Explain { 1072 ctx.WriteString(comma) 1073 ctx.WriteString("EXPLAIN") 1074 comma = ", " 1075 } 1076 if node.Mode != UniqueRanges { 1077 ctx.WriteString(comma) 1078 switch node.Mode { 1079 case ExpandTables: 1080 ctx.WriteString("TABLES") 1081 case ExpandIndexes: 1082 ctx.WriteString("INDEXES") 1083 } 1084 } 1085 } 1086 1087 // ShowRangeForRow represents a SHOW RANGE FOR ROW statement. 1088 type ShowRangeForRow struct { 1089 TableOrIndex TableIndexName 1090 Row Exprs 1091 } 1092 1093 // Format implements the NodeFormatter interface. 1094 func (node *ShowRangeForRow) Format(ctx *FmtCtx) { 1095 ctx.WriteString("SHOW RANGE FROM ") 1096 if node.TableOrIndex.Index != "" { 1097 ctx.WriteString("INDEX ") 1098 } else { 1099 ctx.WriteString("TABLE ") 1100 } 1101 ctx.FormatNode(&node.TableOrIndex) 1102 ctx.WriteString(" FOR ROW (") 1103 ctx.FormatNode(&node.Row) 1104 ctx.WriteString(")") 1105 } 1106 1107 // ShowFingerprints represents a SHOW EXPERIMENTAL_FINGERPRINTS statement. 1108 type ShowFingerprints struct { 1109 TenantSpec *TenantSpec 1110 Table *UnresolvedObjectName 1111 } 1112 1113 // Format implements the NodeFormatter interface. 1114 func (node *ShowFingerprints) Format(ctx *FmtCtx) { 1115 if node.Table != nil { 1116 ctx.WriteString("SHOW EXPERIMENTAL_FINGERPRINTS FROM TABLE ") 1117 ctx.FormatNode(node.Table) 1118 } else { 1119 ctx.WriteString("SHOW EXPERIMENTAL_FINGERPRINTS FROM VIRTUAL CLUSTER ") 1120 ctx.FormatNode(node.TenantSpec) 1121 } 1122 } 1123 1124 // ShowTableStats represents a SHOW STATISTICS FOR TABLE statement. 1125 type ShowTableStats struct { 1126 Table *UnresolvedObjectName 1127 UsingJSON bool 1128 Options KVOptions 1129 } 1130 1131 // Format implements the NodeFormatter interface. 1132 func (node *ShowTableStats) Format(ctx *FmtCtx) { 1133 ctx.WriteString("SHOW STATISTICS ") 1134 if node.UsingJSON { 1135 ctx.WriteString("USING JSON ") 1136 } 1137 ctx.WriteString("FOR TABLE ") 1138 ctx.FormatNode(node.Table) 1139 if len(node.Options) > 0 { 1140 ctx.WriteString(" WITH OPTIONS (") 1141 ctx.FormatNode(&node.Options) 1142 ctx.WriteString(")") 1143 } 1144 } 1145 1146 // ShowTenantOptions represents the WITH clause in SHOW VIRTUAL CLUSTER. 1147 type ShowTenantOptions struct { 1148 WithReplication bool 1149 WithCapabilities bool 1150 } 1151 1152 // ShowTenant represents a SHOW VIRTUAL CLUSTER statement. 1153 type ShowTenant struct { 1154 TenantSpec *TenantSpec 1155 ShowTenantOptions 1156 } 1157 1158 // Format implements the NodeFormatter interface. 1159 func (node *ShowTenant) Format(ctx *FmtCtx) { 1160 ctx.WriteString("SHOW VIRTUAL CLUSTER ") 1161 ctx.FormatNode(node.TenantSpec) 1162 1163 withs := []string{} 1164 if node.WithReplication { 1165 withs = append(withs, "REPLICATION STATUS") 1166 } 1167 if node.WithCapabilities { 1168 withs = append(withs, "CAPABILITIES") 1169 } 1170 if len(withs) > 0 { 1171 ctx.WriteString(" WITH ") 1172 ctx.WriteString(strings.Join(withs, ", ")) 1173 } 1174 } 1175 1176 // ShowHistogram represents a SHOW HISTOGRAM statement. 1177 type ShowHistogram struct { 1178 HistogramID int64 1179 } 1180 1181 // Format implements the NodeFormatter interface. 1182 func (node *ShowHistogram) Format(ctx *FmtCtx) { 1183 ctx.Printf("SHOW HISTOGRAM %d", node.HistogramID) 1184 } 1185 1186 // ShowPartitions represents a SHOW PARTITIONS statement. 1187 type ShowPartitions struct { 1188 IsDB bool 1189 Database Name 1190 1191 IsIndex bool 1192 Index TableIndexName 1193 1194 IsTable bool 1195 Table *UnresolvedObjectName 1196 } 1197 1198 // Format implements the NodeFormatter interface. 1199 func (node *ShowPartitions) Format(ctx *FmtCtx) { 1200 if node.IsDB { 1201 ctx.Printf("SHOW PARTITIONS FROM DATABASE ") 1202 ctx.FormatNode(&node.Database) 1203 } else if node.IsIndex { 1204 ctx.Printf("SHOW PARTITIONS FROM INDEX ") 1205 ctx.FormatNode(&node.Index) 1206 } else { 1207 ctx.Printf("SHOW PARTITIONS FROM TABLE ") 1208 ctx.FormatNode(node.Table) 1209 } 1210 } 1211 1212 // ScheduledJobExecutorType is a type identifying the names of 1213 // the supported scheduled job executors. 1214 type ScheduledJobExecutorType int 1215 1216 const ( 1217 // InvalidExecutor is a placeholder for an invalid executor type. 1218 InvalidExecutor ScheduledJobExecutorType = iota 1219 1220 // ScheduledBackupExecutor is an executor responsible for 1221 // the execution of the scheduled backups. 1222 ScheduledBackupExecutor 1223 1224 // ScheduledSQLStatsCompactionExecutor is an executor responsible for the 1225 // execution of the scheduled SQL Stats compaction. 1226 ScheduledSQLStatsCompactionExecutor 1227 1228 // ScheduledRowLevelTTLExecutor is an executor responsible for the cleanup 1229 // of rows on row level TTL tables. 1230 ScheduledRowLevelTTLExecutor 1231 1232 // ScheduledSchemaTelemetryExecutor is an executor responsible for the logging 1233 // of schema telemetry. 1234 ScheduledSchemaTelemetryExecutor 1235 1236 // ScheduledChangefeedExecutor is an executor responsible for 1237 // the execution of the scheduled changefeeds. 1238 ScheduledChangefeedExecutor 1239 ) 1240 1241 var scheduleExecutorInternalNames = map[ScheduledJobExecutorType]string{ 1242 InvalidExecutor: "unknown-executor", 1243 ScheduledBackupExecutor: "scheduled-backup-executor", 1244 ScheduledSQLStatsCompactionExecutor: "scheduled-sql-stats-compaction-executor", 1245 ScheduledRowLevelTTLExecutor: "scheduled-row-level-ttl-executor", 1246 ScheduledSchemaTelemetryExecutor: "scheduled-schema-telemetry-executor", 1247 ScheduledChangefeedExecutor: "scheduled-changefeed-executor", 1248 } 1249 1250 // InternalName returns an internal executor name. 1251 // This name can be used to filter matching schedules. 1252 func (t ScheduledJobExecutorType) InternalName() string { 1253 return scheduleExecutorInternalNames[t] 1254 } 1255 1256 // UserName returns a user friendly executor name. 1257 func (t ScheduledJobExecutorType) UserName() string { 1258 switch t { 1259 case ScheduledBackupExecutor: 1260 return "BACKUP" 1261 case ScheduledSQLStatsCompactionExecutor: 1262 return "SQL STATISTICS" 1263 case ScheduledRowLevelTTLExecutor: 1264 return "ROW LEVEL TTL" 1265 case ScheduledSchemaTelemetryExecutor: 1266 return "SCHEMA TELEMETRY" 1267 case ScheduledChangefeedExecutor: 1268 return "CHANGEFEED" 1269 } 1270 return "unsupported-executor" 1271 } 1272 1273 // ScheduleState describes what kind of schedules to display 1274 type ScheduleState int 1275 1276 const ( 1277 // SpecifiedSchedules indicates that show schedules should 1278 // only show subset of schedules. 1279 SpecifiedSchedules ScheduleState = iota 1280 1281 // ActiveSchedules indicates that show schedules should 1282 // only show those schedules that are currently active. 1283 ActiveSchedules 1284 1285 // PausedSchedules indicates that show schedules should 1286 // only show those schedules that are currently paused. 1287 PausedSchedules 1288 ) 1289 1290 // Format implements the NodeFormatter interface. 1291 func (s ScheduleState) Format(ctx *FmtCtx) { 1292 switch s { 1293 case ActiveSchedules: 1294 ctx.WriteString("RUNNING") 1295 case PausedSchedules: 1296 ctx.WriteString("PAUSED") 1297 default: 1298 // Nothing 1299 } 1300 } 1301 1302 // ShowSchedules represents a SHOW SCHEDULES statement. 1303 type ShowSchedules struct { 1304 WhichSchedules ScheduleState 1305 ExecutorType ScheduledJobExecutorType 1306 ScheduleID Expr 1307 } 1308 1309 var _ Statement = &ShowSchedules{} 1310 1311 // Format implements the NodeFormatter interface. 1312 func (n *ShowSchedules) Format(ctx *FmtCtx) { 1313 if n.ScheduleID != nil { 1314 ctx.WriteString("SHOW SCHEDULE ") 1315 ctx.FormatNode(n.ScheduleID) 1316 return 1317 } 1318 ctx.Printf("SHOW") 1319 1320 if n.WhichSchedules != SpecifiedSchedules { 1321 ctx.WriteString(" ") 1322 ctx.FormatNode(&n.WhichSchedules) 1323 } 1324 1325 ctx.Printf(" SCHEDULES") 1326 1327 if n.ExecutorType != InvalidExecutor { 1328 // TODO(knz): beware of using ctx.FormatNode here if 1329 // FOR changes to support expressions. 1330 ctx.Printf(" FOR %s", n.ExecutorType.UserName()) 1331 } 1332 } 1333 1334 // ShowDefaultPrivileges represents a SHOW DEFAULT PRIVILEGES statement. 1335 type ShowDefaultPrivileges struct { 1336 Roles RoleSpecList 1337 ForAllRoles bool 1338 ForGrantee bool 1339 // If Schema is not specified, SHOW DEFAULT PRIVILEGES is being 1340 // run on the current database. 1341 Schema Name 1342 } 1343 1344 var _ Statement = &ShowDefaultPrivileges{} 1345 1346 // Format implements the NodeFormatter interface. 1347 func (n *ShowDefaultPrivileges) Format(ctx *FmtCtx) { 1348 ctx.WriteString("SHOW DEFAULT PRIVILEGES ") 1349 if len(n.Roles) > 0 { 1350 if n.ForGrantee { 1351 ctx.WriteString("FOR GRANTEE ") 1352 } else { 1353 ctx.WriteString("FOR ROLE ") 1354 } 1355 1356 for i := range n.Roles { 1357 if i > 0 { 1358 ctx.WriteString(", ") 1359 } 1360 ctx.FormatNode(&n.Roles[i]) 1361 } 1362 ctx.WriteString(" ") 1363 } else if n.ForAllRoles { 1364 ctx.WriteString("FOR ALL ROLES ") 1365 } 1366 if n.Schema != Name("") { 1367 ctx.WriteString("IN SCHEMA ") 1368 ctx.FormatNode(&n.Schema) 1369 } 1370 } 1371 1372 // ShowTransferState represents a SHOW TRANSFER STATE statement. 1373 type ShowTransferState struct { 1374 TransferKey *StrVal 1375 } 1376 1377 // Format implements the NodeFormatter interface. 1378 func (node *ShowTransferState) Format(ctx *FmtCtx) { 1379 ctx.WriteString("SHOW TRANSFER STATE") 1380 if node.TransferKey != nil { 1381 ctx.WriteString(" WITH ") 1382 ctx.FormatNode(node.TransferKey) 1383 } 1384 } 1385 1386 // ShowCompletions represents a SHOW COMPLETIONS statement. 1387 type ShowCompletions struct { 1388 Statement *StrVal 1389 Offset *NumVal 1390 } 1391 1392 // Format implements the NodeFormatter interface. 1393 func (s ShowCompletions) Format(ctx *FmtCtx) { 1394 ctx.WriteString("SHOW COMPLETIONS AT OFFSET ") 1395 s.Offset.Format(ctx) 1396 ctx.WriteString(" FOR ") 1397 ctx.FormatNode(s.Statement) 1398 } 1399 1400 var _ Statement = &ShowCompletions{} 1401 1402 // ShowCreateRoutine represents a SHOW CREATE FUNCTION or SHOW CREATE PROCEDURE 1403 // statement. 1404 type ShowCreateRoutine struct { 1405 Name ResolvableFunctionReference 1406 Procedure bool 1407 } 1408 1409 // Format implements the NodeFormatter interface. 1410 func (node *ShowCreateRoutine) Format(ctx *FmtCtx) { 1411 if node.Procedure { 1412 ctx.WriteString("SHOW CREATE PROCEDURE ") 1413 } else { 1414 ctx.WriteString("SHOW CREATE FUNCTION ") 1415 } 1416 ctx.FormatNode(&node.Name) 1417 } 1418 1419 var _ Statement = &ShowCreateRoutine{} 1420 1421 // ShowCreateExternalConnections represents a SHOW CREATE EXTERNAL CONNECTION 1422 // statement. 1423 type ShowCreateExternalConnections struct { 1424 ConnectionLabel Expr 1425 } 1426 1427 // Format implements the NodeFormatter interface. 1428 func (node *ShowCreateExternalConnections) Format(ctx *FmtCtx) { 1429 if node.ConnectionLabel != nil { 1430 ctx.WriteString("SHOW CREATE EXTERNAL CONNECTION ") 1431 ctx.FormatNode(node.ConnectionLabel) 1432 return 1433 } 1434 ctx.Printf("SHOW CREATE ALL EXTERNAL CONNECTIONS") 1435 } 1436 1437 var _ Statement = &ShowCreateExternalConnections{} 1438 1439 // ShowCommitTimestamp represents a SHOW COMMIT TIMESTAMP statement. 1440 // 1441 // If the current session is in an open transaction state, this statement will 1442 // implicitly commit the underlying kv transaction and return the HLC timestamp 1443 // at which it committed. The transaction state machine will be left in a state 1444 // such that only COMMIT or RELEASE cockroach_savepoint; COMMIT are acceptable. 1445 // The statement may also be sent after RELEASE cockroach_savepoint; and before 1446 // COMMIT. 1447 // 1448 // If the current session is not in an open transaction state, this statement 1449 // will return the commit timestamp of the previous transaction, assuming there 1450 // was one. 1451 type ShowCommitTimestamp struct{} 1452 1453 func (s ShowCommitTimestamp) Format(ctx *FmtCtx) { 1454 ctx.Printf("SHOW COMMIT TIMESTAMP") 1455 } 1456 1457 var _ Statement = (*ShowCommitTimestamp)(nil)