From a180a82b188c35771b8551ab83490e6c345cafa7 Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Tue, 4 Jul 2023 13:53:32 +0200 Subject: [PATCH 01/17] sql: backup option `INCLUDE_ALL_VIRTUAL_CLUSTERS` This aliases `INCLUDE_ALL_SECONDARY_TENANTS` which becomes hidden. Release note: None --- docs/generated/sql/bnf/BUILD.bazel | 2 + docs/generated/sql/bnf/backup_options.bnf | 11 +++ docs/generated/sql/bnf/restore_options.bnf | 21 ++++++ docs/generated/sql/bnf/stmt_block.bnf | 12 ++-- pkg/cmd/docgen/diagrams.go | 8 +++ pkg/gen/bnf.bzl | 2 + pkg/gen/diagrams.bzl | 2 + pkg/gen/docs.bzl | 2 + pkg/sql/parser/sql.y | 21 ++++-- pkg/sql/parser/testdata/backup_restore | 80 +++++++++++++++------- pkg/sql/sem/tree/backup.go | 8 +-- 11 files changed, 130 insertions(+), 39 deletions(-) create mode 100644 docs/generated/sql/bnf/backup_options.bnf create mode 100644 docs/generated/sql/bnf/restore_options.bnf diff --git a/docs/generated/sql/bnf/BUILD.bazel b/docs/generated/sql/bnf/BUILD.bazel index 4109c0392e31..4931f6fffdd7 100644 --- a/docs/generated/sql/bnf/BUILD.bazel +++ b/docs/generated/sql/bnf/BUILD.bazel @@ -67,6 +67,7 @@ FILES = [ "alter_zone_table_stmt", "analyze_stmt", "backup", + "backup_options", "begin_stmt", "begin_transaction", "cancel_all_jobs_stmt", @@ -185,6 +186,7 @@ FILES = [ "reset_session_stmt", "reset_stmt", "restore", + "restore_options", "resume_all_jobs_stmt", "resume_job", "resume_schedule", diff --git a/docs/generated/sql/bnf/backup_options.bnf b/docs/generated/sql/bnf/backup_options.bnf new file mode 100644 index 000000000000..dd0f3afbabfa --- /dev/null +++ b/docs/generated/sql/bnf/backup_options.bnf @@ -0,0 +1,11 @@ +backup_options ::= + 'ENCRYPTION_PASSPHRASE' '=' string_or_placeholder + | 'REVISION_HISTORY' + | 'REVISION_HISTORY' '=' a_expr + | 'DETACHED' + | 'DETACHED' '=' 'TRUE' + | 'DETACHED' '=' 'FALSE' + | 'KMS' '=' string_or_placeholder_opt_list + | 'INCREMENTAL_LOCATION' '=' string_or_placeholder_opt_list + | 'EXECUTION' 'LOCALITY' '=' string_or_placeholder + | 'INCLUDE_ALL_VIRTUAL_CLUSTERS' '=' a_expr diff --git a/docs/generated/sql/bnf/restore_options.bnf b/docs/generated/sql/bnf/restore_options.bnf new file mode 100644 index 000000000000..c7994fe525ab --- /dev/null +++ b/docs/generated/sql/bnf/restore_options.bnf @@ -0,0 +1,21 @@ +restore_options ::= + 'ENCRYPTION_PASSPHRASE' '=' string_or_placeholder + | 'KMS' '=' string_or_placeholder_opt_list + | 'INTO_DB' '=' string_or_placeholder + | 'SKIP_MISSING_FOREIGN_KEYS' + | 'SKIP_MISSING_SEQUENCES' + | 'SKIP_MISSING_SEQUENCE_OWNERS' + | 'SKIP_MISSING_VIEWS' + | 'SKIP_MISSING_UDFS' + | 'DETACHED' + | 'SKIP_LOCALITIES_CHECK' + | 'DEBUG_PAUSE_ON' '=' string_or_placeholder + | 'NEW_DB_NAME' '=' string_or_placeholder + | 'INCLUDE_ALL_VIRTUAL_CLUSTERS' + | 'INCLUDE_ALL_VIRTUAL_CLUSTERS' '=' a_expr + | 'INCREMENTAL_LOCATION' '=' string_or_placeholder_opt_list + | 'TENANT_NAME' '=' string_or_placeholder + | 'TENANT' '=' string_or_placeholder + | 'SCHEMA_ONLY' + | 'VERIFY_BACKUP_TABLE_DATA' + | 'UNSAFE_RESTORE_INCOMPATIBLE_VERSION' diff --git a/docs/generated/sql/bnf/stmt_block.bnf b/docs/generated/sql/bnf/stmt_block.bnf index 14ceea13c785..ef5fb280d7ec 100644 --- a/docs/generated/sql/bnf/stmt_block.bnf +++ b/docs/generated/sql/bnf/stmt_block.bnf @@ -1176,6 +1176,7 @@ unreserved_keyword ::= | 'INCLUDE' | 'INCLUDING' | 'INCLUDE_ALL_SECONDARY_TENANTS' + | 'INCLUDE_ALL_VIRTUAL_CLUSTERS' | 'INCREMENT' | 'INCREMENTAL' | 'INCREMENTAL_LOCATION' @@ -2323,8 +2324,7 @@ backup_options ::= | 'KMS' '=' string_or_placeholder_opt_list | 'INCREMENTAL_LOCATION' '=' string_or_placeholder_opt_list | 'EXECUTION' 'LOCALITY' '=' string_or_placeholder - | 'INCLUDE_ALL_SECONDARY_TENANTS' - | 'INCLUDE_ALL_SECONDARY_TENANTS' '=' a_expr + | include_all_clusters '=' a_expr c_expr ::= d_expr @@ -2687,8 +2687,8 @@ restore_options ::= | 'SKIP_LOCALITIES_CHECK' | 'DEBUG_PAUSE_ON' '=' string_or_placeholder | 'NEW_DB_NAME' '=' string_or_placeholder - | 'INCLUDE_ALL_SECONDARY_TENANTS' - | 'INCLUDE_ALL_SECONDARY_TENANTS' '=' a_expr + | include_all_clusters + | include_all_clusters '=' a_expr | 'INCREMENTAL_LOCATION' '=' string_or_placeholder_opt_list | 'TENANT_NAME' '=' string_or_placeholder | 'TENANT' '=' string_or_placeholder @@ -3013,6 +3013,9 @@ role_option ::= | password_clause | valid_until_clause +include_all_clusters ::= + 'INCLUDE_ALL_VIRTUAL_CLUSTERS' + array_subscripts ::= ( array_subscript ) ( ( array_subscript ) )* @@ -3703,6 +3706,7 @@ bare_label_keywords ::= | 'IN' | 'INCLUDE' | 'INCLUDE_ALL_SECONDARY_TENANTS' + | 'INCLUDE_ALL_VIRTUAL_CLUSTERS' | 'INCLUDING' | 'INCREMENT' | 'INCREMENTAL' diff --git a/pkg/cmd/docgen/diagrams.go b/pkg/cmd/docgen/diagrams.go index f2d03c9f77b3..d707f608e1cd 100644 --- a/pkg/cmd/docgen/diagrams.go +++ b/pkg/cmd/docgen/diagrams.go @@ -1638,6 +1638,14 @@ var specs = []stmtSpec{ name: "opt_frame_clause", inline: []string{"frame_extent"}, }, + { + name: "backup_options", + inline: []string{"include_all_clusters"}, + }, + { + name: "restore_options", + inline: []string{"include_all_clusters"}, + }, } // getAllStmtSpecs returns a slice of stmtSpecs for all sql.y statements that diff --git a/pkg/gen/bnf.bzl b/pkg/gen/bnf.bzl index 4c32c6604366..e6e726ab4f31 100644 --- a/pkg/gen/bnf.bzl +++ b/pkg/gen/bnf.bzl @@ -67,6 +67,7 @@ BNF_SRCS = [ "//docs/generated/sql/bnf:alter_zone_table_stmt.bnf", "//docs/generated/sql/bnf:analyze_stmt.bnf", "//docs/generated/sql/bnf:backup.bnf", + "//docs/generated/sql/bnf:backup_options.bnf", "//docs/generated/sql/bnf:begin_stmt.bnf", "//docs/generated/sql/bnf:begin_transaction.bnf", "//docs/generated/sql/bnf:cancel_all_jobs_stmt.bnf", @@ -185,6 +186,7 @@ BNF_SRCS = [ "//docs/generated/sql/bnf:reset_session_stmt.bnf", "//docs/generated/sql/bnf:reset_stmt.bnf", "//docs/generated/sql/bnf:restore.bnf", + "//docs/generated/sql/bnf:restore_options.bnf", "//docs/generated/sql/bnf:resume_all_jobs_stmt.bnf", "//docs/generated/sql/bnf:resume_job.bnf", "//docs/generated/sql/bnf:resume_schedule.bnf", diff --git a/pkg/gen/diagrams.bzl b/pkg/gen/diagrams.bzl index 1b3736f6dab0..33670bfc1bc7 100644 --- a/pkg/gen/diagrams.bzl +++ b/pkg/gen/diagrams.bzl @@ -67,6 +67,7 @@ DIAGRAMS_SRCS = [ "//docs/generated/sql/bnf:alter_zone_table.html", "//docs/generated/sql/bnf:analyze.html", "//docs/generated/sql/bnf:backup.html", + "//docs/generated/sql/bnf:backup_options.html", "//docs/generated/sql/bnf:begin.html", "//docs/generated/sql/bnf:begin_transaction.html", "//docs/generated/sql/bnf:cancel.html", @@ -185,6 +186,7 @@ DIAGRAMS_SRCS = [ "//docs/generated/sql/bnf:reset_csetting.html", "//docs/generated/sql/bnf:reset_session.html", "//docs/generated/sql/bnf:restore.html", + "//docs/generated/sql/bnf:restore_options.html", "//docs/generated/sql/bnf:resume.html", "//docs/generated/sql/bnf:resume_all_jobs.html", "//docs/generated/sql/bnf:resume_job.html", diff --git a/pkg/gen/docs.bzl b/pkg/gen/docs.bzl index 89a1ff1e5da8..552187ba9017 100644 --- a/pkg/gen/docs.bzl +++ b/pkg/gen/docs.bzl @@ -79,6 +79,7 @@ DOCS_SRCS = [ "//docs/generated/sql/bnf:alter_zone_table_stmt.bnf", "//docs/generated/sql/bnf:analyze_stmt.bnf", "//docs/generated/sql/bnf:backup.bnf", + "//docs/generated/sql/bnf:backup_options.bnf", "//docs/generated/sql/bnf:begin_stmt.bnf", "//docs/generated/sql/bnf:begin_transaction.bnf", "//docs/generated/sql/bnf:cancel_all_jobs_stmt.bnf", @@ -197,6 +198,7 @@ DOCS_SRCS = [ "//docs/generated/sql/bnf:reset_session_stmt.bnf", "//docs/generated/sql/bnf:reset_stmt.bnf", "//docs/generated/sql/bnf:restore.bnf", + "//docs/generated/sql/bnf:restore_options.bnf", "//docs/generated/sql/bnf:resume_all_jobs_stmt.bnf", "//docs/generated/sql/bnf:resume_job.bnf", "//docs/generated/sql/bnf:resume_schedule.bnf", diff --git a/pkg/sql/parser/sql.y b/pkg/sql/parser/sql.y index 9bf9062151cb..b3e3215badac 100644 --- a/pkg/sql/parser/sql.y +++ b/pkg/sql/parser/sql.y @@ -943,7 +943,7 @@ func (u *sqlSymUnion) showCreateFormatOption() tree.ShowCreateFormatOption { %token IDENTITY %token IF IFERROR IFNULL IGNORE_FOREIGN_KEYS ILIKE IMMEDIATE IMMUTABLE IMPORT IN INCLUDE -%token INCLUDING INCLUDE_ALL_SECONDARY_TENANTS INCREMENT INCREMENTAL INCREMENTAL_LOCATION +%token INCLUDING INCLUDE_ALL_SECONDARY_TENANTS INCLUDE_ALL_VIRTUAL_CLUSTERS INCREMENT INCREMENTAL INCREMENTAL_LOCATION %token INET INET_CONTAINED_BY_OR_EQUALS %token INET_CONTAINS_OR_EQUALS INDEX INDEXES INHERITS INJECT INITIALLY %token INDEX_BEFORE_PAREN INDEX_BEFORE_NAME_THEN_PAREN INDEX_AFTER_ORDER_BY_BEFORE_AT @@ -3174,7 +3174,7 @@ opt_clear_data: // kms="[kms_provider]://[kms_host]/[master_key_identifier]?[parameters]" : encrypt backups using KMS // detached: execute backup job asynchronously, without waiting for its completion // incremental_location: specify a different path to store the incremental backup -// include_all_secondary_tenants: enable backups of all secondary tenants during a cluster backup in the system tenant +// include_all_virtual_clusters: enable backups of all virtual clusters during a cluster backup // // %SeeAlso: RESTORE, WEBDOCS/backup.html backup_stmt: @@ -3300,15 +3300,20 @@ backup_options: { $$.val = &tree.BackupOptions{ExecutionLocality: $4.expr()} } -| INCLUDE_ALL_SECONDARY_TENANTS +| include_all_clusters { + /* SKIP DOC */ $$.val = &tree.BackupOptions{IncludeAllSecondaryTenants: tree.MakeDBool(true)} } -| INCLUDE_ALL_SECONDARY_TENANTS '=' a_expr +| include_all_clusters '=' a_expr { $$.val = &tree.BackupOptions{IncludeAllSecondaryTenants: $3.expr()} } +include_all_clusters: + INCLUDE_ALL_SECONDARY_TENANTS { /* SKIP DOC */ } +| INCLUDE_ALL_VIRTUAL_CLUSTERS { } + // %Help: CREATE SCHEDULE FOR BACKUP - backup data periodically // %Category: CCL // %Text: @@ -3620,7 +3625,7 @@ drop_external_connection_stmt: // skip_localities_check: ignore difference of zone configuration between restore cluster and backup cluster // debug_pause_on: describes the events that the job should pause itself on for debugging purposes. // new_db_name: renames the restored database. only applies to database restores -// include_all_secondary_tenants: enable backups of all secondary tenants during a cluster backup in the system tenant +// include_all_virtual_clusters: enable backups of all virtual clusters during a cluster backup // %SeeAlso: BACKUP, WEBDOCS/restore.html restore_stmt: RESTORE FROM list_of_string_or_placeholder_opt_list opt_as_of_clause opt_with_restore_options @@ -3780,11 +3785,11 @@ restore_options: { $$.val = &tree.RestoreOptions{NewDBName: $3.expr()} } -| INCLUDE_ALL_SECONDARY_TENANTS +| include_all_clusters { $$.val = &tree.RestoreOptions{IncludeAllSecondaryTenants: tree.MakeDBool(true)} } -| INCLUDE_ALL_SECONDARY_TENANTS '=' a_expr +| include_all_clusters '=' a_expr { $$.val = &tree.RestoreOptions{IncludeAllSecondaryTenants: $3.expr()} } @@ -16555,6 +16560,7 @@ unreserved_keyword: | INCLUDE | INCLUDING | INCLUDE_ALL_SECONDARY_TENANTS +| INCLUDE_ALL_VIRTUAL_CLUSTERS | INCREMENT | INCREMENTAL | INCREMENTAL_LOCATION @@ -17067,6 +17073,7 @@ bare_label_keywords: | IN | INCLUDE | INCLUDE_ALL_SECONDARY_TENANTS +| INCLUDE_ALL_VIRTUAL_CLUSTERS | INCLUDING | INCREMENT | INCREMENTAL diff --git a/pkg/sql/parser/testdata/backup_restore b/pkg/sql/parser/testdata/backup_restore index 66de8d820552..faf210be294b 100644 --- a/pkg/sql/parser/testdata/backup_restore +++ b/pkg/sql/parser/testdata/backup_restore @@ -791,37 +791,69 @@ RESTORE TABLE (foo) FROM ('bar') WITH skip_missing_foreign_keys, skip_missing_se RESTORE TABLE foo FROM '_' WITH skip_missing_foreign_keys, skip_missing_sequences, detached -- literals removed RESTORE TABLE _ FROM 'bar' WITH skip_missing_foreign_keys, skip_missing_sequences, detached -- identifiers removed +parse +BACKUP INTO 'bar' WITH include_all_virtual_clusters = $1, detached +---- +BACKUP INTO 'bar' WITH detached, include_all_virtual_clusters = $1 -- normalized! +BACKUP INTO ('bar') WITH detached, include_all_virtual_clusters = ($1) -- fully parenthesized +BACKUP INTO '_' WITH detached, include_all_virtual_clusters = $1 -- literals removed +BACKUP INTO 'bar' WITH detached, include_all_virtual_clusters = $1 -- identifiers removed + parse BACKUP INTO 'bar' WITH include_all_secondary_tenants = $1, detached ---- -BACKUP INTO 'bar' WITH detached, include_all_secondary_tenants = $1 -- normalized! -BACKUP INTO ('bar') WITH detached, include_all_secondary_tenants = ($1) -- fully parenthesized -BACKUP INTO '_' WITH detached, include_all_secondary_tenants = $1 -- literals removed -BACKUP INTO 'bar' WITH detached, include_all_secondary_tenants = $1 -- identifiers removed +BACKUP INTO 'bar' WITH detached, include_all_virtual_clusters = $1 -- normalized! +BACKUP INTO ('bar') WITH detached, include_all_virtual_clusters = ($1) -- fully parenthesized +BACKUP INTO '_' WITH detached, include_all_virtual_clusters = $1 -- literals removed +BACKUP INTO 'bar' WITH detached, include_all_virtual_clusters = $1 -- identifiers removed + +parse +BACKUP INTO 'bar' WITH include_all_virtual_clusters, detached +---- +BACKUP INTO 'bar' WITH detached, include_all_virtual_clusters = true -- normalized! +BACKUP INTO ('bar') WITH detached, include_all_virtual_clusters = (true) -- fully parenthesized +BACKUP INTO '_' WITH detached, include_all_virtual_clusters = _ -- literals removed +BACKUP INTO 'bar' WITH detached, include_all_virtual_clusters = true -- identifiers removed parse BACKUP INTO 'bar' WITH include_all_secondary_tenants, detached ---- -BACKUP INTO 'bar' WITH detached, include_all_secondary_tenants = true -- normalized! -BACKUP INTO ('bar') WITH detached, include_all_secondary_tenants = (true) -- fully parenthesized -BACKUP INTO '_' WITH detached, include_all_secondary_tenants = _ -- literals removed -BACKUP INTO 'bar' WITH detached, include_all_secondary_tenants = true -- identifiers removed +BACKUP INTO 'bar' WITH detached, include_all_virtual_clusters = true -- normalized! +BACKUP INTO ('bar') WITH detached, include_all_virtual_clusters = (true) -- fully parenthesized +BACKUP INTO '_' WITH detached, include_all_virtual_clusters = _ -- literals removed +BACKUP INTO 'bar' WITH detached, include_all_virtual_clusters = true -- identifiers removed + +parse +RESTORE FROM LATEST IN 'bar' WITH include_all_virtual_clusters = $1, detached +---- +RESTORE FROM 'latest' IN 'bar' WITH detached, include_all_virtual_clusters = $1 -- normalized! +RESTORE FROM ('latest') IN ('bar') WITH detached, include_all_virtual_clusters = ($1) -- fully parenthesized +RESTORE FROM '_' IN '_' WITH detached, include_all_virtual_clusters = $1 -- literals removed +RESTORE FROM 'latest' IN 'bar' WITH detached, include_all_virtual_clusters = $1 -- identifiers removed parse RESTORE FROM LATEST IN 'bar' WITH include_all_secondary_tenants = $1, detached ---- -RESTORE FROM 'latest' IN 'bar' WITH detached, include_all_secondary_tenants = $1 -- normalized! -RESTORE FROM ('latest') IN ('bar') WITH detached, include_all_secondary_tenants = ($1) -- fully parenthesized -RESTORE FROM '_' IN '_' WITH detached, include_all_secondary_tenants = $1 -- literals removed -RESTORE FROM 'latest' IN 'bar' WITH detached, include_all_secondary_tenants = $1 -- identifiers removed +RESTORE FROM 'latest' IN 'bar' WITH detached, include_all_virtual_clusters = $1 -- normalized! +RESTORE FROM ('latest') IN ('bar') WITH detached, include_all_virtual_clusters = ($1) -- fully parenthesized +RESTORE FROM '_' IN '_' WITH detached, include_all_virtual_clusters = $1 -- literals removed +RESTORE FROM 'latest' IN 'bar' WITH detached, include_all_virtual_clusters = $1 -- identifiers removed + +parse +RESTORE FROM LATEST IN 'bar' WITH include_all_virtual_clusters, detached +---- +RESTORE FROM 'latest' IN 'bar' WITH detached, include_all_virtual_clusters = true -- normalized! +RESTORE FROM ('latest') IN ('bar') WITH detached, include_all_virtual_clusters = (true) -- fully parenthesized +RESTORE FROM '_' IN '_' WITH detached, include_all_virtual_clusters = _ -- literals removed +RESTORE FROM 'latest' IN 'bar' WITH detached, include_all_virtual_clusters = true -- identifiers removed parse RESTORE FROM LATEST IN 'bar' WITH include_all_secondary_tenants, detached ---- -RESTORE FROM 'latest' IN 'bar' WITH detached, include_all_secondary_tenants = true -- normalized! -RESTORE FROM ('latest') IN ('bar') WITH detached, include_all_secondary_tenants = (true) -- fully parenthesized -RESTORE FROM '_' IN '_' WITH detached, include_all_secondary_tenants = _ -- literals removed -RESTORE FROM 'latest' IN 'bar' WITH detached, include_all_secondary_tenants = true -- identifiers removed +RESTORE FROM 'latest' IN 'bar' WITH detached, include_all_virtual_clusters = true -- normalized! +RESTORE FROM ('latest') IN ('bar') WITH detached, include_all_virtual_clusters = (true) -- fully parenthesized +RESTORE FROM '_' IN '_' WITH detached, include_all_virtual_clusters = _ -- literals removed +RESTORE FROM 'latest' IN 'bar' WITH detached, include_all_virtual_clusters = true -- identifiers removed parse RESTORE FROM LATEST IN 'bar' WITH unsafe_restore_incompatible_version, detached @@ -873,12 +905,12 @@ BACKUP foo TO 'bar' WITH detached=true, revision_history, detached=true ^ error -BACKUP TO 'bar' WITH include_all_secondary_tenants=false, include_all_secondary_tenants +BACKUP TO 'bar' WITH include_all_virtual_clusters=false, include_all_secondary_tenants ---- -at or near "EOF": syntax error: include_all_secondary_tenants specified multiple times +at or near "EOF": syntax error: include_all_virtual_clusters specified multiple times DETAIL: source SQL: -BACKUP TO 'bar' WITH include_all_secondary_tenants=false, include_all_secondary_tenants - ^ +BACKUP TO 'bar' WITH include_all_virtual_clusters=false, include_all_secondary_tenants + ^ error BACKUP foo TO 'bar' WITH detached=$1, revision_history @@ -931,12 +963,12 @@ RESTORE foo FROM 'bar' WITH skip_missing_udfs, skip_missing_views, skip_missing_ ^ error -RESTORE FROM 'bar' WITH include_all_secondary_tenants=false, include_all_secondary_tenants +RESTORE FROM 'bar' WITH include_all_virtual_clusters=false, include_all_secondary_tenants ---- -at or near "EOF": syntax error: include_all_secondary_tenants specified multiple times +at or near "EOF": syntax error: include_all_virtual_clusters specified multiple times DETAIL: source SQL: -RESTORE FROM 'bar' WITH include_all_secondary_tenants=false, include_all_secondary_tenants - ^ +RESTORE FROM 'bar' WITH include_all_virtual_clusters=false, include_all_secondary_tenants + ^ error RESTORE FROM 'bar' WITH unsafe_restore_incompatible_version, unsafe_restore_incompatible_version diff --git a/pkg/sql/sem/tree/backup.go b/pkg/sql/sem/tree/backup.go index cd46a6b1dde3..cac9cad26c06 100644 --- a/pkg/sql/sem/tree/backup.go +++ b/pkg/sql/sem/tree/backup.go @@ -306,7 +306,7 @@ func (o *BackupOptions) Format(ctx *FmtCtx) { if o.IncludeAllSecondaryTenants != nil { maybeAddSep() - ctx.WriteString("include_all_secondary_tenants = ") + ctx.WriteString("include_all_virtual_clusters = ") ctx.FormatNode(o.IncludeAllSecondaryTenants) } } @@ -356,7 +356,7 @@ func (o *BackupOptions) CombineWith(other *BackupOptions) error { if o.IncludeAllSecondaryTenants != nil { if other.IncludeAllSecondaryTenants != nil { - return errors.New("include_all_secondary_tenants specified multiple times") + return errors.New("include_all_virtual_clusters specified multiple times") } } else { o.IncludeAllSecondaryTenants = other.IncludeAllSecondaryTenants @@ -457,7 +457,7 @@ func (o *RestoreOptions) Format(ctx *FmtCtx) { if o.IncludeAllSecondaryTenants != nil { maybeAddSep() - ctx.WriteString("include_all_secondary_tenants = ") + ctx.WriteString("include_all_virtual_clusters = ") ctx.FormatNode(o.IncludeAllSecondaryTenants) } @@ -618,7 +618,7 @@ func (o *RestoreOptions) CombineWith(other *RestoreOptions) error { if o.IncludeAllSecondaryTenants != nil { if other.IncludeAllSecondaryTenants != nil { - return errors.New("include_all_secondary_tenants specified multiple times") + return errors.New("include_all_virtual_clusters specified multiple times") } } else { o.IncludeAllSecondaryTenants = other.IncludeAllSecondaryTenants From 874c83bd4ee4dd6f297147d43061905505bc6ab9 Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Tue, 4 Jul 2023 14:17:29 +0200 Subject: [PATCH 02/17] backupccl: use `include_all_virtual_clusters` in errors and tests Release note: None --- pkg/ccl/backupccl/backup_planning.go | 2 +- pkg/ccl/backupccl/backup_test.go | 22 +++++++++---------- .../backupccl/restore_old_versions_test.go | 2 +- pkg/ccl/backupccl/restore_planning.go | 2 +- .../alter-schedule/backup-options | 18 +++++++-------- .../testdata/backup-restore/restore-tenants | 20 ++++++++--------- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/pkg/ccl/backupccl/backup_planning.go b/pkg/ccl/backupccl/backup_planning.go index 9de56d2245bb..89ced6b9325a 100644 --- a/pkg/ccl/backupccl/backup_planning.go +++ b/pkg/ccl/backupccl/backup_planning.go @@ -682,7 +682,7 @@ func backupPlanHook( } if includeAllSecondaryTenants && backupStmt.Coverage() != tree.AllDescriptors { - return errors.New("the include_all_secondary_tenants option is only supported for full cluster backups") + return errors.New("the include_all_virtual_clusters option is only supported for full cluster backups") } var asOfInterval int64 diff --git a/pkg/ccl/backupccl/backup_test.go b/pkg/ccl/backupccl/backup_test.go index 350ea97f1718..c969c96a4178 100644 --- a/pkg/ccl/backupccl/backup_test.go +++ b/pkg/ccl/backupccl/backup_test.go @@ -3552,7 +3552,7 @@ func TestBackupTenantsWithRevisionHistory(t *testing.T) { _, err = sqlDB.DB.ExecContext(ctx, `BACKUP TENANT 10 TO 'nodelocal://1/foo' WITH revision_history`) require.Contains(t, fmt.Sprint(err), msg) - _, err = sqlDB.DB.ExecContext(ctx, `BACKUP TO 'nodelocal://1/bar' WITH revision_history, include_all_secondary_tenants`) + _, err = sqlDB.DB.ExecContext(ctx, `BACKUP TO 'nodelocal://1/bar' WITH revision_history, include_all_virtual_clusters`) require.Contains(t, fmt.Sprint(err), msg) } @@ -6699,7 +6699,7 @@ func TestBackupRestoreInsideTenant(t *testing.T) { httpAddr, httpServerCleanup := makeInsecureHTTPServer(t) defer httpServerCleanup() - systemDB.Exec(t, `BACKUP TO $1 WITH include_all_secondary_tenants`, httpAddr) + systemDB.Exec(t, `BACKUP TO $1 WITH include_all_virtual_clusters`, httpAddr) tenant20C2, cleanupT20C2 := makeTenant(srv2, 20) defer cleanupT20C2() @@ -6709,7 +6709,7 @@ func TestBackupRestoreInsideTenant(t *testing.T) { // This is disallowed because the cluster restore includes other // tenants, which can't be restored inside a tenant. tenant20C2.ExpectErr(t, `only the system tenant can restore other tenants`, - `RESTORE FROM $1 WITH include_all_secondary_tenants`, httpAddr) + `RESTORE FROM $1 WITH include_all_virtual_clusters`, httpAddr) }) t.Run("with-no-tenant", func(t *testing.T) { @@ -6769,13 +6769,13 @@ func TestBackupRestoreTenantSettings(t *testing.T) { systemDB.Exec(t, `BACKUP TO $1`, backup2HttpAddr) t.Run("cluster-restore-into-tenant-with-tenant-settings-succeeds", func(t *testing.T) { - tenant2C2.Exec(t, `RESTORE FROM $1 WITH include_all_secondary_tenants`, backup2HttpAddr) + tenant2C2.Exec(t, `RESTORE FROM $1 WITH include_all_virtual_clusters`, backup2HttpAddr) }) _, systemDB2, cleanupDB2 := backupRestoreTestSetupEmpty(t, singleNode, dir, InitManualReplication, base.TestClusterArgs{}) defer cleanupDB2() t.Run("cluster-restore-into-cluster-with-tenant-settings-succeeds", func(t *testing.T) { - systemDB2.Exec(t, `RESTORE FROM $1 WITH include_all_secondary_tenants`, backup2HttpAddr) + systemDB2.Exec(t, `RESTORE FROM $1 WITH include_all_virtual_clusters`, backup2HttpAddr) systemDB2.CheckQueryResults(t, `SELECT * FROM system.tenant_settings`, systemDB.QueryStr(t, `SELECT * FROM system.tenant_settings`)) }) } @@ -6878,7 +6878,7 @@ func TestBackupRestoreInsideMultiPodTenant(t *testing.T) { httpAddr, httpServerCleanup := makeInsecureHTTPServer(t) defer httpServerCleanup() - systemDB.Exec(t, `BACKUP TO $1 WITH include_all_secondary_tenants`, httpAddr) + systemDB.Exec(t, `BACKUP TO $1 WITH include_all_virtual_clusters`, httpAddr) tenant20C2, cleanupT20C2 := makeTenant(srv2, 20, false) defer cleanupT20C2() @@ -6888,7 +6888,7 @@ func TestBackupRestoreInsideMultiPodTenant(t *testing.T) { // This is disallowed because the cluster restore includes other // tenants, which can't be restored inside a tenant. tenant20C2.ExpectErr(t, `only the system tenant can restore other tenants`, - `RESTORE FROM $1 WITH include_all_secondary_tenants`, httpAddr) + `RESTORE FROM $1 WITH include_all_virtual_clusters`, httpAddr) }) t.Run("with-no-tenant", func(t *testing.T) { @@ -6989,12 +6989,12 @@ func TestBackupRestoreTenant(t *testing.T) { // BACKUP tenant 10 at ts1, before they created bar2. systemDB.Exec(t, `BACKUP TENANT 10 TO 'nodelocal://1/t10' AS OF SYSTEM TIME `+ts1) // Also create a full cluster backup. It should contain the tenant. - systemDB.Exec(t, fmt.Sprintf("BACKUP TO 'nodelocal://1/clusterwide' AS OF SYSTEM TIME %s WITH include_all_secondary_tenants", ts1)) + systemDB.Exec(t, fmt.Sprintf("BACKUP TO 'nodelocal://1/clusterwide' AS OF SYSTEM TIME %s WITH include_all_virtual_clusters", ts1)) // Incrementally backup tenant 10 again, capturing up to ts2. systemDB.Exec(t, `BACKUP TENANT 10 TO 'nodelocal://1/t10' AS OF SYSTEM TIME `+ts2) // Run full cluster backup incrementally to ts2 as well. - systemDB.Exec(t, fmt.Sprintf("BACKUP TO 'nodelocal://1/clusterwide' AS OF SYSTEM TIME %s WITH include_all_secondary_tenants", ts2)) + systemDB.Exec(t, fmt.Sprintf("BACKUP TO 'nodelocal://1/clusterwide' AS OF SYSTEM TIME %s WITH include_all_virtual_clusters", ts2)) systemDB.Exec(t, `BACKUP TENANT 11 TO 'nodelocal://1/t11'`) systemDB.Exec(t, `BACKUP TENANT 20 TO 'nodelocal://1/t20'`) @@ -7262,7 +7262,7 @@ func TestBackupRestoreTenant(t *testing.T) { `{"capabilities": {}, "deprecatedId": "1"}`, }, }) - restoreDB.Exec(t, `RESTORE FROM 'nodelocal://1/clusterwide' WITH include_all_secondary_tenants`) + restoreDB.Exec(t, `RESTORE FROM 'nodelocal://1/clusterwide' WITH include_all_virtual_clusters`) restoreDB.CheckQueryResults(t, `select id, active, name, data_state, service_mode, crdb_internal.pb_to_json('cockroach.multitenant.ProtoInfo', info) from system.tenants`, [][]string{ @@ -9684,7 +9684,7 @@ func TestProtectRestoreTargets(t *testing.T) { MustMakeTenantID(10)}) require.NoError(t, err) } - sqlDB.Exec(t, `BACKUP INTO $1 WITH include_all_secondary_tenants`, localFoo) + sqlDB.Exec(t, `BACKUP INTO $1 WITH include_all_virtual_clusters`, localFoo) for _, subtest := range []struct { name string diff --git a/pkg/ccl/backupccl/restore_old_versions_test.go b/pkg/ccl/backupccl/restore_old_versions_test.go index d10ba84c8dbe..13bc1ae65101 100644 --- a/pkg/ccl/backupccl/restore_old_versions_test.go +++ b/pkg/ccl/backupccl/restore_old_versions_test.go @@ -471,7 +471,7 @@ func fullClusterRestoreWithTenants(exportDir string) func(t *testing.T) { sqlDB.CheckQueryResults(t, fmt.Sprintf("SELECT count(*) FROM [SHOW BACKUP LATEST IN '%s'] WHERE object_type = 'TENANT'", localFoo), [][]string{ {"2"}, }) - sqlDB.Exec(t, fmt.Sprintf("RESTORE FROM LATEST IN '%s' WITH UNSAFE_RESTORE_INCOMPATIBLE_VERSION, include_all_secondary_tenants", localFoo)) + sqlDB.Exec(t, fmt.Sprintf("RESTORE FROM LATEST IN '%s' WITH UNSAFE_RESTORE_INCOMPATIBLE_VERSION, include_all_virtual_clusters", localFoo)) sqlDB.CheckQueryResults(t, "SHOW TENANTS", [][]string{ {"1", "system", "ready", "shared"}, {"5", "tenant-5", "ready", "none"}, diff --git a/pkg/ccl/backupccl/restore_planning.go b/pkg/ccl/backupccl/restore_planning.go index f8fc0e78e7ac..208cf18c9b65 100644 --- a/pkg/ccl/backupccl/restore_planning.go +++ b/pkg/ccl/backupccl/restore_planning.go @@ -1166,7 +1166,7 @@ func restorePlanHook( var restoreAllTenants bool if restoreStmt.Options.IncludeAllSecondaryTenants != nil { if restoreStmt.DescriptorCoverage != tree.AllDescriptors { - return nil, nil, nil, false, errors.New("the include_all_secondary_tenants option is only supported for full cluster restores") + return nil, nil, nil, false, errors.New("the include_all_virtual_clusters option is only supported for full cluster restores") } var err error restoreAllTenants, err = exprEval.Bool(ctx, restoreStmt.Options.IncludeAllSecondaryTenants) diff --git a/pkg/ccl/backupccl/testdata/backup-restore/alter-schedule/backup-options b/pkg/ccl/backupccl/testdata/backup-restore/alter-schedule/backup-options index 6b5dd6663dd5..f61620598af2 100644 --- a/pkg/ccl/backupccl/testdata/backup-restore/alter-schedule/backup-options +++ b/pkg/ccl/backupccl/testdata/backup-restore/alter-schedule/backup-options @@ -108,18 +108,18 @@ BACKUP INTO 'nodelocal://1/example-schedule' WITH revision_history = true, detac BACKUP INTO LATEST IN 'nodelocal://1/example-schedule' WITH revision_history = true, detached exec-sql -alter backup schedule $incID set with include_all_secondary_tenants = true +alter backup schedule $incID set with include_all_virtual_clusters = true ---- query-sql with schedules as (show schedules for backup) select command from schedules where label='datatest' order by backup_type asc; ---- -BACKUP INTO 'nodelocal://1/example-schedule' WITH revision_history = true, detached, include_all_secondary_tenants = true -BACKUP INTO LATEST IN 'nodelocal://1/example-schedule' WITH revision_history = true, detached, include_all_secondary_tenants = true +BACKUP INTO 'nodelocal://1/example-schedule' WITH revision_history = true, detached, include_all_virtual_clusters = true +BACKUP INTO LATEST IN 'nodelocal://1/example-schedule' WITH revision_history = true, detached, include_all_virtual_clusters = true exec-sql -create schedule 'with-secondary' for backup into 'nodelocal://1/example-schedule-with-secondary' WITH include_all_secondary_tenants recurring '@daily' full backup '@weekly'; +create schedule 'with-secondary' for backup into 'nodelocal://1/example-schedule-with-secondary' WITH include_all_virtual_clusters recurring '@daily' full backup '@weekly'; ---- let $withSecondaryFullID $withSecondaryIncID @@ -129,15 +129,15 @@ with schedules as (show schedules for backup) select id from schedules where lab query-sql with schedules as (show schedules for backup) select command from schedules where label='with-secondary' order by backup_type asc; ---- -BACKUP INTO 'nodelocal://1/example-schedule-with-secondary' WITH detached, include_all_secondary_tenants = true -BACKUP INTO LATEST IN 'nodelocal://1/example-schedule-with-secondary' WITH detached, include_all_secondary_tenants = true +BACKUP INTO 'nodelocal://1/example-schedule-with-secondary' WITH detached, include_all_virtual_clusters = true +BACKUP INTO LATEST IN 'nodelocal://1/example-schedule-with-secondary' WITH detached, include_all_virtual_clusters = true exec-sql -alter backup schedule $withSecondaryIncID set with Include_all_secondary_tenants = false +alter backup schedule $withSecondaryIncID set with include_all_virtual_clusters = false ---- query-sql with schedules as (show schedules for backup) select command from schedules where label='with-secondary' order by backup_type asc; ---- -BACKUP INTO 'nodelocal://1/example-schedule-with-secondary' WITH detached, include_all_secondary_tenants = false -BACKUP INTO LATEST IN 'nodelocal://1/example-schedule-with-secondary' WITH detached, include_all_secondary_tenants = false +BACKUP INTO 'nodelocal://1/example-schedule-with-secondary' WITH detached, include_all_virtual_clusters = false +BACKUP INTO LATEST IN 'nodelocal://1/example-schedule-with-secondary' WITH detached, include_all_virtual_clusters = false diff --git a/pkg/ccl/backupccl/testdata/backup-restore/restore-tenants b/pkg/ccl/backupccl/testdata/backup-restore/restore-tenants index 2458186bf443..3fc105055786 100644 --- a/pkg/ccl/backupccl/testdata/backup-restore/restore-tenants +++ b/pkg/ccl/backupccl/testdata/backup-restore/restore-tenants @@ -38,16 +38,16 @@ BACKUP INTO 'nodelocal://1/cluster_without_tenants' ---- exec-sql -BACKUP INTO 'nodelocal://1/cluster_with_tenants' WITH include_all_secondary_tenants +BACKUP INTO 'nodelocal://1/cluster_with_tenants' WITH include_all_virtual_clusters ---- -exec-sql expect-error-regex=(the include_all_secondary_tenants option is only supported for full cluster backups) -BACKUP TABLE tab1 INTO 'nodelocal://1/table_backup' WITH include_all_secondary_tenants +exec-sql expect-error-regex=(the include_all_virtual_clusters option is only supported for full cluster backups) +BACKUP TABLE tab1 INTO 'nodelocal://1/table_backup' WITH include_all_virtual_clusters ---- regex matches error -exec-sql expect-error-regex=(the include_all_secondary_tenants option is only supported for full cluster backups) -BACKUP DATABASE db1 INTO 'nodelocal://1/database_backup' WITH include_all_secondary_tenants +exec-sql expect-error-regex=(the include_all_virtual_clusters option is only supported for full cluster backups) +BACKUP DATABASE db1 INTO 'nodelocal://1/database_backup' WITH include_all_virtual_clusters ---- regex matches error @@ -72,7 +72,7 @@ SET CLUSTER SETTING jobs.debug.pausepoints = 'restore.before_flow' ---- restore expect-pausepoint tag=a -RESTORE FROM LATEST IN 'nodelocal://1/cluster_with_tenants' WITH include_all_secondary_tenants +RESTORE FROM LATEST IN 'nodelocal://1/cluster_with_tenants' WITH include_all_virtual_clusters ---- job paused at pausepoint @@ -163,13 +163,13 @@ SELECT id,name,service_mode FROM system.tenants WHERE name = 'another-name'; new-cluster name=s3 share-io-dir=s1 disable-tenant ---- -exec-sql expect-error-regex=(the include_all_secondary_tenants option is only supported for full cluster restores) -RESTORE DATABASE db1 FROM LATEST IN 'nodelocal://1/cluster_with_tenants' WITH include_all_secondary_tenants +exec-sql expect-error-regex=(the include_all_virtual_clusters option is only supported for full cluster restores) +RESTORE DATABASE db1 FROM LATEST IN 'nodelocal://1/cluster_with_tenants' WITH include_all_virtual_clusters ---- regex matches error -exec-sql expect-error-regex=(the include_all_secondary_tenants option is only supported for full cluster restores) -RESTORE TABLE tab1 FROM LATEST IN 'nodelocal://1/cluster_with_tenants' WITH include_all_secondary_tenants +exec-sql expect-error-regex=(the include_all_virtual_clusters option is only supported for full cluster restores) +RESTORE TABLE tab1 FROM LATEST IN 'nodelocal://1/cluster_with_tenants' WITH include_all_virtual_clusters ---- regex matches error From 8fe9b39111b1255dd2c92cdd1e8a3143d0c1d79f Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Tue, 4 Jul 2023 14:08:51 +0200 Subject: [PATCH 03/17] sql: new option `VIRTUAL_CLUSTER_NAME` This aliases `TENANT_NAME` which becomes hidden. Release note: None --- docs/generated/sql/bnf/restore_options.bnf | 2 +- docs/generated/sql/bnf/stmt_block.bnf | 7 ++++++- pkg/cmd/docgen/diagrams.go | 2 +- pkg/sql/parser/sql.y | 9 ++++++++- pkg/sql/parser/testdata/backup_restore | 16 ++++++++++++---- pkg/sql/sem/tree/backup.go | 2 +- 6 files changed, 29 insertions(+), 9 deletions(-) diff --git a/docs/generated/sql/bnf/restore_options.bnf b/docs/generated/sql/bnf/restore_options.bnf index c7994fe525ab..7b43760afa0f 100644 --- a/docs/generated/sql/bnf/restore_options.bnf +++ b/docs/generated/sql/bnf/restore_options.bnf @@ -14,7 +14,7 @@ restore_options ::= | 'INCLUDE_ALL_VIRTUAL_CLUSTERS' | 'INCLUDE_ALL_VIRTUAL_CLUSTERS' '=' a_expr | 'INCREMENTAL_LOCATION' '=' string_or_placeholder_opt_list - | 'TENANT_NAME' '=' string_or_placeholder + | 'VIRTUAL_CLUSTER_NAME' '=' string_or_placeholder | 'TENANT' '=' string_or_placeholder | 'SCHEMA_ONLY' | 'VERIFY_BACKUP_TABLE_DATA' diff --git a/docs/generated/sql/bnf/stmt_block.bnf b/docs/generated/sql/bnf/stmt_block.bnf index ef5fb280d7ec..e6b8b22557f9 100644 --- a/docs/generated/sql/bnf/stmt_block.bnf +++ b/docs/generated/sql/bnf/stmt_block.bnf @@ -1465,6 +1465,7 @@ unreserved_keyword ::= | 'VIEWCLUSTERMETADATA' | 'VIEWCLUSTERSETTING' | 'VIEWDEBUG' + | 'VIRTUAL_CLUSTER_NAME' | 'VISIBLE' | 'VISIBILITY' | 'VOLATILE' @@ -2690,7 +2691,7 @@ restore_options ::= | include_all_clusters | include_all_clusters '=' a_expr | 'INCREMENTAL_LOCATION' '=' string_or_placeholder_opt_list - | 'TENANT_NAME' '=' string_or_placeholder + | virtual_cluster_name '=' string_or_placeholder | 'TENANT' '=' string_or_placeholder | 'SCHEMA_ONLY' | 'VERIFY_BACKUP_TABLE_DATA' @@ -3241,6 +3242,9 @@ array_expr ::= '[' opt_expr_list ']' | '[' array_expr_list ']' +virtual_cluster_name ::= + 'VIRTUAL_CLUSTER_NAME' + scrub_option ::= 'INDEX' 'ALL' | 'INDEX' '(' name_list ')' @@ -4057,6 +4061,7 @@ bare_label_keywords ::= | 'VIEWCLUSTERSETTING' | 'VIEWDEBUG' | 'VIRTUAL' + | 'VIRTUAL_CLUSTER_NAME' | 'VISIBLE' | 'VISIBILITY' | 'VOLATILE' diff --git a/pkg/cmd/docgen/diagrams.go b/pkg/cmd/docgen/diagrams.go index d707f608e1cd..1bebcbb7b35b 100644 --- a/pkg/cmd/docgen/diagrams.go +++ b/pkg/cmd/docgen/diagrams.go @@ -1644,7 +1644,7 @@ var specs = []stmtSpec{ }, { name: "restore_options", - inline: []string{"include_all_clusters"}, + inline: []string{"include_all_clusters", "virtual_cluster_name"}, }, } diff --git a/pkg/sql/parser/sql.y b/pkg/sql/parser/sql.y index b3e3215badac..2eda3e5c8e24 100644 --- a/pkg/sql/parser/sql.y +++ b/pkg/sql/parser/sql.y @@ -1007,6 +1007,7 @@ func (u *sqlSymUnion) showCreateFormatOption() tree.ShowCreateFormatOption { %token VALID VALIDATE VALUE VALUES VARBIT VARCHAR VARIADIC VERIFY_BACKUP_TABLE_DATA VIEW VARYING VIEWACTIVITY VIEWACTIVITYREDACTED VIEWDEBUG %token VIEWCLUSTERMETADATA VIEWCLUSTERSETTING VIRTUAL VISIBLE INVISIBLE VISIBILITY VOLATILE VOTERS +%token VIRTUAL_CLUSTER_NAME %token WHEN WHERE WINDOW WITH WITHIN WITHOUT WORK WRITE @@ -3797,7 +3798,7 @@ restore_options: { $$.val = &tree.RestoreOptions{IncrementalStorage: $3.stringOrPlaceholderOptList()} } -| TENANT_NAME '=' string_or_placeholder +| virtual_cluster_name '=' string_or_placeholder { $$.val = &tree.RestoreOptions{AsTenant: $3.expr()} } @@ -3818,6 +3819,10 @@ restore_options: $$.val = &tree.RestoreOptions{UnsafeRestoreIncompatibleVersion: true} } +virtual_cluster_name: + TENANT_NAME { /* SKIP DOC */ } +| VIRTUAL_CLUSTER_NAME { } + import_format: name { @@ -16849,6 +16854,7 @@ unreserved_keyword: | VIEWCLUSTERMETADATA | VIEWCLUSTERSETTING | VIEWDEBUG +| VIRTUAL_CLUSTER_NAME | VISIBLE | VISIBILITY | VOLATILE @@ -17424,6 +17430,7 @@ bare_label_keywords: | VIEWCLUSTERSETTING | VIEWDEBUG | VIRTUAL +| VIRTUAL_CLUSTER_NAME | VISIBLE | VISIBILITY | VOLATILE diff --git a/pkg/sql/parser/testdata/backup_restore b/pkg/sql/parser/testdata/backup_restore index faf210be294b..66c40edf707d 100644 --- a/pkg/sql/parser/testdata/backup_restore +++ b/pkg/sql/parser/testdata/backup_restore @@ -752,12 +752,20 @@ RESTORE TENANT _ FROM ($1, $1) AS OF SYSTEM TIME '_' -- literals removed RESTORE TENANT 36 FROM ($1, $2) AS OF SYSTEM TIME '1' -- identifiers removed parse -RESTORE TENANT 36 FROM ($1, $2) WITH tenant_name = 'tenant-5' +RESTORE TENANT 36 FROM ($1, $2) WITH virtual_cluster_name = 'tenant-5' ---- +RESTORE TENANT 36 FROM ($1, $2) WITH virtual_cluster_name = 'tenant-5' +RESTORE TENANT 36 FROM (($1), ($2)) WITH virtual_cluster_name = ('tenant-5') -- fully parenthesized +RESTORE TENANT _ FROM ($1, $1) WITH virtual_cluster_name = '_' -- literals removed +RESTORE TENANT 36 FROM ($1, $2) WITH virtual_cluster_name = 'tenant-5' -- identifiers removed + +parse RESTORE TENANT 36 FROM ($1, $2) WITH tenant_name = 'tenant-5' -RESTORE TENANT 36 FROM (($1), ($2)) WITH tenant_name = ('tenant-5') -- fully parenthesized -RESTORE TENANT _ FROM ($1, $1) WITH tenant_name = '_' -- literals removed -RESTORE TENANT 36 FROM ($1, $2) WITH tenant_name = 'tenant-5' -- identifiers removed +---- +RESTORE TENANT 36 FROM ($1, $2) WITH virtual_cluster_name = 'tenant-5' -- normalized! +RESTORE TENANT 36 FROM (($1), ($2)) WITH virtual_cluster_name = ('tenant-5') -- fully parenthesized +RESTORE TENANT _ FROM ($1, $1) WITH virtual_cluster_name = '_' -- literals removed +RESTORE TENANT 36 FROM ($1, $2) WITH virtual_cluster_name = 'tenant-5' -- identifiers removed parse RESTORE TENANT 36 FROM ($1, $2) WITH tenant = '5' diff --git a/pkg/sql/sem/tree/backup.go b/pkg/sql/sem/tree/backup.go index cac9cad26c06..0b3d77f88899 100644 --- a/pkg/sql/sem/tree/backup.go +++ b/pkg/sql/sem/tree/backup.go @@ -469,7 +469,7 @@ func (o *RestoreOptions) Format(ctx *FmtCtx) { if o.AsTenant != nil { maybeAddSep() - ctx.WriteString("tenant_name = ") + ctx.WriteString("virtual_cluster_name = ") ctx.FormatNode(o.AsTenant) } From f34ece3e9ad99b0ac2b4cb5abde00d676ce94a6f Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Tue, 4 Jul 2023 14:19:21 +0200 Subject: [PATCH 04/17] backupccl: use `virtual_cluster_name` in tests Release note: None --- pkg/ccl/backupccl/backup_test.go | 8 ++++---- pkg/ccl/backupccl/restore_planning.go | 2 +- pkg/ccl/backupccl/tenant_backup_nemesis_test.go | 4 ++-- pkg/ccl/backupccl/testdata/backup-restore/restore-tenants | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/ccl/backupccl/backup_test.go b/pkg/ccl/backupccl/backup_test.go index c969c96a4178..814d316153f7 100644 --- a/pkg/ccl/backupccl/backup_test.go +++ b/pkg/ccl/backupccl/backup_test.go @@ -7319,7 +7319,7 @@ func TestBackupRestoreTenant(t *testing.T) { restoreDB.Exec(t, `DROP TENANT [20] IMMEDIATE`) - restoreDB.Exec(t, `RESTORE TENANT 11 FROM 'nodelocal://1/clusterwide' WITH tenant_name = 'tenant-20'`) + restoreDB.Exec(t, `RESTORE TENANT 11 FROM 'nodelocal://1/clusterwide' WITH virtual_cluster_name = 'tenant-20'`) _, restoreConn20 := serverutils.StartTenant( t, restoreTC.Server(0), base.TestTenantArgs{TenantName: "tenant-20", DisableCreateTenant: true}, ) @@ -7333,7 +7333,7 @@ func TestBackupRestoreTenant(t *testing.T) { // Remove tenant 11, then confirm restoring 11 over 10 fails. restoreDB.Exec(t, `DROP TENANT [11] IMMEDIATE`) - restoreDB.ExpectErr(t, `exists`, `RESTORE TENANT 11 FROM 'nodelocal://1/clusterwide' WITH tenant_name = 'tenant-10'`) + restoreDB.ExpectErr(t, `exists`, `RESTORE TENANT 11 FROM 'nodelocal://1/clusterwide' WITH virtual_cluster_name = 'tenant-10'`) // Verify tenant 20 is still unaffected. restoreTenant20.CheckQueryResults(t, `select * from foo.baz`, tenant11.QueryStr(t, `select * from foo.baz`)) @@ -9692,11 +9692,11 @@ func TestProtectRestoreTargets(t *testing.T) { }{ { name: "tenant", - restoreStmt: `RESTORE TENANT 10 FROM LATEST IN $1 WITH detached, tenant_name = 'tenant-20'`, + restoreStmt: `RESTORE TENANT 10 FROM LATEST IN $1 WITH detached, virtual_cluster_name = 'tenant-20'`, }, { name: "tenantid", - restoreStmt: `RESTORE TENANT 10 FROM LATEST IN $1 WITH detached, tenant = '20', tenant_name = 'othername'`, + restoreStmt: `RESTORE TENANT 10 FROM LATEST IN $1 WITH detached, tenant = '20', virtual_cluster_name = 'othername'`, }, { name: "database", diff --git a/pkg/ccl/backupccl/restore_planning.go b/pkg/ccl/backupccl/restore_planning.go index 208cf18c9b65..3d0bbd52260e 100644 --- a/pkg/ccl/backupccl/restore_planning.go +++ b/pkg/ccl/backupccl/restore_planning.go @@ -78,7 +78,7 @@ const ( restoreOptSkipMissingViews = "skip_missing_views" restoreOptSkipLocalitiesCheck = "skip_localities_check" restoreOptDebugPauseOn = "debug_pause_on" - restoreOptAsTenant = "tenant_name" + restoreOptAsTenant = "virtual_cluster_name" restoreOptForceTenantID = "tenant" // The temporary database system tables will be restored into for full diff --git a/pkg/ccl/backupccl/tenant_backup_nemesis_test.go b/pkg/ccl/backupccl/tenant_backup_nemesis_test.go index a579fcea13bd..99fd5250d71f 100644 --- a/pkg/ccl/backupccl/tenant_backup_nemesis_test.go +++ b/pkg/ccl/backupccl/tenant_backup_nemesis_test.go @@ -102,7 +102,7 @@ func TestTenantBackupWithCanceledImport(t *testing.T) { tenant10DB.Exec(t, "SHOW JOBS WHEN COMPLETE (SELECT job_id FROM [SHOW JOBS] WHERE job_type = 'IMPORT')") hostSQLDB.Exec(t, "BACKUP TENANT 10 INTO LATEST IN 'nodelocal://1/tenant-backup'") - hostSQLDB.Exec(t, "RESTORE TENANT 10 FROM LATEST IN 'nodelocal://1/tenant-backup' WITH tenant_name = 'tenant-11'") + hostSQLDB.Exec(t, "RESTORE TENANT 10 FROM LATEST IN 'nodelocal://1/tenant-backup' WITH virtual_cluster_name = 'tenant-11'") tenant11, err := tc.Servers[0].StartTenant(ctx, base.TestTenantArgs{ TenantName: "tenant-11", @@ -245,7 +245,7 @@ func TestTenantBackupNemesis(t *testing.T) { }) require.NoError(t, g.Wait()) - restoreQuery := fmt.Sprintf("RESTORE TENANT 10 FROM LATEST IN '%s' AS OF SYSTEM TIME %s WITH tenant_name = 'tenant-11'", backupLoc, aost) + restoreQuery := fmt.Sprintf("RESTORE TENANT 10 FROM LATEST IN '%s' AS OF SYSTEM TIME %s WITH virtual_cluster_name = 'tenant-11'", backupLoc, aost) t.Logf("backup-nemesis: restoring tenant 10 into 11: %s", restoreQuery) hostSQLDB.Exec(t, restoreQuery) diff --git a/pkg/ccl/backupccl/testdata/backup-restore/restore-tenants b/pkg/ccl/backupccl/testdata/backup-restore/restore-tenants index 3fc105055786..a0ac34d713ce 100644 --- a/pkg/ccl/backupccl/testdata/backup-restore/restore-tenants +++ b/pkg/ccl/backupccl/testdata/backup-restore/restore-tenants @@ -117,17 +117,17 @@ RESTORE TENANT 6 FROM LATEST IN 'nodelocal://1/tenant6'; regex matches error exec-sql expect-error-regex=(invalid tenant name) -RESTORE TENANT 6 FROM LATEST IN 'nodelocal://1/tenant6' WITH tenant_name = 'invalid_name'; +RESTORE TENANT 6 FROM LATEST IN 'nodelocal://1/tenant6' WITH virtual_cluster_name = 'invalid_name'; ---- regex matches error exec-sql expect-error-regex=(tenant with name "tenant-6" already exists) -RESTORE TENANT 6 FROM LATEST IN 'nodelocal://1/tenant6' WITH tenant_name = 'tenant-6'; +RESTORE TENANT 6 FROM LATEST IN 'nodelocal://1/tenant6' WITH virtual_cluster_name = 'tenant-6'; ---- regex matches error exec-sql -RESTORE TENANT 6 FROM LATEST IN 'nodelocal://1/tenant6' WITH tenant_name = 'newname'; +RESTORE TENANT 6 FROM LATEST IN 'nodelocal://1/tenant6' WITH virtual_cluster_name = 'newname'; ---- query-sql @@ -152,7 +152,7 @@ BACKUP TENANT 2 INTO 'nodelocal://1/tenant2' ---- exec-sql -RESTORE TENANT 2 FROM LATEST IN 'nodelocal://1/tenant2' WITH tenant_name = 'another-name'; +RESTORE TENANT 2 FROM LATEST IN 'nodelocal://1/tenant2' WITH virtual_cluster_name = 'another-name'; ---- query-sql From 37c8b014277b90d9468dc5e4c750b8031cfaff4a Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Tue, 4 Jul 2023 14:25:46 +0200 Subject: [PATCH 05/17] sql: new option `VIRTUAL_CLUSTER` This aliases `TENANT` (in `RESTORE` options) which becomes hidden. Release note: None --- docs/generated/sql/bnf/restore_options.bnf | 2 +- docs/generated/sql/bnf/stmt_block.bnf | 7 ++++++- pkg/cmd/docgen/diagrams.go | 2 +- pkg/sql/parser/sql.y | 10 ++++++++-- pkg/sql/parser/testdata/backup_restore | 16 ++++++++++++---- pkg/sql/sem/tree/backup.go | 4 ++-- 6 files changed, 30 insertions(+), 11 deletions(-) diff --git a/docs/generated/sql/bnf/restore_options.bnf b/docs/generated/sql/bnf/restore_options.bnf index 7b43760afa0f..736464485d5a 100644 --- a/docs/generated/sql/bnf/restore_options.bnf +++ b/docs/generated/sql/bnf/restore_options.bnf @@ -15,7 +15,7 @@ restore_options ::= | 'INCLUDE_ALL_VIRTUAL_CLUSTERS' '=' a_expr | 'INCREMENTAL_LOCATION' '=' string_or_placeholder_opt_list | 'VIRTUAL_CLUSTER_NAME' '=' string_or_placeholder - | 'TENANT' '=' string_or_placeholder + | 'VIRTUAL_CLUSTER' '=' string_or_placeholder | 'SCHEMA_ONLY' | 'VERIFY_BACKUP_TABLE_DATA' | 'UNSAFE_RESTORE_INCOMPATIBLE_VERSION' diff --git a/docs/generated/sql/bnf/stmt_block.bnf b/docs/generated/sql/bnf/stmt_block.bnf index e6b8b22557f9..3002841b8513 100644 --- a/docs/generated/sql/bnf/stmt_block.bnf +++ b/docs/generated/sql/bnf/stmt_block.bnf @@ -1466,6 +1466,7 @@ unreserved_keyword ::= | 'VIEWCLUSTERSETTING' | 'VIEWDEBUG' | 'VIRTUAL_CLUSTER_NAME' + | 'VIRTUAL_CLUSTER' | 'VISIBLE' | 'VISIBILITY' | 'VOLATILE' @@ -2692,7 +2693,7 @@ restore_options ::= | include_all_clusters '=' a_expr | 'INCREMENTAL_LOCATION' '=' string_or_placeholder_opt_list | virtual_cluster_name '=' string_or_placeholder - | 'TENANT' '=' string_or_placeholder + | virtual_cluster_opt '=' string_or_placeholder | 'SCHEMA_ONLY' | 'VERIFY_BACKUP_TABLE_DATA' | 'UNSAFE_RESTORE_INCOMPATIBLE_VERSION' @@ -3245,6 +3246,9 @@ array_expr ::= virtual_cluster_name ::= 'VIRTUAL_CLUSTER_NAME' +virtual_cluster_opt ::= + 'VIRTUAL_CLUSTER' + scrub_option ::= 'INDEX' 'ALL' | 'INDEX' '(' name_list ')' @@ -4062,6 +4066,7 @@ bare_label_keywords ::= | 'VIEWDEBUG' | 'VIRTUAL' | 'VIRTUAL_CLUSTER_NAME' + | 'VIRTUAL_CLUSTER' | 'VISIBLE' | 'VISIBILITY' | 'VOLATILE' diff --git a/pkg/cmd/docgen/diagrams.go b/pkg/cmd/docgen/diagrams.go index 1bebcbb7b35b..d4e07ab333df 100644 --- a/pkg/cmd/docgen/diagrams.go +++ b/pkg/cmd/docgen/diagrams.go @@ -1644,7 +1644,7 @@ var specs = []stmtSpec{ }, { name: "restore_options", - inline: []string{"include_all_clusters", "virtual_cluster_name"}, + inline: []string{"include_all_clusters", "virtual_cluster_name", "virtual_cluster_opt"}, }, } diff --git a/pkg/sql/parser/sql.y b/pkg/sql/parser/sql.y index 2eda3e5c8e24..240d86c99e55 100644 --- a/pkg/sql/parser/sql.y +++ b/pkg/sql/parser/sql.y @@ -1007,7 +1007,7 @@ func (u *sqlSymUnion) showCreateFormatOption() tree.ShowCreateFormatOption { %token VALID VALIDATE VALUE VALUES VARBIT VARCHAR VARIADIC VERIFY_BACKUP_TABLE_DATA VIEW VARYING VIEWACTIVITY VIEWACTIVITYREDACTED VIEWDEBUG %token VIEWCLUSTERMETADATA VIEWCLUSTERSETTING VIRTUAL VISIBLE INVISIBLE VISIBILITY VOLATILE VOTERS -%token VIRTUAL_CLUSTER_NAME +%token VIRTUAL_CLUSTER_NAME VIRTUAL_CLUSTER %token WHEN WHERE WINDOW WITH WITHIN WITHOUT WORK WRITE @@ -3802,7 +3802,7 @@ restore_options: { $$.val = &tree.RestoreOptions{AsTenant: $3.expr()} } -| TENANT '=' string_or_placeholder +| virtual_cluster_opt '=' string_or_placeholder { $$.val = &tree.RestoreOptions{ForceTenantID: $3.expr()} } @@ -3819,6 +3819,10 @@ restore_options: $$.val = &tree.RestoreOptions{UnsafeRestoreIncompatibleVersion: true} } +virtual_cluster_opt: + TENANT { /* SKIP DOC */ } +| VIRTUAL_CLUSTER { } + virtual_cluster_name: TENANT_NAME { /* SKIP DOC */ } | VIRTUAL_CLUSTER_NAME { } @@ -16855,6 +16859,7 @@ unreserved_keyword: | VIEWCLUSTERSETTING | VIEWDEBUG | VIRTUAL_CLUSTER_NAME +| VIRTUAL_CLUSTER | VISIBLE | VISIBILITY | VOLATILE @@ -17431,6 +17436,7 @@ bare_label_keywords: | VIEWDEBUG | VIRTUAL | VIRTUAL_CLUSTER_NAME +| VIRTUAL_CLUSTER | VISIBLE | VISIBILITY | VOLATILE diff --git a/pkg/sql/parser/testdata/backup_restore b/pkg/sql/parser/testdata/backup_restore index 66c40edf707d..a247921f4042 100644 --- a/pkg/sql/parser/testdata/backup_restore +++ b/pkg/sql/parser/testdata/backup_restore @@ -768,12 +768,20 @@ RESTORE TENANT _ FROM ($1, $1) WITH virtual_cluster_name = '_' -- literals remov RESTORE TENANT 36 FROM ($1, $2) WITH virtual_cluster_name = 'tenant-5' -- identifiers removed parse -RESTORE TENANT 36 FROM ($1, $2) WITH tenant = '5' +RESTORE TENANT 36 FROM ($1, $2) WITH virtual_cluster = '5' ---- +RESTORE TENANT 36 FROM ($1, $2) WITH virtual_cluster = '5' +RESTORE TENANT 36 FROM (($1), ($2)) WITH virtual_cluster = ('5') -- fully parenthesized +RESTORE TENANT _ FROM ($1, $1) WITH virtual_cluster = '_' -- literals removed +RESTORE TENANT 36 FROM ($1, $2) WITH virtual_cluster = '5' -- identifiers removed + +parse RESTORE TENANT 36 FROM ($1, $2) WITH tenant = '5' -RESTORE TENANT 36 FROM (($1), ($2)) WITH tenant = ('5') -- fully parenthesized -RESTORE TENANT _ FROM ($1, $1) WITH tenant = '_' -- literals removed -RESTORE TENANT 36 FROM ($1, $2) WITH tenant = '5' -- identifiers removed +---- +RESTORE TENANT 36 FROM ($1, $2) WITH virtual_cluster = '5' -- normalized! +RESTORE TENANT 36 FROM (($1), ($2)) WITH virtual_cluster = ('5') -- fully parenthesized +RESTORE TENANT _ FROM ($1, $1) WITH virtual_cluster = '_' -- literals removed +RESTORE TENANT 36 FROM ($1, $2) WITH virtual_cluster = '5' -- identifiers removed parse BACKUP TABLE foo TO 'bar' WITH revision_history, detached diff --git a/pkg/sql/sem/tree/backup.go b/pkg/sql/sem/tree/backup.go index 0b3d77f88899..c18318690934 100644 --- a/pkg/sql/sem/tree/backup.go +++ b/pkg/sql/sem/tree/backup.go @@ -475,7 +475,7 @@ func (o *RestoreOptions) Format(ctx *FmtCtx) { if o.ForceTenantID != nil { maybeAddSep() - ctx.WriteString("tenant = ") + ctx.WriteString("virtual_cluster = ") ctx.FormatNode(o.ForceTenantID) } @@ -598,7 +598,7 @@ func (o *RestoreOptions) CombineWith(other *RestoreOptions) error { if o.ForceTenantID == nil { o.ForceTenantID = other.ForceTenantID } else if other.ForceTenantID != nil { - return errors.New("tenant option specified multiple times") + return errors.New("virtual_cluster option specified multiple times") } if o.SchemaOnly { From 046a107d04977ee954006d388b2a9e1571d30f3d Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Tue, 4 Jul 2023 14:28:17 +0200 Subject: [PATCH 06/17] backupccl: use the `virtual_cluster` option in tests Release note: None --- pkg/ccl/backupccl/backup_test.go | 2 +- pkg/ccl/backupccl/restore_planning.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/ccl/backupccl/backup_test.go b/pkg/ccl/backupccl/backup_test.go index 814d316153f7..baa9b49f0ee8 100644 --- a/pkg/ccl/backupccl/backup_test.go +++ b/pkg/ccl/backupccl/backup_test.go @@ -9696,7 +9696,7 @@ func TestProtectRestoreTargets(t *testing.T) { }, { name: "tenantid", - restoreStmt: `RESTORE TENANT 10 FROM LATEST IN $1 WITH detached, tenant = '20', virtual_cluster_name = 'othername'`, + restoreStmt: `RESTORE TENANT 10 FROM LATEST IN $1 WITH detached, virtual_cluster = '20', virtual_cluster_name = 'othername'`, }, { name: "database", diff --git a/pkg/ccl/backupccl/restore_planning.go b/pkg/ccl/backupccl/restore_planning.go index 3d0bbd52260e..35fde530514e 100644 --- a/pkg/ccl/backupccl/restore_planning.go +++ b/pkg/ccl/backupccl/restore_planning.go @@ -79,7 +79,7 @@ const ( restoreOptSkipLocalitiesCheck = "skip_localities_check" restoreOptDebugPauseOn = "debug_pause_on" restoreOptAsTenant = "virtual_cluster_name" - restoreOptForceTenantID = "tenant" + restoreOptForceTenantID = "virtual_cluster" // The temporary database system tables will be restored into for full // cluster backups. From 386e207eb0e19de08428eaa7b915f3cdd74d957a Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Tue, 4 Jul 2023 14:35:59 +0200 Subject: [PATCH 07/17] sql: `CREATE VIRTUAL CLUSTER` (aliased by `CREATE TENANT`) Release note: None --- .../streamingccl/streamingest/testdata/simple | 2 +- pkg/sql/logictest/testdata/logic_test/tenant | 2 +- pkg/sql/parser/help_test.go | 3 +- pkg/sql/parser/sql.y | 28 +++-- pkg/sql/parser/testdata/create_tenant | 103 ---------------- .../parser/testdata/create_virtual_cluster | 111 ++++++++++++++++++ pkg/sql/parser/testdata/prepared_stmts | 26 ++-- pkg/sql/sem/tree/create.go | 12 +- pkg/sql/sem/tree/stmt.go | 6 +- 9 files changed, 158 insertions(+), 135 deletions(-) delete mode 100644 pkg/sql/parser/testdata/create_tenant create mode 100644 pkg/sql/parser/testdata/create_virtual_cluster diff --git a/pkg/ccl/streamingccl/streamingest/testdata/simple b/pkg/ccl/streamingccl/streamingest/testdata/simple index fc0b0931f71d..0cddcbf835f5 100644 --- a/pkg/ccl/streamingccl/streamingest/testdata/simple +++ b/pkg/ccl/streamingccl/streamingest/testdata/simple @@ -23,7 +23,7 @@ CREATE FUNCTION strip_host(s string) returns string language sql AS $$ select co query-sql as=destination-system SELECT strip_host(description) FROM [SHOW JOBS] WHERE job_type='STREAM INGESTION' ---- -CREATE TENANT destination FROM REPLICATION OF source ON 'postgres://root@?sslcert=redacted&sslkey=redacted&sslmode=verify-full&sslrootcert=redacted' +CREATE VIRTUAL CLUSTER destination FROM REPLICATION OF source ON 'postgres://root@?sslcert=redacted&sslkey=redacted&sslmode=verify-full&sslrootcert=redacted' query-sql as=destination-system SELECT strip_host(source_cluster_uri) FROM [SHOW TENANT destination WITH REPLICATION STATUS] diff --git a/pkg/sql/logictest/testdata/logic_test/tenant b/pkg/sql/logictest/testdata/logic_test/tenant index 10f25a72452b..f16cc788bb7a 100644 --- a/pkg/sql/logictest/testdata/logic_test/tenant +++ b/pkg/sql/logictest/testdata/logic_test/tenant @@ -134,7 +134,7 @@ CREATE TENANT IF NOT EXISTS three statement ok set default_transaction_read_only = on; -statement error cannot execute CREATE TENANT in a read-only transaction +statement error cannot execute CREATE VIRTUAL CLUSTER in a read-only transaction CREATE TENANT four; statement ok diff --git a/pkg/sql/parser/help_test.go b/pkg/sql/parser/help_test.go index 641a0385d705..c5daa6f4064a 100644 --- a/pkg/sql/parser/help_test.go +++ b/pkg/sql/parser/help_test.go @@ -153,7 +153,8 @@ func TestContextualHelp(t *testing.T) { {`CREATE EXTERNAL CONNECTION ??`, `CREATE EXTERNAL CONNECTION`}, - {`CREATE TENANT ??`, `CREATE TENANT`}, + {`CREATE VIRTUAL CLUSTER ??`, `CREATE VIRTUAL CLUSTER`}, + {`CREATE TENANT ??`, `CREATE VIRTUAL CLUSTER`}, {`CREATE USER blih ??`, `CREATE ROLE`}, {`CREATE USER blih WITH ??`, `CREATE ROLE`}, diff --git a/pkg/sql/parser/sql.y b/pkg/sql/parser/sql.y index 240d86c99e55..e26a6907fbe2 100644 --- a/pkg/sql/parser/sql.y +++ b/pkg/sql/parser/sql.y @@ -1188,7 +1188,7 @@ func (u *sqlSymUnion) showCreateFormatOption() tree.ShowCreateFormatOption { %type create_schema_stmt %type create_table_stmt %type create_table_as_stmt -%type create_tenant_stmt +%type create_virtual_cluster_stmt %type create_view_stmt %type create_sequence_stmt %type create_func_stmt @@ -4411,18 +4411,18 @@ create_stmt: | create_changefeed_stmt // EXTEND WITH HELP: CREATE CHANGEFEED | create_extension_stmt // EXTEND WITH HELP: CREATE EXTENSION | create_external_connection_stmt // EXTEND WITH HELP: CREATE EXTERNAL CONNECTION -| create_tenant_stmt // EXTEND WITH HELP: CREATE TENANT +| create_virtual_cluster_stmt // EXTEND WITH HELP: CREATE VIRTUAL CLUSTER | create_schedule_stmt // help texts in sub-rule | create_unsupported {} | CREATE error // SHOW HELP: CREATE -// %Help: CREATE TENANT - create new tenant +// %Help: CREATE VIRTUAL CLUSTER - create a new virtual cluster // %Category: Experimental // %Text: -// CREATE TENANT [ IF NOT EXISTS ] name [ LIKE ] -// CREATE TENANT [ IF NOT EXISTS ] name [ LIKE ] FROM REPLICATION OF ON [ WITH OPTIONS ... ] -create_tenant_stmt: - CREATE TENANT d_expr opt_like_tenant +// CREATE VIRTUAL CLUSTER [ IF NOT EXISTS ] name [ LIKE ] +// CREATE VIRTUAL CLUSTER [ IF NOT EXISTS ] name [ LIKE ] FROM REPLICATION OF ON [ WITH OPTIONS ... ] +create_virtual_cluster_stmt: + CREATE virtual_cluster d_expr opt_like_tenant { /* SKIP DOC */ $$.val = &tree.CreateTenant{ @@ -4430,7 +4430,7 @@ create_tenant_stmt: Like: $4.likeTenantSpec(), } } -| CREATE TENANT IF NOT EXISTS d_expr opt_like_tenant +| CREATE virtual_cluster IF NOT EXISTS d_expr opt_like_tenant { /* SKIP DOC */ $$.val = &tree.CreateTenant{ @@ -4439,7 +4439,7 @@ create_tenant_stmt: Like: $7.likeTenantSpec(), } } -| CREATE TENANT d_expr opt_like_tenant FROM REPLICATION OF d_expr ON d_expr opt_with_tenant_replication_options +| CREATE virtual_cluster d_expr opt_like_tenant FROM REPLICATION OF d_expr ON d_expr opt_with_tenant_replication_options { /* SKIP DOC */ $$.val = &tree.CreateTenantFromReplication{ @@ -4450,7 +4450,7 @@ create_tenant_stmt: Like: $4.likeTenantSpec(), } } -| CREATE TENANT IF NOT EXISTS d_expr opt_like_tenant FROM REPLICATION OF d_expr ON d_expr opt_with_tenant_replication_options +| CREATE virtual_cluster IF NOT EXISTS d_expr opt_like_tenant FROM REPLICATION OF d_expr ON d_expr opt_with_tenant_replication_options { /* SKIP DOC */ $$.val = &tree.CreateTenantFromReplication{ @@ -4462,9 +4462,13 @@ create_tenant_stmt: Like: $7.likeTenantSpec(), } } -| CREATE TENANT error // SHOW HELP: CREATE TENANT +| CREATE virtual_cluster error // SHOW HELP: CREATE VIRTUAL CLUSTER -// opt_like_tenant defines a LIKE clause for CREATE TENANT. +virtual_cluster: + TENANT { /* SKIP DOC */ } +| VIRTUAL CLUSTER + +// opt_like_tenant defines a LIKE clause for CREATE VIRTUAL CLUSTER. // Eventually this can grow to support INCLUDING/EXCLUDING options // like in CREATE TABLE. opt_like_tenant: diff --git a/pkg/sql/parser/testdata/create_tenant b/pkg/sql/parser/testdata/create_tenant deleted file mode 100644 index aab67a4f6eb6..000000000000 --- a/pkg/sql/parser/testdata/create_tenant +++ /dev/null @@ -1,103 +0,0 @@ -parse -CREATE TENANT bar ----- -CREATE TENANT bar -CREATE TENANT (bar) -- fully parenthesized -CREATE TENANT bar -- literals removed -CREATE TENANT _ -- identifiers removed - -parse -CREATE TENANT "bar-with-hyphen" ----- -CREATE TENANT "bar-with-hyphen" -CREATE TENANT ("bar-with-hyphen") -- fully parenthesized -CREATE TENANT "bar-with-hyphen" -- literals removed -CREATE TENANT _ -- identifiers removed - -parse -CREATE TENANT IF NOT EXISTS bar ----- -CREATE TENANT IF NOT EXISTS bar -CREATE TENANT IF NOT EXISTS (bar) -- fully parenthesized -CREATE TENANT IF NOT EXISTS bar -- literals removed -CREATE TENANT IF NOT EXISTS _ -- identifiers removed - -parse -CREATE TENANT foo LIKE bar ----- -CREATE TENANT foo LIKE bar -CREATE TENANT (foo) LIKE (bar) -- fully parenthesized -CREATE TENANT foo LIKE bar -- literals removed -CREATE TENANT _ LIKE _ -- identifiers removed - -parse -CREATE TENANT foo LIKE [123] ----- -CREATE TENANT foo LIKE [123] -CREATE TENANT (foo) LIKE [(123)] -- fully parenthesized -CREATE TENANT foo LIKE [_] -- literals removed -CREATE TENANT _ LIKE [123] -- identifiers removed - -parse -CREATE TENANT destination FROM REPLICATION OF source ON 'pgurl' ----- -CREATE TENANT destination FROM REPLICATION OF source ON 'pgurl' -CREATE TENANT (destination) FROM REPLICATION OF (source) ON ('pgurl') -- fully parenthesized -CREATE TENANT destination FROM REPLICATION OF source ON '_' -- literals removed -CREATE TENANT _ FROM REPLICATION OF _ ON 'pgurl' -- identifiers removed - -parse -CREATE TENANT IF NOT EXISTS destination FROM REPLICATION OF source ON 'pgurl' ----- -CREATE TENANT IF NOT EXISTS destination FROM REPLICATION OF source ON 'pgurl' -CREATE TENANT IF NOT EXISTS (destination) FROM REPLICATION OF (source) ON ('pgurl') -- fully parenthesized -CREATE TENANT IF NOT EXISTS destination FROM REPLICATION OF source ON '_' -- literals removed -CREATE TENANT IF NOT EXISTS _ FROM REPLICATION OF _ ON 'pgurl' -- identifiers removed - -parse -CREATE TENANT destination LIKE bar FROM REPLICATION OF source ON 'pgurl' ----- -CREATE TENANT destination LIKE bar FROM REPLICATION OF source ON 'pgurl' -CREATE TENANT (destination) LIKE (bar) FROM REPLICATION OF (source) ON ('pgurl') -- fully parenthesized -CREATE TENANT destination LIKE bar FROM REPLICATION OF source ON '_' -- literals removed -CREATE TENANT _ LIKE _ FROM REPLICATION OF _ ON 'pgurl' -- identifiers removed - -parse -CREATE TENANT destination LIKE [123] FROM REPLICATION OF source ON 'pgurl' ----- -CREATE TENANT destination LIKE [123] FROM REPLICATION OF source ON 'pgurl' -CREATE TENANT (destination) LIKE [(123)] FROM REPLICATION OF (source) ON ('pgurl') -- fully parenthesized -CREATE TENANT destination LIKE [_] FROM REPLICATION OF source ON '_' -- literals removed -CREATE TENANT _ LIKE [123] FROM REPLICATION OF _ ON 'pgurl' -- identifiers removed - -parse -CREATE TENANT "destination-hyphen" FROM REPLICATION OF "source-hyphen" ON 'pgurl' ----- -CREATE TENANT "destination-hyphen" FROM REPLICATION OF "source-hyphen" ON 'pgurl' -CREATE TENANT ("destination-hyphen") FROM REPLICATION OF ("source-hyphen") ON ('pgurl') -- fully parenthesized -CREATE TENANT "destination-hyphen" FROM REPLICATION OF "source-hyphen" ON '_' -- literals removed -CREATE TENANT _ FROM REPLICATION OF _ ON 'pgurl' -- identifiers removed - -parse -CREATE TENANT "destination-hyphen" FROM REPLICATION OF "source-hyphen" ON 'pgurl' WITH RETENTION = '36h' ----- -CREATE TENANT "destination-hyphen" FROM REPLICATION OF "source-hyphen" ON 'pgurl' WITH RETENTION = '36h' -CREATE TENANT ("destination-hyphen") FROM REPLICATION OF ("source-hyphen") ON ('pgurl') WITH RETENTION = ('36h') -- fully parenthesized -CREATE TENANT "destination-hyphen" FROM REPLICATION OF "source-hyphen" ON '_' WITH RETENTION = '_' -- literals removed -CREATE TENANT _ FROM REPLICATION OF _ ON 'pgurl' WITH RETENTION = '36h' -- identifiers removed - -parse -CREATE TENANT "destination-hyphen" FROM REPLICATION OF "source-hyphen" ON 'pgurl' WITH OPTIONS (RETENTION = '36h') ----- -CREATE TENANT "destination-hyphen" FROM REPLICATION OF "source-hyphen" ON 'pgurl' WITH RETENTION = '36h' -- normalized! -CREATE TENANT ("destination-hyphen") FROM REPLICATION OF ("source-hyphen") ON ('pgurl') WITH RETENTION = ('36h') -- fully parenthesized -CREATE TENANT "destination-hyphen" FROM REPLICATION OF "source-hyphen" ON '_' WITH RETENTION = '_' -- literals removed -CREATE TENANT _ FROM REPLICATION OF _ ON 'pgurl' WITH RETENTION = '36h' -- identifiers removed - -parse -CREATE TENANT destination FROM REPLICATION OF ('a'||'b') ON ('pg'||'url') ----- -CREATE TENANT destination FROM REPLICATION OF ('a' || 'b') ON ('pg' || 'url') -- normalized! -CREATE TENANT (destination) FROM REPLICATION OF (((('a') || ('b')))) ON (((('pg') || ('url')))) -- fully parenthesized -CREATE TENANT destination FROM REPLICATION OF ('_' || '_') ON ('_' || '_') -- literals removed -CREATE TENANT _ FROM REPLICATION OF ('a' || 'b') ON ('pg' || 'url') -- identifiers removed diff --git a/pkg/sql/parser/testdata/create_virtual_cluster b/pkg/sql/parser/testdata/create_virtual_cluster new file mode 100644 index 000000000000..0d149f113b26 --- /dev/null +++ b/pkg/sql/parser/testdata/create_virtual_cluster @@ -0,0 +1,111 @@ +parse +CREATE VIRTUAL CLUSTER bar +---- +CREATE VIRTUAL CLUSTER bar +CREATE VIRTUAL CLUSTER (bar) -- fully parenthesized +CREATE VIRTUAL CLUSTER bar -- literals removed +CREATE VIRTUAL CLUSTER _ -- identifiers removed + +parse +CREATE TENANT bar +---- +CREATE VIRTUAL CLUSTER bar -- normalized! +CREATE VIRTUAL CLUSTER (bar) -- fully parenthesized +CREATE VIRTUAL CLUSTER bar -- literals removed +CREATE VIRTUAL CLUSTER _ -- identifiers removed + +parse +CREATE VIRTUAL CLUSTER "bar-with-hyphen" +---- +CREATE VIRTUAL CLUSTER "bar-with-hyphen" +CREATE VIRTUAL CLUSTER ("bar-with-hyphen") -- fully parenthesized +CREATE VIRTUAL CLUSTER "bar-with-hyphen" -- literals removed +CREATE VIRTUAL CLUSTER _ -- identifiers removed + +parse +CREATE VIRTUAL CLUSTER IF NOT EXISTS bar +---- +CREATE VIRTUAL CLUSTER IF NOT EXISTS bar +CREATE VIRTUAL CLUSTER IF NOT EXISTS (bar) -- fully parenthesized +CREATE VIRTUAL CLUSTER IF NOT EXISTS bar -- literals removed +CREATE VIRTUAL CLUSTER IF NOT EXISTS _ -- identifiers removed + +parse +CREATE VIRTUAL CLUSTER foo LIKE bar +---- +CREATE VIRTUAL CLUSTER foo LIKE bar +CREATE VIRTUAL CLUSTER (foo) LIKE (bar) -- fully parenthesized +CREATE VIRTUAL CLUSTER foo LIKE bar -- literals removed +CREATE VIRTUAL CLUSTER _ LIKE _ -- identifiers removed + +parse +CREATE VIRTUAL CLUSTER foo LIKE [123] +---- +CREATE VIRTUAL CLUSTER foo LIKE [123] +CREATE VIRTUAL CLUSTER (foo) LIKE [(123)] -- fully parenthesized +CREATE VIRTUAL CLUSTER foo LIKE [_] -- literals removed +CREATE VIRTUAL CLUSTER _ LIKE [123] -- identifiers removed + +parse +CREATE VIRTUAL CLUSTER destination FROM REPLICATION OF source ON 'pgurl' +---- +CREATE VIRTUAL CLUSTER destination FROM REPLICATION OF source ON 'pgurl' +CREATE VIRTUAL CLUSTER (destination) FROM REPLICATION OF (source) ON ('pgurl') -- fully parenthesized +CREATE VIRTUAL CLUSTER destination FROM REPLICATION OF source ON '_' -- literals removed +CREATE VIRTUAL CLUSTER _ FROM REPLICATION OF _ ON 'pgurl' -- identifiers removed + +parse +CREATE VIRTUAL CLUSTER IF NOT EXISTS destination FROM REPLICATION OF source ON 'pgurl' +---- +CREATE VIRTUAL CLUSTER IF NOT EXISTS destination FROM REPLICATION OF source ON 'pgurl' +CREATE VIRTUAL CLUSTER IF NOT EXISTS (destination) FROM REPLICATION OF (source) ON ('pgurl') -- fully parenthesized +CREATE VIRTUAL CLUSTER IF NOT EXISTS destination FROM REPLICATION OF source ON '_' -- literals removed +CREATE VIRTUAL CLUSTER IF NOT EXISTS _ FROM REPLICATION OF _ ON 'pgurl' -- identifiers removed + +parse +CREATE VIRTUAL CLUSTER destination LIKE bar FROM REPLICATION OF source ON 'pgurl' +---- +CREATE VIRTUAL CLUSTER destination LIKE bar FROM REPLICATION OF source ON 'pgurl' +CREATE VIRTUAL CLUSTER (destination) LIKE (bar) FROM REPLICATION OF (source) ON ('pgurl') -- fully parenthesized +CREATE VIRTUAL CLUSTER destination LIKE bar FROM REPLICATION OF source ON '_' -- literals removed +CREATE VIRTUAL CLUSTER _ LIKE _ FROM REPLICATION OF _ ON 'pgurl' -- identifiers removed + +parse +CREATE VIRTUAL CLUSTER destination LIKE [123] FROM REPLICATION OF source ON 'pgurl' +---- +CREATE VIRTUAL CLUSTER destination LIKE [123] FROM REPLICATION OF source ON 'pgurl' +CREATE VIRTUAL CLUSTER (destination) LIKE [(123)] FROM REPLICATION OF (source) ON ('pgurl') -- fully parenthesized +CREATE VIRTUAL CLUSTER destination LIKE [_] FROM REPLICATION OF source ON '_' -- literals removed +CREATE VIRTUAL CLUSTER _ LIKE [123] FROM REPLICATION OF _ ON 'pgurl' -- identifiers removed + +parse +CREATE VIRTUAL CLUSTER "destination-hyphen" FROM REPLICATION OF "source-hyphen" ON 'pgurl' +---- +CREATE VIRTUAL CLUSTER "destination-hyphen" FROM REPLICATION OF "source-hyphen" ON 'pgurl' +CREATE VIRTUAL CLUSTER ("destination-hyphen") FROM REPLICATION OF ("source-hyphen") ON ('pgurl') -- fully parenthesized +CREATE VIRTUAL CLUSTER "destination-hyphen" FROM REPLICATION OF "source-hyphen" ON '_' -- literals removed +CREATE VIRTUAL CLUSTER _ FROM REPLICATION OF _ ON 'pgurl' -- identifiers removed + +parse +CREATE VIRTUAL CLUSTER "destination-hyphen" FROM REPLICATION OF "source-hyphen" ON 'pgurl' WITH RETENTION = '36h' +---- +CREATE VIRTUAL CLUSTER "destination-hyphen" FROM REPLICATION OF "source-hyphen" ON 'pgurl' WITH RETENTION = '36h' +CREATE VIRTUAL CLUSTER ("destination-hyphen") FROM REPLICATION OF ("source-hyphen") ON ('pgurl') WITH RETENTION = ('36h') -- fully parenthesized +CREATE VIRTUAL CLUSTER "destination-hyphen" FROM REPLICATION OF "source-hyphen" ON '_' WITH RETENTION = '_' -- literals removed +CREATE VIRTUAL CLUSTER _ FROM REPLICATION OF _ ON 'pgurl' WITH RETENTION = '36h' -- identifiers removed + +parse +CREATE VIRTUAL CLUSTER "destination-hyphen" FROM REPLICATION OF "source-hyphen" ON 'pgurl' WITH OPTIONS (RETENTION = '36h') +---- +CREATE VIRTUAL CLUSTER "destination-hyphen" FROM REPLICATION OF "source-hyphen" ON 'pgurl' WITH RETENTION = '36h' -- normalized! +CREATE VIRTUAL CLUSTER ("destination-hyphen") FROM REPLICATION OF ("source-hyphen") ON ('pgurl') WITH RETENTION = ('36h') -- fully parenthesized +CREATE VIRTUAL CLUSTER "destination-hyphen" FROM REPLICATION OF "source-hyphen" ON '_' WITH RETENTION = '_' -- literals removed +CREATE VIRTUAL CLUSTER _ FROM REPLICATION OF _ ON 'pgurl' WITH RETENTION = '36h' -- identifiers removed + +parse +CREATE VIRTUAL CLUSTER destination FROM REPLICATION OF ('a'||'b') ON ('pg'||'url') +---- +CREATE VIRTUAL CLUSTER destination FROM REPLICATION OF ('a' || 'b') ON ('pg' || 'url') -- normalized! +CREATE VIRTUAL CLUSTER (destination) FROM REPLICATION OF (((('a') || ('b')))) ON (((('pg') || ('url')))) -- fully parenthesized +CREATE VIRTUAL CLUSTER destination FROM REPLICATION OF ('_' || '_') ON ('_' || '_') -- literals removed +CREATE VIRTUAL CLUSTER _ FROM REPLICATION OF ('a' || 'b') ON ('pg' || 'url') -- identifiers removed diff --git a/pkg/sql/parser/testdata/prepared_stmts b/pkg/sql/parser/testdata/prepared_stmts index b3f891f694ad..0d280dbb1bee 100644 --- a/pkg/sql/parser/testdata/prepared_stmts +++ b/pkg/sql/parser/testdata/prepared_stmts @@ -191,20 +191,28 @@ PREPARE a (STRING) AS CANCEL SESSIONS IF EXISTS SELECT $1 -- literals removed PREPARE _ (STRING) AS CANCEL SESSIONS IF EXISTS SELECT $1 -- identifiers removed parse -PREPARE a AS CREATE TENANT "some-string" +PREPARE a AS CREATE VIRTUAL CLUSTER "some-string" ---- +PREPARE a AS CREATE VIRTUAL CLUSTER "some-string" +PREPARE a AS CREATE VIRTUAL CLUSTER ("some-string") -- fully parenthesized +PREPARE a AS CREATE VIRTUAL CLUSTER "some-string" -- literals removed +PREPARE _ AS CREATE VIRTUAL CLUSTER _ -- identifiers removed + +parse PREPARE a AS CREATE TENANT "some-string" -PREPARE a AS CREATE TENANT ("some-string") -- fully parenthesized -PREPARE a AS CREATE TENANT "some-string" -- literals removed -PREPARE _ AS CREATE TENANT _ -- identifiers removed +---- +PREPARE a AS CREATE VIRTUAL CLUSTER "some-string" -- normalized! +PREPARE a AS CREATE VIRTUAL CLUSTER ("some-string") -- fully parenthesized +PREPARE a AS CREATE VIRTUAL CLUSTER "some-string" -- literals removed +PREPARE _ AS CREATE VIRTUAL CLUSTER _ -- identifiers removed parse -PREPARE a (STRING) AS CREATE TENANT a +PREPARE a (STRING) AS CREATE VIRTUAL CLUSTER a ---- -PREPARE a (STRING) AS CREATE TENANT a -PREPARE a (STRING) AS CREATE TENANT (a) -- fully parenthesized -PREPARE a (STRING) AS CREATE TENANT a -- literals removed -PREPARE _ (STRING) AS CREATE TENANT _ -- identifiers removed +PREPARE a (STRING) AS CREATE VIRTUAL CLUSTER a +PREPARE a (STRING) AS CREATE VIRTUAL CLUSTER (a) -- fully parenthesized +PREPARE a (STRING) AS CREATE VIRTUAL CLUSTER a -- literals removed +PREPARE _ (STRING) AS CREATE VIRTUAL CLUSTER _ -- identifiers removed parse PREPARE a AS CANCEL JOBS SELECT 1 diff --git a/pkg/sql/sem/tree/create.go b/pkg/sql/sem/tree/create.go index ae440b751d6e..f003f5f6a6df 100644 --- a/pkg/sql/sem/tree/create.go +++ b/pkg/sql/sem/tree/create.go @@ -2178,7 +2178,7 @@ func (node *CreateExternalConnection) Format(ctx *FmtCtx) { ctx.FormatNode(node.As) } -// CreateTenant represents a CREATE TENANT statement. +// CreateTenant represents a CREATE VIRTUAL CLUSTER statement. type CreateTenant struct { IfNotExists bool TenantSpec *TenantSpec @@ -2187,7 +2187,7 @@ type CreateTenant struct { // Format implements the NodeFormatter interface. func (node *CreateTenant) Format(ctx *FmtCtx) { - ctx.WriteString("CREATE TENANT ") + ctx.WriteString("CREATE VIRTUAL CLUSTER ") if node.IfNotExists { ctx.WriteString("IF NOT EXISTS ") } @@ -2195,7 +2195,7 @@ func (node *CreateTenant) Format(ctx *FmtCtx) { ctx.FormatNode(node.Like) } -// LikeTenantSpec represents a LIKE clause in CREATE TENANT. +// LikeTenantSpec represents a LIKE clause in CREATE VIRTUAL CLUSTER. type LikeTenantSpec struct { OtherTenant *TenantSpec } @@ -2208,7 +2208,7 @@ func (node *LikeTenantSpec) Format(ctx *FmtCtx) { ctx.FormatNode(node.OtherTenant) } -// CreateTenantFromReplication represents a CREATE TENANT...FROM REPLICATION +// CreateTenantFromReplication represents a CREATE VIRTUAL CLUSTER...FROM REPLICATION // statement. type CreateTenantFromReplication struct { IfNotExists bool @@ -2230,7 +2230,7 @@ type CreateTenantFromReplication struct { Like *LikeTenantSpec } -// TenantReplicationOptions options for the CREATE TENANT FROM REPLICATION command. +// TenantReplicationOptions options for the CREATE VIRTUAL CLUSTER FROM REPLICATION command. type TenantReplicationOptions struct { Retention Expr } @@ -2239,7 +2239,7 @@ var _ NodeFormatter = &TenantReplicationOptions{} // Format implements the NodeFormatter interface. func (node *CreateTenantFromReplication) Format(ctx *FmtCtx) { - ctx.WriteString("CREATE TENANT ") + ctx.WriteString("CREATE VIRTUAL CLUSTER ") if node.IfNotExists { ctx.WriteString("IF NOT EXISTS ") } diff --git a/pkg/sql/sem/tree/stmt.go b/pkg/sql/sem/tree/stmt.go index 0c58cd4e19b2..b93138fb1ca8 100644 --- a/pkg/sql/sem/tree/stmt.go +++ b/pkg/sql/sem/tree/stmt.go @@ -854,7 +854,7 @@ func (*CreateTenant) StatementReturnType() StatementReturnType { return Ack } func (*CreateTenant) StatementType() StatementType { return TypeDCL } // StatementTag returns a short string identifying the type of statement. -func (*CreateTenant) StatementTag() string { return "CREATE TENANT" } +func (*CreateTenant) StatementTag() string { return "CREATE VIRTUAL CLUSTER" } // StatementReturnType implements the Statement interface. func (*CreateTenantFromReplication) StatementReturnType() StatementReturnType { return Rows } @@ -863,7 +863,9 @@ func (*CreateTenantFromReplication) StatementReturnType() StatementReturnType { func (*CreateTenantFromReplication) StatementType() StatementType { return TypeDML } // StatementTag returns a short string identifying the type of statement. -func (*CreateTenantFromReplication) StatementTag() string { return "CREATE TENANT FROM REPLICATION" } +func (*CreateTenantFromReplication) StatementTag() string { + return "CREATE VIRTUAL CLUSTER FROM REPLICATION" +} func (*CreateTenantFromReplication) cclOnlyStatement() {} From 2375b61f43e5ebd5610c919db9c5087515e796f6 Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Tue, 4 Jul 2023 17:25:07 +0200 Subject: [PATCH 08/17] sql: use `CREATE VIRTUAL CLUSTER` in errors and help texts Release note: None --- pkg/ccl/streamingccl/streamingest/alter_replication_job.go | 2 +- .../streamingccl/streamingest/stream_ingestion_planning.go | 4 ++-- pkg/configprofiles/profiles.go | 6 +++--- pkg/sql/create_tenant.go | 4 ++-- pkg/sql/sem/builtins/builtins.go | 4 ++-- pkg/sql/tenant_accessors.go | 2 +- pkg/sql/tenant_creation.go | 2 +- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pkg/ccl/streamingccl/streamingest/alter_replication_job.go b/pkg/ccl/streamingccl/streamingest/alter_replication_job.go index 86ba6e777464..eb5593f0a06b 100644 --- a/pkg/ccl/streamingccl/streamingest/alter_replication_job.go +++ b/pkg/ccl/streamingccl/streamingest/alter_replication_job.go @@ -40,7 +40,7 @@ var alterReplicationCutoverHeader = colinfo.ResultColumns{ } // ResolvedTenantReplicationOptions represents options from an -// evaluated CREATE TENANT FROM REPLICATION command. +// evaluated CREATE VIRTUAL CLUSTER FROM REPLICATION command. type resolvedTenantReplicationOptions struct { retention *int32 } diff --git a/pkg/ccl/streamingccl/streamingest/stream_ingestion_planning.go b/pkg/ccl/streamingccl/streamingest/stream_ingestion_planning.go index 88c76a2aa04f..1cce8df90ba2 100644 --- a/pkg/ccl/streamingccl/streamingest/stream_ingestion_planning.go +++ b/pkg/ccl/streamingccl/streamingest/stream_ingestion_planning.go @@ -152,7 +152,7 @@ func ingestionPlanHook( if err := utilccl.CheckEnterpriseEnabled( p.ExecCfg().Settings, p.ExecCfg().NodeInfo.LogicalClusterID(), - "CREATE TENANT FROM REPLICATION", + "CREATE VIRTUAL CLUSTER FROM REPLICATION", ); err != nil { return err } @@ -218,7 +218,7 @@ func ingestionPlanHook( } // Create the producer job first for the purpose of observability, user is // able to know the producer job id immediately after executing - // CREATE TENANT ... FROM REPLICATION. + // CREATE VIRTUAL CLUSTER ... FROM REPLICATION. replicationProducerSpec, err := client.Create(ctx, roachpb.TenantName(sourceTenant)) if err != nil { return err diff --git a/pkg/configprofiles/profiles.go b/pkg/configprofiles/profiles.go index e31de8f0c149..d7975421de7f 100644 --- a/pkg/configprofiles/profiles.go +++ b/pkg/configprofiles/profiles.go @@ -101,7 +101,7 @@ var multitenantClusterInitTasks = []autoconfigpb.Task{ /* txnSQL */ []string{ // Create a main secondary tenant template. - "CREATE TENANT template", + "CREATE VIRTUAL CLUSTER template", "ALTER TENANT template GRANT ALL CAPABILITIES", // Enable admin scatter/split in tenant SQL. // TODO(knz): Move this to in-tenant config task. @@ -110,7 +110,7 @@ var multitenantClusterInitTasks = []autoconfigpb.Task{ }, ), // Finally. - makeTask("use the application tenant template by default in CREATE TENANT", + makeTask("use the application tenant template by default in CREATE VIRTUAL CLUSTER", /* nonTxnSQL */ []string{ "SET CLUSTER SETTING sql.create_tenant.default_template = 'template'", }, @@ -124,7 +124,7 @@ var multitenantClusterWithAppServiceInitTasks = append( nil, /* nonTxnSQL */ /* txnSQL */ []string{ // Create the app tenant record. - "CREATE TENANT application", + "CREATE VIRTUAL CLUSTER application", // Run the service for the application tenant. "ALTER TENANT application START SERVICE SHARED", }, diff --git a/pkg/sql/create_tenant.go b/pkg/sql/create_tenant.go index fa9e0c69691d..eac03eb01e3e 100644 --- a/pkg/sql/create_tenant.go +++ b/pkg/sql/create_tenant.go @@ -25,13 +25,13 @@ type createTenantNode struct { } func (p *planner) CreateTenantNode(ctx context.Context, n *tree.CreateTenant) (planNode, error) { - tspec, err := p.planTenantSpec(ctx, n.TenantSpec, "CREATE TENANT") + tspec, err := p.planTenantSpec(ctx, n.TenantSpec, "CREATE VIRTUAL CLUSTER") if err != nil { return nil, err } var likeTenantSpec tenantSpec if n.Like.OtherTenant != nil { - likeTenantSpec, err = p.planTenantSpec(ctx, n.Like.OtherTenant, "CREATE TENANT LIKE") + likeTenantSpec, err = p.planTenantSpec(ctx, n.Like.OtherTenant, "CREATE VIRTUAL CLUSTER LIKE") if err != nil { return nil, err } diff --git a/pkg/sql/sem/builtins/builtins.go b/pkg/sql/sem/builtins/builtins.go index 26dabe32a348..e7adee722448 100644 --- a/pkg/sql/sem/builtins/builtins.go +++ b/pkg/sql/sem/builtins/builtins.go @@ -4952,7 +4952,7 @@ value if you rely on the HLC for accuracy.`, Volatility: volatility.Volatile, Language: tree.FunctionLangSQL, }, - // This overload is deprecated. Use CREATE TENANT instead. + // This overload is deprecated. Use CREATE VIRTUAL CLUSTER instead. tree.Overload{ Types: tree.ParamTypes{ {Name: "name", Typ: types.String}, @@ -4960,7 +4960,7 @@ value if you rely on the HLC for accuracy.`, ReturnType: tree.FixedReturnType(types.Int), Body: `SELECT crdb_internal.create_tenant(json_build_object('name', $1))`, Info: `create_tenant(name) is an alias for create_tenant('{"name": name}'::jsonb). -DO NOT USE -- USE 'CREATE TENANT' INSTEAD`, +DO NOT USE -- USE 'CREATE VIRTUAL CLUSTER' INSTEAD`, Volatility: volatility.Volatile, Language: tree.FunctionLangSQL, }, diff --git a/pkg/sql/tenant_accessors.go b/pkg/sql/tenant_accessors.go index 09bbb3f1cba5..f00f4517eded 100644 --- a/pkg/sql/tenant_accessors.go +++ b/pkg/sql/tenant_accessors.go @@ -252,7 +252,7 @@ var defaultTenantConfigTemplate = func() *settings.StringSetting { s := settings.RegisterStringSetting( settings.SystemOnly, "sql.create_tenant.default_template", - "tenant to use as configuration template when LIKE is not specified in CREATE TENANT", + "tenant to use as configuration template when LIKE is not specified in CREATE VIRTUAL CLUSTER", // We use the empty string so that no template is used by default // (i.e. empty proto, no setting overrides). "", diff --git a/pkg/sql/tenant_creation.go b/pkg/sql/tenant_creation.go index 1280ebc368ff..384f5b212aae 100644 --- a/pkg/sql/tenant_creation.go +++ b/pkg/sql/tenant_creation.go @@ -67,7 +67,7 @@ func (p *planner) CreateTenant( // Tenant creation via this interface (which includes // crdb_internal.create_tenant) should be prevented from gobbling // up the entire tenant ID space by asking for too large values. - // Otherwise, CREATE TENANT will not be possible any more. + // Otherwise, CREATE VIRTUAL CLUSTER will not be possible any more. return tid, pgerror.Newf(pgcode.ProgramLimitExceeded, "tenant ID %d out of range", *ctcfg.ID) } From aca0936c885ba3c417b84eaefec10076772bd883 Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Tue, 4 Jul 2023 14:39:27 +0200 Subject: [PATCH 09/17] sql: `DROP VIRTUAL CLUSTER` (aliased by `DROP TENANT`) Release note: None --- docs/generated/sql/bnf/BUILD.bazel | 1 - docs/generated/sql/bnf/drop_stmt.bnf | 1 - docs/generated/sql/bnf/drop_tenant_stmt.bnf | 3 - docs/generated/sql/bnf/stmt_block.bnf | 168 +++++++++---------- pkg/gen/bnf.bzl | 1 - pkg/gen/diagrams.bzl | 1 - pkg/gen/docs.bzl | 1 - pkg/multitenant/mtinfopb/info.proto | 6 +- pkg/sql/logictest/testdata/logic_test/tenant | 2 +- pkg/sql/parser/help_test.go | 7 +- pkg/sql/parser/sql.y | 18 +- pkg/sql/parser/testdata/drop_tenant | 47 ------ pkg/sql/parser/testdata/drop_virtual_cluster | 55 ++++++ pkg/sql/sem/tree/drop.go | 4 +- pkg/sql/sem/tree/stmt.go | 2 +- 15 files changed, 156 insertions(+), 161 deletions(-) delete mode 100644 docs/generated/sql/bnf/drop_tenant_stmt.bnf delete mode 100644 pkg/sql/parser/testdata/drop_tenant create mode 100644 pkg/sql/parser/testdata/drop_virtual_cluster diff --git a/docs/generated/sql/bnf/BUILD.bazel b/docs/generated/sql/bnf/BUILD.bazel index 4931f6fffdd7..f16eca162a02 100644 --- a/docs/generated/sql/bnf/BUILD.bazel +++ b/docs/generated/sql/bnf/BUILD.bazel @@ -127,7 +127,6 @@ FILES = [ "drop_sequence_stmt", "drop_stmt", "drop_table", - "drop_tenant_stmt", "drop_type", "drop_view", "execute_stmt", diff --git a/docs/generated/sql/bnf/drop_stmt.bnf b/docs/generated/sql/bnf/drop_stmt.bnf index 5f6410141b32..5f66b113a16f 100644 --- a/docs/generated/sql/bnf/drop_stmt.bnf +++ b/docs/generated/sql/bnf/drop_stmt.bnf @@ -10,4 +10,3 @@ drop_stmt ::= | drop_role_stmt | drop_schedule_stmt | drop_external_connection_stmt - | drop_tenant_stmt diff --git a/docs/generated/sql/bnf/drop_tenant_stmt.bnf b/docs/generated/sql/bnf/drop_tenant_stmt.bnf deleted file mode 100644 index b79ab5275dfd..000000000000 --- a/docs/generated/sql/bnf/drop_tenant_stmt.bnf +++ /dev/null @@ -1,3 +0,0 @@ -drop_tenant_stmt ::= - 'DROP' 'TENANT' tenant_spec opt_immediate - | 'DROP' 'TENANT' 'IF' 'EXISTS' tenant_spec opt_immediate diff --git a/docs/generated/sql/bnf/stmt_block.bnf b/docs/generated/sql/bnf/stmt_block.bnf index 3002841b8513..931c026a8c5d 100644 --- a/docs/generated/sql/bnf/stmt_block.bnf +++ b/docs/generated/sql/bnf/stmt_block.bnf @@ -205,7 +205,6 @@ drop_stmt ::= | drop_role_stmt | drop_schedule_stmt | drop_external_connection_stmt - | drop_tenant_stmt explain_stmt ::= 'EXPLAIN' explainable_stmt @@ -651,10 +650,6 @@ drop_schedule_stmt ::= drop_external_connection_stmt ::= 'DROP' 'EXTERNAL' 'CONNECTION' string_or_placeholder -drop_tenant_stmt ::= - 'DROP' 'TENANT' tenant_spec opt_immediate - | 'DROP' 'TENANT' 'IF' 'EXISTS' tenant_spec opt_immediate - explainable_stmt ::= preparable_stmt | comment_stmt @@ -1856,13 +1851,6 @@ drop_func_stmt ::= 'DROP' 'FUNCTION' function_with_paramtypes_list opt_drop_behavior | 'DROP' 'FUNCTION' 'IF' 'EXISTS' function_with_paramtypes_list opt_drop_behavior -tenant_spec ::= - d_expr - | '[' a_expr ']' - -opt_immediate ::= - 'IMMEDIATE' - explain_option_name ::= non_reserved_word @@ -1972,6 +1960,10 @@ show_csettings_stmt ::= | 'SHOW' 'CLUSTER' 'SETTINGS' | 'SHOW' 'PUBLIC' 'CLUSTER' 'SETTINGS' +tenant_spec ::= + d_expr + | '[' a_expr ']' + opt_on_targets_roles ::= 'ON' targets_roles | @@ -2630,31 +2622,6 @@ view_name_list ::= sequence_name_list ::= db_object_name_list -d_expr ::= - 'ICONST' - | 'FCONST' - | 'SCONST' - | 'BCONST' - | 'BITCONST' - | typed_literal - | interval_value - | 'TRUE' - | 'FALSE' - | 'NULL' - | column_path_with_star - | '@' iconst64 - | 'PLACEHOLDER' - | '(' a_expr ')' '.' '*' - | '(' a_expr ')' '.' unrestricted_name - | '(' a_expr ')' '.' '@' 'ICONST' - | '(' a_expr ')' - | func_expr - | select_with_parens - | labeled_row - | 'ARRAY' select_with_parens - | 'ARRAY' row - | 'ARRAY' array_expr - non_reserved_word ::= 'identifier' | unreserved_keyword @@ -2740,6 +2707,31 @@ show_backup_connection_options ::= | 'TIME' '=' string_or_placeholder | 'CONCURRENTLY' '=' a_expr +d_expr ::= + 'ICONST' + | 'FCONST' + | 'SCONST' + | 'BCONST' + | 'BITCONST' + | typed_literal + | interval_value + | 'TRUE' + | 'FALSE' + | 'NULL' + | column_path_with_star + | '@' iconst64 + | 'PLACEHOLDER' + | '(' a_expr ')' '.' '*' + | '(' a_expr ')' '.' unrestricted_name + | '(' a_expr ')' '.' '@' 'ICONST' + | '(' a_expr ')' + | func_expr + | select_with_parens + | labeled_row + | 'ARRAY' select_with_parens + | 'ARRAY' row + | 'ARRAY' array_expr + targets_roles ::= 'ROLE' role_spec_list | 'SCHEMA' schema_name_list @@ -3217,32 +3209,6 @@ only_signed_fconst ::= db_object_name_list ::= ( db_object_name ) ( ( ',' db_object_name ) )* -typed_literal ::= - func_name_no_crdb_extra 'SCONST' - | const_typename 'SCONST' - -interval_value ::= - 'INTERVAL' 'SCONST' opt_interval_qualifier - | 'INTERVAL' '(' iconst32 ')' 'SCONST' - -column_path_with_star ::= - column_path - | db_object_name_component '.' unrestricted_name '.' unrestricted_name '.' '*' - | db_object_name_component '.' unrestricted_name '.' '*' - | db_object_name_component '.' '*' - -func_expr ::= - func_application within_group_clause filter_clause over_clause - | func_expr_common_subexpr - -labeled_row ::= - row - | '(' row 'AS' name_list ')' - -array_expr ::= - '[' opt_expr_list ']' - | '[' array_expr_list ']' - virtual_cluster_name ::= 'VIRTUAL_CLUSTER_NAME' @@ -3304,6 +3270,32 @@ show_backup_options ::= | 'ENCRYPTION_INFO_DIR' '=' string_or_placeholder | 'DEBUG_DUMP_METADATA_SST' +typed_literal ::= + func_name_no_crdb_extra 'SCONST' + | const_typename 'SCONST' + +interval_value ::= + 'INTERVAL' 'SCONST' opt_interval_qualifier + | 'INTERVAL' '(' iconst32 ')' 'SCONST' + +column_path_with_star ::= + column_path + | db_object_name_component '.' unrestricted_name '.' unrestricted_name '.' '*' + | db_object_name_component '.' unrestricted_name '.' '*' + | db_object_name_component '.' '*' + +func_expr ::= + func_application within_group_clause filter_clause over_clause + | func_expr_common_subexpr + +labeled_row ::= + row + | '(' row 'AS' name_list ')' + +array_expr ::= + '[' opt_expr_list ']' + | '[' array_expr_list ']' + schema_wildcard ::= wildcard_pattern @@ -4127,6 +4119,25 @@ opt_nulls_order ::= | 'NULLS' 'LAST' | +group_by_list ::= + ( group_by_item ) ( ( ',' group_by_item ) )* + +window_definition_list ::= + ( window_definition ) ( ( ',' window_definition ) )* + +for_locking_strength ::= + 'FOR' 'UPDATE' + | 'FOR' 'NO' 'KEY' 'UPDATE' + | 'FOR' 'SHARE' + | 'FOR' 'KEY' 'SHARE' + +opt_locked_rels ::= + 'OF' table_name_list + +opt_nowait_or_skip ::= + 'SKIP' 'LOCKED' + | 'NOWAIT' + func_name_no_crdb_extra ::= type_function_name_no_crdb_extra | prefixed_column_path @@ -4183,25 +4194,6 @@ func_expr_common_subexpr ::= array_expr_list ::= ( array_expr ) ( ( ',' array_expr ) )* -group_by_list ::= - ( group_by_item ) ( ( ',' group_by_item ) )* - -window_definition_list ::= - ( window_definition ) ( ( ',' window_definition ) )* - -for_locking_strength ::= - 'FOR' 'UPDATE' - | 'FOR' 'NO' 'KEY' 'UPDATE' - | 'FOR' 'SHARE' - | 'FOR' 'KEY' 'SHARE' - -opt_locked_rels ::= - 'OF' table_name_list - -opt_nowait_or_skip ::= - 'SKIP' 'LOCKED' - | 'NOWAIT' - wildcard_pattern ::= name '.' '*' @@ -4396,6 +4388,12 @@ rowsfrom_item ::= opt_col_def_list ::= '(' col_def_list ')' +group_by_item ::= + a_expr + +window_definition ::= + window_name 'AS' window_specification + func_application_name ::= func_name | '[' 'FUNCTION' iconst32 ']' @@ -4435,12 +4433,6 @@ special_function ::= | 'GREATEST' '(' expr_list ')' | 'LEAST' '(' expr_list ')' -group_by_item ::= - a_expr - -window_definition ::= - window_name 'AS' window_specification - func_param_class ::= 'IN' diff --git a/pkg/gen/bnf.bzl b/pkg/gen/bnf.bzl index e6e726ab4f31..7f8cce5a6f45 100644 --- a/pkg/gen/bnf.bzl +++ b/pkg/gen/bnf.bzl @@ -127,7 +127,6 @@ BNF_SRCS = [ "//docs/generated/sql/bnf:drop_sequence_stmt.bnf", "//docs/generated/sql/bnf:drop_stmt.bnf", "//docs/generated/sql/bnf:drop_table.bnf", - "//docs/generated/sql/bnf:drop_tenant_stmt.bnf", "//docs/generated/sql/bnf:drop_type.bnf", "//docs/generated/sql/bnf:drop_view.bnf", "//docs/generated/sql/bnf:execute_stmt.bnf", diff --git a/pkg/gen/diagrams.bzl b/pkg/gen/diagrams.bzl index 33670bfc1bc7..0bbc858a92dc 100644 --- a/pkg/gen/diagrams.bzl +++ b/pkg/gen/diagrams.bzl @@ -127,7 +127,6 @@ DIAGRAMS_SRCS = [ "//docs/generated/sql/bnf:drop_schema.html", "//docs/generated/sql/bnf:drop_sequence.html", "//docs/generated/sql/bnf:drop_table.html", - "//docs/generated/sql/bnf:drop_tenant.html", "//docs/generated/sql/bnf:drop_type.html", "//docs/generated/sql/bnf:drop_view.html", "//docs/generated/sql/bnf:execute.html", diff --git a/pkg/gen/docs.bzl b/pkg/gen/docs.bzl index 552187ba9017..224d2c816eb3 100644 --- a/pkg/gen/docs.bzl +++ b/pkg/gen/docs.bzl @@ -139,7 +139,6 @@ DOCS_SRCS = [ "//docs/generated/sql/bnf:drop_sequence_stmt.bnf", "//docs/generated/sql/bnf:drop_stmt.bnf", "//docs/generated/sql/bnf:drop_table.bnf", - "//docs/generated/sql/bnf:drop_tenant_stmt.bnf", "//docs/generated/sql/bnf:drop_type.bnf", "//docs/generated/sql/bnf:drop_view.bnf", "//docs/generated/sql/bnf:execute_stmt.bnf", diff --git a/pkg/multitenant/mtinfopb/info.proto b/pkg/multitenant/mtinfopb/info.proto index f12c651d2990..e62a5288f690 100644 --- a/pkg/multitenant/mtinfopb/info.proto +++ b/pkg/multitenant/mtinfopb/info.proto @@ -42,9 +42,9 @@ message ProtoInfo { // DeprecatedDataState is the state of the tenant's keyspace (DEPRECATED). optional DeprecatedDataState deprecated_data_state = 2 [(gogoproto.nullable) = false]; - // DroppedName is the name the tenant had before DROP TENANT was - // run on the tenant. It should be empty for active or adding - // tenants. + // DroppedName is the name the tenant had before DROP VIRTUAL + // CLUSTER was run on the tenant. It should be empty for active or + // adding tenants. optional string dropped_name = 3 [ (gogoproto.nullable) = false, (gogoproto.casttype) = "github.com/cockroachdb/cockroach/pkg/roachpb.TenantName"]; diff --git a/pkg/sql/logictest/testdata/logic_test/tenant b/pkg/sql/logictest/testdata/logic_test/tenant index f16cc788bb7a..e53e884016c2 100644 --- a/pkg/sql/logictest/testdata/logic_test/tenant +++ b/pkg/sql/logictest/testdata/logic_test/tenant @@ -187,7 +187,7 @@ DROP TENANT "five-requiring-quotes" statement ok set default_transaction_read_only = on; -statement error cannot execute DROP TENANT in a read-only transaction +statement error cannot execute DROP VIRTUAL CLUSTER in a read-only transaction DROP TENANT three statement ok diff --git a/pkg/sql/parser/help_test.go b/pkg/sql/parser/help_test.go index c5daa6f4064a..c74d0a8dccea 100644 --- a/pkg/sql/parser/help_test.go +++ b/pkg/sql/parser/help_test.go @@ -229,9 +229,10 @@ func TestContextualHelp(t *testing.T) { {`DROP SCHEMA ??`, `DROP SCHEMA`}, - {`DROP TENANT ??`, `DROP TENANT`}, - {`DROP TENANT IF ??`, `DROP TENANT`}, - {`DROP TENANT IF EXISTS ??`, `DROP TENANT`}, + {`DROP VIRTUAL CLUSTER ??`, `DROP VIRTUAL CLUSTER`}, + {`DROP TENANT ??`, `DROP VIRTUAL CLUSTER`}, + {`DROP VIRTUAL CLUSTER IF ??`, `DROP VIRTUAL CLUSTER`}, + {`DROP VIRTUAL CLUSTER IF EXISTS ??`, `DROP VIRTUAL CLUSTER`}, {`EXPLAIN (??`, `EXPLAIN`}, {`EXPLAIN SELECT 1 ??`, `SELECT`}, diff --git a/pkg/sql/parser/sql.y b/pkg/sql/parser/sql.y index e26a6907fbe2..ca65098f025c 100644 --- a/pkg/sql/parser/sql.y +++ b/pkg/sql/parser/sql.y @@ -1216,7 +1216,7 @@ func (u *sqlSymUnion) showCreateFormatOption() tree.ShowCreateFormatOption { %type drop_view_stmt %type drop_sequence_stmt %type drop_func_stmt -%type drop_tenant_stmt +%type drop_virtual_cluster_stmt %type opt_immediate %type analyze_stmt @@ -5395,7 +5395,7 @@ drop_stmt: | drop_role_stmt // EXTEND WITH HELP: DROP ROLE | drop_schedule_stmt // EXTEND WITH HELP: DROP SCHEDULES | drop_external_connection_stmt // EXTEND WITH HELP: DROP EXTERNAL CONNECTION -| drop_tenant_stmt // EXTEND WITH HELP: DROP TENANT +| drop_virtual_cluster_stmt // EXTEND WITH HELP: DROP VIRTUAL CLUSTER | drop_unsupported {} | DROP error // SHOW HELP: DROP @@ -5542,27 +5542,29 @@ drop_type_stmt: } | DROP TYPE error // SHOW HELP: DROP TYPE -// %Help: DROP TENANT - remove a tenant +// %Help: DROP VIRTUAL CLUSTER - remove a virtual cluster // %Category: Experimental -// %Text: DROP TENANT [IF EXISTS] [IMMEDIATE] -drop_tenant_stmt: - DROP TENANT tenant_spec opt_immediate +// %Text: DROP VIRTUAL CLUSTER [IF EXISTS] [IMMEDIATE] +drop_virtual_cluster_stmt: + DROP virtual_cluster tenant_spec opt_immediate { + /* SKIP DOC */ $$.val = &tree.DropTenant{ TenantSpec: $3.tenantSpec(), IfExists: false, Immediate: $4.bool(), } } -| DROP TENANT IF EXISTS tenant_spec opt_immediate +| DROP virtual_cluster IF EXISTS tenant_spec opt_immediate { + /* SKIP DOC */ $$.val = &tree.DropTenant{ TenantSpec: $5.tenantSpec(), IfExists: true, Immediate: $6.bool(), } } -| DROP TENANT error // SHOW HELP: DROP TENANT +| DROP virtual_cluster error // SHOW HELP: DROP VIRTUAL CLUSTER opt_immediate: /* EMPTY */ diff --git a/pkg/sql/parser/testdata/drop_tenant b/pkg/sql/parser/testdata/drop_tenant deleted file mode 100644 index 9da78f9bb976..000000000000 --- a/pkg/sql/parser/testdata/drop_tenant +++ /dev/null @@ -1,47 +0,0 @@ -parse -DROP TENANT foo ----- -DROP TENANT foo -DROP TENANT (foo) -- fully parenthesized -DROP TENANT foo -- literals removed -DROP TENANT _ -- identifiers removed - -parse -DROP TENANT "foo-with-hyphen" ----- -DROP TENANT "foo-with-hyphen" -DROP TENANT ("foo-with-hyphen") -- fully parenthesized -DROP TENANT "foo-with-hyphen" -- literals removed -DROP TENANT _ -- identifiers removed - -parse -DROP TENANT IF EXISTS foo ----- -DROP TENANT IF EXISTS foo -DROP TENANT IF EXISTS (foo) -- fully parenthesized -DROP TENANT IF EXISTS foo -- literals removed -DROP TENANT IF EXISTS _ -- identifiers removed - -parse -DROP TENANT [123] ----- -DROP TENANT [123] -DROP TENANT [(123)] -- fully parenthesized -DROP TENANT [_] -- literals removed -DROP TENANT [123] -- identifiers removed - -parse -DROP TENANT [123::INT] ----- -DROP TENANT [123::INT8] -- normalized! -DROP TENANT [((123)::INT8)] -- fully parenthesized -DROP TENANT [_::INT8] -- literals removed -DROP TENANT [123::INT8] -- identifiers removed - -parse -DROP TENANT foo IMMEDIATE ----- -DROP TENANT foo IMMEDIATE -DROP TENANT (foo) IMMEDIATE -- fully parenthesized -DROP TENANT foo IMMEDIATE -- literals removed -DROP TENANT _ IMMEDIATE -- identifiers removed diff --git a/pkg/sql/parser/testdata/drop_virtual_cluster b/pkg/sql/parser/testdata/drop_virtual_cluster new file mode 100644 index 000000000000..4577ce5a778a --- /dev/null +++ b/pkg/sql/parser/testdata/drop_virtual_cluster @@ -0,0 +1,55 @@ +parse +DROP VIRTUAL CLUSTER foo +---- +DROP VIRTUAL CLUSTER foo +DROP VIRTUAL CLUSTER (foo) -- fully parenthesized +DROP VIRTUAL CLUSTER foo -- literals removed +DROP VIRTUAL CLUSTER _ -- identifiers removed + +parse +DROP TENANT foo +---- +DROP VIRTUAL CLUSTER foo -- normalized! +DROP VIRTUAL CLUSTER (foo) -- fully parenthesized +DROP VIRTUAL CLUSTER foo -- literals removed +DROP VIRTUAL CLUSTER _ -- identifiers removed + +parse +DROP VIRTUAL CLUSTER "foo-with-hyphen" +---- +DROP VIRTUAL CLUSTER "foo-with-hyphen" +DROP VIRTUAL CLUSTER ("foo-with-hyphen") -- fully parenthesized +DROP VIRTUAL CLUSTER "foo-with-hyphen" -- literals removed +DROP VIRTUAL CLUSTER _ -- identifiers removed + +parse +DROP VIRTUAL CLUSTER IF EXISTS foo +---- +DROP VIRTUAL CLUSTER IF EXISTS foo +DROP VIRTUAL CLUSTER IF EXISTS (foo) -- fully parenthesized +DROP VIRTUAL CLUSTER IF EXISTS foo -- literals removed +DROP VIRTUAL CLUSTER IF EXISTS _ -- identifiers removed + +parse +DROP VIRTUAL CLUSTER [123] +---- +DROP VIRTUAL CLUSTER [123] +DROP VIRTUAL CLUSTER [(123)] -- fully parenthesized +DROP VIRTUAL CLUSTER [_] -- literals removed +DROP VIRTUAL CLUSTER [123] -- identifiers removed + +parse +DROP VIRTUAL CLUSTER [123::INT] +---- +DROP VIRTUAL CLUSTER [123::INT8] -- normalized! +DROP VIRTUAL CLUSTER [((123)::INT8)] -- fully parenthesized +DROP VIRTUAL CLUSTER [_::INT8] -- literals removed +DROP VIRTUAL CLUSTER [123::INT8] -- identifiers removed + +parse +DROP VIRTUAL CLUSTER foo IMMEDIATE +---- +DROP VIRTUAL CLUSTER foo IMMEDIATE +DROP VIRTUAL CLUSTER (foo) IMMEDIATE -- fully parenthesized +DROP VIRTUAL CLUSTER foo IMMEDIATE -- literals removed +DROP VIRTUAL CLUSTER _ IMMEDIATE -- identifiers removed diff --git a/pkg/sql/sem/tree/drop.go b/pkg/sql/sem/tree/drop.go index 50a438f438f7..d6a58094b90d 100644 --- a/pkg/sql/sem/tree/drop.go +++ b/pkg/sql/sem/tree/drop.go @@ -235,7 +235,7 @@ func (node *DropExternalConnection) Format(ctx *FmtCtx) { } } -// DropTenant represents a DROP TENANT command. +// DropTenant represents a DROP VIRTUAL CLUSTER command. type DropTenant struct { TenantSpec *TenantSpec IfExists bool @@ -246,7 +246,7 @@ var _ Statement = &DropTenant{} // Format implements the NodeFormatter interface. func (node *DropTenant) Format(ctx *FmtCtx) { - ctx.WriteString("DROP TENANT ") + ctx.WriteString("DROP VIRTUAL CLUSTER ") if node.IfExists { ctx.WriteString("IF EXISTS ") } diff --git a/pkg/sql/sem/tree/stmt.go b/pkg/sql/sem/tree/stmt.go index b93138fb1ca8..78dab8d9796d 100644 --- a/pkg/sql/sem/tree/stmt.go +++ b/pkg/sql/sem/tree/stmt.go @@ -1096,7 +1096,7 @@ func (*DropTenant) StatementReturnType() StatementReturnType { return Ack } func (*DropTenant) StatementType() StatementType { return TypeDCL } // StatementTag implements the Statement interface. -func (*DropTenant) StatementTag() string { return "DROP TENANT" } +func (*DropTenant) StatementTag() string { return "DROP VIRTUAL CLUSTER" } // StatementReturnType implements the Statement interface. func (*Execute) StatementReturnType() StatementReturnType { return Unknown } From f43bd0641055b22abebd3595d381f6d610f7eab9 Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Tue, 4 Jul 2023 17:17:33 +0200 Subject: [PATCH 10/17] sql: use `DROP VIRTUAL CLUSTER` in errors and help texts Release note: None --- pkg/sql/drop_tenant.go | 2 +- pkg/sql/sem/builtins/builtins.go | 4 ++-- pkg/sql/tenant_deletion.go | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/sql/drop_tenant.go b/pkg/sql/drop_tenant.go index 93b20db14f4a..449e4d8b28d8 100644 --- a/pkg/sql/drop_tenant.go +++ b/pkg/sql/drop_tenant.go @@ -32,7 +32,7 @@ func (p *planner) DropTenant(ctx context.Context, n *tree.DropTenant) (planNode, return nil, err } - tspec, err := p.planTenantSpec(ctx, n.TenantSpec, "DROP TENANT") + tspec, err := p.planTenantSpec(ctx, n.TenantSpec, "DROP VIRTUAL CLUSTER") if err != nil { return nil, err } diff --git a/pkg/sql/sem/builtins/builtins.go b/pkg/sql/sem/builtins/builtins.go index e7adee722448..460a7d1c8772 100644 --- a/pkg/sql/sem/builtins/builtins.go +++ b/pkg/sql/sem/builtins/builtins.go @@ -4996,7 +4996,7 @@ DO NOT USE -- USE 'CREATE VIRTUAL CLUSTER' INSTEAD`, }, ReturnType: tree.FixedReturnType(types.Int), Body: `SELECT crdb_internal.destroy_tenant($1, false)`, - Info: "DO NOT USE -- USE 'DROP TENANT' INSTEAD.", + Info: "DO NOT USE -- USE 'DROP VIRTUAL CLUSTER' INSTEAD.", Volatility: volatility.Volatile, Language: tree.FunctionLangSQL, }, @@ -5022,7 +5022,7 @@ DO NOT USE -- USE 'CREATE VIRTUAL CLUSTER' INSTEAD`, } return args[0], nil }, - Info: "DO NOT USE -- USE 'DROP TENANT IMMEDIATE' INSTEAD.", + Info: "DO NOT USE -- USE 'DROP VIRTUAL CLUSTER IMMEDIATE' INSTEAD.", Volatility: volatility.Volatile, }, ), diff --git a/pkg/sql/tenant_deletion.go b/pkg/sql/tenant_deletion.go index 66e3a491ee7e..69e5743eaabc 100644 --- a/pkg/sql/tenant_deletion.go +++ b/pkg/sql/tenant_deletion.go @@ -33,14 +33,14 @@ func (p *planner) DropTenantByID( ctx context.Context, tenID uint64, synchronousImmediateDrop, ignoreServiceMode bool, ) error { if p.SessionData().DisableDropTenant || p.SessionData().SafeUpdates { - err := errors.Newf("DROP TENANT causes irreversible data loss") + err := errors.Newf("DROP VIRTUAL CLUSTER causes irreversible data loss") err = errors.WithMessage(err, "rejected (via sql_safe_updates or disable_drop_tenant)") err = pgerror.WithCandidateCode(err, pgcode.Warning) return err } if p.EvalContext().TxnReadOnly { - return readOnlyError("DROP TENANT") + return readOnlyError("DROP VIRTUAL CLUSTER") } if err := rejectIfCantCoordinateMultiTenancy(p.execCfg.Codec, "drop"); err != nil { @@ -99,7 +99,7 @@ func dropTenantInternal( if info.ServiceMode != mtinfopb.ServiceModeNone { return errors.WithHint(pgerror.Newf(pgcode.ObjectNotInPrerequisiteState, "cannot drop tenant %q (%d) in service mode %v", info.Name, tenID, info.ServiceMode), - "Use ALTER TENANT STOP SERVICE before DROP TENANT.") + "Use ALTER TENANT STOP SERVICE before DROP VIRTUAL CLUSTER.") } } From 14aaee8908fe4cd79d62292d56f037e6ebf50ad2 Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Tue, 4 Jul 2023 15:10:39 +0200 Subject: [PATCH 11/17] sql: `SHOW VIRTUAL CLUSTER[s]` (aliased by `SHOW TENANT[s]`) Release note: None --- docs/generated/sql/bnf/BUILD.bazel | 1 - docs/generated/sql/bnf/show_tenant_stmt.bnf | 4 - docs/generated/sql/bnf/show_var.bnf | 1 - docs/generated/sql/bnf/stmt_block.bnf | 14 +--- pkg/gen/bnf.bzl | 1 - pkg/gen/diagrams.bzl | 1 - pkg/gen/docs.bzl | 1 - pkg/sql/catalog/colinfo/result_columns.go | 6 +- pkg/sql/parser/help_test.go | 6 +- pkg/sql/parser/lexer.go | 7 +- pkg/sql/parser/sql.y | 71 ++++++++++------ pkg/sql/parser/testdata/show | 86 +++++++++++--------- pkg/sql/sem/builtins/replication_builtins.go | 4 +- pkg/sql/sem/tree/show.go | 6 +- pkg/sql/sem/tree/stmt.go | 2 +- pkg/sql/show_tenant.go | 4 +- 16 files changed, 114 insertions(+), 101 deletions(-) delete mode 100644 docs/generated/sql/bnf/show_tenant_stmt.bnf diff --git a/docs/generated/sql/bnf/BUILD.bazel b/docs/generated/sql/bnf/BUILD.bazel index f16eca162a02..f36d383a538a 100644 --- a/docs/generated/sql/bnf/BUILD.bazel +++ b/docs/generated/sql/bnf/BUILD.bazel @@ -247,7 +247,6 @@ FILES = [ "show_stats", "show_survival_goal_stmt", "show_tables", - "show_tenant_stmt", "show_trace", "show_transactions_stmt", "show_transfer_stmt", diff --git a/docs/generated/sql/bnf/show_tenant_stmt.bnf b/docs/generated/sql/bnf/show_tenant_stmt.bnf deleted file mode 100644 index 36496113c396..000000000000 --- a/docs/generated/sql/bnf/show_tenant_stmt.bnf +++ /dev/null @@ -1,4 +0,0 @@ -show_tenant_stmt ::= - 'SHOW' 'TENANTS' opt_show_tenant_options - | 'SHOW' 'TENANT_ALL' 'ALL' opt_show_tenant_options - | 'SHOW' 'TENANT' tenant_spec opt_show_tenant_options diff --git a/docs/generated/sql/bnf/show_var.bnf b/docs/generated/sql/bnf/show_var.bnf index 0bc2f6087522..e7af2f5ba330 100644 --- a/docs/generated/sql/bnf/show_var.bnf +++ b/docs/generated/sql/bnf/show_var.bnf @@ -29,7 +29,6 @@ show_stmt ::= | show_sessions_stmt | show_stats_stmt | show_tables_stmt - | show_tenant_stmt | show_trace_stmt | show_transactions_stmt | show_transfer_stmt diff --git a/docs/generated/sql/bnf/stmt_block.bnf b/docs/generated/sql/bnf/stmt_block.bnf index 931c026a8c5d..6637b6bfdda2 100644 --- a/docs/generated/sql/bnf/stmt_block.bnf +++ b/docs/generated/sql/bnf/stmt_block.bnf @@ -294,7 +294,6 @@ show_stmt ::= | show_sessions_stmt | show_stats_stmt | show_tables_stmt - | show_tenant_stmt | show_trace_stmt | show_transactions_stmt | show_transfer_stmt @@ -931,11 +930,6 @@ show_tables_stmt ::= | 'SHOW' 'TABLES' 'FROM' name with_comment | 'SHOW' 'TABLES' with_comment -show_tenant_stmt ::= - 'SHOW' 'TENANTS' opt_show_tenant_options - | 'SHOW' 'TENANT_ALL' 'ALL' opt_show_tenant_options - | 'SHOW' 'TENANT' tenant_spec opt_show_tenant_options - show_trace_stmt ::= 'SHOW' opt_compact 'TRACE' 'FOR' 'SESSION' | 'SHOW' opt_compact 'KV' 'TRACE' 'FOR' 'SESSION' @@ -1056,6 +1050,7 @@ unreserved_keyword ::= | 'CHECK_FILES' | 'CLOSE' | 'CLUSTER' + | 'CLUSTERS' | 'COLUMNS' | 'COMMENT' | 'COMMENTS' @@ -1995,9 +1990,6 @@ statements_or_queries ::= opt_show_ranges_options ::= 'WITH' show_ranges_options -opt_show_tenant_options ::= - 'WITH' show_tenant_options - opt_compact ::= 'COMPACT' | @@ -2745,9 +2737,6 @@ show_job_options ::= show_ranges_options ::= ( 'TABLES' | 'INDEXES' | 'DETAILS' | 'KEYS' | 'EXPLAIN' ) ( ( ',' 'TABLES' | ',' 'INDEXES' | ',' 'DETAILS' | ',' 'EXPLAIN' | ',' 'KEYS' ) )* -show_tenant_options ::= - ( 'REPLICATION' 'STATUS' | 'CAPABILITIES' ) ( ( ',' 'REPLICATION' 'STATUS' | ',' 'CAPABILITIES' ) )* - partition ::= 'PARTITION' partition_name @@ -3555,6 +3544,7 @@ bare_label_keywords ::= | 'CHECK_FILES' | 'CLOSE' | 'CLUSTER' + | 'CLUSTERS' | 'COALESCE' | 'COLLATION' | 'COLUMN' diff --git a/pkg/gen/bnf.bzl b/pkg/gen/bnf.bzl index 7f8cce5a6f45..1b17baf5346e 100644 --- a/pkg/gen/bnf.bzl +++ b/pkg/gen/bnf.bzl @@ -247,7 +247,6 @@ BNF_SRCS = [ "//docs/generated/sql/bnf:show_stats.bnf", "//docs/generated/sql/bnf:show_survival_goal_stmt.bnf", "//docs/generated/sql/bnf:show_tables.bnf", - "//docs/generated/sql/bnf:show_tenant_stmt.bnf", "//docs/generated/sql/bnf:show_trace.bnf", "//docs/generated/sql/bnf:show_transactions_stmt.bnf", "//docs/generated/sql/bnf:show_transfer_stmt.bnf", diff --git a/pkg/gen/diagrams.bzl b/pkg/gen/diagrams.bzl index 0bbc858a92dc..8f19b937877a 100644 --- a/pkg/gen/diagrams.bzl +++ b/pkg/gen/diagrams.bzl @@ -245,7 +245,6 @@ DIAGRAMS_SRCS = [ "//docs/generated/sql/bnf:show_stats.html", "//docs/generated/sql/bnf:show_survival_goal.html", "//docs/generated/sql/bnf:show_tables.html", - "//docs/generated/sql/bnf:show_tenant.html", "//docs/generated/sql/bnf:show_trace.html", "//docs/generated/sql/bnf:show_transactions.html", "//docs/generated/sql/bnf:show_transfer.html", diff --git a/pkg/gen/docs.bzl b/pkg/gen/docs.bzl index 224d2c816eb3..77416ac1fb91 100644 --- a/pkg/gen/docs.bzl +++ b/pkg/gen/docs.bzl @@ -259,7 +259,6 @@ DOCS_SRCS = [ "//docs/generated/sql/bnf:show_stats.bnf", "//docs/generated/sql/bnf:show_survival_goal_stmt.bnf", "//docs/generated/sql/bnf:show_tables.bnf", - "//docs/generated/sql/bnf:show_tenant_stmt.bnf", "//docs/generated/sql/bnf:show_trace.bnf", "//docs/generated/sql/bnf:show_transactions_stmt.bnf", "//docs/generated/sql/bnf:show_transfer_stmt.bnf", diff --git a/pkg/sql/catalog/colinfo/result_columns.go b/pkg/sql/catalog/colinfo/result_columns.go index 5284ecbfc45f..4a44fa8617e1 100644 --- a/pkg/sql/catalog/colinfo/result_columns.go +++ b/pkg/sql/catalog/colinfo/result_columns.go @@ -283,7 +283,7 @@ func init() { } } -// TenantColumns appear in all SHOW TENANT queries. +// TenantColumns appear in all SHOW VIRTUAL CLUSTER queries. var TenantColumns = ResultColumns{ {Name: "id", Typ: types.Int}, {Name: "name", Typ: types.String}, @@ -292,7 +292,7 @@ var TenantColumns = ResultColumns{ } // TenantColumnsWithReplication is appended to TenantColumns for -// SHOW TENANT ... WITH REPLICATION STATUS queries. +// SHOW VIRTUAL CLUSTER ... WITH REPLICATION STATUS queries. var TenantColumnsWithReplication = ResultColumns{ {Name: "source_tenant_name", Typ: types.String}, {Name: "source_cluster_uri", Typ: types.String}, @@ -306,7 +306,7 @@ var TenantColumnsWithReplication = ResultColumns{ } // TenantColumnsWithCapabilities is appended to TenantColumns for -// SHOW TENANT ... WITH CAPABILITIES queries. +// SHOW VIRTUAL CLUSTER ... WITH CAPABILITIES queries. var TenantColumnsWithCapabilities = ResultColumns{ {Name: "capability_name", Typ: types.String}, {Name: "capability_value", Typ: types.String}, diff --git a/pkg/sql/parser/help_test.go b/pkg/sql/parser/help_test.go index c74d0a8dccea..8b90e8c7aeee 100644 --- a/pkg/sql/parser/help_test.go +++ b/pkg/sql/parser/help_test.go @@ -427,8 +427,10 @@ func TestContextualHelp(t *testing.T) { {`SHOW TABLES FROM ??`, `SHOW TABLES`}, {`SHOW TABLES FROM blah ??`, `SHOW TABLES`}, - {`SHOW TENANT ??`, `SHOW TENANT`}, - {`SHOW TENANT ?? WITH REPLICATION STATUS`, `SHOW TENANT`}, + {`SHOW VIRTUAL CLUSTER ??`, `SHOW VIRTUAL CLUSTER`}, + {`SHOW TENANT ??`, `SHOW VIRTUAL CLUSTER`}, + {`SHOW VIRTUAL CLUSTER ?? WITH REPLICATION STATUS`, `SHOW VIRTUAL CLUSTER`}, + {`SHOW TENANT ?? WITH REPLICATION STATUS`, `SHOW VIRTUAL CLUSTER`}, {`SHOW TRANSACTION PRIORITY ??`, `SHOW TRANSACTION`}, {`SHOW TRANSACTION STATUS ??`, `SHOW TRANSACTION`}, diff --git a/pkg/sql/parser/lexer.go b/pkg/sql/parser/lexer.go index a9786c227e3a..3f15d0748699 100644 --- a/pkg/sql/parser/lexer.go +++ b/pkg/sql/parser/lexer.go @@ -205,7 +205,7 @@ func (l *lexer) Lex(lval *sqlSymType) int { } } - case NOT, WITH, AS, GENERATED, NULLS, RESET, ROLE, USER, ON, TENANT, SET: + case NOT, WITH, AS, GENERATED, NULLS, RESET, ROLE, USER, ON, TENANT, CLUSTER, SET: nextToken := sqlSymType{} if l.lastPos+1 < len(l.tokens) { nextToken = l.tokens[l.lastPos+1] @@ -279,6 +279,11 @@ func (l *lexer) Lex(lval *sqlSymType) int { case ALL: lval.id = TENANT_ALL } + case CLUSTER: + switch nextToken.id { + case ALL: + lval.id = CLUSTER_ALL + } case SET: switch nextToken.id { case TRACING: diff --git a/pkg/sql/parser/sql.y b/pkg/sql/parser/sql.y index ca65098f025c..afbd89a6903e 100644 --- a/pkg/sql/parser/sql.y +++ b/pkg/sql/parser/sql.y @@ -911,7 +911,7 @@ func (u *sqlSymUnion) showCreateFormatOption() tree.ShowCreateFormatOption { %token CACHE CALL CALLED CANCEL CANCELQUERY CAPABILITIES CAPABILITY CASCADE CASE CAST CBRT CHANGEFEED CHAR %token CHARACTER CHARACTERISTICS CHECK CHECK_FILES CLOSE -%token CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT +%token CLUSTER CLUSTERS COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT %token COMMITTED COMPACT COMPLETE COMPLETIONS CONCAT CONCURRENTLY CONFIGURATION CONFIGURATIONS CONFIGURE %token CONFLICT CONNECTION CONNECTIONS CONSTRAINT CONSTRAINTS CONTAINS CONTROLCHANGEFEED CONTROLJOB %token CONVERSION CONVERT COPY COST COVERING CREATE CREATEDB CREATELOGIN CREATEROLE @@ -1033,9 +1033,9 @@ func (u *sqlSymUnion) showCreateFormatOption() tree.ShowCreateFormatOption { // - ON_LA is needed for ON UPDATE and ON DELETE expressions for foreign key // references. // - TENANT_ALL is used to differentiate `ALTER TENANT ` from -// `ALTER TENANT ALL`. +// `ALTER TENANT ALL`. Ditto `CLUSTER_ALL` and `CLUSTER ALL`. %token NOT_LA NULLS_LA WITH_LA AS_LA GENERATED_ALWAYS GENERATED_BY_DEFAULT RESET_ALL ROLE_ALL -%token USER_ALL ON_LA TENANT_ALL SET_TRACING +%token USER_ALL ON_LA TENANT_ALL CLUSTER_ALL SET_TRACING %union { id int32 @@ -1297,7 +1297,7 @@ func (u *sqlSymUnion) showCreateFormatOption() tree.ShowCreateFormatOption { %type show_syntax_stmt %type show_last_query_stats_stmt %type show_tables_stmt -%type show_tenant_stmt opt_show_tenant_options show_tenant_options +%type show_virtual_cluster_stmt opt_show_tenant_options show_tenant_options %type show_trace_stmt %type show_transaction_stmt %type show_transactions_stmt @@ -1492,7 +1492,7 @@ func (u *sqlSymUnion) showCreateFormatOption() tree.ShowCreateFormatOption { %type execute_param_clause %type opt_interval_qualifier interval_qualifier interval_second %type overlay_placing -%type <*tree.TenantSpec> tenant_spec +%type <*tree.TenantSpec> tenant_spec virtual_cluster_spec_opt_all %type opt_unique opt_concurrently opt_cluster opt_without_index %type opt_index_access_method @@ -5921,39 +5921,54 @@ backup_kms: } } -// %Help: SHOW TENANT - display tenant information +// %Help: SHOW VIRTUAL CLUSTER - display metadata about virtual clusters // %Category: Experimental // %Text: -// SHOW TENANT { | ALL } [ WITH ] -// SHOW TENANTS [ WITH ] +// SHOW VIRTUAL CLUSTER { | ALL } [ WITH ] +// SHOW VIRTUAL CLUSTERS [ WITH ] // // Options: // REPLICATION STATUS // CAPABILITIES -show_tenant_stmt: - SHOW TENANTS opt_show_tenant_options +show_virtual_cluster_stmt: + SHOW virtual_cluster_spec_opt_all opt_show_tenant_options { - $$.val = &tree.ShowTenant{ - TenantSpec: &tree.TenantSpec{All: true}, - ShowTenantOptions: $3.showTenantOpts(), - } + /* SKIP DOC */ + $$.val = &tree.ShowTenant{ + TenantSpec: $2.tenantSpec(), + ShowTenantOptions: $3.showTenantOpts(), + } } -| SHOW TENANT_ALL ALL opt_show_tenant_options +| SHOW virtual_cluster error // SHOW HELP: SHOW VIRTUAL CLUSTER + +virtual_cluster_spec_opt_all: + TENANT_ALL ALL { - $$.val = &tree.ShowTenant{ - TenantSpec: &tree.TenantSpec{All: true}, - ShowTenantOptions: $4.showTenantOpts(), - } + /* SKIP DOC */ + $$.val = &tree.TenantSpec{All: true} } -| SHOW TENANT tenant_spec opt_show_tenant_options +| TENANTS { - $$.val = &tree.ShowTenant{ - TenantSpec: $3.tenantSpec(), - ShowTenantOptions: $4.showTenantOpts(), - - } + /* SKIP DOC */ + $$.val = &tree.TenantSpec{All: true} + } +| TENANT tenant_spec + { + /* SKIP DOC */ + $$.val = $2.tenantSpec() + } +| VIRTUAL CLUSTER_ALL ALL + { + $$.val = &tree.TenantSpec{All: true} + } +| VIRTUAL CLUSTERS + { + $$.val = &tree.TenantSpec{All: true} + } +| VIRTUAL CLUSTER tenant_spec + { + $$.val = $3.tenantSpec() } -| SHOW TENANT error // SHOW HELP: SHOW TENANT opt_show_tenant_options: /* EMPTY */ @@ -7083,7 +7098,7 @@ show_stmt: | show_stats_stmt // EXTEND WITH HELP: SHOW STATISTICS | show_syntax_stmt // EXTEND WITH HELP: SHOW SYNTAX | show_tables_stmt // EXTEND WITH HELP: SHOW TABLES -| show_tenant_stmt // EXTEND WITH HELP: SHOW TENANT +| show_virtual_cluster_stmt // EXTEND WITH HELP: SHOW VIRTUAL CLUSTER | show_trace_stmt // EXTEND WITH HELP: SHOW TRACE | show_transaction_stmt // EXTEND WITH HELP: SHOW TRANSACTION | show_transactions_stmt // EXTEND WITH HELP: SHOW TRANSACTIONS @@ -16460,6 +16475,7 @@ unreserved_keyword: | CHECK_FILES | CLOSE | CLUSTER +| CLUSTERS | COLUMNS | COMMENT | COMMENTS @@ -16939,6 +16955,7 @@ bare_label_keywords: | CHECK_FILES | CLOSE | CLUSTER +| CLUSTERS | COALESCE | COLLATION | COLUMN diff --git a/pkg/sql/parser/testdata/show b/pkg/sql/parser/testdata/show index 2c03dc9c4b44..db7d26297487 100644 --- a/pkg/sql/parser/testdata/show +++ b/pkg/sql/parser/testdata/show @@ -1957,68 +1957,76 @@ SHOW CREATE SECONDARY INDEXES FROM t -- literals removed SHOW CREATE SECONDARY INDEXES FROM _ -- identifiers removed parse -SHOW TENANT foo +SHOW VIRTUAL CLUSTER foo ---- +SHOW VIRTUAL CLUSTER foo +SHOW VIRTUAL CLUSTER (foo) -- fully parenthesized +SHOW VIRTUAL CLUSTER foo -- literals removed +SHOW VIRTUAL CLUSTER _ -- identifiers removed + +parse SHOW TENANT foo -SHOW TENANT (foo) -- fully parenthesized -SHOW TENANT foo -- literals removed -SHOW TENANT _ -- identifiers removed +---- +SHOW VIRTUAL CLUSTER foo -- normalized! +SHOW VIRTUAL CLUSTER (foo) -- fully parenthesized +SHOW VIRTUAL CLUSTER foo -- literals removed +SHOW VIRTUAL CLUSTER _ -- identifiers removed parse -SHOW TENANT foo WITH REPLICATION STATUS +SHOW VIRTUAL CLUSTER foo WITH REPLICATION STATUS ---- -SHOW TENANT foo WITH REPLICATION STATUS -SHOW TENANT (foo) WITH REPLICATION STATUS -- fully parenthesized -SHOW TENANT foo WITH REPLICATION STATUS -- literals removed -SHOW TENANT _ WITH REPLICATION STATUS -- identifiers removed +SHOW VIRTUAL CLUSTER foo WITH REPLICATION STATUS +SHOW VIRTUAL CLUSTER (foo) WITH REPLICATION STATUS -- fully parenthesized +SHOW VIRTUAL CLUSTER foo WITH REPLICATION STATUS -- literals removed +SHOW VIRTUAL CLUSTER _ WITH REPLICATION STATUS -- identifiers removed parse -SHOW TENANT foo WITH CAPABILITIES +SHOW VIRTUAL CLUSTER foo WITH CAPABILITIES ---- -SHOW TENANT foo WITH CAPABILITIES -SHOW TENANT (foo) WITH CAPABILITIES -- fully parenthesized -SHOW TENANT foo WITH CAPABILITIES -- literals removed -SHOW TENANT _ WITH CAPABILITIES -- identifiers removed +SHOW VIRTUAL CLUSTER foo WITH CAPABILITIES +SHOW VIRTUAL CLUSTER (foo) WITH CAPABILITIES -- fully parenthesized +SHOW VIRTUAL CLUSTER foo WITH CAPABILITIES -- literals removed +SHOW VIRTUAL CLUSTER _ WITH CAPABILITIES -- identifiers removed parse -SHOW TENANTS +SHOW VIRTUAL CLUSTERS ---- -SHOW TENANT ALL -- normalized! -SHOW TENANT ALL -- fully parenthesized -SHOW TENANT ALL -- literals removed -SHOW TENANT ALL -- identifiers removed +SHOW VIRTUAL CLUSTER ALL -- normalized! +SHOW VIRTUAL CLUSTER ALL -- fully parenthesized +SHOW VIRTUAL CLUSTER ALL -- literals removed +SHOW VIRTUAL CLUSTER ALL -- identifiers removed parse -SHOW TENANTS WITH REPLICATION STATUS +SHOW VIRTUAL CLUSTERS WITH REPLICATION STATUS ---- -SHOW TENANT ALL WITH REPLICATION STATUS -- normalized! -SHOW TENANT ALL WITH REPLICATION STATUS -- fully parenthesized -SHOW TENANT ALL WITH REPLICATION STATUS -- literals removed -SHOW TENANT ALL WITH REPLICATION STATUS -- identifiers removed +SHOW VIRTUAL CLUSTER ALL WITH REPLICATION STATUS -- normalized! +SHOW VIRTUAL CLUSTER ALL WITH REPLICATION STATUS -- fully parenthesized +SHOW VIRTUAL CLUSTER ALL WITH REPLICATION STATUS -- literals removed +SHOW VIRTUAL CLUSTER ALL WITH REPLICATION STATUS -- identifiers removed parse -SHOW TENANT ALL +SHOW VIRTUAL CLUSTER ALL ---- -SHOW TENANT ALL -SHOW TENANT ALL -- fully parenthesized -SHOW TENANT ALL -- literals removed -SHOW TENANT ALL -- identifiers removed +SHOW VIRTUAL CLUSTER ALL +SHOW VIRTUAL CLUSTER ALL -- fully parenthesized +SHOW VIRTUAL CLUSTER ALL -- literals removed +SHOW VIRTUAL CLUSTER ALL -- identifiers removed parse -SHOW TENANT ALL WITH REPLICATION STATUS +SHOW VIRTUAL CLUSTER ALL WITH REPLICATION STATUS ---- -SHOW TENANT ALL WITH REPLICATION STATUS -SHOW TENANT ALL WITH REPLICATION STATUS -- fully parenthesized -SHOW TENANT ALL WITH REPLICATION STATUS -- literals removed -SHOW TENANT ALL WITH REPLICATION STATUS -- identifiers removed +SHOW VIRTUAL CLUSTER ALL WITH REPLICATION STATUS +SHOW VIRTUAL CLUSTER ALL WITH REPLICATION STATUS -- fully parenthesized +SHOW VIRTUAL CLUSTER ALL WITH REPLICATION STATUS -- literals removed +SHOW VIRTUAL CLUSTER ALL WITH REPLICATION STATUS -- identifiers removed parse -SHOW TENANT foo WITH REPLICATION STATUS, CAPABILITIES +SHOW VIRTUAL CLUSTER foo WITH REPLICATION STATUS, CAPABILITIES ---- -SHOW TENANT foo WITH REPLICATION STATUS, CAPABILITIES -SHOW TENANT (foo) WITH REPLICATION STATUS, CAPABILITIES -- fully parenthesized -SHOW TENANT foo WITH REPLICATION STATUS, CAPABILITIES -- literals removed -SHOW TENANT _ WITH REPLICATION STATUS, CAPABILITIES -- identifiers removed +SHOW VIRTUAL CLUSTER foo WITH REPLICATION STATUS, CAPABILITIES +SHOW VIRTUAL CLUSTER (foo) WITH REPLICATION STATUS, CAPABILITIES -- fully parenthesized +SHOW VIRTUAL CLUSTER foo WITH REPLICATION STATUS, CAPABILITIES -- literals removed +SHOW VIRTUAL CLUSTER _ WITH REPLICATION STATUS, CAPABILITIES -- identifiers removed parse SHOW BACKUP 'family' IN ('string', 'placeholder', 'placeholder', 'placeholder', 'string', 'placeholder', 'string', 'placeholder') WITH incremental_location = 'nullif', privileges, debug_dump_metadata_sst diff --git a/pkg/sql/sem/builtins/replication_builtins.go b/pkg/sql/sem/builtins/replication_builtins.go index eaf6606ac5e1..c83d2a5afe82 100644 --- a/pkg/sql/sem/builtins/replication_builtins.go +++ b/pkg/sql/sem/builtins/replication_builtins.go @@ -93,7 +93,7 @@ var replicationBuiltins = map[string]builtinDefinition{ // Keeping this builtin as 'unimplemented' in order to reserve the oid. return tree.DNull, errors.New("unimplemented") }, - Info: "DEPRECATED, consider using `SHOW TENANT name WITH REPLICATION STATUS`", + Info: "DEPRECATED, consider using `SHOW VIRTUAL CLUSTER name WITH REPLICATION STATUS`", Volatility: volatility.Volatile, }, ), @@ -114,7 +114,7 @@ var replicationBuiltins = map[string]builtinDefinition{ // Keeping this builtin as 'unimplemented' in order to reserve the oid. return tree.DNull, errors.New("unimplemented") }, - Info: "DEPRECATED, consider using `SHOW TENANT name WITH REPLICATION STATUS`", + Info: "DEPRECATED, consider using `SHOW VIRTUAL CLUSTER name WITH REPLICATION STATUS`", Volatility: volatility.Volatile, }, ), diff --git a/pkg/sql/sem/tree/show.go b/pkg/sql/sem/tree/show.go index fcf222faf16a..fc929a641600 100644 --- a/pkg/sql/sem/tree/show.go +++ b/pkg/sql/sem/tree/show.go @@ -1120,13 +1120,13 @@ func (node *ShowTableStats) Format(ctx *FmtCtx) { } } -// ShowTenantOptions represents the WITH clause in SHOW TENANT. +// ShowTenantOptions represents the WITH clause in SHOW VIRTUAL CLUSTER. type ShowTenantOptions struct { WithReplication bool WithCapabilities bool } -// ShowTenant represents a SHOW TENANT statement. +// ShowTenant represents a SHOW VIRTUAL CLUSTER statement. type ShowTenant struct { TenantSpec *TenantSpec ShowTenantOptions @@ -1134,7 +1134,7 @@ type ShowTenant struct { // Format implements the NodeFormatter interface. func (node *ShowTenant) Format(ctx *FmtCtx) { - ctx.WriteString("SHOW TENANT ") + ctx.WriteString("SHOW VIRTUAL CLUSTER ") ctx.FormatNode(node.TenantSpec) withs := []string{} diff --git a/pkg/sql/sem/tree/stmt.go b/pkg/sql/sem/tree/stmt.go index 78dab8d9796d..7e8b88f32fb7 100644 --- a/pkg/sql/sem/tree/stmt.go +++ b/pkg/sql/sem/tree/stmt.go @@ -1916,7 +1916,7 @@ func (*ShowTenant) StatementReturnType() StatementReturnType { return Rows } func (*ShowTenant) StatementType() StatementType { return TypeDML } // StatementTag returns a short string identifying the type of statement. -func (*ShowTenant) StatementTag() string { return "SHOW TENANT" } +func (*ShowTenant) StatementTag() string { return "SHOW VIRTUAL CLUSTER" } // StatementReturnType implements the Statement interface. func (*ShowFunctions) StatementReturnType() StatementReturnType { return Rows } diff --git a/pkg/sql/show_tenant.go b/pkg/sql/show_tenant.go index 964b804ff290..11599bc26f7d 100644 --- a/pkg/sql/show_tenant.go +++ b/pkg/sql/show_tenant.go @@ -64,7 +64,7 @@ func (p *planner) ShowTenant(ctx context.Context, n *tree.ShowTenant) (planNode, return nil, err } - tspec, err := p.planTenantSpec(ctx, n.TenantSpec, "SHOW TENANT") + tspec, err := p.planTenantSpec(ctx, n.TenantSpec, "SHOW VIRTUAL CLUSTER") if err != nil { return nil, err } @@ -223,7 +223,7 @@ func (n *showTenantNode) Values() tree.Datums { } if n.withReplication { - // This is a 'SHOW TENANT name WITH REPLICATION STATUS' command. + // This is a 'SHOW VIRTUAL CLUSTER name WITH REPLICATION STATUS' command. sourceTenantName := tree.DNull sourceClusterUri := tree.DNull replicationJobId := tree.DNull From 1eaeebf270b9c14eda5e67fbaa0c648d73739147 Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Tue, 4 Jul 2023 15:16:12 +0200 Subject: [PATCH 12/17] sql: `SHOW CLUSTER SETTING[s] FOR VIRTUAL CLUSTER` (aliased by `...FOR TENANT`) Release note: None --- docs/generated/sql/bnf/BUILD.bazel | 1 - .../show_local_or_tenant_csettings_stmt.bnf | 3 - docs/generated/sql/bnf/show_var.bnf | 1 - docs/generated/sql/bnf/stmt_block.bnf | 420 +++++++++--------- pkg/gen/bnf.bzl | 1 - pkg/gen/diagrams.bzl | 1 - pkg/gen/docs.bzl | 1 - pkg/sql/parser/help_test.go | 7 + pkg/sql/parser/sql.y | 20 +- pkg/sql/parser/testdata/show | 182 ++++---- pkg/sql/sem/tree/tenant_settings.go | 8 +- 11 files changed, 324 insertions(+), 321 deletions(-) delete mode 100644 docs/generated/sql/bnf/show_local_or_tenant_csettings_stmt.bnf diff --git a/docs/generated/sql/bnf/BUILD.bazel b/docs/generated/sql/bnf/BUILD.bazel index f36d383a538a..bfea71cbf69b 100644 --- a/docs/generated/sql/bnf/BUILD.bazel +++ b/docs/generated/sql/bnf/BUILD.bazel @@ -229,7 +229,6 @@ FILES = [ "show_indexes_stmt", "show_jobs", "show_keys", - "show_local_or_tenant_csettings_stmt", "show_locality", "show_locality_stmt", "show_partitions_stmt", diff --git a/docs/generated/sql/bnf/show_local_or_tenant_csettings_stmt.bnf b/docs/generated/sql/bnf/show_local_or_tenant_csettings_stmt.bnf deleted file mode 100644 index fd83ba3fe0f4..000000000000 --- a/docs/generated/sql/bnf/show_local_or_tenant_csettings_stmt.bnf +++ /dev/null @@ -1,3 +0,0 @@ -show_local_or_tenant_csettings_stmt ::= - show_csettings_stmt - | show_csettings_stmt 'FOR' 'TENANT' tenant_spec diff --git a/docs/generated/sql/bnf/show_var.bnf b/docs/generated/sql/bnf/show_var.bnf index e7af2f5ba330..620b311f5d71 100644 --- a/docs/generated/sql/bnf/show_var.bnf +++ b/docs/generated/sql/bnf/show_var.bnf @@ -5,7 +5,6 @@ show_stmt ::= | show_create_stmt | show_create_schedules_stmt | show_create_external_connections_stmt - | show_local_or_tenant_csettings_stmt | show_databases_stmt | show_enums_stmt | show_types_stmt diff --git a/docs/generated/sql/bnf/stmt_block.bnf b/docs/generated/sql/bnf/stmt_block.bnf index 6637b6bfdda2..f8b278d03d1b 100644 --- a/docs/generated/sql/bnf/stmt_block.bnf +++ b/docs/generated/sql/bnf/stmt_block.bnf @@ -270,7 +270,6 @@ show_stmt ::= | show_create_stmt | show_create_schedules_stmt | show_create_external_connections_stmt - | show_local_or_tenant_csettings_stmt | show_databases_stmt | show_enums_stmt | show_types_stmt @@ -811,10 +810,6 @@ show_create_external_connections_stmt ::= 'SHOW' 'CREATE' 'ALL' 'EXTERNAL' 'CONNECTIONS' | 'SHOW' 'CREATE' 'EXTERNAL' 'CONNECTION' string_or_placeholder -show_local_or_tenant_csettings_stmt ::= - show_csettings_stmt - | show_csettings_stmt 'FOR' 'TENANT' tenant_spec - show_databases_stmt ::= 'SHOW' 'DATABASES' with_comment @@ -1948,17 +1943,6 @@ with_comment ::= opt_show_create_format_options ::= 'WITH' 'REDACT' -show_csettings_stmt ::= - 'SHOW' 'CLUSTER' 'SETTING' var_name - | 'SHOW' 'CLUSTER' 'SETTING' 'ALL' - | 'SHOW' 'ALL' 'CLUSTER' 'SETTINGS' - | 'SHOW' 'CLUSTER' 'SETTINGS' - | 'SHOW' 'PUBLIC' 'CLUSTER' 'SETTINGS' - -tenant_spec ::= - d_expr - | '[' a_expr ']' - opt_on_targets_roles ::= 'ON' targets_roles | @@ -2699,31 +2683,6 @@ show_backup_connection_options ::= | 'TIME' '=' string_or_placeholder | 'CONCURRENTLY' '=' a_expr -d_expr ::= - 'ICONST' - | 'FCONST' - | 'SCONST' - | 'BCONST' - | 'BITCONST' - | typed_literal - | interval_value - | 'TRUE' - | 'FALSE' - | 'NULL' - | column_path_with_star - | '@' iconst64 - | 'PLACEHOLDER' - | '(' a_expr ')' '.' '*' - | '(' a_expr ')' '.' unrestricted_name - | '(' a_expr ')' '.' '@' 'ICONST' - | '(' a_expr ')' - | func_expr - | select_with_parens - | labeled_row - | 'ARRAY' select_with_parens - | 'ARRAY' row - | 'ARRAY' array_expr - targets_roles ::= 'ROLE' role_spec_list | 'SCHEMA' schema_name_list @@ -2999,6 +2958,31 @@ role_option ::= include_all_clusters ::= 'INCLUDE_ALL_VIRTUAL_CLUSTERS' +d_expr ::= + 'ICONST' + | 'FCONST' + | 'SCONST' + | 'BCONST' + | 'BITCONST' + | typed_literal + | interval_value + | 'TRUE' + | 'FALSE' + | 'NULL' + | column_path_with_star + | '@' iconst64 + | 'PLACEHOLDER' + | '(' a_expr ')' '.' '*' + | '(' a_expr ')' '.' unrestricted_name + | '(' a_expr ')' '.' '@' 'ICONST' + | '(' a_expr ')' + | func_expr + | select_with_parens + | labeled_row + | 'ARRAY' select_with_parens + | 'ARRAY' row + | 'ARRAY' array_expr + array_subscripts ::= ( array_subscript ) ( ( array_subscript ) )* @@ -3259,32 +3243,6 @@ show_backup_options ::= | 'ENCRYPTION_INFO_DIR' '=' string_or_placeholder | 'DEBUG_DUMP_METADATA_SST' -typed_literal ::= - func_name_no_crdb_extra 'SCONST' - | const_typename 'SCONST' - -interval_value ::= - 'INTERVAL' 'SCONST' opt_interval_qualifier - | 'INTERVAL' '(' iconst32 ')' 'SCONST' - -column_path_with_star ::= - column_path - | db_object_name_component '.' unrestricted_name '.' unrestricted_name '.' '*' - | db_object_name_component '.' unrestricted_name '.' '*' - | db_object_name_component '.' '*' - -func_expr ::= - func_application within_group_clause filter_clause over_clause - | func_expr_common_subexpr - -labeled_row ::= - row - | '(' row 'AS' name_list ')' - -array_expr ::= - '[' opt_expr_list ']' - | '[' array_expr_list ']' - schema_wildcard ::= wildcard_pattern @@ -3413,6 +3371,32 @@ valid_until_clause ::= 'VALID' 'UNTIL' string_or_placeholder | 'VALID' 'UNTIL' 'NULL' +typed_literal ::= + func_name_no_crdb_extra 'SCONST' + | const_typename 'SCONST' + +interval_value ::= + 'INTERVAL' 'SCONST' opt_interval_qualifier + | 'INTERVAL' '(' iconst32 ')' 'SCONST' + +column_path_with_star ::= + column_path + | db_object_name_component '.' unrestricted_name '.' unrestricted_name '.' '*' + | db_object_name_component '.' unrestricted_name '.' '*' + | db_object_name_component '.' '*' + +func_expr ::= + func_application within_group_clause filter_clause over_clause + | func_expr_common_subexpr + +labeled_row ::= + row + | '(' row 'AS' name_list ')' + +array_expr ::= + '[' opt_expr_list ']' + | '[' array_expr_list ']' + array_subscript ::= '[' a_expr ']' | '[' opt_slice_bound ':' opt_slice_bound ']' @@ -4128,62 +4112,6 @@ opt_nowait_or_skip ::= 'SKIP' 'LOCKED' | 'NOWAIT' -func_name_no_crdb_extra ::= - type_function_name_no_crdb_extra - | prefixed_column_path - -opt_interval_qualifier ::= - interval_qualifier - | - -func_application ::= - func_application_name '(' ')' - | func_application_name '(' expr_list opt_sort_clause ')' - | func_application_name '(' 'ALL' expr_list opt_sort_clause ')' - | func_application_name '(' 'DISTINCT' expr_list ')' - | func_application_name '(' '*' ')' - -within_group_clause ::= - 'WITHIN' 'GROUP' '(' single_sort_clause ')' - | - -filter_clause ::= - 'FILTER' '(' 'WHERE' a_expr ')' - | - -over_clause ::= - 'OVER' window_specification - | 'OVER' window_name - | - -func_expr_common_subexpr ::= - 'COLLATION' 'FOR' '(' a_expr ')' - | 'CURRENT_DATE' - | 'CURRENT_SCHEMA' - | 'CURRENT_CATALOG' - | 'CURRENT_TIMESTAMP' - | 'CURRENT_TIME' - | 'LOCALTIMESTAMP' - | 'LOCALTIME' - | 'CURRENT_USER' - | 'CURRENT_ROLE' - | 'SESSION_USER' - | 'USER' - | 'CAST' '(' a_expr 'AS' cast_target ')' - | 'ANNOTATE_TYPE' '(' a_expr ',' typename ')' - | 'IF' '(' a_expr ',' a_expr ',' a_expr ')' - | 'IFERROR' '(' a_expr ',' a_expr ',' a_expr ')' - | 'IFERROR' '(' a_expr ',' a_expr ')' - | 'ISERROR' '(' a_expr ')' - | 'ISERROR' '(' a_expr ',' a_expr ')' - | 'NULLIF' '(' a_expr ',' a_expr ')' - | 'IFNULL' '(' a_expr ',' a_expr ')' - | 'COALESCE' '(' expr_list ')' - | special_function - -array_expr_list ::= - ( array_expr ) ( ( ',' array_expr ) )* - wildcard_pattern ::= name '.' '*' @@ -4317,6 +4245,62 @@ storage_parameter_key_list ::= partition_by_index ::= partition_by +func_name_no_crdb_extra ::= + type_function_name_no_crdb_extra + | prefixed_column_path + +opt_interval_qualifier ::= + interval_qualifier + | + +func_application ::= + func_application_name '(' ')' + | func_application_name '(' expr_list opt_sort_clause ')' + | func_application_name '(' 'ALL' expr_list opt_sort_clause ')' + | func_application_name '(' 'DISTINCT' expr_list ')' + | func_application_name '(' '*' ')' + +within_group_clause ::= + 'WITHIN' 'GROUP' '(' single_sort_clause ')' + | + +filter_clause ::= + 'FILTER' '(' 'WHERE' a_expr ')' + | + +over_clause ::= + 'OVER' window_specification + | 'OVER' window_name + | + +func_expr_common_subexpr ::= + 'COLLATION' 'FOR' '(' a_expr ')' + | 'CURRENT_DATE' + | 'CURRENT_SCHEMA' + | 'CURRENT_CATALOG' + | 'CURRENT_TIMESTAMP' + | 'CURRENT_TIME' + | 'LOCALTIMESTAMP' + | 'LOCALTIME' + | 'CURRENT_USER' + | 'CURRENT_ROLE' + | 'SESSION_USER' + | 'USER' + | 'CAST' '(' a_expr 'AS' cast_target ')' + | 'ANNOTATE_TYPE' '(' a_expr ',' typename ')' + | 'IF' '(' a_expr ',' a_expr ',' a_expr ')' + | 'IFERROR' '(' a_expr ',' a_expr ',' a_expr ')' + | 'IFERROR' '(' a_expr ',' a_expr ')' + | 'ISERROR' '(' a_expr ')' + | 'ISERROR' '(' a_expr ',' a_expr ')' + | 'NULLIF' '(' a_expr ',' a_expr ')' + | 'IFNULL' '(' a_expr ',' a_expr ')' + | 'COALESCE' '(' expr_list ')' + | special_function + +array_expr_list ::= + ( array_expr ) ( ( ',' array_expr ) )* + opt_slice_bound ::= a_expr | @@ -4384,45 +4368,6 @@ group_by_item ::= window_definition ::= window_name 'AS' window_specification -func_application_name ::= - func_name - | '[' 'FUNCTION' iconst32 ']' - -single_sort_clause ::= - 'ORDER' 'BY' sortby - | 'ORDER' 'BY' sortby ',' sortby_list - -window_specification ::= - '(' opt_existing_window_name opt_partition_clause opt_sort_clause opt_frame_clause ')' - -window_name ::= - name - -special_function ::= - 'CURRENT_DATE' '(' ')' - | 'CURRENT_SCHEMA' '(' ')' - | 'CURRENT_TIMESTAMP' '(' ')' - | 'CURRENT_TIMESTAMP' '(' a_expr ')' - | 'CURRENT_TIME' '(' ')' - | 'CURRENT_TIME' '(' a_expr ')' - | 'LOCALTIMESTAMP' '(' ')' - | 'LOCALTIMESTAMP' '(' a_expr ')' - | 'LOCALTIME' '(' ')' - | 'LOCALTIME' '(' a_expr ')' - | 'CURRENT_USER' '(' ')' - | 'SESSION_USER' '(' ')' - | 'EXTRACT' '(' extract_list ')' - | 'EXTRACT_DURATION' '(' extract_list ')' - | 'OVERLAY' '(' overlay_list ')' - | 'POSITION' '(' position_list ')' - | 'SUBSTRING' '(' substr_list ')' - | 'TRIM' '(' 'BOTH' trim_list ')' - | 'TRIM' '(' 'LEADING' trim_list ')' - | 'TRIM' '(' 'TRAILING' trim_list ')' - | 'TRIM' '(' trim_list ')' - | 'GREATEST' '(' expr_list ')' - | 'LEAST' '(' expr_list ')' - func_param_class ::= 'IN' @@ -4506,6 +4451,45 @@ reference_actions ::= | reference_on_delete reference_on_update | +func_application_name ::= + func_name + | '[' 'FUNCTION' iconst32 ']' + +single_sort_clause ::= + 'ORDER' 'BY' sortby + | 'ORDER' 'BY' sortby ',' sortby_list + +window_specification ::= + '(' opt_existing_window_name opt_partition_clause opt_sort_clause opt_frame_clause ')' + +window_name ::= + name + +special_function ::= + 'CURRENT_DATE' '(' ')' + | 'CURRENT_SCHEMA' '(' ')' + | 'CURRENT_TIMESTAMP' '(' ')' + | 'CURRENT_TIMESTAMP' '(' a_expr ')' + | 'CURRENT_TIME' '(' ')' + | 'CURRENT_TIME' '(' a_expr ')' + | 'LOCALTIMESTAMP' '(' ')' + | 'LOCALTIMESTAMP' '(' a_expr ')' + | 'LOCALTIME' '(' ')' + | 'LOCALTIME' '(' a_expr ')' + | 'CURRENT_USER' '(' ')' + | 'SESSION_USER' '(' ')' + | 'EXTRACT' '(' extract_list ')' + | 'EXTRACT_DURATION' '(' extract_list ')' + | 'OVERLAY' '(' overlay_list ')' + | 'POSITION' '(' position_list ')' + | 'SUBSTRING' '(' substr_list ')' + | 'TRIM' '(' 'BOTH' trim_list ')' + | 'TRIM' '(' 'LEADING' trim_list ')' + | 'TRIM' '(' 'TRAILING' trim_list ')' + | 'TRIM' '(' trim_list ')' + | 'GREATEST' '(' expr_list ')' + | 'LEAST' '(' expr_list ')' + list_partition ::= partition 'VALUES' 'IN' '(' expr_list ')' opt_partition_by @@ -4528,6 +4512,30 @@ create_as_params ::= col_def_list ::= ( col_def ) ( ( ',' col_def ) )* +type_function_name ::= + 'identifier' + | unreserved_keyword + | type_func_name_keyword + +char_aliases ::= + 'CHAR' + | 'CHARACTER' + +col_qualification ::= + 'CONSTRAINT' constraint_name col_qualification_elem + | col_qualification_elem + | 'COLLATE' collation_name + | 'FAMILY' family_name + | 'CREATE' 'FAMILY' family_name + | 'CREATE' 'FAMILY' + | 'CREATE' 'IF' 'NOT' 'EXISTS' 'FAMILY' family_name + +reference_on_update ::= + 'ON' 'UPDATE' reference_action + +reference_on_delete ::= + 'ON' 'DELETE' reference_action + func_name ::= type_function_name | prefixed_column_path @@ -4572,30 +4580,6 @@ trim_list ::= | 'FROM' expr_list | expr_list -type_function_name ::= - 'identifier' - | unreserved_keyword - | type_func_name_keyword - -char_aliases ::= - 'CHAR' - | 'CHARACTER' - -col_qualification ::= - 'CONSTRAINT' constraint_name col_qualification_elem - | col_qualification_elem - | 'COLLATE' collation_name - | 'FAMILY' family_name - | 'CREATE' 'FAMILY' family_name - | 'CREATE' 'FAMILY' - | 'CREATE' 'IF' 'NOT' 'EXISTS' 'FAMILY' family_name - -reference_on_update ::= - 'ON' 'UPDATE' reference_action - -reference_on_delete ::= - 'ON' 'DELETE' reference_action - opt_partition_by ::= partition_by | @@ -4607,6 +4591,31 @@ col_def ::= name | name typename +col_qualification_elem ::= + 'NOT' 'NULL' + | 'NULL' + | 'NOT' 'VISIBLE' + | 'UNIQUE' + | 'PRIMARY' 'KEY' opt_with_storage_parameter_list + | 'PRIMARY' 'KEY' 'USING' 'HASH' opt_hash_sharded_bucket_count opt_with_storage_parameter_list + | 'CHECK' '(' a_expr ')' + | 'DEFAULT' b_expr + | 'ON' 'UPDATE' b_expr + | 'REFERENCES' table_name opt_name_parens key_match reference_actions + | generated_as '(' a_expr ')' 'STORED' + | generated_as '(' a_expr ')' 'VIRTUAL' + | generated_always_as 'IDENTITY' '(' opt_sequence_option_list ')' + | generated_by_default_as 'IDENTITY' '(' opt_sequence_option_list ')' + | generated_always_as 'IDENTITY' + | generated_by_default_as 'IDENTITY' + +reference_action ::= + 'NO' 'ACTION' + | 'RESTRICT' + | 'CASCADE' + | 'SET' 'NULL' + | 'SET' 'DEFAULT' + frame_extent ::= frame_bound | 'BETWEEN' frame_bound 'AND' frame_bound @@ -4637,38 +4646,6 @@ substr_from ::= substr_for ::= 'FOR' a_expr -col_qualification_elem ::= - 'NOT' 'NULL' - | 'NULL' - | 'NOT' 'VISIBLE' - | 'UNIQUE' - | 'PRIMARY' 'KEY' opt_with_storage_parameter_list - | 'PRIMARY' 'KEY' 'USING' 'HASH' opt_hash_sharded_bucket_count opt_with_storage_parameter_list - | 'CHECK' '(' a_expr ')' - | 'DEFAULT' b_expr - | 'ON' 'UPDATE' b_expr - | 'REFERENCES' table_name opt_name_parens key_match reference_actions - | generated_as '(' a_expr ')' 'STORED' - | generated_as '(' a_expr ')' 'VIRTUAL' - | generated_always_as 'IDENTITY' '(' opt_sequence_option_list ')' - | generated_by_default_as 'IDENTITY' '(' opt_sequence_option_list ')' - | generated_always_as 'IDENTITY' - | generated_by_default_as 'IDENTITY' - -reference_action ::= - 'NO' 'ACTION' - | 'RESTRICT' - | 'CASCADE' - | 'SET' 'NULL' - | 'SET' 'DEFAULT' - -frame_bound ::= - 'UNBOUNDED' 'PRECEDING' - | 'UNBOUNDED' 'FOLLOWING' - | 'CURRENT' 'ROW' - | a_expr 'PRECEDING' - | a_expr 'FOLLOWING' - opt_name_parens ::= '(' name ')' | @@ -4682,3 +4659,10 @@ generated_always_as ::= generated_by_default_as ::= 'GENERATED_BY_DEFAULT' 'BY' 'DEFAULT' 'AS' + +frame_bound ::= + 'UNBOUNDED' 'PRECEDING' + | 'UNBOUNDED' 'FOLLOWING' + | 'CURRENT' 'ROW' + | a_expr 'PRECEDING' + | a_expr 'FOLLOWING' diff --git a/pkg/gen/bnf.bzl b/pkg/gen/bnf.bzl index 1b17baf5346e..243b543d143e 100644 --- a/pkg/gen/bnf.bzl +++ b/pkg/gen/bnf.bzl @@ -229,7 +229,6 @@ BNF_SRCS = [ "//docs/generated/sql/bnf:show_indexes_stmt.bnf", "//docs/generated/sql/bnf:show_jobs.bnf", "//docs/generated/sql/bnf:show_keys.bnf", - "//docs/generated/sql/bnf:show_local_or_tenant_csettings_stmt.bnf", "//docs/generated/sql/bnf:show_locality.bnf", "//docs/generated/sql/bnf:show_locality_stmt.bnf", "//docs/generated/sql/bnf:show_partitions_stmt.bnf", diff --git a/pkg/gen/diagrams.bzl b/pkg/gen/diagrams.bzl index 8f19b937877a..68f052810626 100644 --- a/pkg/gen/diagrams.bzl +++ b/pkg/gen/diagrams.bzl @@ -228,7 +228,6 @@ DIAGRAMS_SRCS = [ "//docs/generated/sql/bnf:show_indexes.html", "//docs/generated/sql/bnf:show_jobs.html", "//docs/generated/sql/bnf:show_keys.html", - "//docs/generated/sql/bnf:show_local_or_tenant_csettings.html", "//docs/generated/sql/bnf:show_locality.html", "//docs/generated/sql/bnf:show_partitions.html", "//docs/generated/sql/bnf:show_range_for_row.html", diff --git a/pkg/gen/docs.bzl b/pkg/gen/docs.bzl index 77416ac1fb91..fd8d25e96e7b 100644 --- a/pkg/gen/docs.bzl +++ b/pkg/gen/docs.bzl @@ -241,7 +241,6 @@ DOCS_SRCS = [ "//docs/generated/sql/bnf:show_indexes_stmt.bnf", "//docs/generated/sql/bnf:show_jobs.bnf", "//docs/generated/sql/bnf:show_keys.bnf", - "//docs/generated/sql/bnf:show_local_or_tenant_csettings_stmt.bnf", "//docs/generated/sql/bnf:show_locality.bnf", "//docs/generated/sql/bnf:show_locality_stmt.bnf", "//docs/generated/sql/bnf:show_partitions_stmt.bnf", diff --git a/pkg/sql/parser/help_test.go b/pkg/sql/parser/help_test.go index 8b90e8c7aeee..da800640f1c9 100644 --- a/pkg/sql/parser/help_test.go +++ b/pkg/sql/parser/help_test.go @@ -364,6 +364,13 @@ func TestContextualHelp(t *testing.T) { {`SHOW CLUSTER SETTING all ??`, `SHOW CLUSTER SETTING`}, {`SHOW ALL CLUSTER ??`, `SHOW CLUSTER SETTING`}, + + {`SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER ??`, `SHOW CLUSTER SETTING`}, + {`SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER ??`, `SHOW CLUSTER SETTING`}, + {`SHOW CLUSTER SETTINGS FOR VIRTUAL CLUSTER ??`, `SHOW CLUSTER SETTING`}, + {`SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER ??`, `SHOW CLUSTER SETTING`}, + + // Compatibility. {`SHOW CLUSTER SETTING a FOR TENANT ??`, `SHOW CLUSTER SETTING`}, {`SHOW ALL CLUSTER SETTINGS FOR TENANT ??`, `SHOW CLUSTER SETTING`}, {`SHOW CLUSTER SETTINGS FOR TENANT ??`, `SHOW CLUSTER SETTING`}, diff --git a/pkg/sql/parser/sql.y b/pkg/sql/parser/sql.y index afbd89a6903e..b2af2b4dcc3e 100644 --- a/pkg/sql/parser/sql.y +++ b/pkg/sql/parser/sql.y @@ -1270,7 +1270,7 @@ func (u *sqlSymUnion) showCreateFormatOption() tree.ShowCreateFormatOption { %type opt_show_create_format_options %type show_create_schedules_stmt %type show_create_external_connections_stmt -%type show_csettings_stmt show_local_or_tenant_csettings_stmt +%type show_csettings_stmt show_local_or_virtual_cluster_csettings_stmt %type show_databases_stmt %type show_default_privileges_stmt %type show_enums_stmt @@ -7071,7 +7071,7 @@ show_stmt: | show_create_stmt // EXTEND WITH HELP: SHOW CREATE | show_create_schedules_stmt // EXTEND WITH HELP: SHOW CREATE SCHEDULES | show_create_external_connections_stmt // EXTEND WITH HELP: SHOW CREATE EXTERNAL CONNECTIONS -| show_local_or_tenant_csettings_stmt // EXTEND WITH HELP: SHOW CLUSTER SETTING +| show_local_or_virtual_cluster_csettings_stmt // EXTEND WITH HELP: SHOW CLUSTER SETTING | show_databases_stmt // EXTEND WITH HELP: SHOW DATABASES | show_enums_stmt // EXTEND WITH HELP: SHOW ENUMS | show_types_stmt // EXTEND WITH HELP: SHOW TYPES @@ -7659,8 +7659,8 @@ show_backup_connection_options: // %Help: SHOW CLUSTER SETTING - display cluster settings // %Category: Cfg // %Text: -// SHOW CLUSTER SETTING [ FOR TENANT ] -// SHOW [ PUBLIC | ALL ] CLUSTER SETTINGS [ FOR TENANT ] +// SHOW CLUSTER SETTING [ FOR VIRTUAL CLUSTER ] +// SHOW [ PUBLIC | ALL ] CLUSTER SETTINGS [ FOR VIRTUAL CLUSTER ] // %SeeAlso: WEBDOCS/cluster-settings.html show_csettings_stmt: SHOW CLUSTER SETTING var_name @@ -7687,11 +7687,15 @@ show_csettings_stmt: } | SHOW PUBLIC CLUSTER error // SHOW HELP: SHOW CLUSTER SETTING -show_local_or_tenant_csettings_stmt: +show_local_or_virtual_cluster_csettings_stmt: show_csettings_stmt - { $$.val = $1.stmt() } -| show_csettings_stmt FOR TENANT tenant_spec { + /* SKIP DOC */ + $$.val = $1.stmt() + } +| show_csettings_stmt FOR virtual_cluster tenant_spec + { + /* SKIP DOC */ switch t := $1.stmt().(type) { case *tree.ShowClusterSetting: $$.val = &tree.ShowTenantClusterSetting{ @@ -7705,7 +7709,7 @@ show_local_or_tenant_csettings_stmt: } } } -| show_csettings_stmt FOR TENANT error // SHOW HELP: SHOW CLUSTER SETTING +| show_csettings_stmt FOR virtual_cluster error // SHOW HELP: SHOW CLUSTER SETTING // %Help: SHOW COLUMNS - list columns in relation // %Category: DDL diff --git a/pkg/sql/parser/testdata/show b/pkg/sql/parser/testdata/show index db7d26297487..96b2c84b3744 100644 --- a/pkg/sql/parser/testdata/show +++ b/pkg/sql/parser/testdata/show @@ -127,140 +127,156 @@ SHOW PUBLIC CLUSTER SETTINGS -- literals removed SHOW PUBLIC CLUSTER SETTINGS -- identifiers removed parse -SHOW CLUSTER SETTING a FOR TENANT 123 +SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER 123 ---- +SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER 123 +SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER (123) -- fully parenthesized +SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER _ -- literals removed +SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER 123 -- identifiers removed + +parse SHOW CLUSTER SETTING a FOR TENANT 123 -SHOW CLUSTER SETTING a FOR TENANT (123) -- fully parenthesized -SHOW CLUSTER SETTING a FOR TENANT _ -- literals removed -SHOW CLUSTER SETTING a FOR TENANT 123 -- identifiers removed +---- +SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER 123 -- normalized! +SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER (123) -- fully parenthesized +SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER _ -- literals removed +SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER 123 -- identifiers removed parse -SHOW CLUSTER SETTING a FOR TENANT (1+1) +SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER (1+1) ---- -SHOW CLUSTER SETTING a FOR TENANT (1 + 1) -- normalized! -SHOW CLUSTER SETTING a FOR TENANT ((((1) + (1)))) -- fully parenthesized -SHOW CLUSTER SETTING a FOR TENANT (_ + _) -- literals removed -SHOW CLUSTER SETTING a FOR TENANT (1 + 1) -- identifiers removed +SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER (1 + 1) -- normalized! +SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER ((((1) + (1)))) -- fully parenthesized +SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER (_ + _) -- literals removed +SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER (1 + 1) -- identifiers removed parse -SHOW CLUSTER SETTING a FOR TENANT $1 +SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER $1 ---- -SHOW CLUSTER SETTING a FOR TENANT $1 -SHOW CLUSTER SETTING a FOR TENANT ($1) -- fully parenthesized -SHOW CLUSTER SETTING a FOR TENANT $1 -- literals removed -SHOW CLUSTER SETTING a FOR TENANT $1 -- identifiers removed +SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER $1 +SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER ($1) -- fully parenthesized +SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER $1 -- literals removed +SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER $1 -- identifiers removed parse -EXPLAIN SHOW CLUSTER SETTING a FOR TENANT 1 +EXPLAIN SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER 1 ---- -EXPLAIN SHOW CLUSTER SETTING a FOR TENANT 1 -EXPLAIN SHOW CLUSTER SETTING a FOR TENANT (1) -- fully parenthesized -EXPLAIN SHOW CLUSTER SETTING a FOR TENANT _ -- literals removed -EXPLAIN SHOW CLUSTER SETTING a FOR TENANT 1 -- identifiers removed +EXPLAIN SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER 1 +EXPLAIN SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER (1) -- fully parenthesized +EXPLAIN SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER _ -- literals removed +EXPLAIN SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER 1 -- identifiers removed parse -EXPLAIN SHOW CLUSTER SETTING a FOR TENANT 123 +EXPLAIN SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER 123 ---- -EXPLAIN SHOW CLUSTER SETTING a FOR TENANT 123 -EXPLAIN SHOW CLUSTER SETTING a FOR TENANT (123) -- fully parenthesized -EXPLAIN SHOW CLUSTER SETTING a FOR TENANT _ -- literals removed -EXPLAIN SHOW CLUSTER SETTING a FOR TENANT 123 -- identifiers removed +EXPLAIN SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER 123 +EXPLAIN SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER (123) -- fully parenthesized +EXPLAIN SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER _ -- literals removed +EXPLAIN SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER 123 -- identifiers removed parse -EXPLAIN SHOW CLUSTER SETTING a FOR TENANT (1+1) +EXPLAIN SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER (1+1) ---- -EXPLAIN SHOW CLUSTER SETTING a FOR TENANT (1 + 1) -- normalized! -EXPLAIN SHOW CLUSTER SETTING a FOR TENANT ((((1) + (1)))) -- fully parenthesized -EXPLAIN SHOW CLUSTER SETTING a FOR TENANT (_ + _) -- literals removed -EXPLAIN SHOW CLUSTER SETTING a FOR TENANT (1 + 1) -- identifiers removed +EXPLAIN SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER (1 + 1) -- normalized! +EXPLAIN SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER ((((1) + (1)))) -- fully parenthesized +EXPLAIN SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER (_ + _) -- literals removed +EXPLAIN SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER (1 + 1) -- identifiers removed parse -EXPLAIN SHOW CLUSTER SETTING a FOR TENANT $1 +EXPLAIN SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER $1 ---- -EXPLAIN SHOW CLUSTER SETTING a FOR TENANT $1 -EXPLAIN SHOW CLUSTER SETTING a FOR TENANT ($1) -- fully parenthesized -EXPLAIN SHOW CLUSTER SETTING a FOR TENANT $1 -- literals removed -EXPLAIN SHOW CLUSTER SETTING a FOR TENANT $1 -- identifiers removed +EXPLAIN SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER $1 +EXPLAIN SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER ($1) -- fully parenthesized +EXPLAIN SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER $1 -- literals removed +EXPLAIN SHOW CLUSTER SETTING a FOR VIRTUAL CLUSTER $1 -- identifiers removed parse SHOW ALL CLUSTER SETTINGS FOR TENANT 1 ---- -SHOW ALL CLUSTER SETTINGS FOR TENANT 1 -SHOW ALL CLUSTER SETTINGS FOR TENANT (1) -- fully parenthesized -SHOW ALL CLUSTER SETTINGS FOR TENANT _ -- literals removed -SHOW ALL CLUSTER SETTINGS FOR TENANT 1 -- identifiers removed +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER 1 -- normalized! +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER (1) -- fully parenthesized +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER _ -- literals removed +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER 1 -- identifiers removed + +parse +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER 1 +---- +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER 1 +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER (1) -- fully parenthesized +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER _ -- literals removed +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER 1 -- identifiers removed parse -SHOW ALL CLUSTER SETTINGS FOR TENANT 123 +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER 123 ---- -SHOW ALL CLUSTER SETTINGS FOR TENANT 123 -SHOW ALL CLUSTER SETTINGS FOR TENANT (123) -- fully parenthesized -SHOW ALL CLUSTER SETTINGS FOR TENANT _ -- literals removed -SHOW ALL CLUSTER SETTINGS FOR TENANT 123 -- identifiers removed +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER 123 +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER (123) -- fully parenthesized +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER _ -- literals removed +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER 123 -- identifiers removed parse -SHOW ALL CLUSTER SETTINGS FOR TENANT (1+1) +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER (1+1) ---- -SHOW ALL CLUSTER SETTINGS FOR TENANT (1 + 1) -- normalized! -SHOW ALL CLUSTER SETTINGS FOR TENANT ((((1) + (1)))) -- fully parenthesized -SHOW ALL CLUSTER SETTINGS FOR TENANT (_ + _) -- literals removed -SHOW ALL CLUSTER SETTINGS FOR TENANT (1 + 1) -- identifiers removed +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER (1 + 1) -- normalized! +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER ((((1) + (1)))) -- fully parenthesized +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER (_ + _) -- literals removed +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER (1 + 1) -- identifiers removed parse -SHOW ALL CLUSTER SETTINGS FOR TENANT $1 +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER $1 ---- -SHOW ALL CLUSTER SETTINGS FOR TENANT $1 -SHOW ALL CLUSTER SETTINGS FOR TENANT ($1) -- fully parenthesized -SHOW ALL CLUSTER SETTINGS FOR TENANT $1 -- literals removed -SHOW ALL CLUSTER SETTINGS FOR TENANT $1 -- identifiers removed +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER $1 +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER ($1) -- fully parenthesized +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER $1 -- literals removed +SHOW ALL CLUSTER SETTINGS FOR VIRTUAL CLUSTER $1 -- identifiers removed parse -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT 123 +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER 123 ---- -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT 123 -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT (123) -- fully parenthesized -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT _ -- literals removed -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT 123 -- identifiers removed +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER 123 +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER (123) -- fully parenthesized +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER _ -- literals removed +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER 123 -- identifiers removed parse -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT (1+1) +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER (1+1) ---- -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT (1 + 1) -- normalized! -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT ((((1) + (1)))) -- fully parenthesized -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT (_ + _) -- literals removed -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT (1 + 1) -- identifiers removed +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER (1 + 1) -- normalized! +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER ((((1) + (1)))) -- fully parenthesized +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER (_ + _) -- literals removed +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER (1 + 1) -- identifiers removed parse -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT $1 +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER $1 ---- -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT $1 -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT ($1) -- fully parenthesized -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT $1 -- literals removed -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT $1 -- identifiers removed +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER $1 +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER ($1) -- fully parenthesized +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER $1 -- literals removed +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER $1 -- identifiers removed parse -SHOW CLUSTER SETTINGS FOR TENANT 123 +SHOW CLUSTER SETTINGS FOR VIRTUAL CLUSTER 123 ---- -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT 123 -- normalized! -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT (123) -- fully parenthesized -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT _ -- literals removed -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT 123 -- identifiers removed +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER 123 -- normalized! +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER (123) -- fully parenthesized +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER _ -- literals removed +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER 123 -- identifiers removed parse -SHOW CLUSTER SETTINGS FOR TENANT (1+1) +SHOW CLUSTER SETTINGS FOR VIRTUAL CLUSTER (1+1) ---- -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT (1 + 1) -- normalized! -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT ((((1) + (1)))) -- fully parenthesized -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT (_ + _) -- literals removed -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT (1 + 1) -- identifiers removed +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER (1 + 1) -- normalized! +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER ((((1) + (1)))) -- fully parenthesized +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER (_ + _) -- literals removed +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER (1 + 1) -- identifiers removed parse -SHOW CLUSTER SETTINGS FOR TENANT $1 +SHOW CLUSTER SETTINGS FOR VIRTUAL CLUSTER $1 ---- -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT $1 -- normalized! -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT ($1) -- fully parenthesized -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT $1 -- literals removed -SHOW PUBLIC CLUSTER SETTINGS FOR TENANT $1 -- identifiers removed +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER $1 -- normalized! +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER ($1) -- fully parenthesized +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER $1 -- literals removed +SHOW PUBLIC CLUSTER SETTINGS FOR VIRTUAL CLUSTER $1 -- identifiers removed parse SHOW DATABASES diff --git a/pkg/sql/sem/tree/tenant_settings.go b/pkg/sql/sem/tree/tenant_settings.go index f928b859f011..36f25c4ccae1 100644 --- a/pkg/sql/sem/tree/tenant_settings.go +++ b/pkg/sql/sem/tree/tenant_settings.go @@ -25,7 +25,7 @@ func (n *AlterTenantSetClusterSetting) Format(ctx *FmtCtx) { ctx.FormatNode(&n.SetClusterSetting) } -// ShowTenantClusterSetting represents a SHOW CLUSTER SETTING ... FOR TENANT statement. +// ShowTenantClusterSetting represents a SHOW CLUSTER SETTING ... FOR VIRTUAL CLUSTER statement. type ShowTenantClusterSetting struct { *ShowClusterSetting TenantSpec *TenantSpec @@ -34,11 +34,11 @@ type ShowTenantClusterSetting struct { // Format implements the NodeFormatter interface. func (node *ShowTenantClusterSetting) Format(ctx *FmtCtx) { ctx.FormatNode(node.ShowClusterSetting) - ctx.WriteString(" FOR TENANT ") + ctx.WriteString(" FOR VIRTUAL CLUSTER ") ctx.FormatNode(node.TenantSpec) } -// ShowTenantClusterSettingList represents a SHOW CLUSTER SETTINGS FOR TENANT statement. +// ShowTenantClusterSettingList represents a SHOW CLUSTER SETTINGS FOR VIRTUAL CLUSTER statement. type ShowTenantClusterSettingList struct { *ShowClusterSettingList TenantSpec *TenantSpec @@ -47,6 +47,6 @@ type ShowTenantClusterSettingList struct { // Format implements the NodeFormatter interface. func (node *ShowTenantClusterSettingList) Format(ctx *FmtCtx) { ctx.FormatNode(node.ShowClusterSettingList) - ctx.WriteString(" FOR TENANT ") + ctx.WriteString(" FOR VIRTUAL CLUSTER ") ctx.FormatNode(node.TenantSpec) } From 352c852d8bdf3a88174d8c08c9da9aed80b3dd73 Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Tue, 4 Jul 2023 15:21:10 +0200 Subject: [PATCH 13/17] sql: `BACKUP VIRTUAL CLUSTER` (aliased by `BACKUP TENANT`) Release note: None --- docs/generated/sql/bnf/stmt_block.bnf | 8 ++-- pkg/sql/parser/sql.y | 6 ++- pkg/sql/parser/testdata/backup_restore | 56 +++++++++++++++----------- pkg/sql/sem/tree/backup.go | 2 +- 4 files changed, 40 insertions(+), 32 deletions(-) diff --git a/docs/generated/sql/bnf/stmt_block.bnf b/docs/generated/sql/bnf/stmt_block.bnf index f8b278d03d1b..5ea97b361785 100644 --- a/docs/generated/sql/bnf/stmt_block.bnf +++ b/docs/generated/sql/bnf/stmt_block.bnf @@ -727,8 +727,6 @@ backup_targets ::= | complex_table_pattern | table_pattern ',' table_pattern_list | 'TABLE' table_pattern_list - | 'TENANT' iconst64 - | 'TENANT' 'identifier' | 'DATABASE' name_list resume_jobs_stmt ::= @@ -1873,9 +1871,6 @@ var_name ::= restore_options_list ::= ( restore_options ) ( ( ',' restore_options ) )* -iconst64 ::= - 'ICONST' - opt_scrub_options_clause ::= 'WITH' 'OPTIONS' scrub_option_list | @@ -2278,6 +2273,9 @@ alter_func_set_schema_stmt ::= alter_func_dep_extension_stmt ::= 'ALTER' 'FUNCTION' function_with_paramtypes opt_no 'DEPENDS' 'ON' 'EXTENSION' name +iconst64 ::= + 'ICONST' + alter_backup_schedule_cmds ::= ( alter_backup_schedule_cmd ) ( ( ',' alter_backup_schedule_cmd ) )* diff --git a/pkg/sql/parser/sql.y b/pkg/sql/parser/sql.y index b2af2b4dcc3e..0a74f923bafa 100644 --- a/pkg/sql/parser/sql.y +++ b/pkg/sql/parser/sql.y @@ -8995,16 +8995,18 @@ backup_targets: } // TODO(knz): This should learn how to parse more complex expressions // and placeholders. -| TENANT iconst64 +| virtual_cluster iconst64 { + /* SKIP DOC */ tenID := uint64($2.int64()) if tenID == 0 { return setErr(sqllex, errors.New("invalid tenant ID")) } $$.val = tree.BackupTargetList{TenantID: tree.TenantID{Specified: true, ID: tenID}} } -| TENANT IDENT +| virtual_cluster IDENT { + /* SKIP DOC */ // TODO(knz): This rule can go away once the main clause above supports // arbitrary expressions. if $2 != "_" { diff --git a/pkg/sql/parser/testdata/backup_restore b/pkg/sql/parser/testdata/backup_restore index a247921f4042..db5ca40a3646 100644 --- a/pkg/sql/parser/testdata/backup_restore +++ b/pkg/sql/parser/testdata/backup_restore @@ -392,12 +392,20 @@ BACKUP TABLE foo TO '_' WITH detached = FALSE -- literals removed BACKUP TABLE _ TO 'bar' WITH detached = FALSE -- identifiers removed parse -BACKUP TENANT 36 TO 'bar' +BACKUP VIRTUAL CLUSTER 36 TO 'bar' ---- +BACKUP VIRTUAL CLUSTER 36 TO 'bar' +BACKUP VIRTUAL CLUSTER 36 TO ('bar') -- fully parenthesized +BACKUP VIRTUAL CLUSTER _ TO '_' -- literals removed +BACKUP VIRTUAL CLUSTER 36 TO 'bar' -- identifiers removed + +parse BACKUP TENANT 36 TO 'bar' -BACKUP TENANT 36 TO ('bar') -- fully parenthesized -BACKUP TENANT _ TO '_' -- literals removed -BACKUP TENANT 36 TO 'bar' -- identifiers removed +---- +BACKUP VIRTUAL CLUSTER 36 TO 'bar' -- normalized! +BACKUP VIRTUAL CLUSTER 36 TO ('bar') -- fully parenthesized +BACKUP VIRTUAL CLUSTER _ TO '_' -- literals removed +BACKUP VIRTUAL CLUSTER 36 TO 'bar' -- identifiers removed parse RESTORE TABLE foo FROM 'bar' @@ -746,42 +754,42 @@ RESTORE TABLE foo FROM 'bar' WITH encryption_passphrase = 'secret', into_db = 'b parse RESTORE TENANT 36 FROM ($1, $2) AS OF SYSTEM TIME '1' ---- -RESTORE TENANT 36 FROM ($1, $2) AS OF SYSTEM TIME '1' -RESTORE TENANT 36 FROM (($1), ($2)) AS OF SYSTEM TIME ('1') -- fully parenthesized -RESTORE TENANT _ FROM ($1, $1) AS OF SYSTEM TIME '_' -- literals removed -RESTORE TENANT 36 FROM ($1, $2) AS OF SYSTEM TIME '1' -- identifiers removed +RESTORE VIRTUAL CLUSTER 36 FROM ($1, $2) AS OF SYSTEM TIME '1' -- normalized! +RESTORE VIRTUAL CLUSTER 36 FROM (($1), ($2)) AS OF SYSTEM TIME ('1') -- fully parenthesized +RESTORE VIRTUAL CLUSTER _ FROM ($1, $1) AS OF SYSTEM TIME '_' -- literals removed +RESTORE VIRTUAL CLUSTER 36 FROM ($1, $2) AS OF SYSTEM TIME '1' -- identifiers removed parse RESTORE TENANT 36 FROM ($1, $2) WITH virtual_cluster_name = 'tenant-5' ---- -RESTORE TENANT 36 FROM ($1, $2) WITH virtual_cluster_name = 'tenant-5' -RESTORE TENANT 36 FROM (($1), ($2)) WITH virtual_cluster_name = ('tenant-5') -- fully parenthesized -RESTORE TENANT _ FROM ($1, $1) WITH virtual_cluster_name = '_' -- literals removed -RESTORE TENANT 36 FROM ($1, $2) WITH virtual_cluster_name = 'tenant-5' -- identifiers removed +RESTORE VIRTUAL CLUSTER 36 FROM ($1, $2) WITH virtual_cluster_name = 'tenant-5' -- normalized! +RESTORE VIRTUAL CLUSTER 36 FROM (($1), ($2)) WITH virtual_cluster_name = ('tenant-5') -- fully parenthesized +RESTORE VIRTUAL CLUSTER _ FROM ($1, $1) WITH virtual_cluster_name = '_' -- literals removed +RESTORE VIRTUAL CLUSTER 36 FROM ($1, $2) WITH virtual_cluster_name = 'tenant-5' -- identifiers removed parse RESTORE TENANT 36 FROM ($1, $2) WITH tenant_name = 'tenant-5' ---- -RESTORE TENANT 36 FROM ($1, $2) WITH virtual_cluster_name = 'tenant-5' -- normalized! -RESTORE TENANT 36 FROM (($1), ($2)) WITH virtual_cluster_name = ('tenant-5') -- fully parenthesized -RESTORE TENANT _ FROM ($1, $1) WITH virtual_cluster_name = '_' -- literals removed -RESTORE TENANT 36 FROM ($1, $2) WITH virtual_cluster_name = 'tenant-5' -- identifiers removed +RESTORE VIRTUAL CLUSTER 36 FROM ($1, $2) WITH virtual_cluster_name = 'tenant-5' -- normalized! +RESTORE VIRTUAL CLUSTER 36 FROM (($1), ($2)) WITH virtual_cluster_name = ('tenant-5') -- fully parenthesized +RESTORE VIRTUAL CLUSTER _ FROM ($1, $1) WITH virtual_cluster_name = '_' -- literals removed +RESTORE VIRTUAL CLUSTER 36 FROM ($1, $2) WITH virtual_cluster_name = 'tenant-5' -- identifiers removed parse RESTORE TENANT 36 FROM ($1, $2) WITH virtual_cluster = '5' ---- -RESTORE TENANT 36 FROM ($1, $2) WITH virtual_cluster = '5' -RESTORE TENANT 36 FROM (($1), ($2)) WITH virtual_cluster = ('5') -- fully parenthesized -RESTORE TENANT _ FROM ($1, $1) WITH virtual_cluster = '_' -- literals removed -RESTORE TENANT 36 FROM ($1, $2) WITH virtual_cluster = '5' -- identifiers removed +RESTORE VIRTUAL CLUSTER 36 FROM ($1, $2) WITH virtual_cluster = '5' -- normalized! +RESTORE VIRTUAL CLUSTER 36 FROM (($1), ($2)) WITH virtual_cluster = ('5') -- fully parenthesized +RESTORE VIRTUAL CLUSTER _ FROM ($1, $1) WITH virtual_cluster = '_' -- literals removed +RESTORE VIRTUAL CLUSTER 36 FROM ($1, $2) WITH virtual_cluster = '5' -- identifiers removed parse RESTORE TENANT 36 FROM ($1, $2) WITH tenant = '5' ---- -RESTORE TENANT 36 FROM ($1, $2) WITH virtual_cluster = '5' -- normalized! -RESTORE TENANT 36 FROM (($1), ($2)) WITH virtual_cluster = ('5') -- fully parenthesized -RESTORE TENANT _ FROM ($1, $1) WITH virtual_cluster = '_' -- literals removed -RESTORE TENANT 36 FROM ($1, $2) WITH virtual_cluster = '5' -- identifiers removed +RESTORE VIRTUAL CLUSTER 36 FROM ($1, $2) WITH virtual_cluster = '5' -- normalized! +RESTORE VIRTUAL CLUSTER 36 FROM (($1), ($2)) WITH virtual_cluster = ('5') -- fully parenthesized +RESTORE VIRTUAL CLUSTER _ FROM ($1, $1) WITH virtual_cluster = '_' -- literals removed +RESTORE VIRTUAL CLUSTER 36 FROM ($1, $2) WITH virtual_cluster = '5' -- identifiers removed parse BACKUP TABLE foo TO 'bar' WITH revision_history, detached diff --git a/pkg/sql/sem/tree/backup.go b/pkg/sql/sem/tree/backup.go index c18318690934..61cb70aaffeb 100644 --- a/pkg/sql/sem/tree/backup.go +++ b/pkg/sql/sem/tree/backup.go @@ -677,7 +677,7 @@ func (tl *BackupTargetList) Format(ctx *FmtCtx) { ctx.WriteString("SCHEMA ") ctx.FormatNode(&tl.Schemas) } else if tl.TenantID.Specified { - ctx.WriteString("TENANT ") + ctx.WriteString("VIRTUAL CLUSTER ") ctx.FormatNode(&tl.TenantID) } else { if tl.Tables.SequenceOnly { From a47897a387c021f5966fad892053925b7b22c7c6 Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Tue, 4 Jul 2023 15:52:31 +0200 Subject: [PATCH 14/17] sql: `ALTER VIRTUAL CLUSTER` (aliased by `ALTER TENANT`) Release note: None --- .../alter_replication_job_test.go | 4 +- pkg/sql/parser/help_test.go | 52 ++- pkg/sql/parser/sql.y | 139 +++--- pkg/sql/parser/testdata/alter_tenant | 306 ------------- pkg/sql/parser/testdata/alter_virtual_cluster | 410 ++++++++++++++++++ pkg/sql/sem/asof/as_of.go | 4 +- pkg/sql/sem/tree/alter_tenant.go | 20 +- pkg/sql/sem/tree/stmt.go | 12 +- pkg/sql/sem/tree/tenant_settings.go | 4 +- 9 files changed, 547 insertions(+), 404 deletions(-) delete mode 100644 pkg/sql/parser/testdata/alter_tenant create mode 100644 pkg/sql/parser/testdata/alter_virtual_cluster diff --git a/pkg/ccl/streamingccl/streamingest/alter_replication_job_test.go b/pkg/ccl/streamingccl/streamingest/alter_replication_job_test.go index f602742bfdd5..a395ceaad9fb 100644 --- a/pkg/ccl/streamingccl/streamingest/alter_replication_job_test.go +++ b/pkg/ccl/streamingccl/streamingest/alter_replication_job_test.go @@ -133,8 +133,8 @@ func TestAlterTenantPauseResume(t *testing.T) { t.Run("pause-resume-in-readonly-txn", func(t *testing.T) { c.DestSysSQL.Exec(t, `set default_transaction_read_only = on;`) - c.DestSysSQL.ExpectErr(t, "cannot execute ALTER TENANT REPLICATION in a read-only transaction", `ALTER TENANT $1 PAUSE REPLICATION`, "foo") - c.DestSysSQL.ExpectErr(t, "cannot execute ALTER TENANT REPLICATION in a read-only transaction", `ALTER TENANT $1 RESUME REPLICATION`, "foo") + c.DestSysSQL.ExpectErr(t, "cannot execute ALTER VIRTUAL CLUSTER REPLICATION in a read-only transaction", `ALTER TENANT $1 PAUSE REPLICATION`, "foo") + c.DestSysSQL.ExpectErr(t, "cannot execute ALTER VIRTUAL CLUSTER REPLICATION in a read-only transaction", `ALTER TENANT $1 RESUME REPLICATION`, "foo") c.DestSysSQL.Exec(t, `set default_transaction_read_only = off;`) }) diff --git a/pkg/sql/parser/help_test.go b/pkg/sql/parser/help_test.go index da800640f1c9..d3924320d423 100644 --- a/pkg/sql/parser/help_test.go +++ b/pkg/sql/parser/help_test.go @@ -51,26 +51,50 @@ func TestContextualHelp(t *testing.T) { {`ALTER TABLE blah RENAME TO blih ??`, `ALTER TABLE`}, {`ALTER TABLE blah SPLIT AT (SELECT 1) ??`, `ALTER TABLE`}, - {`ALTER TENANT 1 ??`, `ALTER TENANT`}, - {`ALTER TENANT 1 SET ??`, `ALTER TENANT`}, - {`ALTER TENANT 1 RESET ??`, `ALTER TENANT`}, + {`ALTER VIRTUAL CLUSTER 1 ??`, `ALTER VIRTUAL CLUSTER`}, + {`ALTER VIRTUAL CLUSTER 1 SET ??`, `ALTER VIRTUAL CLUSTER`}, + {`ALTER VIRTUAL CLUSTER 1 RESET ??`, `ALTER VIRTUAL CLUSTER`}, - {`ALTER TENANT ALL ??`, `ALTER TENANT CLUSTER SETTING`}, - {`ALTER TENANT ALL SET ??`, `ALTER TENANT CLUSTER SETTING`}, - {`ALTER TENANT ALL RESET ??`, `ALTER TENANT CLUSTER SETTING`}, + // Compatibility. + {`ALTER TENANT 1 ??`, `ALTER VIRTUAL CLUSTER`}, + {`ALTER TENANT 1 SET ??`, `ALTER VIRTUAL CLUSTER`}, + {`ALTER TENANT 1 RESET ??`, `ALTER VIRTUAL CLUSTER`}, + + {`ALTER VIRTUAL CLUSTER ALL ??`, `ALTER VIRTUAL CLUSTER SETTING`}, + {`ALTER VIRTUAL CLUSTER ALL SET ??`, `ALTER VIRTUAL CLUSTER SETTING`}, + {`ALTER VIRTUAL CLUSTER ALL RESET ??`, `ALTER VIRTUAL CLUSTER SETTING`}, + + // Compatibility. + {`ALTER TENANT ALL ??`, `ALTER VIRTUAL CLUSTER SETTING`}, + {`ALTER TENANT ALL SET ??`, `ALTER VIRTUAL CLUSTER SETTING`}, + {`ALTER TENANT ALL RESET ??`, `ALTER VIRTUAL CLUSTER SETTING`}, + + {`ALTER VIRTUAL CLUSTER 'foo' RESUME REPLICATION ??`, `ALTER VIRTUAL CLUSTER REPLICATION`}, + {`ALTER VIRTUAL CLUSTER 'foo' PAUSE REPLICATION ??`, `ALTER VIRTUAL CLUSTER REPLICATION`}, - {`ALTER TENANT 'foo' RESUME REPLICATION ??`, `ALTER TENANT REPLICATION`}, - {`ALTER TENANT 'foo' PAUSE REPLICATION ??`, `ALTER TENANT REPLICATION`}, + // Compatibility. + {`ALTER TENANT 'foo' RESUME REPLICATION ??`, `ALTER VIRTUAL CLUSTER REPLICATION`}, + {`ALTER TENANT 'foo' PAUSE REPLICATION ??`, `ALTER VIRTUAL CLUSTER REPLICATION`}, + + {`ALTER TENANT foo RENAME TO bar ??`, `ALTER VIRTUAL CLUSTER RENAME`}, + {`ALTER VIRTUAL CLUSTER foo RENAME TO bar ??`, `ALTER VIRTUAL CLUSTER RENAME`}, - {`ALTER TENANT foo RENAME TO bar ??`, `ALTER TENANT RENAME`}, + {`ALTER VIRTUAL CLUSTER foo START SERVICE ??`, `ALTER VIRTUAL CLUSTER SERVICE`}, + {`ALTER VIRTUAL CLUSTER foo STOP ??`, `ALTER VIRTUAL CLUSTER SERVICE`}, - {`ALTER TENANT foo START SERVICE ??`, `ALTER TENANT SERVICE`}, - {`ALTER TENANT foo STOP ??`, `ALTER TENANT SERVICE`}, + // Compatibility. + {`ALTER TENANT foo START SERVICE ??`, `ALTER VIRTUAL CLUSTER SERVICE`}, + {`ALTER TENANT foo STOP ??`, `ALTER VIRTUAL CLUSTER SERVICE`}, - {`ALTER TENANT foo GRANT ??`, `ALTER TENANT CAPABILITY`}, - {`ALTER TENANT foo REVOKE ??`, `ALTER TENANT CAPABILITY`}, + {`ALTER VIRTUAL CLUSTER foo GRANT ??`, `ALTER VIRTUAL CLUSTER CAPABILITY`}, + {`ALTER VIRTUAL CLUSTER foo REVOKE ??`, `ALTER VIRTUAL CLUSTER CAPABILITY`}, + + // Compatibility. + {`ALTER TENANT foo GRANT ??`, `ALTER VIRTUAL CLUSTER CAPABILITY`}, + {`ALTER TENANT foo REVOKE ??`, `ALTER VIRTUAL CLUSTER CAPABILITY`}, - {`ALTER TENANT ??`, `ALTER TENANT`}, + {`ALTER VIRTUAL CLUSTER ??`, `ALTER VIRTUAL CLUSTER`}, + {`ALTER TENANT ??`, `ALTER VIRTUAL CLUSTER`}, {`ALTER TYPE ??`, `ALTER TYPE`}, {`ALTER TYPE t ??`, `ALTER TYPE`}, diff --git a/pkg/sql/parser/sql.y b/pkg/sql/parser/sql.y index 0a74f923bafa..3c98108fc637 100644 --- a/pkg/sql/parser/sql.y +++ b/pkg/sql/parser/sql.y @@ -1082,22 +1082,22 @@ func (u *sqlSymUnion) showCreateFormatOption() tree.ShowCreateFormatOption { %type alter_table_locality_stmt %type alter_table_owner_stmt -// ALTER TENANT -%type alter_tenant_stmt +// ALTER VIRTUAL CLUSTER +%type alter_virtual_cluster_stmt -// ALTER TENANT CAPABILITY +// ALTER VIRTUAL CLUSTER CAPABILITY %type tenant_capability tenant_capability_list -// ALTER TENANT CLUSTER SETTINGS -%type alter_tenant_csetting_stmt +// ALTER VIRTUAL CLUSTER SET CLUSTER SETTING +%type alter_virtual_cluster_csetting_stmt -// ALTER TENANT CAPABILITY -%type alter_tenant_capability_stmt +// ALTER VIRTUAL CLUSTER CAPABILITY +%type alter_virtual_cluster_capability_stmt -// Other ALTER TENANT statements. -%type alter_tenant_replication_stmt -%type alter_tenant_rename_stmt -%type alter_tenant_service_stmt +// Other ALTER VIRTUAL CLUSTER statements. +%type alter_virtual_cluster_replication_stmt +%type alter_virtual_cluster_rename_stmt +%type alter_virtual_cluster_service_stmt // ALTER PARTITION %type alter_zone_partition_stmt @@ -1803,7 +1803,7 @@ stmt_without_legacy_transaction: alter_stmt: alter_ddl_stmt // help texts in sub-rule | alter_role_stmt // EXTEND WITH HELP: ALTER ROLE -| alter_tenant_stmt /* SKIP DOC */ +| alter_virtual_cluster_stmt /* SKIP DOC */ | alter_unsupported_stmt | ALTER error // SHOW HELP: ALTER @@ -6554,16 +6554,19 @@ set_csetting_stmt: | SET CLUSTER error // SHOW HELP: SET CLUSTER SETTING -// %Help: ALTER TENANT - alter tenant configuration +// %Help: ALTER VIRTUAL CLUSTER - alter configuration of virtual clusters // %Category: Group -// %Text: ALTER TENANT REPLICATION, ALTER TENANT CLUSTER SETTING, ALTER TENANT CAPABILITY, ALTER TENANT RENAME, ALTER TENANT SERVICE -alter_tenant_stmt: - alter_tenant_replication_stmt // EXTEND WITH HELP: ALTER TENANT REPLICATION -| alter_tenant_csetting_stmt // EXTEND WITH HELP: ALTER TENANT CLUSTER SETTING -| alter_tenant_capability_stmt // EXTEND WITH HELP: ALTER TENANT CAPABILITY -| alter_tenant_rename_stmt // EXTEND WITH HELP: ALTER TENANT RENAME -| alter_tenant_service_stmt // EXTEND WITH HELP: ALTER TENANT SERVICE -| ALTER TENANT error // SHOW HELP: ALTER TENANT +// %Text: +// ALTER VIRTUAL CLUSTER REPLICATION, ALTER VIRTUAL CLUSTER SETTING, +// ALTER VIRTUAL CLUSTER CAPABILITY, ALTER VIRTUAL CLUSTER RENAME, +// ALTER VIRTUAL CLUSTER SERVICE +alter_virtual_cluster_stmt: + alter_virtual_cluster_replication_stmt // EXTEND WITH HELP: ALTER VIRTUAL CLUSTER REPLICATION +| alter_virtual_cluster_csetting_stmt // EXTEND WITH HELP: ALTER VIRTUAL CLUSTER SETTING +| alter_virtual_cluster_capability_stmt // EXTEND WITH HELP: ALTER VIRTUAL CLUSTER CAPABILITY +| alter_virtual_cluster_rename_stmt // EXTEND WITH HELP: ALTER VIRTUAL CLUSTER RENAME +| alter_virtual_cluster_service_stmt // EXTEND WITH HELP: ALTER VIRTUAL CLUSTER SERVICE +| ALTER virtual_cluster error // SHOW HELP: ALTER VIRTUAL CLUSTER tenant_spec: d_expr @@ -6571,12 +6574,12 @@ tenant_spec: | '[' a_expr ']' { $$.val = &tree.TenantSpec{IsName: false, Expr: $2.expr()} } -// %Help: ALTER TENANT RENAME - rename a tenant +// %Help: ALTER VIRTUAL CLUSTER RENAME - rename a virtual cluster // %Category: Experimental // %Text: -// ALTER TENANT RENAME TO -alter_tenant_rename_stmt: - ALTER TENANT tenant_spec RENAME TO d_expr +// ALTER VIRTUAL CLUSTER RENAME TO +alter_virtual_cluster_rename_stmt: + ALTER virtual_cluster tenant_spec RENAME TO d_expr { /* SKIP DOC */ $$.val = &tree.AlterTenantRename{ @@ -6585,14 +6588,14 @@ alter_tenant_rename_stmt: } } -// %Help: ALTER TENANT SERVICE - alter tenant service mode +// %Help: ALTER VIRTUAL CLUSTER SERVICE - alter service mode of a virtual cluster // %Category: Experimental // %Text: -// ALTER TENANT START SERVICE EXTERNAL -// ALTER TENANT START SERVICE SHARED -// ALTER TENANT STOP SERVICE -alter_tenant_service_stmt: - ALTER TENANT tenant_spec START SERVICE EXTERNAL +// ALTER VIRTUAL CLUSTER START SERVICE EXTERNAL +// ALTER VIRTUAL CLUSTER START SERVICE SHARED +// ALTER VIRTUAL CLUSTER STOP SERVICE +alter_virtual_cluster_service_stmt: + ALTER virtual_cluster tenant_spec START SERVICE EXTERNAL { /* SKIP DOC */ $$.val = &tree.AlterTenantService{ @@ -6600,7 +6603,7 @@ alter_tenant_service_stmt: Command: tree.TenantStartServiceExternal, } } -| ALTER TENANT tenant_spec START SERVICE SHARED +| ALTER virtual_cluster tenant_spec START SERVICE SHARED { /* SKIP DOC */ $$.val = &tree.AlterTenantService{ @@ -6608,7 +6611,7 @@ alter_tenant_service_stmt: Command: tree.TenantStartServiceShared, } } -| ALTER TENANT tenant_spec STOP SERVICE +| ALTER virtual_cluster tenant_spec STOP SERVICE { /* SKIP DOC */ $$.val = &tree.AlterTenantService{ @@ -6616,20 +6619,20 @@ alter_tenant_service_stmt: Command: tree.TenantStopService, } } -| ALTER TENANT tenant_spec START error // SHOW HELP: ALTER TENANT SERVICE -| ALTER TENANT tenant_spec STOP error // SHOW HELP: ALTER TENANT SERVICE +| ALTER virtual_cluster tenant_spec START error // SHOW HELP: ALTER VIRTUAL CLUSTER SERVICE +| ALTER virtual_cluster tenant_spec STOP error // SHOW HELP: ALTER VIRTUAL CLUSTER SERVICE -// %Help: ALTER TENANT REPLICATION - alter tenant replication stream +// %Help: ALTER VIRTUAL CLUSTER REPLICATION - alter replication stream between virtual clusters // %Category: Experimental // %Text: -// ALTER TENANT PAUSE REPLICATION -// ALTER TENANT RESUME REPLICATION -// ALTER TENANT COMPLETE REPLICATION TO LATEST -// ALTER TENANT COMPLETE REPLICATION TO SYSTEM TIME 'time' -// ALTER TENANT SET REPLICATION opt=value,... -alter_tenant_replication_stmt: - ALTER TENANT tenant_spec PAUSE REPLICATION +// ALTER VIRTUAL CLUSTER PAUSE REPLICATION +// ALTER VIRTUAL CLUSTER RESUME REPLICATION +// ALTER VIRTUAL CLUSTER COMPLETE REPLICATION TO LATEST +// ALTER VIRTUAL CLUSTER COMPLETE REPLICATION TO SYSTEM TIME 'time' +// ALTER VIRTUAL CLUSTER SET REPLICATION opt=value,... +alter_virtual_cluster_replication_stmt: + ALTER virtual_cluster tenant_spec PAUSE REPLICATION { /* SKIP DOC */ $$.val = &tree.AlterTenantReplication{ @@ -6637,7 +6640,7 @@ alter_tenant_replication_stmt: Command: tree.PauseJob, } } -| ALTER TENANT tenant_spec RESUME REPLICATION +| ALTER virtual_cluster tenant_spec RESUME REPLICATION { /* SKIP DOC */ $$.val = &tree.AlterTenantReplication{ @@ -6645,7 +6648,7 @@ alter_tenant_replication_stmt: Command: tree.ResumeJob, } } -| ALTER TENANT tenant_spec COMPLETE REPLICATION TO SYSTEM TIME a_expr +| ALTER virtual_cluster tenant_spec COMPLETE REPLICATION TO SYSTEM TIME a_expr { /* SKIP DOC */ $$.val = &tree.AlterTenantReplication{ @@ -6655,7 +6658,7 @@ alter_tenant_replication_stmt: }, } } -| ALTER TENANT tenant_spec COMPLETE REPLICATION TO LATEST +| ALTER virtual_cluster tenant_spec COMPLETE REPLICATION TO LATEST { /* SKIP DOC */ $$.val = &tree.AlterTenantReplication{ @@ -6665,7 +6668,7 @@ alter_tenant_replication_stmt: }, } } -| ALTER TENANT tenant_spec SET REPLICATION tenant_replication_options_list +| ALTER virtual_cluster tenant_spec SET REPLICATION tenant_replication_options_list { /* SKIP DOC */ $$.val = &tree.AlterTenantReplication{ @@ -6675,14 +6678,14 @@ alter_tenant_replication_stmt: } -// %Help: ALTER TENANT CLUSTER SETTING - alter tenant cluster settings +// %Help: ALTER VIRTUAL CLUSTER SETTING - alter cluster setting overrides for virtual clusters // %Category: Group // %Text: -// ALTER TENANT { | ALL } SET CLUSTER SETTING { TO | = } -// ALTER TENANT { | ALL } RESET CLUSTER SETTING +// ALTER VIRTUAL CLUSTER { | ALL } SET CLUSTER SETTING { TO | = } +// ALTER VIRTUAL CLUSTER { | ALL } RESET CLUSTER SETTING // %SeeAlso: SET CLUSTER SETTING -alter_tenant_csetting_stmt: - ALTER TENANT tenant_spec set_or_reset_csetting_stmt +alter_virtual_cluster_csetting_stmt: + ALTER virtual_cluster tenant_spec set_or_reset_csetting_stmt { /* SKIP DOC */ csettingStmt := $4.stmt().(*tree.SetClusterSetting) @@ -6700,7 +6703,17 @@ alter_tenant_csetting_stmt: TenantSpec: &tree.TenantSpec{All: true}, } } -| ALTER TENANT_ALL ALL error // SHOW HELP: ALTER TENANT CLUSTER SETTING +| ALTER VIRTUAL CLUSTER_ALL ALL set_or_reset_csetting_stmt + { + /* SKIP DOC */ + csettingStmt := $5.stmt().(*tree.SetClusterSetting) + $$.val = &tree.AlterTenantSetClusterSetting{ + SetClusterSetting: *csettingStmt, + TenantSpec: &tree.TenantSpec{All: true}, + } + } +| ALTER VIRTUAL CLUSTER_ALL ALL error // SHOW HELP: ALTER VIRTUAL CLUSTER SETTING +| ALTER TENANT_ALL ALL error // SHOW HELP: ALTER VIRTUAL CLUSTER SETTING set_or_reset_csetting_stmt: reset_csetting_stmt @@ -6710,13 +6723,13 @@ to_or_eq: '=' | TO -// %Help: ALTER TENANT CAPABILITY - alter tenant capability +// %Help: ALTER VIRTUAL CLUSTER CAPABILITY - alter system capability of virtual cluster // %Category: Group // %Text: -// ALTER TENANT GRANT CAPABILITY { TO | = } -// ALTER TENANT REVOKE CAPABILITY -alter_tenant_capability_stmt: - ALTER TENANT tenant_spec GRANT CAPABILITY tenant_capability_list +// ALTER VIRTUAL CLUSTER GRANT CAPABILITY { TO | = } +// ALTER VIRTUAL CLUSTER REVOKE CAPABILITY +alter_virtual_cluster_capability_stmt: + ALTER virtual_cluster tenant_spec GRANT CAPABILITY tenant_capability_list { /* SKIP DOC */ $$.val = &tree.AlterTenantCapability{ @@ -6724,7 +6737,7 @@ alter_tenant_capability_stmt: Capabilities: $6.tenantCapabilities(), } } -| ALTER TENANT tenant_spec GRANT ALL CAPABILITIES +| ALTER virtual_cluster tenant_spec GRANT ALL CAPABILITIES { /* SKIP DOC */ $$.val = &tree.AlterTenantCapability{ @@ -6732,7 +6745,7 @@ alter_tenant_capability_stmt: AllCapabilities: true, } } -| ALTER TENANT tenant_spec REVOKE CAPABILITY tenant_capability_list +| ALTER virtual_cluster tenant_spec REVOKE CAPABILITY tenant_capability_list { /* SKIP DOC */ $$.val = &tree.AlterTenantCapability{ @@ -6741,7 +6754,7 @@ alter_tenant_capability_stmt: IsRevoke: true, } } -| ALTER TENANT tenant_spec REVOKE ALL CAPABILITIES +| ALTER virtual_cluster tenant_spec REVOKE ALL CAPABILITIES { /* SKIP DOC */ $$.val = &tree.AlterTenantCapability{ @@ -6750,8 +6763,8 @@ alter_tenant_capability_stmt: IsRevoke: true, } } -| ALTER TENANT tenant_spec GRANT error // SHOW HELP: ALTER TENANT CAPABILITY -| ALTER TENANT tenant_spec REVOKE error // SHOW HELP: ALTER TENANT CAPABILITY +| ALTER virtual_cluster tenant_spec GRANT error // SHOW HELP: ALTER VIRTUAL CLUSTER CAPABILITY +| ALTER virtual_cluster tenant_spec REVOKE error // SHOW HELP: ALTER VIRTUAL CLUSTER CAPABILITY tenant_capability: var_name diff --git a/pkg/sql/parser/testdata/alter_tenant b/pkg/sql/parser/testdata/alter_tenant deleted file mode 100644 index 3e706ac5768b..000000000000 --- a/pkg/sql/parser/testdata/alter_tenant +++ /dev/null @@ -1,306 +0,0 @@ -parse -ALTER TENANT 123 RESET CLUSTER SETTING a ----- -ALTER TENANT 123 SET CLUSTER SETTING a = DEFAULT -- normalized! -ALTER TENANT (123) SET CLUSTER SETTING a = (DEFAULT) -- fully parenthesized -ALTER TENANT _ SET CLUSTER SETTING a = DEFAULT -- literals removed -ALTER TENANT 123 SET CLUSTER SETTING a = DEFAULT -- identifiers removed - -parse -ALTER TENANT [123::INT] RESET CLUSTER SETTING a ----- -ALTER TENANT [123::INT8] SET CLUSTER SETTING a = DEFAULT -- normalized! -ALTER TENANT [((123)::INT8)] SET CLUSTER SETTING a = (DEFAULT) -- fully parenthesized -ALTER TENANT [_::INT8] SET CLUSTER SETTING a = DEFAULT -- literals removed -ALTER TENANT [123::INT8] SET CLUSTER SETTING a = DEFAULT -- identifiers removed - -parse -ALTER TENANT abc RESET CLUSTER SETTING a ----- -ALTER TENANT abc SET CLUSTER SETTING a = DEFAULT -- normalized! -ALTER TENANT (abc) SET CLUSTER SETTING a = (DEFAULT) -- fully parenthesized -ALTER TENANT abc SET CLUSTER SETTING a = DEFAULT -- literals removed -ALTER TENANT _ SET CLUSTER SETTING a = DEFAULT -- identifiers removed - -parse -ALTER TENANT (1+1) SET CLUSTER SETTING a = 3 ----- -ALTER TENANT (1 + 1) SET CLUSTER SETTING a = 3 -- normalized! -ALTER TENANT ((((1) + (1)))) SET CLUSTER SETTING a = (3) -- fully parenthesized -ALTER TENANT (_ + _) SET CLUSTER SETTING a = _ -- literals removed -ALTER TENANT (1 + 1) SET CLUSTER SETTING a = 3 -- identifiers removed - -parse -ALTER TENANT abc SET CLUSTER SETTING a = 3 ----- -ALTER TENANT abc SET CLUSTER SETTING a = 3 -ALTER TENANT (abc) SET CLUSTER SETTING a = (3) -- fully parenthesized -ALTER TENANT abc SET CLUSTER SETTING a = _ -- literals removed -ALTER TENANT _ SET CLUSTER SETTING a = 3 -- identifiers removed - - -parse -ALTER TENANT $1 SET CLUSTER SETTING a = 3 ----- -ALTER TENANT $1 SET CLUSTER SETTING a = 3 -ALTER TENANT ($1) SET CLUSTER SETTING a = (3) -- fully parenthesized -ALTER TENANT $1 SET CLUSTER SETTING a = _ -- literals removed -ALTER TENANT $1 SET CLUSTER SETTING a = 3 -- identifiers removed - -parse -ALTER TENANT ALL SET CLUSTER SETTING a = 3 ----- -ALTER TENANT ALL SET CLUSTER SETTING a = 3 -ALTER TENANT ALL SET CLUSTER SETTING a = (3) -- fully parenthesized -ALTER TENANT ALL SET CLUSTER SETTING a = _ -- literals removed -ALTER TENANT ALL SET CLUSTER SETTING a = 3 -- identifiers removed - -parse -ALTER TENANT 123 RESET CLUSTER SETTING a ----- -ALTER TENANT 123 SET CLUSTER SETTING a = DEFAULT -- normalized! -ALTER TENANT (123) SET CLUSTER SETTING a = (DEFAULT) -- fully parenthesized -ALTER TENANT _ SET CLUSTER SETTING a = DEFAULT -- literals removed -ALTER TENANT 123 SET CLUSTER SETTING a = DEFAULT -- identifiers removed - -parse -ALTER TENANT (1+1) RESET CLUSTER SETTING a ----- -ALTER TENANT (1 + 1) SET CLUSTER SETTING a = DEFAULT -- normalized! -ALTER TENANT ((((1) + (1)))) SET CLUSTER SETTING a = (DEFAULT) -- fully parenthesized -ALTER TENANT (_ + _) SET CLUSTER SETTING a = DEFAULT -- literals removed -ALTER TENANT (1 + 1) SET CLUSTER SETTING a = DEFAULT -- identifiers removed - -parse -ALTER TENANT $1 RESET CLUSTER SETTING a ----- -ALTER TENANT $1 SET CLUSTER SETTING a = DEFAULT -- normalized! -ALTER TENANT ($1) SET CLUSTER SETTING a = (DEFAULT) -- fully parenthesized -ALTER TENANT $1 SET CLUSTER SETTING a = DEFAULT -- literals removed -ALTER TENANT $1 SET CLUSTER SETTING a = DEFAULT -- identifiers removed - -parse -ALTER TENANT ALL RESET CLUSTER SETTING a ----- -ALTER TENANT ALL SET CLUSTER SETTING a = DEFAULT -- normalized! -ALTER TENANT ALL SET CLUSTER SETTING a = (DEFAULT) -- fully parenthesized -ALTER TENANT ALL SET CLUSTER SETTING a = DEFAULT -- literals removed -ALTER TENANT ALL SET CLUSTER SETTING a = DEFAULT -- identifiers removed - -parse -ALTER TENANT foo RESUME REPLICATION ----- -ALTER TENANT foo RESUME REPLICATION -ALTER TENANT (foo) RESUME REPLICATION -- fully parenthesized -ALTER TENANT foo RESUME REPLICATION -- literals removed -ALTER TENANT _ RESUME REPLICATION -- identifiers removed - -parse -ALTER TENANT 'foo-with-hyphen' RESUME REPLICATION ----- -ALTER TENANT 'foo-with-hyphen' RESUME REPLICATION -ALTER TENANT ('foo-with-hyphen') RESUME REPLICATION -- fully parenthesized -ALTER TENANT '_' RESUME REPLICATION -- literals removed -ALTER TENANT 'foo-with-hyphen' RESUME REPLICATION -- identifiers removed - -parse -ALTER TENANT $1 RESUME REPLICATION ----- -ALTER TENANT $1 RESUME REPLICATION -ALTER TENANT ($1) RESUME REPLICATION -- fully parenthesized -ALTER TENANT $1 RESUME REPLICATION -- literals removed -ALTER TENANT $1 RESUME REPLICATION -- identifiers removed - -parse -ALTER TENANT (SELECT 'foo') RESUME REPLICATION ----- -ALTER TENANT (SELECT 'foo') RESUME REPLICATION -ALTER TENANT ((SELECT ('foo'))) RESUME REPLICATION -- fully parenthesized -ALTER TENANT (SELECT '_') RESUME REPLICATION -- literals removed -ALTER TENANT (SELECT 'foo') RESUME REPLICATION -- identifiers removed - -parse -ALTER TENANT 'foo' PAUSE REPLICATION ----- -ALTER TENANT 'foo' PAUSE REPLICATION -ALTER TENANT ('foo') PAUSE REPLICATION -- fully parenthesized -ALTER TENANT '_' PAUSE REPLICATION -- literals removed -ALTER TENANT 'foo' PAUSE REPLICATION -- identifiers removed - -parse -ALTER TENANT 'foo-with-hyphen' PAUSE REPLICATION ----- -ALTER TENANT 'foo-with-hyphen' PAUSE REPLICATION -ALTER TENANT ('foo-with-hyphen') PAUSE REPLICATION -- fully parenthesized -ALTER TENANT '_' PAUSE REPLICATION -- literals removed -ALTER TENANT 'foo-with-hyphen' PAUSE REPLICATION -- identifiers removed - -parse -ALTER TENANT $1 PAUSE REPLICATION ----- -ALTER TENANT $1 PAUSE REPLICATION -ALTER TENANT ($1) PAUSE REPLICATION -- fully parenthesized -ALTER TENANT $1 PAUSE REPLICATION -- literals removed -ALTER TENANT $1 PAUSE REPLICATION -- identifiers removed - -parse -ALTER TENANT $1 COMPLETE REPLICATION TO LATEST ----- -ALTER TENANT $1 COMPLETE REPLICATION TO LATEST -ALTER TENANT ($1) COMPLETE REPLICATION TO LATEST -- fully parenthesized -ALTER TENANT $1 COMPLETE REPLICATION TO LATEST -- literals removed -ALTER TENANT $1 COMPLETE REPLICATION TO LATEST -- identifiers removed - -parse -ALTER TENANT 'foo' COMPLETE REPLICATION TO LATEST ----- -ALTER TENANT 'foo' COMPLETE REPLICATION TO LATEST -ALTER TENANT ('foo') COMPLETE REPLICATION TO LATEST -- fully parenthesized -ALTER TENANT '_' COMPLETE REPLICATION TO LATEST -- literals removed -ALTER TENANT 'foo' COMPLETE REPLICATION TO LATEST -- identifiers removed - -parse -ALTER TENANT $1 COMPLETE REPLICATION TO SYSTEM TIME $2 ----- -ALTER TENANT $1 COMPLETE REPLICATION TO SYSTEM TIME $2 -ALTER TENANT ($1) COMPLETE REPLICATION TO SYSTEM TIME ($2) -- fully parenthesized -ALTER TENANT $1 COMPLETE REPLICATION TO SYSTEM TIME $1 -- literals removed -ALTER TENANT $1 COMPLETE REPLICATION TO SYSTEM TIME $2 -- identifiers removed - -parse -ALTER TENANT $1 COMPLETE REPLICATION TO SYSTEM TIME $2 ----- -ALTER TENANT $1 COMPLETE REPLICATION TO SYSTEM TIME $2 -ALTER TENANT ($1) COMPLETE REPLICATION TO SYSTEM TIME ($2) -- fully parenthesized -ALTER TENANT $1 COMPLETE REPLICATION TO SYSTEM TIME $1 -- literals removed -ALTER TENANT $1 COMPLETE REPLICATION TO SYSTEM TIME $2 -- identifiers removed - -parse -ALTER TENANT 'foo' COMPLETE REPLICATION TO SYSTEM TIME '-2' ----- -ALTER TENANT 'foo' COMPLETE REPLICATION TO SYSTEM TIME '-2' -ALTER TENANT ('foo') COMPLETE REPLICATION TO SYSTEM TIME ('-2') -- fully parenthesized -ALTER TENANT '_' COMPLETE REPLICATION TO SYSTEM TIME '_' -- literals removed -ALTER TENANT 'foo' COMPLETE REPLICATION TO SYSTEM TIME '-2' -- identifiers removed - -parse -ALTER TENANT 'foo' SET REPLICATION RETENTION = '-2h' ----- -ALTER TENANT 'foo' SET REPLICATION RETENTION = '-2h' -ALTER TENANT ('foo') SET REPLICATION RETENTION = ('-2h') -- fully parenthesized -ALTER TENANT '_' SET REPLICATION RETENTION = '_' -- literals removed -ALTER TENANT 'foo' SET REPLICATION RETENTION = '-2h' -- identifiers removed - -parse -ALTER TENANT 'foo' RENAME TO bar ----- -ALTER TENANT 'foo' RENAME TO bar -ALTER TENANT ('foo') RENAME TO (bar) -- fully parenthesized -ALTER TENANT '_' RENAME TO bar -- literals removed -ALTER TENANT 'foo' RENAME TO _ -- identifiers removed - -# Regression test for #99853 -parse -ALTER TENANT 'string' RENAME TO INTERVAL 'string' MINUTE TO SECOND ----- -ALTER TENANT 'string' RENAME TO ('string'::INTERVAL MINUTE TO SECOND) -- normalized! -ALTER TENANT ('string') RENAME TO ((('string')::INTERVAL MINUTE TO SECOND)) -- fully parenthesized -ALTER TENANT '_' RENAME TO ('_'::INTERVAL MINUTE TO SECOND) -- literals removed -ALTER TENANT 'string' RENAME TO ('string'::INTERVAL MINUTE TO SECOND) -- identifiers removed - -# Regression test for #95612 -parse -ALTER TENANT INTERVAL 'string' MINUTE RESET CLUSTER SETTING ident ----- -ALTER TENANT ('string'::INTERVAL MINUTE) SET CLUSTER SETTING ident = DEFAULT -- normalized! -ALTER TENANT ((('string')::INTERVAL MINUTE)) SET CLUSTER SETTING ident = (DEFAULT) -- fully parenthesized -ALTER TENANT ('_'::INTERVAL MINUTE) SET CLUSTER SETTING ident = DEFAULT -- literals removed -ALTER TENANT ('string'::INTERVAL MINUTE) SET CLUSTER SETTING ident = DEFAULT -- identifiers removed - -parse -ALTER TENANT 123 GRANT ALL CAPABILITIES ----- -ALTER TENANT 123 GRANT ALL CAPABILITIES -ALTER TENANT (123) GRANT ALL CAPABILITIES -- fully parenthesized -ALTER TENANT _ GRANT ALL CAPABILITIES -- literals removed -ALTER TENANT 123 GRANT ALL CAPABILITIES -- identifiers removed - -parse -ALTER TENANT 123 GRANT CAPABILITY a = 3 ----- -ALTER TENANT 123 GRANT CAPABILITY a = 3 -ALTER TENANT (123) GRANT CAPABILITY a = (3) -- fully parenthesized -ALTER TENANT _ GRANT CAPABILITY a = _ -- literals removed -ALTER TENANT 123 GRANT CAPABILITY a = 3 -- identifiers removed - -parse -ALTER TENANT (1+1) GRANT CAPABILITY a = 3 ----- -ALTER TENANT (1 + 1) GRANT CAPABILITY a = 3 -- normalized! -ALTER TENANT ((((1) + (1)))) GRANT CAPABILITY a = (3) -- fully parenthesized -ALTER TENANT (_ + _) GRANT CAPABILITY a = _ -- literals removed -ALTER TENANT (1 + 1) GRANT CAPABILITY a = 3 -- identifiers removed - -parse -ALTER TENANT $1 GRANT CAPABILITY a = 3 ----- -ALTER TENANT $1 GRANT CAPABILITY a = 3 -ALTER TENANT ($1) GRANT CAPABILITY a = (3) -- fully parenthesized -ALTER TENANT $1 GRANT CAPABILITY a = _ -- literals removed -ALTER TENANT $1 GRANT CAPABILITY a = 3 -- identifiers removed - -parse -ALTER TENANT 123 REVOKE ALL CAPABILITIES ----- -ALTER TENANT 123 REVOKE ALL CAPABILITIES -ALTER TENANT (123) REVOKE ALL CAPABILITIES -- fully parenthesized -ALTER TENANT _ REVOKE ALL CAPABILITIES -- literals removed -ALTER TENANT 123 REVOKE ALL CAPABILITIES -- identifiers removed - -parse -ALTER TENANT 123 REVOKE CAPABILITY a ----- -ALTER TENANT 123 REVOKE CAPABILITY a -ALTER TENANT (123) REVOKE CAPABILITY a -- fully parenthesized -ALTER TENANT _ REVOKE CAPABILITY a -- literals removed -ALTER TENANT 123 REVOKE CAPABILITY a -- identifiers removed - -parse -ALTER TENANT (1+1) REVOKE CAPABILITY a ----- -ALTER TENANT (1 + 1) REVOKE CAPABILITY a -- normalized! -ALTER TENANT ((((1) + (1)))) REVOKE CAPABILITY a -- fully parenthesized -ALTER TENANT (_ + _) REVOKE CAPABILITY a -- literals removed -ALTER TENANT (1 + 1) REVOKE CAPABILITY a -- identifiers removed - -parse -ALTER TENANT $1 REVOKE CAPABILITY a ----- -ALTER TENANT $1 REVOKE CAPABILITY a -ALTER TENANT ($1) REVOKE CAPABILITY a -- fully parenthesized -ALTER TENANT $1 REVOKE CAPABILITY a -- literals removed -ALTER TENANT $1 REVOKE CAPABILITY a -- identifiers removed - -parse -ALTER TENANT 'foo' START SERVICE EXTERNAL ----- -ALTER TENANT 'foo' START SERVICE EXTERNAL -ALTER TENANT ('foo') START SERVICE EXTERNAL -- fully parenthesized -ALTER TENANT '_' START SERVICE EXTERNAL -- literals removed -ALTER TENANT 'foo' START SERVICE EXTERNAL -- identifiers removed - -parse -ALTER TENANT 'foo' START SERVICE SHARED ----- -ALTER TENANT 'foo' START SERVICE SHARED -ALTER TENANT ('foo') START SERVICE SHARED -- fully parenthesized -ALTER TENANT '_' START SERVICE SHARED -- literals removed -ALTER TENANT 'foo' START SERVICE SHARED -- identifiers removed - -parse -ALTER TENANT 'foo' STOP SERVICE ----- -ALTER TENANT 'foo' STOP SERVICE -ALTER TENANT ('foo') STOP SERVICE -- fully parenthesized -ALTER TENANT '_' STOP SERVICE -- literals removed -ALTER TENANT 'foo' STOP SERVICE -- identifiers removed diff --git a/pkg/sql/parser/testdata/alter_virtual_cluster b/pkg/sql/parser/testdata/alter_virtual_cluster new file mode 100644 index 000000000000..fdb715814fda --- /dev/null +++ b/pkg/sql/parser/testdata/alter_virtual_cluster @@ -0,0 +1,410 @@ +parse +ALTER VIRTUAL CLUSTER 123 RESET CLUSTER SETTING a +---- +ALTER VIRTUAL CLUSTER 123 SET CLUSTER SETTING a = DEFAULT -- normalized! +ALTER VIRTUAL CLUSTER (123) SET CLUSTER SETTING a = (DEFAULT) -- fully parenthesized +ALTER VIRTUAL CLUSTER _ SET CLUSTER SETTING a = DEFAULT -- literals removed +ALTER VIRTUAL CLUSTER 123 SET CLUSTER SETTING a = DEFAULT -- identifiers removed + +parse +ALTER TENANT 123 RESET CLUSTER SETTING a +---- +ALTER VIRTUAL CLUSTER 123 SET CLUSTER SETTING a = DEFAULT -- normalized! +ALTER VIRTUAL CLUSTER (123) SET CLUSTER SETTING a = (DEFAULT) -- fully parenthesized +ALTER VIRTUAL CLUSTER _ SET CLUSTER SETTING a = DEFAULT -- literals removed +ALTER VIRTUAL CLUSTER 123 SET CLUSTER SETTING a = DEFAULT -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER [123::INT] RESET CLUSTER SETTING a +---- +ALTER VIRTUAL CLUSTER [123::INT8] SET CLUSTER SETTING a = DEFAULT -- normalized! +ALTER VIRTUAL CLUSTER [((123)::INT8)] SET CLUSTER SETTING a = (DEFAULT) -- fully parenthesized +ALTER VIRTUAL CLUSTER [_::INT8] SET CLUSTER SETTING a = DEFAULT -- literals removed +ALTER VIRTUAL CLUSTER [123::INT8] SET CLUSTER SETTING a = DEFAULT -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER abc RESET CLUSTER SETTING a +---- +ALTER VIRTUAL CLUSTER abc SET CLUSTER SETTING a = DEFAULT -- normalized! +ALTER VIRTUAL CLUSTER (abc) SET CLUSTER SETTING a = (DEFAULT) -- fully parenthesized +ALTER VIRTUAL CLUSTER abc SET CLUSTER SETTING a = DEFAULT -- literals removed +ALTER VIRTUAL CLUSTER _ SET CLUSTER SETTING a = DEFAULT -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER (1+1) SET CLUSTER SETTING a = 3 +---- +ALTER VIRTUAL CLUSTER (1 + 1) SET CLUSTER SETTING a = 3 -- normalized! +ALTER VIRTUAL CLUSTER ((((1) + (1)))) SET CLUSTER SETTING a = (3) -- fully parenthesized +ALTER VIRTUAL CLUSTER (_ + _) SET CLUSTER SETTING a = _ -- literals removed +ALTER VIRTUAL CLUSTER (1 + 1) SET CLUSTER SETTING a = 3 -- identifiers removed + +parse +ALTER TENANT (1+1) SET CLUSTER SETTING a = 3 +---- +ALTER VIRTUAL CLUSTER (1 + 1) SET CLUSTER SETTING a = 3 -- normalized! +ALTER VIRTUAL CLUSTER ((((1) + (1)))) SET CLUSTER SETTING a = (3) -- fully parenthesized +ALTER VIRTUAL CLUSTER (_ + _) SET CLUSTER SETTING a = _ -- literals removed +ALTER VIRTUAL CLUSTER (1 + 1) SET CLUSTER SETTING a = 3 -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER abc SET CLUSTER SETTING a = 3 +---- +ALTER VIRTUAL CLUSTER abc SET CLUSTER SETTING a = 3 +ALTER VIRTUAL CLUSTER (abc) SET CLUSTER SETTING a = (3) -- fully parenthesized +ALTER VIRTUAL CLUSTER abc SET CLUSTER SETTING a = _ -- literals removed +ALTER VIRTUAL CLUSTER _ SET CLUSTER SETTING a = 3 -- identifiers removed + + +parse +ALTER VIRTUAL CLUSTER $1 SET CLUSTER SETTING a = 3 +---- +ALTER VIRTUAL CLUSTER $1 SET CLUSTER SETTING a = 3 +ALTER VIRTUAL CLUSTER ($1) SET CLUSTER SETTING a = (3) -- fully parenthesized +ALTER VIRTUAL CLUSTER $1 SET CLUSTER SETTING a = _ -- literals removed +ALTER VIRTUAL CLUSTER $1 SET CLUSTER SETTING a = 3 -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER ALL SET CLUSTER SETTING a = 3 +---- +ALTER VIRTUAL CLUSTER ALL SET CLUSTER SETTING a = 3 +ALTER VIRTUAL CLUSTER ALL SET CLUSTER SETTING a = (3) -- fully parenthesized +ALTER VIRTUAL CLUSTER ALL SET CLUSTER SETTING a = _ -- literals removed +ALTER VIRTUAL CLUSTER ALL SET CLUSTER SETTING a = 3 -- identifiers removed + +parse +ALTER TENANT ALL SET CLUSTER SETTING a = 3 +---- +ALTER VIRTUAL CLUSTER ALL SET CLUSTER SETTING a = 3 -- normalized! +ALTER VIRTUAL CLUSTER ALL SET CLUSTER SETTING a = (3) -- fully parenthesized +ALTER VIRTUAL CLUSTER ALL SET CLUSTER SETTING a = _ -- literals removed +ALTER VIRTUAL CLUSTER ALL SET CLUSTER SETTING a = 3 -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER 123 RESET CLUSTER SETTING a +---- +ALTER VIRTUAL CLUSTER 123 SET CLUSTER SETTING a = DEFAULT -- normalized! +ALTER VIRTUAL CLUSTER (123) SET CLUSTER SETTING a = (DEFAULT) -- fully parenthesized +ALTER VIRTUAL CLUSTER _ SET CLUSTER SETTING a = DEFAULT -- literals removed +ALTER VIRTUAL CLUSTER 123 SET CLUSTER SETTING a = DEFAULT -- identifiers removed + +parse +ALTER TENANT 123 RESET CLUSTER SETTING a +---- +ALTER VIRTUAL CLUSTER 123 SET CLUSTER SETTING a = DEFAULT -- normalized! +ALTER VIRTUAL CLUSTER (123) SET CLUSTER SETTING a = (DEFAULT) -- fully parenthesized +ALTER VIRTUAL CLUSTER _ SET CLUSTER SETTING a = DEFAULT -- literals removed +ALTER VIRTUAL CLUSTER 123 SET CLUSTER SETTING a = DEFAULT -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER (1+1) RESET CLUSTER SETTING a +---- +ALTER VIRTUAL CLUSTER (1 + 1) SET CLUSTER SETTING a = DEFAULT -- normalized! +ALTER VIRTUAL CLUSTER ((((1) + (1)))) SET CLUSTER SETTING a = (DEFAULT) -- fully parenthesized +ALTER VIRTUAL CLUSTER (_ + _) SET CLUSTER SETTING a = DEFAULT -- literals removed +ALTER VIRTUAL CLUSTER (1 + 1) SET CLUSTER SETTING a = DEFAULT -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER $1 RESET CLUSTER SETTING a +---- +ALTER VIRTUAL CLUSTER $1 SET CLUSTER SETTING a = DEFAULT -- normalized! +ALTER VIRTUAL CLUSTER ($1) SET CLUSTER SETTING a = (DEFAULT) -- fully parenthesized +ALTER VIRTUAL CLUSTER $1 SET CLUSTER SETTING a = DEFAULT -- literals removed +ALTER VIRTUAL CLUSTER $1 SET CLUSTER SETTING a = DEFAULT -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER ALL RESET CLUSTER SETTING a +---- +ALTER VIRTUAL CLUSTER ALL SET CLUSTER SETTING a = DEFAULT -- normalized! +ALTER VIRTUAL CLUSTER ALL SET CLUSTER SETTING a = (DEFAULT) -- fully parenthesized +ALTER VIRTUAL CLUSTER ALL SET CLUSTER SETTING a = DEFAULT -- literals removed +ALTER VIRTUAL CLUSTER ALL SET CLUSTER SETTING a = DEFAULT -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER foo RESUME REPLICATION +---- +ALTER VIRTUAL CLUSTER foo RESUME REPLICATION +ALTER VIRTUAL CLUSTER (foo) RESUME REPLICATION -- fully parenthesized +ALTER VIRTUAL CLUSTER foo RESUME REPLICATION -- literals removed +ALTER VIRTUAL CLUSTER _ RESUME REPLICATION -- identifiers removed + +parse +ALTER TENANT foo RESUME REPLICATION +---- +ALTER VIRTUAL CLUSTER foo RESUME REPLICATION -- normalized! +ALTER VIRTUAL CLUSTER (foo) RESUME REPLICATION -- fully parenthesized +ALTER VIRTUAL CLUSTER foo RESUME REPLICATION -- literals removed +ALTER VIRTUAL CLUSTER _ RESUME REPLICATION -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER 'foo-with-hyphen' RESUME REPLICATION +---- +ALTER VIRTUAL CLUSTER 'foo-with-hyphen' RESUME REPLICATION +ALTER VIRTUAL CLUSTER ('foo-with-hyphen') RESUME REPLICATION -- fully parenthesized +ALTER VIRTUAL CLUSTER '_' RESUME REPLICATION -- literals removed +ALTER VIRTUAL CLUSTER 'foo-with-hyphen' RESUME REPLICATION -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER $1 RESUME REPLICATION +---- +ALTER VIRTUAL CLUSTER $1 RESUME REPLICATION +ALTER VIRTUAL CLUSTER ($1) RESUME REPLICATION -- fully parenthesized +ALTER VIRTUAL CLUSTER $1 RESUME REPLICATION -- literals removed +ALTER VIRTUAL CLUSTER $1 RESUME REPLICATION -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER (SELECT 'foo') RESUME REPLICATION +---- +ALTER VIRTUAL CLUSTER (SELECT 'foo') RESUME REPLICATION +ALTER VIRTUAL CLUSTER ((SELECT ('foo'))) RESUME REPLICATION -- fully parenthesized +ALTER VIRTUAL CLUSTER (SELECT '_') RESUME REPLICATION -- literals removed +ALTER VIRTUAL CLUSTER (SELECT 'foo') RESUME REPLICATION -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER 'foo' PAUSE REPLICATION +---- +ALTER VIRTUAL CLUSTER 'foo' PAUSE REPLICATION +ALTER VIRTUAL CLUSTER ('foo') PAUSE REPLICATION -- fully parenthesized +ALTER VIRTUAL CLUSTER '_' PAUSE REPLICATION -- literals removed +ALTER VIRTUAL CLUSTER 'foo' PAUSE REPLICATION -- identifiers removed + +parse +ALTER TENANT 'foo' PAUSE REPLICATION +---- +ALTER VIRTUAL CLUSTER 'foo' PAUSE REPLICATION -- normalized! +ALTER VIRTUAL CLUSTER ('foo') PAUSE REPLICATION -- fully parenthesized +ALTER VIRTUAL CLUSTER '_' PAUSE REPLICATION -- literals removed +ALTER VIRTUAL CLUSTER 'foo' PAUSE REPLICATION -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER 'foo-with-hyphen' PAUSE REPLICATION +---- +ALTER VIRTUAL CLUSTER 'foo-with-hyphen' PAUSE REPLICATION +ALTER VIRTUAL CLUSTER ('foo-with-hyphen') PAUSE REPLICATION -- fully parenthesized +ALTER VIRTUAL CLUSTER '_' PAUSE REPLICATION -- literals removed +ALTER VIRTUAL CLUSTER 'foo-with-hyphen' PAUSE REPLICATION -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER $1 PAUSE REPLICATION +---- +ALTER VIRTUAL CLUSTER $1 PAUSE REPLICATION +ALTER VIRTUAL CLUSTER ($1) PAUSE REPLICATION -- fully parenthesized +ALTER VIRTUAL CLUSTER $1 PAUSE REPLICATION -- literals removed +ALTER VIRTUAL CLUSTER $1 PAUSE REPLICATION -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER $1 COMPLETE REPLICATION TO LATEST +---- +ALTER VIRTUAL CLUSTER $1 COMPLETE REPLICATION TO LATEST +ALTER VIRTUAL CLUSTER ($1) COMPLETE REPLICATION TO LATEST -- fully parenthesized +ALTER VIRTUAL CLUSTER $1 COMPLETE REPLICATION TO LATEST -- literals removed +ALTER VIRTUAL CLUSTER $1 COMPLETE REPLICATION TO LATEST -- identifiers removed + +parse +ALTER TENANT $1 COMPLETE REPLICATION TO LATEST +---- +ALTER VIRTUAL CLUSTER $1 COMPLETE REPLICATION TO LATEST -- normalized! +ALTER VIRTUAL CLUSTER ($1) COMPLETE REPLICATION TO LATEST -- fully parenthesized +ALTER VIRTUAL CLUSTER $1 COMPLETE REPLICATION TO LATEST -- literals removed +ALTER VIRTUAL CLUSTER $1 COMPLETE REPLICATION TO LATEST -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER 'foo' COMPLETE REPLICATION TO LATEST +---- +ALTER VIRTUAL CLUSTER 'foo' COMPLETE REPLICATION TO LATEST +ALTER VIRTUAL CLUSTER ('foo') COMPLETE REPLICATION TO LATEST -- fully parenthesized +ALTER VIRTUAL CLUSTER '_' COMPLETE REPLICATION TO LATEST -- literals removed +ALTER VIRTUAL CLUSTER 'foo' COMPLETE REPLICATION TO LATEST -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER $1 COMPLETE REPLICATION TO SYSTEM TIME $2 +---- +ALTER VIRTUAL CLUSTER $1 COMPLETE REPLICATION TO SYSTEM TIME $2 +ALTER VIRTUAL CLUSTER ($1) COMPLETE REPLICATION TO SYSTEM TIME ($2) -- fully parenthesized +ALTER VIRTUAL CLUSTER $1 COMPLETE REPLICATION TO SYSTEM TIME $1 -- literals removed +ALTER VIRTUAL CLUSTER $1 COMPLETE REPLICATION TO SYSTEM TIME $2 -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER $1 COMPLETE REPLICATION TO SYSTEM TIME $2 +---- +ALTER VIRTUAL CLUSTER $1 COMPLETE REPLICATION TO SYSTEM TIME $2 +ALTER VIRTUAL CLUSTER ($1) COMPLETE REPLICATION TO SYSTEM TIME ($2) -- fully parenthesized +ALTER VIRTUAL CLUSTER $1 COMPLETE REPLICATION TO SYSTEM TIME $1 -- literals removed +ALTER VIRTUAL CLUSTER $1 COMPLETE REPLICATION TO SYSTEM TIME $2 -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER 'foo' COMPLETE REPLICATION TO SYSTEM TIME '-2' +---- +ALTER VIRTUAL CLUSTER 'foo' COMPLETE REPLICATION TO SYSTEM TIME '-2' +ALTER VIRTUAL CLUSTER ('foo') COMPLETE REPLICATION TO SYSTEM TIME ('-2') -- fully parenthesized +ALTER VIRTUAL CLUSTER '_' COMPLETE REPLICATION TO SYSTEM TIME '_' -- literals removed +ALTER VIRTUAL CLUSTER 'foo' COMPLETE REPLICATION TO SYSTEM TIME '-2' -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER 'foo' SET REPLICATION RETENTION = '-2h' +---- +ALTER VIRTUAL CLUSTER 'foo' SET REPLICATION RETENTION = '-2h' +ALTER VIRTUAL CLUSTER ('foo') SET REPLICATION RETENTION = ('-2h') -- fully parenthesized +ALTER VIRTUAL CLUSTER '_' SET REPLICATION RETENTION = '_' -- literals removed +ALTER VIRTUAL CLUSTER 'foo' SET REPLICATION RETENTION = '-2h' -- identifiers removed + +parse +ALTER TENANT 'foo' SET REPLICATION RETENTION = '-2h' +---- +ALTER VIRTUAL CLUSTER 'foo' SET REPLICATION RETENTION = '-2h' -- normalized! +ALTER VIRTUAL CLUSTER ('foo') SET REPLICATION RETENTION = ('-2h') -- fully parenthesized +ALTER VIRTUAL CLUSTER '_' SET REPLICATION RETENTION = '_' -- literals removed +ALTER VIRTUAL CLUSTER 'foo' SET REPLICATION RETENTION = '-2h' -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER 'foo' RENAME TO bar +---- +ALTER VIRTUAL CLUSTER 'foo' RENAME TO bar +ALTER VIRTUAL CLUSTER ('foo') RENAME TO (bar) -- fully parenthesized +ALTER VIRTUAL CLUSTER '_' RENAME TO bar -- literals removed +ALTER VIRTUAL CLUSTER 'foo' RENAME TO _ -- identifiers removed + +parse +ALTER TENANT 'foo' RENAME TO bar +---- +ALTER VIRTUAL CLUSTER 'foo' RENAME TO bar -- normalized! +ALTER VIRTUAL CLUSTER ('foo') RENAME TO (bar) -- fully parenthesized +ALTER VIRTUAL CLUSTER '_' RENAME TO bar -- literals removed +ALTER VIRTUAL CLUSTER 'foo' RENAME TO _ -- identifiers removed + +# Regression test for #99853 +parse +ALTER VIRTUAL CLUSTER 'string' RENAME TO INTERVAL 'string' MINUTE TO SECOND +---- +ALTER VIRTUAL CLUSTER 'string' RENAME TO ('string'::INTERVAL MINUTE TO SECOND) -- normalized! +ALTER VIRTUAL CLUSTER ('string') RENAME TO ((('string')::INTERVAL MINUTE TO SECOND)) -- fully parenthesized +ALTER VIRTUAL CLUSTER '_' RENAME TO ('_'::INTERVAL MINUTE TO SECOND) -- literals removed +ALTER VIRTUAL CLUSTER 'string' RENAME TO ('string'::INTERVAL MINUTE TO SECOND) -- identifiers removed + +# Regression test for #95612 +parse +ALTER VIRTUAL CLUSTER INTERVAL 'string' MINUTE RESET CLUSTER SETTING ident +---- +ALTER VIRTUAL CLUSTER ('string'::INTERVAL MINUTE) SET CLUSTER SETTING ident = DEFAULT -- normalized! +ALTER VIRTUAL CLUSTER ((('string')::INTERVAL MINUTE)) SET CLUSTER SETTING ident = (DEFAULT) -- fully parenthesized +ALTER VIRTUAL CLUSTER ('_'::INTERVAL MINUTE) SET CLUSTER SETTING ident = DEFAULT -- literals removed +ALTER VIRTUAL CLUSTER ('string'::INTERVAL MINUTE) SET CLUSTER SETTING ident = DEFAULT -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER 123 GRANT ALL CAPABILITIES +---- +ALTER VIRTUAL CLUSTER 123 GRANT ALL CAPABILITIES +ALTER VIRTUAL CLUSTER (123) GRANT ALL CAPABILITIES -- fully parenthesized +ALTER VIRTUAL CLUSTER _ GRANT ALL CAPABILITIES -- literals removed +ALTER VIRTUAL CLUSTER 123 GRANT ALL CAPABILITIES -- identifiers removed + +parse +ALTER TENANT 123 GRANT ALL CAPABILITIES +---- +ALTER VIRTUAL CLUSTER 123 GRANT ALL CAPABILITIES -- normalized! +ALTER VIRTUAL CLUSTER (123) GRANT ALL CAPABILITIES -- fully parenthesized +ALTER VIRTUAL CLUSTER _ GRANT ALL CAPABILITIES -- literals removed +ALTER VIRTUAL CLUSTER 123 GRANT ALL CAPABILITIES -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER 123 GRANT CAPABILITY a = 3 +---- +ALTER VIRTUAL CLUSTER 123 GRANT CAPABILITY a = 3 +ALTER VIRTUAL CLUSTER (123) GRANT CAPABILITY a = (3) -- fully parenthesized +ALTER VIRTUAL CLUSTER _ GRANT CAPABILITY a = _ -- literals removed +ALTER VIRTUAL CLUSTER 123 GRANT CAPABILITY a = 3 -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER (1+1) GRANT CAPABILITY a = 3 +---- +ALTER VIRTUAL CLUSTER (1 + 1) GRANT CAPABILITY a = 3 -- normalized! +ALTER VIRTUAL CLUSTER ((((1) + (1)))) GRANT CAPABILITY a = (3) -- fully parenthesized +ALTER VIRTUAL CLUSTER (_ + _) GRANT CAPABILITY a = _ -- literals removed +ALTER VIRTUAL CLUSTER (1 + 1) GRANT CAPABILITY a = 3 -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER $1 GRANT CAPABILITY a = 3 +---- +ALTER VIRTUAL CLUSTER $1 GRANT CAPABILITY a = 3 +ALTER VIRTUAL CLUSTER ($1) GRANT CAPABILITY a = (3) -- fully parenthesized +ALTER VIRTUAL CLUSTER $1 GRANT CAPABILITY a = _ -- literals removed +ALTER VIRTUAL CLUSTER $1 GRANT CAPABILITY a = 3 -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER 123 REVOKE ALL CAPABILITIES +---- +ALTER VIRTUAL CLUSTER 123 REVOKE ALL CAPABILITIES +ALTER VIRTUAL CLUSTER (123) REVOKE ALL CAPABILITIES -- fully parenthesized +ALTER VIRTUAL CLUSTER _ REVOKE ALL CAPABILITIES -- literals removed +ALTER VIRTUAL CLUSTER 123 REVOKE ALL CAPABILITIES -- identifiers removed + +parse +ALTER TENANT 123 REVOKE ALL CAPABILITIES +---- +ALTER VIRTUAL CLUSTER 123 REVOKE ALL CAPABILITIES -- normalized! +ALTER VIRTUAL CLUSTER (123) REVOKE ALL CAPABILITIES -- fully parenthesized +ALTER VIRTUAL CLUSTER _ REVOKE ALL CAPABILITIES -- literals removed +ALTER VIRTUAL CLUSTER 123 REVOKE ALL CAPABILITIES -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER 123 REVOKE CAPABILITY a +---- +ALTER VIRTUAL CLUSTER 123 REVOKE CAPABILITY a +ALTER VIRTUAL CLUSTER (123) REVOKE CAPABILITY a -- fully parenthesized +ALTER VIRTUAL CLUSTER _ REVOKE CAPABILITY a -- literals removed +ALTER VIRTUAL CLUSTER 123 REVOKE CAPABILITY a -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER (1+1) REVOKE CAPABILITY a +---- +ALTER VIRTUAL CLUSTER (1 + 1) REVOKE CAPABILITY a -- normalized! +ALTER VIRTUAL CLUSTER ((((1) + (1)))) REVOKE CAPABILITY a -- fully parenthesized +ALTER VIRTUAL CLUSTER (_ + _) REVOKE CAPABILITY a -- literals removed +ALTER VIRTUAL CLUSTER (1 + 1) REVOKE CAPABILITY a -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER $1 REVOKE CAPABILITY a +---- +ALTER VIRTUAL CLUSTER $1 REVOKE CAPABILITY a +ALTER VIRTUAL CLUSTER ($1) REVOKE CAPABILITY a -- fully parenthesized +ALTER VIRTUAL CLUSTER $1 REVOKE CAPABILITY a -- literals removed +ALTER VIRTUAL CLUSTER $1 REVOKE CAPABILITY a -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER 'foo' START SERVICE EXTERNAL +---- +ALTER VIRTUAL CLUSTER 'foo' START SERVICE EXTERNAL +ALTER VIRTUAL CLUSTER ('foo') START SERVICE EXTERNAL -- fully parenthesized +ALTER VIRTUAL CLUSTER '_' START SERVICE EXTERNAL -- literals removed +ALTER VIRTUAL CLUSTER 'foo' START SERVICE EXTERNAL -- identifiers removed + +parse +ALTER TENANT 'foo' START SERVICE EXTERNAL +---- +ALTER VIRTUAL CLUSTER 'foo' START SERVICE EXTERNAL -- normalized! +ALTER VIRTUAL CLUSTER ('foo') START SERVICE EXTERNAL -- fully parenthesized +ALTER VIRTUAL CLUSTER '_' START SERVICE EXTERNAL -- literals removed +ALTER VIRTUAL CLUSTER 'foo' START SERVICE EXTERNAL -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER 'foo' START SERVICE SHARED +---- +ALTER VIRTUAL CLUSTER 'foo' START SERVICE SHARED +ALTER VIRTUAL CLUSTER ('foo') START SERVICE SHARED -- fully parenthesized +ALTER VIRTUAL CLUSTER '_' START SERVICE SHARED -- literals removed +ALTER VIRTUAL CLUSTER 'foo' START SERVICE SHARED -- identifiers removed + +parse +ALTER VIRTUAL CLUSTER 'foo' STOP SERVICE +---- +ALTER VIRTUAL CLUSTER 'foo' STOP SERVICE +ALTER VIRTUAL CLUSTER ('foo') STOP SERVICE -- fully parenthesized +ALTER VIRTUAL CLUSTER '_' STOP SERVICE -- literals removed +ALTER VIRTUAL CLUSTER 'foo' STOP SERVICE -- identifiers removed + +parse +ALTER TENANT 'foo' STOP SERVICE +---- +ALTER VIRTUAL CLUSTER 'foo' STOP SERVICE -- normalized! +ALTER VIRTUAL CLUSTER ('foo') STOP SERVICE -- fully parenthesized +ALTER VIRTUAL CLUSTER '_' STOP SERVICE -- literals removed +ALTER VIRTUAL CLUSTER 'foo' STOP SERVICE -- identifiers removed diff --git a/pkg/sql/sem/asof/as_of.go b/pkg/sql/sem/asof/as_of.go index 0d2d3e80f533..ddfb81dd54cc 100644 --- a/pkg/sql/sem/asof/as_of.go +++ b/pkg/sql/sem/asof/as_of.go @@ -16,7 +16,7 @@ import ( "strings" "time" - "github.com/cockroachdb/apd/v3" + apd "github.com/cockroachdb/apd/v3" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" "github.com/cockroachdb/cockroach/pkg/sql/sem/eval" @@ -224,7 +224,7 @@ const ( Split // ReplicationCutover is when the DatumToHLC() is used for an - // ALTER TENANT ... COMPLETE REPLICATION statement. + // ALTER VIRTUAL CLUSTER ... COMPLETE REPLICATION statement. ReplicationCutover ) diff --git a/pkg/sql/sem/tree/alter_tenant.go b/pkg/sql/sem/tree/alter_tenant.go index 0034b874be2a..410bc2e5f92d 100644 --- a/pkg/sql/sem/tree/alter_tenant.go +++ b/pkg/sql/sem/tree/alter_tenant.go @@ -16,7 +16,7 @@ type ReplicationCutoverTime struct { Latest bool } -// AlterTenantReplication represents an ALTER TENANT REPLICATION statement. +// AlterTenantReplication represents an ALTER VIRTUAL CLUSTER REPLICATION statement. type AlterTenantReplication struct { TenantSpec *TenantSpec Command JobCommand @@ -28,7 +28,7 @@ var _ Statement = &AlterTenantReplication{} // Format implements the NodeFormatter interface. func (n *AlterTenantReplication) Format(ctx *FmtCtx) { - ctx.WriteString("ALTER TENANT ") + ctx.WriteString("ALTER VIRTUAL CLUSTER ") ctx.FormatNode(n.TenantSpec) ctx.WriteByte(' ') if n.Cutover != nil { @@ -54,7 +54,7 @@ type TenantCapability struct { Value Expr } -// AlterTenantCapability represents an ALTER TENANT CAPABILITY statement. +// AlterTenantCapability represents an ALTER VIRTUAL CLUSTER CAPABILITY statement. type AlterTenantCapability struct { TenantSpec *TenantSpec Capabilities []TenantCapability @@ -67,7 +67,7 @@ var _ Statement = &AlterTenantCapability{} // Format implements the NodeFormatter interface. func (n *AlterTenantCapability) Format(ctx *FmtCtx) { - ctx.WriteString("ALTER TENANT ") + ctx.WriteString("ALTER VIRTUAL CLUSTER ") ctx.FormatNode(n.TenantSpec) if n.IsRevoke { ctx.WriteString(" REVOKE ") @@ -92,7 +92,7 @@ func (n *AlterTenantCapability) Format(ctx *FmtCtx) { } } -// TenantSpec designates a tenant for the ALTER TENANT statements. +// TenantSpec designates a tenant for the ALTER VIRTUAL CLUSTER statements. type TenantSpec struct { Expr Expr IsName bool @@ -167,7 +167,7 @@ func (n *TenantSpec) Format(ctx *FmtCtx) { } } -// AlterTenantRename represents an ALTER TENANT RENAME statement. +// AlterTenantRename represents an ALTER VIRTUAL CLUSTER RENAME statement. type AlterTenantRename struct { TenantSpec *TenantSpec @@ -183,19 +183,19 @@ var _ Statement = &AlterTenantRename{} // Format implements the NodeFormatter interface. func (n *AlterTenantRename) Format(ctx *FmtCtx) { - ctx.WriteString("ALTER TENANT ") + ctx.WriteString("ALTER VIRTUAL CLUSTER ") ctx.FormatNode(n.TenantSpec) ctx.WriteString(" RENAME TO ") ctx.FormatNode(n.NewName) } -// AlterTenantService represents an ALTER TENANT START/STOP SERVICE statement. +// AlterTenantService represents an ALTER VIRTUAL CLUSTER START/STOP SERVICE statement. type AlterTenantService struct { TenantSpec *TenantSpec Command TenantServiceCmd } -// TenantServiceCmd represents a parameter to ALTER TENANT. +// TenantServiceCmd represents a parameter to ALTER VIRTUAL CLUSTER. type TenantServiceCmd int8 const ( @@ -211,7 +211,7 @@ var _ Statement = &AlterTenantService{} // Format implements the NodeFormatter interface. func (n *AlterTenantService) Format(ctx *FmtCtx) { - ctx.WriteString("ALTER TENANT ") + ctx.WriteString("ALTER VIRTUAL CLUSTER ") ctx.FormatNode(n.TenantSpec) switch n.Command { case TenantStartServiceExternal: diff --git a/pkg/sql/sem/tree/stmt.go b/pkg/sql/sem/tree/stmt.go index 7e8b88f32fb7..0e65f3d6e478 100644 --- a/pkg/sql/sem/tree/stmt.go +++ b/pkg/sql/sem/tree/stmt.go @@ -491,7 +491,7 @@ func (*AlterTenantCapability) StatementReturnType() StatementReturnType { return func (*AlterTenantCapability) StatementType() StatementType { return TypeDML } // StatementTag returns a short string identifying the type of statement. -func (*AlterTenantCapability) StatementTag() string { return "ALTER TENANT CAPABILITY" } +func (*AlterTenantCapability) StatementTag() string { return "ALTER VIRTUAL CLUSTER CAPABILITY" } // StatementReturnType implements the Statement interface. func (*AlterTenantSetClusterSetting) StatementReturnType() StatementReturnType { return Ack } @@ -500,7 +500,9 @@ func (*AlterTenantSetClusterSetting) StatementReturnType() StatementReturnType { func (*AlterTenantSetClusterSetting) StatementType() StatementType { return TypeDCL } // StatementTag returns a short string identifying the type of statement. -func (*AlterTenantSetClusterSetting) StatementTag() string { return "ALTER TENANT SET CLUSTER SETTING" } +func (*AlterTenantSetClusterSetting) StatementTag() string { + return "ALTER VIRTUAL CLUSTER SET CLUSTER SETTING" +} // StatementReturnType implements the Statement interface. func (*AlterTenantReplication) StatementReturnType() StatementReturnType { return Rows } @@ -509,7 +511,7 @@ func (*AlterTenantReplication) StatementReturnType() StatementReturnType { retur func (*AlterTenantReplication) StatementType() StatementType { return TypeDML } // StatementTag returns a short string identifying the type of statement. -func (*AlterTenantReplication) StatementTag() string { return "ALTER TENANT REPLICATION" } +func (*AlterTenantReplication) StatementTag() string { return "ALTER VIRTUAL CLUSTER REPLICATION" } func (*AlterTenantReplication) cclOnlyStatement() {} @@ -520,7 +522,7 @@ func (*AlterTenantRename) StatementReturnType() StatementReturnType { return Ack func (*AlterTenantRename) StatementType() StatementType { return TypeDCL } // StatementTag returns a short string identifying the type of statement. -func (*AlterTenantRename) StatementTag() string { return "ALTER TENANT RENAME" } +func (*AlterTenantRename) StatementTag() string { return "ALTER VIRTUAL CLUSTER RENAME" } // StatementReturnType implements the Statement interface. func (*AlterTenantService) StatementReturnType() StatementReturnType { return Ack } @@ -529,7 +531,7 @@ func (*AlterTenantService) StatementReturnType() StatementReturnType { return Ac func (*AlterTenantService) StatementType() StatementType { return TypeDCL } // StatementTag returns a short string identifying the type of statement. -func (*AlterTenantService) StatementTag() string { return "ALTER TENANT SERVICE" } +func (*AlterTenantService) StatementTag() string { return "ALTER VIRTUAL CLUSTER SERVICE" } // StatementReturnType implements the Statement interface. func (*AlterType) StatementReturnType() StatementReturnType { return DDL } diff --git a/pkg/sql/sem/tree/tenant_settings.go b/pkg/sql/sem/tree/tenant_settings.go index 36f25c4ccae1..988f5daa638c 100644 --- a/pkg/sql/sem/tree/tenant_settings.go +++ b/pkg/sql/sem/tree/tenant_settings.go @@ -10,7 +10,7 @@ package tree -// AlterTenantSetClusterSetting represents an ALTER TENANT +// AlterTenantSetClusterSetting represents an ALTER VIRTUAL CLUSTER // SET CLUSTER SETTING statement. type AlterTenantSetClusterSetting struct { SetClusterSetting @@ -19,7 +19,7 @@ type AlterTenantSetClusterSetting struct { // Format implements the NodeFormatter interface. func (n *AlterTenantSetClusterSetting) Format(ctx *FmtCtx) { - ctx.WriteString("ALTER TENANT ") + ctx.WriteString("ALTER VIRTUAL CLUSTER ") ctx.FormatNode(n.TenantSpec) ctx.WriteByte(' ') ctx.FormatNode(&n.SetClusterSetting) From 2d0122b5bd0a936bf818807a0770632269137e66 Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Tue, 4 Jul 2023 16:45:24 +0200 Subject: [PATCH 15/17] sql: use `ALTER VIRTUAL CLUSTER` in error messages and config profiles Release note: None --- .../testdata/logic_test/tenant_capability | 4 ++-- .../streamingest/alter_replication_job.go | 14 +++++++------- pkg/configprofiles/profiles.go | 8 ++++---- .../logictest/testdata/logic_test/cluster_settings | 2 +- pkg/sql/rename_tenant.go | 4 ++-- pkg/sql/tenant_capability.go | 2 +- pkg/sql/tenant_deletion.go | 2 +- pkg/sql/tenant_service.go | 2 +- pkg/sql/tenant_settings.go | 6 +++--- pkg/sql/tenant_update.go | 8 ++++---- 10 files changed, 26 insertions(+), 26 deletions(-) diff --git a/pkg/ccl/logictestccl/testdata/logic_test/tenant_capability b/pkg/ccl/logictestccl/testdata/logic_test/tenant_capability index 790382695505..aee307e5204b 100644 --- a/pkg/ccl/logictestccl/testdata/logic_test/tenant_capability +++ b/pkg/ccl/logictestccl/testdata/logic_test/tenant_capability @@ -8,7 +8,7 @@ CREATE TENANT "grant-revoke-error-tenant"; statement error pgcode 42601 unknown capability: "not_a_capability" ALTER TENANT "grant-revoke-error-tenant" GRANT CAPABILITY not_a_capability=true -statement error pgcode 42804 argument of ALTER TENANT CAPABILITY can_admin_split must be type bool, not type int +statement error pgcode 42804 argument of ALTER VIRTUAL CLUSTER CAPABILITY can_admin_split must be type bool, not type int ALTER TENANT "grant-revoke-error-tenant" GRANT CAPABILITY can_admin_split=1 statement error pgcode 22023 parameter "can_admin_split" requires a Boolean value @@ -309,7 +309,7 @@ span_config_bounds {} statement error pgcode 22023 invalid span_config_bounds value ALTER TENANT scb GRANT CAPABILITY span_config_bounds = x'01ab'; -statement error pgcode 42804 argument of ALTER TENANT CAPABILITY span_config_bounds must be type bytes, not type bool +statement error pgcode 42804 argument of ALTER VIRTUAL CLUSTER CAPABILITY span_config_bounds must be type bytes, not type bool ALTER TENANT scb GRANT CAPABILITY span_config_bounds = false; statement error pgcode 42601 value required for capability: span_config_bounds diff --git a/pkg/ccl/streamingccl/streamingest/alter_replication_job.go b/pkg/ccl/streamingccl/streamingest/alter_replication_job.go index eb5593f0a06b..d9836b97a62a 100644 --- a/pkg/ccl/streamingccl/streamingest/alter_replication_job.go +++ b/pkg/ccl/streamingccl/streamingest/alter_replication_job.go @@ -33,7 +33,7 @@ import ( "github.com/cockroachdb/errors" ) -const alterReplicationJobOp = "ALTER TENANT REPLICATION" +const alterReplicationJobOp = "ALTER VIRTUAL CLUSTER REPLICATION" var alterReplicationCutoverHeader = colinfo.ResultColumns{ {Name: "cutover_time", Typ: types.Decimal}, @@ -155,7 +155,7 @@ func alterReplicationJobHook( fn := func(ctx context.Context, _ []sql.PlanNode, resultsCh chan<- tree.Datums) error { if err := utilccl.CheckEnterpriseEnabled( p.ExecCfg().Settings, p.ExecCfg().NodeInfo.LogicalClusterID(), - "ALTER TENANT REPLICATION", + alterReplicationJobOp, ); err != nil { return err } @@ -164,7 +164,7 @@ func alterReplicationJobHook( return err } - tenInfo, err := p.LookupTenantInfo(ctx, alterTenantStmt.TenantSpec, "ALTER TENANT REPLICATION") + tenInfo, err := p.LookupTenantInfo(ctx, alterTenantStmt.TenantSpec, alterReplicationJobOp) if err != nil { return err } @@ -193,11 +193,11 @@ func alterReplicationJobHook( } case tree.PauseJob: if err := jobRegistry.PauseRequested(ctx, p.InternalSQLTxn(), tenInfo.TenantReplicationJobID, - "ALTER TENANT PAUSE REPLICATION"); err != nil { + "ALTER VIRTUAL CLUSTER PAUSE REPLICATION"); err != nil { return err } default: - return errors.New("unsupported job command in ALTER TENANT REPLICATION") + return errors.New("unsupported job command in ALTER VIRTUAL CLUSTER REPLICATION") } } return nil @@ -209,7 +209,7 @@ func alterReplicationJobHook( } // alterTenantJobCutover returns the cutover timestamp that was used to initiate -// the cutover process - if the command is 'ALTER TENANT .. COMPLETE REPLICATION +// the cutover process - if the command is 'ALTER VIRTUAL CLUSTER .. COMPLETE REPLICATION // TO LATEST' then the frontier high water timestamp is used. func alterTenantJobCutover( ctx context.Context, @@ -221,7 +221,7 @@ func alterTenantJobCutover( cutoverTime hlc.Timestamp, ) (hlc.Timestamp, error) { if alterTenantStmt == nil || alterTenantStmt.Cutover == nil { - return hlc.Timestamp{}, errors.AssertionFailedf("unexpected nil ALTER TENANT cutover expression") + return hlc.Timestamp{}, errors.AssertionFailedf("unexpected nil ALTER VIRTUAL CLUSTER cutover expression") } tenantName := tenInfo.Name diff --git a/pkg/configprofiles/profiles.go b/pkg/configprofiles/profiles.go index d7975421de7f..1ec630616b51 100644 --- a/pkg/configprofiles/profiles.go +++ b/pkg/configprofiles/profiles.go @@ -102,11 +102,11 @@ var multitenantClusterInitTasks = []autoconfigpb.Task{ []string{ // Create a main secondary tenant template. "CREATE VIRTUAL CLUSTER template", - "ALTER TENANT template GRANT ALL CAPABILITIES", + "ALTER VIRTUAL CLUSTER template GRANT ALL CAPABILITIES", // Enable admin scatter/split in tenant SQL. // TODO(knz): Move this to in-tenant config task. - "ALTER TENANT template SET CLUSTER SETTING sql.scatter.allow_for_secondary_tenant.enabled = true", - "ALTER TENANT template SET CLUSTER SETTING sql.split_at.allow_for_secondary_tenant.enabled = true", + "ALTER VIRTUAL CLUSTER template SET CLUSTER SETTING sql.scatter.allow_for_secondary_tenant.enabled = true", + "ALTER VIRTUAL CLUSTER template SET CLUSTER SETTING sql.split_at.allow_for_secondary_tenant.enabled = true", }, ), // Finally. @@ -126,7 +126,7 @@ var multitenantClusterWithAppServiceInitTasks = append( // Create the app tenant record. "CREATE VIRTUAL CLUSTER application", // Run the service for the application tenant. - "ALTER TENANT application START SERVICE SHARED", + "ALTER VIRTUAL CLUSTER application START SERVICE SHARED", }, ), makeTask("activate application tenant", diff --git a/pkg/sql/logictest/testdata/logic_test/cluster_settings b/pkg/sql/logictest/testdata/logic_test/cluster_settings index 58c71c953e2a..c98ee6773010 100644 --- a/pkg/sql/logictest/testdata/logic_test/cluster_settings +++ b/pkg/sql/logictest/testdata/logic_test/cluster_settings @@ -291,7 +291,7 @@ statement error admission.kv.enabled is a system-only setting and must be set in ALTER TENANT [10] SET CLUSTER SETTING admission.kv.enabled=true onlyif config 3node-tenant-default-configs -statement error ALTER TENANT can only be called by system operators +statement error ALTER VIRTUAL CLUSTER can only be called by system operators ALTER TENANT [10] SET CLUSTER SETTING server.mem_profile.total_dump_size_limit='10M' skipif config 3node-tenant-default-configs diff --git a/pkg/sql/rename_tenant.go b/pkg/sql/rename_tenant.go index 588c0d1b3e20..81a23d9ba910 100644 --- a/pkg/sql/rename_tenant.go +++ b/pkg/sql/rename_tenant.go @@ -41,12 +41,12 @@ func (p *planner) alterRenameTenant( e = tree.NewStrVal(tree.AsStringWithFlags(s, tree.FmtBareIdentifiers)) } tname, err := p.analyzeExpr( - ctx, e, nil, tree.IndexedVarHelper{}, types.String, true, "ALTER TENANT RENAME") + ctx, e, nil, tree.IndexedVarHelper{}, types.String, true, "ALTER VIRTUAL CLUSTER RENAME") if err != nil { return nil, err } - tspec, err := p.planTenantSpec(ctx, n.TenantSpec, "ALTER TENANT RENAME") + tspec, err := p.planTenantSpec(ctx, n.TenantSpec, "ALTER VIRTUAL CLUSTER RENAME") if err != nil { return nil, err } diff --git a/pkg/sql/tenant_capability.go b/pkg/sql/tenant_capability.go index fa77193a3d4d..0043458a5001 100644 --- a/pkg/sql/tenant_capability.go +++ b/pkg/sql/tenant_capability.go @@ -28,7 +28,7 @@ import ( "github.com/cockroachdb/errors" ) -const alterTenantCapabilityOp = "ALTER TENANT CAPABILITY" +const alterTenantCapabilityOp = "ALTER VIRTUAL CLUSTER CAPABILITY" type alterTenantCapabilityNode struct { n *tree.AlterTenantCapability diff --git a/pkg/sql/tenant_deletion.go b/pkg/sql/tenant_deletion.go index 69e5743eaabc..a553c635ef23 100644 --- a/pkg/sql/tenant_deletion.go +++ b/pkg/sql/tenant_deletion.go @@ -99,7 +99,7 @@ func dropTenantInternal( if info.ServiceMode != mtinfopb.ServiceModeNone { return errors.WithHint(pgerror.Newf(pgcode.ObjectNotInPrerequisiteState, "cannot drop tenant %q (%d) in service mode %v", info.Name, tenID, info.ServiceMode), - "Use ALTER TENANT STOP SERVICE before DROP VIRTUAL CLUSTER.") + "Use ALTER VIRTUAL CLUSTER STOP SERVICE before DROP VIRTUAL CLUSTER.") } } diff --git a/pkg/sql/tenant_service.go b/pkg/sql/tenant_service.go index c842664fc265..c8e442d50020 100644 --- a/pkg/sql/tenant_service.go +++ b/pkg/sql/tenant_service.go @@ -45,7 +45,7 @@ func (p *planner) alterTenantService( return nil, errors.AssertionFailedf("unhandled case: %+v", n) } - tspec, err := p.planTenantSpec(ctx, n.TenantSpec, "ALTER TENANT SERVICE") + tspec, err := p.planTenantSpec(ctx, n.TenantSpec, "ALTER VIRTUAL CLUSTER SERVICE") if err != nil { return nil, err } diff --git a/pkg/sql/tenant_settings.go b/pkg/sql/tenant_settings.go index 95ba4220fde5..268c4f85d4e5 100644 --- a/pkg/sql/tenant_settings.go +++ b/pkg/sql/tenant_settings.go @@ -27,7 +27,7 @@ import ( ) // alterTenantSetClusterSettingNode represents an -// ALTER TENANT ... SET CLUSTER SETTING statement. +// ALTER VIRTUAL CLUSTER ... SET CLUSTER SETTING statement. type alterTenantSetClusterSettingNode struct { name string tenantSpec tenantSpec @@ -52,7 +52,7 @@ func (p *planner) AlterTenantSetClusterSetting( // Error out if we're trying to call this from a non-system tenant. if !p.execCfg.Codec.ForSystemTenant() { return nil, pgerror.Newf(pgcode.InsufficientPrivilege, - "ALTER TENANT can only be called by system operators") + "ALTER VIRTUAL CLUSTER can only be called by system operators") } name := strings.ToLower(n.Name) @@ -67,7 +67,7 @@ func (p *planner) AlterTenantSetClusterSetting( "%s is a system-only setting and must be set in the admin tenant using SET CLUSTER SETTING", name) } - tspec, err := p.planTenantSpec(ctx, n.TenantSpec, "ALTER TENANT SET CLUSTER SETTING "+name) + tspec, err := p.planTenantSpec(ctx, n.TenantSpec, "ALTER VIRTUAL CLUSTER SET CLUSTER SETTING "+name) if err != nil { return nil, err } diff --git a/pkg/sql/tenant_update.go b/pkg/sql/tenant_update.go index 03c7e1c6cb4d..74f2475348a8 100644 --- a/pkg/sql/tenant_update.go +++ b/pkg/sql/tenant_update.go @@ -208,7 +208,7 @@ func (p *planner) setTenantService( ctx context.Context, info *mtinfopb.TenantInfo, newMode mtinfopb.TenantServiceMode, ) error { if p.EvalContext().TxnReadOnly { - return readOnlyError("ALTER TENANT SERVICE") + return readOnlyError("ALTER VIRTUAL CLUSTER SERVICE") } if err := CanManageTenant(ctx, p); err != nil { @@ -230,7 +230,7 @@ func (p *planner) setTenantService( return errors.WithHint(pgerror.Newf(pgcode.ObjectNotInPrerequisiteState, "cannot change service mode %v to %v directly", info.ServiceMode, newMode), - "Use ALTER TENANT STOP SERVICE first.") + "Use ALTER VIRTUAL CLUSTER STOP SERVICE first.") } info.ServiceMode = newMode @@ -241,7 +241,7 @@ func (p *planner) renameTenant( ctx context.Context, info *mtinfopb.TenantInfo, newName roachpb.TenantName, ) error { if p.EvalContext().TxnReadOnly { - return readOnlyError("ALTER TENANT RENAME TO") + return readOnlyError("ALTER VIRTUAL CLUSTER RENAME TO") } if err := rejectIfCantCoordinateMultiTenancy(p.ExecCfg().Codec, "rename tenant"); err != nil { return err @@ -266,7 +266,7 @@ func (p *planner) renameTenant( if info.ServiceMode != mtinfopb.ServiceModeNone { return errors.WithHint(pgerror.Newf(pgcode.ObjectNotInPrerequisiteState, "cannot rename tenant in service mode %v", info.ServiceMode), - "Use ALTER TENANT STOP SERVICE before renaming a tenant.") + "Use ALTER VIRTUAL CLUSTER STOP SERVICE before renaming a tenant.") } info.Name = newName From 2670c2d79286d260b45162b4d0d81c95e262a7bd Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Tue, 4 Jul 2023 16:21:03 +0200 Subject: [PATCH 16/17] sql/parser: rename `tenant_spec` to `virtual_cluster_spec` Release note: None --- pkg/sql/parser/sql.y | 90 ++++++++++++++++++++++---------------------- 1 file changed, 46 insertions(+), 44 deletions(-) diff --git a/pkg/sql/parser/sql.y b/pkg/sql/parser/sql.y index 3c98108fc637..1d0f34469e8d 100644 --- a/pkg/sql/parser/sql.y +++ b/pkg/sql/parser/sql.y @@ -1492,7 +1492,7 @@ func (u *sqlSymUnion) showCreateFormatOption() tree.ShowCreateFormatOption { %type execute_param_clause %type opt_interval_qualifier interval_qualifier interval_second %type overlay_placing -%type <*tree.TenantSpec> tenant_spec virtual_cluster_spec_opt_all +%type <*tree.TenantSpec> virtual_cluster_spec virtual_cluster_spec_opt_all %type opt_unique opt_concurrently opt_cluster opt_without_index %type opt_index_access_method @@ -4419,8 +4419,10 @@ create_stmt: // %Help: CREATE VIRTUAL CLUSTER - create a new virtual cluster // %Category: Experimental // %Text: -// CREATE VIRTUAL CLUSTER [ IF NOT EXISTS ] name [ LIKE ] -// CREATE VIRTUAL CLUSTER [ IF NOT EXISTS ] name [ LIKE ] FROM REPLICATION OF ON [ WITH OPTIONS ... ] +// CREATE VIRTUAL CLUSTER [ IF NOT EXISTS ] name [ LIKE ] [ ] +// +// Replication option: +// FROM REPLICATION OF ON [ WITH OPTIONS ... ] create_virtual_cluster_stmt: CREATE virtual_cluster d_expr opt_like_tenant { @@ -4476,7 +4478,7 @@ opt_like_tenant: { $$.val = &tree.LikeTenantSpec{} } -| LIKE tenant_spec +| LIKE virtual_cluster_spec { $$.val = &tree.LikeTenantSpec{OtherTenant: $2.tenantSpec()} } @@ -5544,9 +5546,9 @@ drop_type_stmt: // %Help: DROP VIRTUAL CLUSTER - remove a virtual cluster // %Category: Experimental -// %Text: DROP VIRTUAL CLUSTER [IF EXISTS] [IMMEDIATE] +// %Text: DROP VIRTUAL CLUSTER [IF EXISTS] [IMMEDIATE] drop_virtual_cluster_stmt: - DROP virtual_cluster tenant_spec opt_immediate + DROP virtual_cluster virtual_cluster_spec opt_immediate { /* SKIP DOC */ $$.val = &tree.DropTenant{ @@ -5555,7 +5557,7 @@ drop_virtual_cluster_stmt: Immediate: $4.bool(), } } -| DROP virtual_cluster IF EXISTS tenant_spec opt_immediate +| DROP virtual_cluster IF EXISTS virtual_cluster_spec opt_immediate { /* SKIP DOC */ $$.val = &tree.DropTenant{ @@ -5924,8 +5926,8 @@ backup_kms: // %Help: SHOW VIRTUAL CLUSTER - display metadata about virtual clusters // %Category: Experimental // %Text: -// SHOW VIRTUAL CLUSTER { | ALL } [ WITH ] -// SHOW VIRTUAL CLUSTERS [ WITH ] +// SHOW VIRTUAL CLUSTER { | ALL } [ WITH ] +// SHOW VIRTUAL CLUSTERS [ WITH ] // // Options: // REPLICATION STATUS @@ -5952,7 +5954,7 @@ virtual_cluster_spec_opt_all: /* SKIP DOC */ $$.val = &tree.TenantSpec{All: true} } -| TENANT tenant_spec +| TENANT virtual_cluster_spec { /* SKIP DOC */ $$.val = $2.tenantSpec() @@ -5965,7 +5967,7 @@ virtual_cluster_spec_opt_all: { $$.val = &tree.TenantSpec{All: true} } -| VIRTUAL CLUSTER tenant_spec +| VIRTUAL CLUSTER virtual_cluster_spec { $$.val = $3.tenantSpec() } @@ -6568,7 +6570,7 @@ alter_virtual_cluster_stmt: | alter_virtual_cluster_service_stmt // EXTEND WITH HELP: ALTER VIRTUAL CLUSTER SERVICE | ALTER virtual_cluster error // SHOW HELP: ALTER VIRTUAL CLUSTER -tenant_spec: +virtual_cluster_spec: d_expr { $$.val = &tree.TenantSpec{IsName: true, Expr: $1.expr()} } | '[' a_expr ']' @@ -6577,9 +6579,9 @@ tenant_spec: // %Help: ALTER VIRTUAL CLUSTER RENAME - rename a virtual cluster // %Category: Experimental // %Text: -// ALTER VIRTUAL CLUSTER RENAME TO +// ALTER VIRTUAL CLUSTER RENAME TO alter_virtual_cluster_rename_stmt: - ALTER virtual_cluster tenant_spec RENAME TO d_expr + ALTER virtual_cluster virtual_cluster_spec RENAME TO d_expr { /* SKIP DOC */ $$.val = &tree.AlterTenantRename{ @@ -6591,11 +6593,11 @@ alter_virtual_cluster_rename_stmt: // %Help: ALTER VIRTUAL CLUSTER SERVICE - alter service mode of a virtual cluster // %Category: Experimental // %Text: -// ALTER VIRTUAL CLUSTER START SERVICE EXTERNAL -// ALTER VIRTUAL CLUSTER START SERVICE SHARED -// ALTER VIRTUAL CLUSTER STOP SERVICE +// ALTER VIRTUAL CLUSTER START SERVICE EXTERNAL +// ALTER VIRTUAL CLUSTER START SERVICE SHARED +// ALTER VIRTUAL CLUSTER STOP SERVICE alter_virtual_cluster_service_stmt: - ALTER virtual_cluster tenant_spec START SERVICE EXTERNAL + ALTER virtual_cluster virtual_cluster_spec START SERVICE EXTERNAL { /* SKIP DOC */ $$.val = &tree.AlterTenantService{ @@ -6603,7 +6605,7 @@ alter_virtual_cluster_service_stmt: Command: tree.TenantStartServiceExternal, } } -| ALTER virtual_cluster tenant_spec START SERVICE SHARED +| ALTER virtual_cluster virtual_cluster_spec START SERVICE SHARED { /* SKIP DOC */ $$.val = &tree.AlterTenantService{ @@ -6611,7 +6613,7 @@ alter_virtual_cluster_service_stmt: Command: tree.TenantStartServiceShared, } } -| ALTER virtual_cluster tenant_spec STOP SERVICE +| ALTER virtual_cluster virtual_cluster_spec STOP SERVICE { /* SKIP DOC */ $$.val = &tree.AlterTenantService{ @@ -6619,20 +6621,20 @@ alter_virtual_cluster_service_stmt: Command: tree.TenantStopService, } } -| ALTER virtual_cluster tenant_spec START error // SHOW HELP: ALTER VIRTUAL CLUSTER SERVICE -| ALTER virtual_cluster tenant_spec STOP error // SHOW HELP: ALTER VIRTUAL CLUSTER SERVICE +| ALTER virtual_cluster virtual_cluster_spec START error // SHOW HELP: ALTER VIRTUAL CLUSTER SERVICE +| ALTER virtual_cluster virtual_cluster_spec STOP error // SHOW HELP: ALTER VIRTUAL CLUSTER SERVICE // %Help: ALTER VIRTUAL CLUSTER REPLICATION - alter replication stream between virtual clusters // %Category: Experimental // %Text: -// ALTER VIRTUAL CLUSTER PAUSE REPLICATION -// ALTER VIRTUAL CLUSTER RESUME REPLICATION -// ALTER VIRTUAL CLUSTER COMPLETE REPLICATION TO LATEST -// ALTER VIRTUAL CLUSTER COMPLETE REPLICATION TO SYSTEM TIME 'time' -// ALTER VIRTUAL CLUSTER SET REPLICATION opt=value,... +// ALTER VIRTUAL CLUSTER PAUSE REPLICATION +// ALTER VIRTUAL CLUSTER RESUME REPLICATION +// ALTER VIRTUAL CLUSTER COMPLETE REPLICATION TO LATEST +// ALTER VIRTUAL CLUSTER COMPLETE REPLICATION TO SYSTEM TIME 'time' +// ALTER VIRTUAL CLUSTER SET REPLICATION opt=value,... alter_virtual_cluster_replication_stmt: - ALTER virtual_cluster tenant_spec PAUSE REPLICATION + ALTER virtual_cluster virtual_cluster_spec PAUSE REPLICATION { /* SKIP DOC */ $$.val = &tree.AlterTenantReplication{ @@ -6640,7 +6642,7 @@ alter_virtual_cluster_replication_stmt: Command: tree.PauseJob, } } -| ALTER virtual_cluster tenant_spec RESUME REPLICATION +| ALTER virtual_cluster virtual_cluster_spec RESUME REPLICATION { /* SKIP DOC */ $$.val = &tree.AlterTenantReplication{ @@ -6648,7 +6650,7 @@ alter_virtual_cluster_replication_stmt: Command: tree.ResumeJob, } } -| ALTER virtual_cluster tenant_spec COMPLETE REPLICATION TO SYSTEM TIME a_expr +| ALTER virtual_cluster virtual_cluster_spec COMPLETE REPLICATION TO SYSTEM TIME a_expr { /* SKIP DOC */ $$.val = &tree.AlterTenantReplication{ @@ -6658,7 +6660,7 @@ alter_virtual_cluster_replication_stmt: }, } } -| ALTER virtual_cluster tenant_spec COMPLETE REPLICATION TO LATEST +| ALTER virtual_cluster virtual_cluster_spec COMPLETE REPLICATION TO LATEST { /* SKIP DOC */ $$.val = &tree.AlterTenantReplication{ @@ -6668,7 +6670,7 @@ alter_virtual_cluster_replication_stmt: }, } } -| ALTER virtual_cluster tenant_spec SET REPLICATION tenant_replication_options_list +| ALTER virtual_cluster virtual_cluster_spec SET REPLICATION tenant_replication_options_list { /* SKIP DOC */ $$.val = &tree.AlterTenantReplication{ @@ -6681,11 +6683,11 @@ alter_virtual_cluster_replication_stmt: // %Help: ALTER VIRTUAL CLUSTER SETTING - alter cluster setting overrides for virtual clusters // %Category: Group // %Text: -// ALTER VIRTUAL CLUSTER { | ALL } SET CLUSTER SETTING { TO | = } -// ALTER VIRTUAL CLUSTER { | ALL } RESET CLUSTER SETTING +// ALTER VIRTUAL CLUSTER { | ALL } SET CLUSTER SETTING { TO | = } +// ALTER VIRTUAL CLUSTER { | ALL } RESET CLUSTER SETTING // %SeeAlso: SET CLUSTER SETTING alter_virtual_cluster_csetting_stmt: - ALTER virtual_cluster tenant_spec set_or_reset_csetting_stmt + ALTER virtual_cluster virtual_cluster_spec set_or_reset_csetting_stmt { /* SKIP DOC */ csettingStmt := $4.stmt().(*tree.SetClusterSetting) @@ -6729,7 +6731,7 @@ to_or_eq: // ALTER VIRTUAL CLUSTER GRANT CAPABILITY { TO | = } // ALTER VIRTUAL CLUSTER REVOKE CAPABILITY alter_virtual_cluster_capability_stmt: - ALTER virtual_cluster tenant_spec GRANT CAPABILITY tenant_capability_list + ALTER virtual_cluster virtual_cluster_spec GRANT CAPABILITY tenant_capability_list { /* SKIP DOC */ $$.val = &tree.AlterTenantCapability{ @@ -6737,7 +6739,7 @@ alter_virtual_cluster_capability_stmt: Capabilities: $6.tenantCapabilities(), } } -| ALTER virtual_cluster tenant_spec GRANT ALL CAPABILITIES +| ALTER virtual_cluster virtual_cluster_spec GRANT ALL CAPABILITIES { /* SKIP DOC */ $$.val = &tree.AlterTenantCapability{ @@ -6745,7 +6747,7 @@ alter_virtual_cluster_capability_stmt: AllCapabilities: true, } } -| ALTER virtual_cluster tenant_spec REVOKE CAPABILITY tenant_capability_list +| ALTER virtual_cluster virtual_cluster_spec REVOKE CAPABILITY tenant_capability_list { /* SKIP DOC */ $$.val = &tree.AlterTenantCapability{ @@ -6754,7 +6756,7 @@ alter_virtual_cluster_capability_stmt: IsRevoke: true, } } -| ALTER virtual_cluster tenant_spec REVOKE ALL CAPABILITIES +| ALTER virtual_cluster virtual_cluster_spec REVOKE ALL CAPABILITIES { /* SKIP DOC */ $$.val = &tree.AlterTenantCapability{ @@ -6763,8 +6765,8 @@ alter_virtual_cluster_capability_stmt: IsRevoke: true, } } -| ALTER virtual_cluster tenant_spec GRANT error // SHOW HELP: ALTER VIRTUAL CLUSTER CAPABILITY -| ALTER virtual_cluster tenant_spec REVOKE error // SHOW HELP: ALTER VIRTUAL CLUSTER CAPABILITY +| ALTER virtual_cluster virtual_cluster_spec GRANT error // SHOW HELP: ALTER VIRTUAL CLUSTER CAPABILITY +| ALTER virtual_cluster virtual_cluster_spec REVOKE error // SHOW HELP: ALTER VIRTUAL CLUSTER CAPABILITY tenant_capability: var_name @@ -7672,8 +7674,8 @@ show_backup_connection_options: // %Help: SHOW CLUSTER SETTING - display cluster settings // %Category: Cfg // %Text: -// SHOW CLUSTER SETTING [ FOR VIRTUAL CLUSTER ] -// SHOW [ PUBLIC | ALL ] CLUSTER SETTINGS [ FOR VIRTUAL CLUSTER ] +// SHOW CLUSTER SETTING [ FOR VIRTUAL CLUSTER ] +// SHOW [ PUBLIC | ALL ] CLUSTER SETTINGS [ FOR VIRTUAL CLUSTER ] // %SeeAlso: WEBDOCS/cluster-settings.html show_csettings_stmt: SHOW CLUSTER SETTING var_name @@ -7706,7 +7708,7 @@ show_local_or_virtual_cluster_csettings_stmt: /* SKIP DOC */ $$.val = $1.stmt() } -| show_csettings_stmt FOR virtual_cluster tenant_spec +| show_csettings_stmt FOR virtual_cluster virtual_cluster_spec { /* SKIP DOC */ switch t := $1.stmt().(type) { From 753fc235ab4399afa5517e4986cbc340fb887b98 Mon Sep 17 00:00:00 2001 From: Raphael 'kena' Poss Date: Tue, 4 Jul 2023 16:32:38 +0200 Subject: [PATCH 17/17] sql/parser: rename some invisible non-terminals Release note: None --- docs/generated/sql/bnf/BUILD.bazel | 3 - .../sql/bnf/opt_show_tenant_options.bnf | 2 - docs/generated/sql/bnf/tenant_capability.bnf | 3 - .../sql/bnf/tenant_capability_list.bnf | 2 - pkg/gen/bnf.bzl | 3 - pkg/gen/diagrams.bzl | 3 - pkg/gen/docs.bzl | 3 - pkg/sql/parser/sql.y | 84 +++++++++++-------- 8 files changed, 49 insertions(+), 54 deletions(-) delete mode 100644 docs/generated/sql/bnf/opt_show_tenant_options.bnf delete mode 100644 docs/generated/sql/bnf/tenant_capability.bnf delete mode 100644 docs/generated/sql/bnf/tenant_capability_list.bnf diff --git a/docs/generated/sql/bnf/BUILD.bazel b/docs/generated/sql/bnf/BUILD.bazel index bfea71cbf69b..274635ebbef9 100644 --- a/docs/generated/sql/bnf/BUILD.bazel +++ b/docs/generated/sql/bnf/BUILD.bazel @@ -162,7 +162,6 @@ FILES = [ "opt_frame_clause", "opt_locality", "opt_persistence_temp_table", - "opt_show_tenant_options", "opt_with_storage_parameter_list", "pause_all_jobs_stmt", "pause_job", @@ -263,8 +262,6 @@ FILES = [ "table_clause", "table_constraint", "table_ref", - "tenant_capability", - "tenant_capability_list", "transaction_stmt", "truncate_stmt", "unique_column_level", diff --git a/docs/generated/sql/bnf/opt_show_tenant_options.bnf b/docs/generated/sql/bnf/opt_show_tenant_options.bnf deleted file mode 100644 index 24f7e7bdba00..000000000000 --- a/docs/generated/sql/bnf/opt_show_tenant_options.bnf +++ /dev/null @@ -1,2 +0,0 @@ -opt_show_tenant_options ::= - 'WITH' show_tenant_options diff --git a/docs/generated/sql/bnf/tenant_capability.bnf b/docs/generated/sql/bnf/tenant_capability.bnf deleted file mode 100644 index 20fcc373191c..000000000000 --- a/docs/generated/sql/bnf/tenant_capability.bnf +++ /dev/null @@ -1,3 +0,0 @@ -tenant_capability ::= - var_name - | var_name to_or_eq var_value diff --git a/docs/generated/sql/bnf/tenant_capability_list.bnf b/docs/generated/sql/bnf/tenant_capability_list.bnf deleted file mode 100644 index 960a9d14efaa..000000000000 --- a/docs/generated/sql/bnf/tenant_capability_list.bnf +++ /dev/null @@ -1,2 +0,0 @@ -tenant_capability_list ::= - tenant_capability ( ( ',' tenant_capability ) )* diff --git a/pkg/gen/bnf.bzl b/pkg/gen/bnf.bzl index 243b543d143e..923ad9141bfd 100644 --- a/pkg/gen/bnf.bzl +++ b/pkg/gen/bnf.bzl @@ -162,7 +162,6 @@ BNF_SRCS = [ "//docs/generated/sql/bnf:opt_frame_clause.bnf", "//docs/generated/sql/bnf:opt_locality.bnf", "//docs/generated/sql/bnf:opt_persistence_temp_table.bnf", - "//docs/generated/sql/bnf:opt_show_tenant_options.bnf", "//docs/generated/sql/bnf:opt_with_storage_parameter_list.bnf", "//docs/generated/sql/bnf:pause_all_jobs_stmt.bnf", "//docs/generated/sql/bnf:pause_job.bnf", @@ -263,8 +262,6 @@ BNF_SRCS = [ "//docs/generated/sql/bnf:table_clause.bnf", "//docs/generated/sql/bnf:table_constraint.bnf", "//docs/generated/sql/bnf:table_ref.bnf", - "//docs/generated/sql/bnf:tenant_capability.bnf", - "//docs/generated/sql/bnf:tenant_capability_list.bnf", "//docs/generated/sql/bnf:transaction_stmt.bnf", "//docs/generated/sql/bnf:truncate_stmt.bnf", "//docs/generated/sql/bnf:unique_column_level.bnf", diff --git a/pkg/gen/diagrams.bzl b/pkg/gen/diagrams.bzl index 68f052810626..9e9fbc04a33d 100644 --- a/pkg/gen/diagrams.bzl +++ b/pkg/gen/diagrams.bzl @@ -162,7 +162,6 @@ DIAGRAMS_SRCS = [ "//docs/generated/sql/bnf:opt_frame_clause.html", "//docs/generated/sql/bnf:opt_locality.html", "//docs/generated/sql/bnf:opt_persistence_temp_table.html", - "//docs/generated/sql/bnf:opt_show_tenant_options.html", "//docs/generated/sql/bnf:opt_with_storage_parameter_list.html", "//docs/generated/sql/bnf:pause.html", "//docs/generated/sql/bnf:pause_all_jobs.html", @@ -261,8 +260,6 @@ DIAGRAMS_SRCS = [ "//docs/generated/sql/bnf:table_clause.html", "//docs/generated/sql/bnf:table_constraint.html", "//docs/generated/sql/bnf:table_ref.html", - "//docs/generated/sql/bnf:tenant_capability.html", - "//docs/generated/sql/bnf:tenant_capability_list.html", "//docs/generated/sql/bnf:transaction.html", "//docs/generated/sql/bnf:truncate.html", "//docs/generated/sql/bnf:unique_column_level.html", diff --git a/pkg/gen/docs.bzl b/pkg/gen/docs.bzl index fd8d25e96e7b..a3447909d33b 100644 --- a/pkg/gen/docs.bzl +++ b/pkg/gen/docs.bzl @@ -174,7 +174,6 @@ DOCS_SRCS = [ "//docs/generated/sql/bnf:opt_frame_clause.bnf", "//docs/generated/sql/bnf:opt_locality.bnf", "//docs/generated/sql/bnf:opt_persistence_temp_table.bnf", - "//docs/generated/sql/bnf:opt_show_tenant_options.bnf", "//docs/generated/sql/bnf:opt_with_storage_parameter_list.bnf", "//docs/generated/sql/bnf:pause_all_jobs_stmt.bnf", "//docs/generated/sql/bnf:pause_job.bnf", @@ -275,8 +274,6 @@ DOCS_SRCS = [ "//docs/generated/sql/bnf:table_clause.bnf", "//docs/generated/sql/bnf:table_constraint.bnf", "//docs/generated/sql/bnf:table_ref.bnf", - "//docs/generated/sql/bnf:tenant_capability.bnf", - "//docs/generated/sql/bnf:tenant_capability_list.bnf", "//docs/generated/sql/bnf:transaction_stmt.bnf", "//docs/generated/sql/bnf:truncate_stmt.bnf", "//docs/generated/sql/bnf:unique_column_level.bnf", diff --git a/pkg/sql/parser/sql.y b/pkg/sql/parser/sql.y index 1d0f34469e8d..6c3b08f3d65e 100644 --- a/pkg/sql/parser/sql.y +++ b/pkg/sql/parser/sql.y @@ -1086,7 +1086,7 @@ func (u *sqlSymUnion) showCreateFormatOption() tree.ShowCreateFormatOption { %type alter_virtual_cluster_stmt // ALTER VIRTUAL CLUSTER CAPABILITY -%type tenant_capability tenant_capability_list +%type virtual_cluster_capability virtual_cluster_capability_list // ALTER VIRTUAL CLUSTER SET CLUSTER SETTING %type alter_virtual_cluster_csetting_stmt @@ -1193,7 +1193,7 @@ func (u *sqlSymUnion) showCreateFormatOption() tree.ShowCreateFormatOption { %type create_sequence_stmt %type create_func_stmt -%type <*tree.LikeTenantSpec> opt_like_tenant +%type <*tree.LikeTenantSpec> opt_like_virtual_cluster %type create_stats_stmt %type <*tree.CreateStatsOptions> opt_create_stats_options @@ -1297,7 +1297,7 @@ func (u *sqlSymUnion) showCreateFormatOption() tree.ShowCreateFormatOption { %type show_syntax_stmt %type show_last_query_stats_stmt %type show_tables_stmt -%type show_virtual_cluster_stmt opt_show_tenant_options show_tenant_options +%type show_virtual_cluster_stmt opt_show_virtual_cluster_options show_virtual_cluster_options %type show_trace_stmt %type show_transaction_stmt %type show_transactions_stmt @@ -1339,7 +1339,7 @@ func (u *sqlSymUnion) showCreateFormatOption() tree.ShowCreateFormatOption { %type <[]tree.KVOption> kv_option_list opt_with_options var_set_list opt_with_schedule_options %type <*tree.BackupOptions> opt_with_backup_options backup_options backup_options_list %type <*tree.RestoreOptions> opt_with_restore_options restore_options restore_options_list -%type <*tree.TenantReplicationOptions> opt_with_tenant_replication_options tenant_replication_options tenant_replication_options_list +%type <*tree.TenantReplicationOptions> opt_with_replication_options replication_options replication_options_list %type show_backup_details %type <*tree.ShowJobOptions> show_job_options show_job_options_list %type <*tree.ShowBackupOptions> opt_with_show_backup_options show_backup_options show_backup_options_list show_backup_connection_options show_backup_connection_options_list @@ -4424,7 +4424,7 @@ create_stmt: // Replication option: // FROM REPLICATION OF ON [ WITH OPTIONS ... ] create_virtual_cluster_stmt: - CREATE virtual_cluster d_expr opt_like_tenant + CREATE virtual_cluster d_expr opt_like_virtual_cluster { /* SKIP DOC */ $$.val = &tree.CreateTenant{ @@ -4432,7 +4432,7 @@ create_virtual_cluster_stmt: Like: $4.likeTenantSpec(), } } -| CREATE virtual_cluster IF NOT EXISTS d_expr opt_like_tenant +| CREATE virtual_cluster IF NOT EXISTS d_expr opt_like_virtual_cluster { /* SKIP DOC */ $$.val = &tree.CreateTenant{ @@ -4441,7 +4441,7 @@ create_virtual_cluster_stmt: Like: $7.likeTenantSpec(), } } -| CREATE virtual_cluster d_expr opt_like_tenant FROM REPLICATION OF d_expr ON d_expr opt_with_tenant_replication_options +| CREATE virtual_cluster d_expr opt_like_virtual_cluster FROM REPLICATION OF d_expr ON d_expr opt_with_replication_options { /* SKIP DOC */ $$.val = &tree.CreateTenantFromReplication{ @@ -4452,7 +4452,7 @@ create_virtual_cluster_stmt: Like: $4.likeTenantSpec(), } } -| CREATE virtual_cluster IF NOT EXISTS d_expr opt_like_tenant FROM REPLICATION OF d_expr ON d_expr opt_with_tenant_replication_options +| CREATE virtual_cluster IF NOT EXISTS d_expr opt_like_virtual_cluster FROM REPLICATION OF d_expr ON d_expr opt_with_replication_options { /* SKIP DOC */ $$.val = &tree.CreateTenantFromReplication{ @@ -4470,10 +4470,10 @@ virtual_cluster: TENANT { /* SKIP DOC */ } | VIRTUAL CLUSTER -// opt_like_tenant defines a LIKE clause for CREATE VIRTUAL CLUSTER. +// opt_like_virtual_cluster defines a LIKE clause for CREATE VIRTUAL CLUSTER. // Eventually this can grow to support INCLUDING/EXCLUDING options // like in CREATE TABLE. -opt_like_tenant: +opt_like_virtual_cluster: /* EMPTY */ { $$.val = &tree.LikeTenantSpec{} @@ -4484,12 +4484,12 @@ opt_like_tenant: } // Optional tenant replication options. -opt_with_tenant_replication_options: - WITH tenant_replication_options_list +opt_with_replication_options: + WITH replication_options_list { $$.val = $2.tenantReplicationOptions() } -| WITH OPTIONS '(' tenant_replication_options_list ')' +| WITH OPTIONS '(' replication_options_list ')' { $$.val = $4.tenantReplicationOptions() } @@ -4498,13 +4498,13 @@ opt_with_tenant_replication_options: $$.val = &tree.TenantReplicationOptions{} } -tenant_replication_options_list: +replication_options_list: // Require at least one option - tenant_replication_options + replication_options { $$.val = $1.tenantReplicationOptions() } -| tenant_replication_options_list ',' tenant_replication_options +| replication_options_list ',' replication_options { if err := $1.tenantReplicationOptions().CombineWith($3.tenantReplicationOptions()); err != nil { return setErr(sqllex, err) @@ -4512,7 +4512,7 @@ tenant_replication_options_list: } // List of valid tenant replication options. -tenant_replication_options: +replication_options: RETENTION '=' d_expr { $$.val = &tree.TenantReplicationOptions{Retention: $3.expr()} @@ -5933,7 +5933,7 @@ backup_kms: // REPLICATION STATUS // CAPABILITIES show_virtual_cluster_stmt: - SHOW virtual_cluster_spec_opt_all opt_show_tenant_options + SHOW virtual_cluster_spec_opt_all opt_show_virtual_cluster_options { /* SKIP DOC */ $$.val = &tree.ShowTenant{ @@ -5972,29 +5972,39 @@ virtual_cluster_spec_opt_all: $$.val = $3.tenantSpec() } -opt_show_tenant_options: +opt_show_virtual_cluster_options: /* EMPTY */ - { $$.val = tree.ShowTenantOptions{} } -| WITH show_tenant_options - { $$.val = $2.showTenantOpts() } + { + /* SKIP DOC */ + $$.val = tree.ShowTenantOptions{} + } +| WITH show_virtual_cluster_options + { + /* SKIP DOC */ + $$.val = $2.showTenantOpts() + } -show_tenant_options: +show_virtual_cluster_options: REPLICATION STATUS { + /* SKIP DOC */ $$.val = tree.ShowTenantOptions{WithReplication: true} } | CAPABILITIES { + /* SKIP DOC */ $$.val = tree.ShowTenantOptions{WithCapabilities: true} } -| show_tenant_options ',' REPLICATION STATUS +| show_virtual_cluster_options ',' REPLICATION STATUS { + /* SKIP DOC */ o := $1.showTenantOpts() o.WithReplication = true $$.val = o } -| show_tenant_options ',' CAPABILITIES +| show_virtual_cluster_options ',' CAPABILITIES { + /* SKIP DOC */ o := $1.showTenantOpts() o.WithCapabilities = true $$.val = o @@ -6670,7 +6680,7 @@ alter_virtual_cluster_replication_stmt: }, } } -| ALTER virtual_cluster virtual_cluster_spec SET REPLICATION tenant_replication_options_list +| ALTER virtual_cluster virtual_cluster_spec SET REPLICATION replication_options_list { /* SKIP DOC */ $$.val = &tree.AlterTenantReplication{ @@ -6731,7 +6741,7 @@ to_or_eq: // ALTER VIRTUAL CLUSTER GRANT CAPABILITY { TO | = } // ALTER VIRTUAL CLUSTER REVOKE CAPABILITY alter_virtual_cluster_capability_stmt: - ALTER virtual_cluster virtual_cluster_spec GRANT CAPABILITY tenant_capability_list + ALTER virtual_cluster virtual_cluster_spec GRANT CAPABILITY virtual_cluster_capability_list { /* SKIP DOC */ $$.val = &tree.AlterTenantCapability{ @@ -6747,7 +6757,7 @@ alter_virtual_cluster_capability_stmt: AllCapabilities: true, } } -| ALTER virtual_cluster virtual_cluster_spec REVOKE CAPABILITY tenant_capability_list +| ALTER virtual_cluster virtual_cluster_spec REVOKE CAPABILITY virtual_cluster_capability_list { /* SKIP DOC */ $$.val = &tree.AlterTenantCapability{ @@ -6768,28 +6778,32 @@ alter_virtual_cluster_capability_stmt: | ALTER virtual_cluster virtual_cluster_spec GRANT error // SHOW HELP: ALTER VIRTUAL CLUSTER CAPABILITY | ALTER virtual_cluster virtual_cluster_spec REVOKE error // SHOW HELP: ALTER VIRTUAL CLUSTER CAPABILITY -tenant_capability: +virtual_cluster_capability: var_name { - $$.val = tree.TenantCapability{ - Name: strings.Join($1.strs(), "."), - } + /* SKIP DOC */ + $$.val = tree.TenantCapability{ + Name: strings.Join($1.strs(), "."), + } } | var_name to_or_eq var_value { + /* SKIP DOC */ $$.val = tree.TenantCapability{ Name: strings.Join($1.strs(), "."), Value: $3.expr(), } } -tenant_capability_list: - tenant_capability +virtual_cluster_capability_list: + virtual_cluster_capability { + /* SKIP DOC */ $$.val = []tree.TenantCapability{$1.tenantCapability()} } -| tenant_capability_list ',' tenant_capability +| virtual_cluster_capability_list ',' virtual_cluster_capability { + /* SKIP DOC */ $$.val = append($1.tenantCapabilities(), $3.tenantCapability()) }