From b6d46c5e95d73406a831c2bb7859f21b5f58c38b Mon Sep 17 00:00:00 2001 From: Chengxiong Ruan Date: Wed, 11 Jan 2023 21:47:04 -0500 Subject: [PATCH] sql/schemachanger: declarative drop function This commit implements DROP FUNCTION given existing declarative schema changer infra (rules and ops). `RemoveObjectParent` is added to handle the removal of function signature from schema. Release note: None --- .../backup-restore/user-defined-functions | 6 +- .../backup_base_generated_test.go | 5 + .../drop_database_multiregion_primary_region | 2 +- .../end_to_end/drop_table_multiregion | 2 +- .../drop_table_multiregion_primary_region | 2 +- .../drop_database_multiregion_primary_region | 5 +- .../testdata/explain/drop_table_multiregion | 3 +- .../drop_table_multiregion_primary_region | 3 +- .../drop_database_multiregion_primary_region | 14 +- .../explain_verbose/drop_table_multiregion | 14 + .../drop_table_multiregion_primary_region | 6 +- pkg/sql/drop_function_test.go | 35 ++- pkg/sql/schemachanger/scbuild/BUILD.bazel | 1 + .../schemachanger/scbuild/builder_state.go | 39 +++ .../scbuild/internal/scbuildstmt/BUILD.bazel | 1 + .../scbuildstmt/alter_table_drop_column.go | 15 + .../internal/scbuildstmt/dependencies.go | 3 + .../internal/scbuildstmt/drop_function.go | 37 +++ .../internal/scbuildstmt/drop_index.go | 30 ++ .../scbuild/internal/scbuildstmt/helpers.go | 17 + .../scbuild/internal/scbuildstmt/process.go | 1 + .../scbuild/testdata/drop_function | 43 +++ .../schemachanger/scdecomp/testdata/function | 4 +- .../scdeps/sctestdeps/BUILD.bazel | 1 + .../scdeps/sctestdeps/test_deps.go | 53 +++- .../scexec/scmutationexec/eventlog.go | 2 + .../scexec/scmutationexec/index.go | 16 + pkg/sql/schemachanger/scop/mutation.go | 6 + .../scop/mutation_visitor_generated.go | 6 + .../scplan/internal/opgen/BUILD.bazel | 7 + .../scplan/internal/opgen/opgen_function.go | 63 ++++ .../internal/opgen/opgen_function_body.go | 60 ++++ .../opgen/opgen_function_leakproof.go | 37 +++ .../internal/opgen/opgen_function_name.go | 37 +++ .../opgen/opgen_function_null_input.go | 37 +++ .../opgen/opgen_function_param_default.go | 39 +++ .../opgen/opgen_function_volatility.go | 37 +++ .../internal/opgen/opgen_object_parent.go | 6 + .../scplan/internal/rules/helpers.go | 7 +- .../scplan/internal/rules/op_drop.go | 4 + .../scplan/internal/rules/testdata/deprules | 22 +- .../scplan/internal/rules/testdata/oprules | 6 +- .../scplan/testdata/alter_table_drop_column | 24 ++ .../scplan/testdata/drop_database | 79 +++++ .../scplan/testdata/drop_function | 160 ++++++++++ .../schemachanger/scplan/testdata/drop_index | 24 ++ .../scplan/testdata/drop_owned_by | 56 ++++ .../schemachanger/scplan/testdata/drop_schema | 64 ++++ .../scplan/testdata/drop_sequence | 24 ++ .../schemachanger/scplan/testdata/drop_table | 38 +++ .../schemachanger/scplan/testdata/drop_type | 16 +- .../schemachanger/scplan/testdata/drop_view | 56 ++++ pkg/sql/schemachanger/screl/attr.go | 21 ++ pkg/sql/schemachanger/screl/scalars.go | 4 +- pkg/sql/schemachanger/sctest/cumulative.go | 1 + .../schemachanger/sctest_generated_test.go | 25 ++ .../testdata/end_to_end/drop_function | 292 ++++++++++++++++++ .../drop_index_with_materialized_view_dep | 5 + .../testdata/end_to_end/drop_table | 4 + .../testdata/explain/drop_function | 69 +++++ .../drop_index_with_materialized_view_dep | 8 + .../schemachanger/testdata/explain/drop_table | 5 + .../testdata/explain_verbose/drop_function | 276 +++++++++++++++++ .../drop_index_with_materialized_view_dep | 14 + .../testdata/explain_verbose/drop_table | 6 + 65 files changed, 1949 insertions(+), 56 deletions(-) create mode 100644 pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_function.go create mode 100644 pkg/sql/schemachanger/scbuild/testdata/drop_function create mode 100644 pkg/sql/schemachanger/scplan/internal/opgen/opgen_function.go create mode 100644 pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_body.go create mode 100644 pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_leakproof.go create mode 100644 pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_name.go create mode 100644 pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_null_input.go create mode 100644 pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_param_default.go create mode 100644 pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_volatility.go create mode 100644 pkg/sql/schemachanger/scplan/testdata/drop_function create mode 100644 pkg/sql/schemachanger/testdata/end_to_end/drop_function create mode 100644 pkg/sql/schemachanger/testdata/explain/drop_function create mode 100644 pkg/sql/schemachanger/testdata/explain_verbose/drop_function diff --git a/pkg/ccl/backupccl/testdata/backup-restore/user-defined-functions b/pkg/ccl/backupccl/testdata/backup-restore/user-defined-functions index 8c5131fd28a8..f71274a81483 100644 --- a/pkg/ccl/backupccl/testdata/backup-restore/user-defined-functions +++ b/pkg/ccl/backupccl/testdata/backup-restore/user-defined-functions @@ -123,8 +123,7 @@ pq: cannot drop sequence sq1 because other objects depend on it exec-sql DROP TABLE sc1.tbl1 ---- -pq: cannot drop relation "tbl1" because function "f1" depends on it -HINT: you can drop f1 instead. +pq: cannot drop table tbl1 because other objects depend on it exec-sql ALTER TABLE sc1.tbl1 RENAME TO tbl1_new @@ -274,8 +273,7 @@ pq: cannot drop sequence sq1 because other objects depend on it exec-sql DROP TABLE sc1.tbl1 ---- -pq: cannot drop relation "tbl1" because function "f1" depends on it -HINT: you can drop f1 instead. +pq: cannot drop table tbl1 because other objects depend on it exec-sql ALTER TABLE sc1.tbl1 RENAME TO tbl1_new diff --git a/pkg/ccl/schemachangerccl/backup_base_generated_test.go b/pkg/ccl/schemachangerccl/backup_base_generated_test.go index 9410194ff93e..f3df746c6acd 100644 --- a/pkg/ccl/schemachangerccl/backup_base_generated_test.go +++ b/pkg/ccl/schemachangerccl/backup_base_generated_test.go @@ -103,6 +103,11 @@ func TestBackup_base_drop_column_with_index(t *testing.T) { defer log.Scope(t).Close(t) sctest.Backup(t, "pkg/sql/schemachanger/testdata/end_to_end/drop_column_with_index", newCluster) } +func TestBackup_base_drop_function(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + sctest.Backup(t, "pkg/sql/schemachanger/testdata/end_to_end/drop_function", newCluster) +} func TestBackup_base_drop_index_hash_sharded_index(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_database_multiregion_primary_region b/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_database_multiregion_primary_region index 5f7623aeffa8..f06c29f5280f 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_database_multiregion_primary_region +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_database_multiregion_primary_region @@ -90,7 +90,7 @@ add synthetic descriptor #108: version: "1" # end StatementPhase # begin PreCommitPhase -## PreCommitPhase stage 1 of 1 with 22 MutationType ops +## PreCommitPhase stage 1 of 1 with 25 MutationType ops delete database namespace entry {0 0 multi_region_test_db} -> 104 delete schema namespace entry {104 0 public} -> 105 delete object namespace entry {104 105 crdb_internal_region} -> 106 diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_table_multiregion b/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_table_multiregion index c777282ea15f..becaf00d1d9b 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_table_multiregion +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_table_multiregion @@ -36,7 +36,7 @@ add synthetic descriptor #108: version: "1" # end StatementPhase # begin PreCommitPhase -## PreCommitPhase stage 1 of 1 with 14 MutationType ops +## PreCommitPhase stage 1 of 1 with 15 MutationType ops delete object namespace entry {104 105 table_regional_by_row} -> 108 upsert descriptor #106 type: diff --git a/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_table_multiregion_primary_region b/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_table_multiregion_primary_region index e5600ca540c3..b068994ffd91 100644 --- a/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_table_multiregion_primary_region +++ b/pkg/ccl/schemachangerccl/testdata/end_to_end/drop_table_multiregion_primary_region @@ -36,7 +36,7 @@ add synthetic descriptor #108: version: "1" # end StatementPhase # begin PreCommitPhase -## PreCommitPhase stage 1 of 1 with 9 MutationType ops +## PreCommitPhase stage 1 of 1 with 10 MutationType ops delete object namespace entry {104 105 table_regional_by_table} -> 108 upsert descriptor #106 type: diff --git a/pkg/ccl/schemachangerccl/testdata/explain/drop_database_multiregion_primary_region b/pkg/ccl/schemachangerccl/testdata/explain/drop_database_multiregion_primary_region index 533110682d33..49d85306df08 100644 --- a/pkg/ccl/schemachangerccl/testdata/explain/drop_database_multiregion_primary_region +++ b/pkg/ccl/schemachangerccl/testdata/explain/drop_database_multiregion_primary_region @@ -81,14 +81,17 @@ Schema change plan for DROP DATABASE ‹multi_region_test_db› CASCADE; │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 108, ColumnID: 1, IndexID: 1} │ │ ├── VALIDATED → ABSENT PrimaryIndex:{DescID: 108, IndexID: 1, ConstraintID: 1} │ │ └── PUBLIC → ABSENT IndexName:{DescID: 108, Name: table_regional_by_table_pkey, IndexID: 1} - │ └── 22 Mutation operations + │ └── 25 Mutation operations │ ├── MarkDescriptorAsDropped {"DescriptorID":104} │ ├── RemoveDatabaseRoleSettings {"DatabaseID":104} │ ├── MarkDescriptorAsDropped {"DescriptorID":105} │ ├── RemoveSchemaParent {"Parent":{"ParentDatabaseID":104,"SchemaID":105}} │ ├── MarkDescriptorAsDropped {"DescriptorID":106} + │ ├── RemoveObjectParent {"ObjectID":106,"ParentSchemaID":105} │ ├── MarkDescriptorAsDropped {"DescriptorID":107} + │ ├── RemoveObjectParent {"ObjectID":107,"ParentSchemaID":105} │ ├── MarkDescriptorAsDropped {"DescriptorID":108} + │ ├── RemoveObjectParent {"ObjectID":108,"ParentSchemaID":105} │ ├── RemoveBackReferenceInTypes {"BackReferencedDescriptorID":108} │ ├── DrainDescriptorName {"Namespace":{"DescriptorID":104,"Name":"multi_region_tes..."}} │ ├── DrainDescriptorName {"Namespace":{"DatabaseID":104,"DescriptorID":105,"Name":"public"}} diff --git a/pkg/ccl/schemachangerccl/testdata/explain/drop_table_multiregion b/pkg/ccl/schemachangerccl/testdata/explain/drop_table_multiregion index de88e8eb889e..aafbdc67da6d 100644 --- a/pkg/ccl/schemachangerccl/testdata/explain/drop_table_multiregion +++ b/pkg/ccl/schemachangerccl/testdata/explain/drop_table_multiregion @@ -49,8 +49,9 @@ Schema change plan for DROP TABLE ‹multi_region_test_db›.‹public›.‹tab │ │ ├── VALIDATED → ABSENT PrimaryIndex:{DescID: 108, IndexID: 1, ConstraintID: 1} │ │ ├── PUBLIC → ABSENT IndexPartitioning:{DescID: 108, IndexID: 1} │ │ └── PUBLIC → ABSENT IndexName:{DescID: 108, Name: table_regional_by_row_pkey, IndexID: 1} - │ └── 14 Mutation operations + │ └── 15 Mutation operations │ ├── MarkDescriptorAsDropped {"DescriptorID":108} + │ ├── RemoveObjectParent {"ObjectID":108,"ParentSchemaID":105} │ ├── RemoveColumnDefaultExpression {"ColumnID":2,"TableID":108} │ ├── UpdateTableBackReferencesInTypes {"BackReferencedTableID":108} │ ├── DrainDescriptorName {"Namespace":{"DatabaseID":104,"DescriptorID":108,"Name":"table_regional_b...","SchemaID":105}} diff --git a/pkg/ccl/schemachangerccl/testdata/explain/drop_table_multiregion_primary_region b/pkg/ccl/schemachangerccl/testdata/explain/drop_table_multiregion_primary_region index be935bddcfaa..08964275b7f8 100644 --- a/pkg/ccl/schemachangerccl/testdata/explain/drop_table_multiregion_primary_region +++ b/pkg/ccl/schemachangerccl/testdata/explain/drop_table_multiregion_primary_region @@ -41,8 +41,9 @@ Schema change plan for DROP TABLE ‹multi_region_test_db›.‹public›.‹tab │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 108, ColumnID: 1, IndexID: 1} │ │ ├── VALIDATED → ABSENT PrimaryIndex:{DescID: 108, IndexID: 1, ConstraintID: 1} │ │ └── PUBLIC → ABSENT IndexName:{DescID: 108, Name: table_regional_by_table_pkey, IndexID: 1} - │ └── 9 Mutation operations + │ └── 10 Mutation operations │ ├── MarkDescriptorAsDropped {"DescriptorID":108} + │ ├── RemoveObjectParent {"ObjectID":108,"ParentSchemaID":105} │ ├── RemoveBackReferenceInTypes {"BackReferencedDescriptorID":108} │ ├── DrainDescriptorName {"Namespace":{"DatabaseID":104,"DescriptorID":108,"Name":"table_regional_b...","SchemaID":105}} │ ├── MakeDeleteOnlyColumnAbsent {"ColumnID":1,"TableID":108} diff --git a/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_database_multiregion_primary_region b/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_database_multiregion_primary_region index 18924e33e117..98a2325ddede 100644 --- a/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_database_multiregion_primary_region +++ b/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_database_multiregion_primary_region @@ -564,7 +564,7 @@ EXPLAIN (ddl, verbose) DROP DATABASE multi_region_test_db CASCADE; │ │ └── • skip PUBLIC → ABSENT operations │ │ rule: "skip index dependents removal ops on relation drop" │ │ -│ └── • 22 Mutation operations +│ └── • 25 Mutation operations │ │ │ ├── • MarkDescriptorAsDropped │ │ DescriptorID: 104 @@ -583,12 +583,24 @@ EXPLAIN (ddl, verbose) DROP DATABASE multi_region_test_db CASCADE; │ ├── • MarkDescriptorAsDropped │ │ DescriptorID: 106 │ │ +│ ├── • RemoveObjectParent +│ │ ObjectID: 106 +│ │ ParentSchemaID: 105 +│ │ │ ├── • MarkDescriptorAsDropped │ │ DescriptorID: 107 │ │ +│ ├── • RemoveObjectParent +│ │ ObjectID: 107 +│ │ ParentSchemaID: 105 +│ │ │ ├── • MarkDescriptorAsDropped │ │ DescriptorID: 108 │ │ +│ ├── • RemoveObjectParent +│ │ ObjectID: 108 +│ │ ParentSchemaID: 105 +│ │ │ ├── • RemoveBackReferenceInTypes │ │ BackReferencedDescriptorID: 108 │ │ TypeIDs: diff --git a/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_table_multiregion b/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_table_multiregion index 2ef6f62c9576..5df5e5fa1eb2 100644 --- a/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_table_multiregion +++ b/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_table_multiregion @@ -361,11 +361,25 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_ │ │ └── • skip PUBLIC → ABSENT operations │ │ rule: "skip index dependents removal ops on relation drop" │ │ +<<<<<<< HEAD │ └── • 14 Mutation operations +======= +│ └── • 16 Mutation operations +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) │ │ │ ├── • MarkDescriptorAsDropped │ │ DescriptorID: 108 │ │ +<<<<<<< HEAD +======= +│ ├── • RemoveAllTableComments +│ │ TableID: 108 +│ │ +│ ├── • RemoveObjectParent +│ │ ObjectID: 108 +│ │ ParentSchemaID: 105 +│ │ +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) │ ├── • RemoveColumnDefaultExpression │ │ ColumnID: 2 │ │ TableID: 108 diff --git a/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_table_multiregion_primary_region b/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_table_multiregion_primary_region index 4674eaf3ecc1..b26e2b21249d 100644 --- a/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_table_multiregion_primary_region +++ b/pkg/ccl/schemachangerccl/testdata/explain_verbose/drop_table_multiregion_primary_region @@ -261,11 +261,15 @@ EXPLAIN (ddl, verbose) DROP TABLE multi_region_test_db.public.table_regional_by_ │ │ └── • skip PUBLIC → ABSENT operations │ │ rule: "skip index dependents removal ops on relation drop" │ │ -│ └── • 9 Mutation operations +│ └── • 10 Mutation operations │ │ │ ├── • MarkDescriptorAsDropped │ │ DescriptorID: 108 │ │ +│ ├── • RemoveObjectParent +│ │ ObjectID: 108 +│ │ ParentSchemaID: 105 +│ │ │ ├── • RemoveBackReferenceInTypes │ │ BackReferencedDescriptorID: 108 │ │ TypeIDs: diff --git a/pkg/sql/drop_function_test.go b/pkg/sql/drop_function_test.go index dfd740348b99..ee3032daa94b 100644 --- a/pkg/sql/drop_function_test.go +++ b/pkg/sql/drop_function_test.go @@ -147,7 +147,7 @@ SELECT nextval(105:::REGCLASS);`, err = sql.TestingDescsTxn(ctx, s, func(ctx context.Context, txn isql.Txn, col *descs.Collection) error { _, err := col.ByIDWithLeased(txn.KV()).WithoutNonPublic().Get().Function(ctx, 109) require.Error(t, err) - require.Regexp(t, "descriptor is being dropped", err.Error()) + require.Regexp(t, "function undefined", err.Error()) // Make sure columns and indexes has correct back references. tn := tree.MakeTableNameWithSchema("defaultdb", "public", "t") @@ -197,6 +197,7 @@ CREATE TABLE t( a INT PRIMARY KEY, b INT, C INT, + d INT, INDEX t_idx_b(b), INDEX t_idx_c(c) ); @@ -209,6 +210,7 @@ CREATE FUNCTION test_sc.f(a notmyworkday) RETURNS INT IMMUTABLE LANGUAGE SQL AS SELECT a FROM t; SELECT b FROM t@t_idx_b; SELECT c FROM t@t_idx_c; + SELECT d FROM t; SELECT a FROM v; SELECT nextval('sq1'); $$; @@ -225,20 +227,23 @@ USE defaultdb; tDB.Exec(t, "SET use_declarative_schema_changer = off;") testCases := []struct { - stmt string - expectedErr string + stmt string + expectedErr string + dscExpectedErr string }{ { stmt: "DROP SEQUENCE sq1", expectedErr: "pq: cannot drop sequence sq1 because other objects depend on it", }, { - stmt: "DROP TABLE t", - expectedErr: `pq: cannot drop relation "t" because function "f" depends on it`, + stmt: "DROP TABLE t", + expectedErr: `pq: cannot drop relation "t" because function "f" depends on it`, + dscExpectedErr: `pq: cannot drop table t because other objects depend on it`, }, { - stmt: "DROP VIEW v", - expectedErr: `pq: cannot drop relation "v" because function "f" depends on it`, + stmt: "DROP VIEW v", + expectedErr: `pq: cannot drop relation "v" because function "f" depends on it`, + dscExpectedErr: `pq: cannot drop view v because other objects depend on it`, }, { stmt: "ALTER TABLE t RENAME TO t_new", @@ -249,8 +254,8 @@ USE defaultdb; expectedErr: `pq: cannot set schema on relation "t" because function "f" depends on it`, }, { - stmt: "ALTER TABLE t DROP COLUMN b", - expectedErr: `pq: cannot drop column "b" because function "f" depends on it`, + stmt: "ALTER TABLE t DROP COLUMN d", + expectedErr: `pq: cannot drop column "d" because function "f" depends on it`, }, { stmt: "ALTER TABLE t RENAME COLUMN b TO bb", @@ -296,7 +301,11 @@ USE defaultdb; for i, tc := range testCases { t.Run(strconv.Itoa(i), func(t *testing.T) { _, err := sqlDB.Exec(tc.stmt) - require.Equal(t, tc.expectedErr, err.Error()) + if tc.dscExpectedErr != "" { + require.Equal(t, tc.dscExpectedErr, err.Error()) + } else { + require.Equal(t, tc.expectedErr, err.Error()) + } }) } } @@ -312,6 +321,7 @@ CREATE TABLE t( a INT PRIMARY KEY, b INT, C INT, + d INT, INDEX t_idx_b(b), INDEX t_idx_c(c) ); @@ -324,6 +334,7 @@ CREATE FUNCTION test_sc.f(a notmyworkday) RETURNS INT IMMUTABLE LANGUAGE SQL AS SELECT a FROM t; SELECT b FROM t@t_idx_b; SELECT c FROM t@t_idx_c; + SELECT d FROM t; SELECT a FROM v; SELECT nextval('sq1'); $$; @@ -347,7 +358,7 @@ $$; }, { testName: "drop column", - stmt: "ALTER TABLE t DROP COLUMN b CASCADE", + stmt: "ALTER TABLE t DROP COLUMN d CASCADE", }, { testName: "drop index", @@ -420,7 +431,7 @@ $$; err = sql.TestingDescsTxn(ctx, s, func(ctx context.Context, txn isql.Txn, col *descs.Collection) error { _, err := col.ByIDWithLeased(txn.KV()).WithoutNonPublic().Get().Function(ctx, 113) require.Error(t, err) - require.Regexp(t, "descriptor is being dropped", err.Error()) + require.Regexp(t, "function undefined", err.Error()) return nil }) require.NoError(t, err) diff --git a/pkg/sql/schemachanger/scbuild/BUILD.bazel b/pkg/sql/schemachanger/scbuild/BUILD.bazel index 3c87717f397c..58bcc3ebc078 100644 --- a/pkg/sql/schemachanger/scbuild/BUILD.bazel +++ b/pkg/sql/schemachanger/scbuild/BUILD.bazel @@ -23,6 +23,7 @@ go_library( "//pkg/sql/catalog/colinfo", "//pkg/sql/catalog/descpb", "//pkg/sql/catalog/descs", + "//pkg/sql/catalog/funcdesc", "//pkg/sql/catalog/nstree", "//pkg/sql/catalog/resolver", "//pkg/sql/catalog/schemaexpr", diff --git a/pkg/sql/schemachanger/scbuild/builder_state.go b/pkg/sql/schemachanger/scbuild/builder_state.go index 8bd17ce1cad7..8034efc1a72f 100644 --- a/pkg/sql/schemachanger/scbuild/builder_state.go +++ b/pkg/sql/schemachanger/scbuild/builder_state.go @@ -19,6 +19,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/funcdesc" "github.com/cockroachdb/cockroach/pkg/sql/catalog/schemaexpr" "github.com/cockroachdb/cockroach/pkg/sql/catalog/seqexpr" "github.com/cockroachdb/cockroach/pkg/sql/catalog/tabledesc" @@ -928,6 +929,44 @@ func (b *builderState) ResolveConstraint( }) } +func (b *builderState) ResolveUDF( + fnObj *tree.FuncObj, p scbuildstmt.ResolveParams, +) scbuildstmt.ElementResultSet { + fd, err := b.cr.ResolveFunction(b.ctx, fnObj.FuncName.ToUnresolvedObjectName().ToUnresolvedName(), b.semaCtx.SearchPath) + if err != nil { + if p.IsExistenceOptional && errors.Is(err, tree.ErrFunctionUndefined) { + return nil + } + panic(err) + } + + paramTypes, err := fnObj.ParamTypes(b.ctx, b.cr) + if err != nil { + return nil + } + ol, err := fd.MatchOverload(paramTypes, fnObj.FuncName.Schema(), b.semaCtx.SearchPath) + if err != nil { + if p.IsExistenceOptional && errors.Is(err, tree.ErrFunctionUndefined) { + return nil + } + panic(err) + } + + if !ol.IsUDF { + panic( + errors.Errorf( + "cannot perform schema change on function %s%s because it is required by the database system", + fnObj.FuncName.Object(), ol.Signature(true), + ), + ) + } + + fnID := funcdesc.UserDefinedFunctionOIDToID(ol.Oid) + b.mustOwn(fnID) + b.ensureDescriptor(fnID) + return b.descCache[fnID].ers +} + func (b *builderState) ensureDescriptor(id catid.DescID) { if _, found := b.descCache[id]; found { return diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/BUILD.bazel b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/BUILD.bazel index 0021dc016c6e..ade7f1c7fdbd 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/BUILD.bazel +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/BUILD.bazel @@ -13,6 +13,7 @@ go_library( "create_index.go", "dependencies.go", "drop_database.go", + "drop_function.go", "drop_index.go", "drop_owned_by.go", "drop_schema.go", diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_drop_column.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_drop_column.go index c5a2ae277380..3f767c9f9470 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_drop_column.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/alter_table_drop_column.go @@ -260,6 +260,15 @@ func dropColumn( dropRestrictDescriptor(b, e.SequenceID) undroppedSeqBackrefsToCheck.Add(e.SequenceID) } + case *scpb.FunctionBody: + if behavior != tree.DropCascade { + _, _, fnName := scpb.FindFunctionName(b.QueryByID(e.FunctionID)) + panic(sqlerrors.NewDependentObjectErrorf( + "cannot drop column %q because function %q depends on it", + cn.Name, fnName.Name), + ) + } + dropCascadeDescriptor(b, e.FunctionID) default: b.Drop(e) } @@ -361,6 +370,12 @@ func walkDropColumnDependencies(b BuildCtx, col *scpb.Column, fn func(e scpb.Ele catalog.MakeTableColSet(elt.ReferencedColumnIDs...).Contains(col.ColumnID) { fn(e) } + case *scpb.FunctionBody: + for _, ref := range elt.UsesTables { + if ref.TableID == col.TableID && catalog.MakeTableColSet(ref.ColumnIDs...).Contains(col.ColumnID) { + fn(e) + } + } } }) } diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/dependencies.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/dependencies.go index 2d180a31ee74..075247ff373f 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/dependencies.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/dependencies.go @@ -305,6 +305,9 @@ type NameResolver interface { // ResolveIndex retrieves an index by name and returns its elements. ResolveIndex(relationID catid.DescID, indexName tree.Name, p ResolveParams) ElementResultSet + // ResolveUDF retrieves a user defined function and returns its elements. + ResolveUDF(fnObj *tree.FuncObj, p ResolveParams) ElementResultSet + // ResolveIndexByName retrieves a table which contains the target // index and returns its elements. Name of database, schema or table may be // missing. diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_function.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_function.go new file mode 100644 index 000000000000..48a4411434b4 --- /dev/null +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_function.go @@ -0,0 +1,37 @@ +// Copyright 2023 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package scbuildstmt + +import ( + "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scerrors" + "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scpb" + "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" +) + +func DropFunction(b BuildCtx, n *tree.DropFunction) { + if n.DropBehavior == tree.DropCascade { + // TODO(chengxiong): remove this when we allow UDF usage. + panic(scerrors.NotImplementedErrorf(n, "cascade dropping functions")) + } + for _, f := range n.Functions { + elts := b.ResolveUDF(&f, ResolveParams{ + IsExistenceOptional: n.IfExists, + }) + _, _, fn := scpb.FindFunction(elts) + if fn == nil { + continue + } + f.FuncName.ObjectNamePrefix = b.NamePrefix(fn) + dropRestrictDescriptor(b, fn.FunctionID) + b.IncrementSubWorkID() + b.IncrementSchemaChangeDropCounter("function") + } +} diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_index.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_index.go index bdf7b235b9da..e60c559b143e 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_index.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/drop_index.go @@ -126,6 +126,9 @@ func dropSecondaryIndex( // dependents. maybeDropDependentViews(next, sie, indexName.Index.String(), dropBehavior) + // Maybe drop dependent functions. + maybeDropDependentFunctions(next, sie, indexName.Index.String(), dropBehavior) + // Maybe drop dependent FK constraints. // A PK or unique constraint is required to serve an inbound FK constraint. // It is possible that there is an inbound FK constraint 'fk' and it's @@ -183,6 +186,33 @@ func maybeDropDependentViews( }) } +func maybeDropDependentFunctions( + b BuildCtx, + toBeDroppedIndex *scpb.SecondaryIndex, + toBeDroppedIndexName string, + dropBehavior tree.DropBehavior, +) { + scpb.ForEachFunctionBody(b.BackReferences(toBeDroppedIndex.TableID), func( + current scpb.Status, target scpb.TargetStatus, e *scpb.FunctionBody, + ) { + for _, forwardRef := range e.UsesTables { + if forwardRef.IndexID != toBeDroppedIndex.IndexID { + continue + } + // This view depends on the to-be-dropped index; + if dropBehavior != tree.DropCascade { + // Get view name for the error message + _, _, fnName := scpb.FindFunctionName(b.QueryByID(e.FunctionID)) + panic(errors.WithHintf( + sqlerrors.NewDependentObjectErrorf("cannot drop index %q because function %q depends on it", + toBeDroppedIndexName, fnName.Name), "you can drop %q instead.", fnName.Name)) + } else { + dropCascadeDescriptor(b, e.FunctionID) + } + } + }) +} + // maybeDropDependentFKConstraints attempts to drop all FK constraints // that depend on the to be dropped index if CASCADE. // A FK constraint can only exist if there is `PRIMARY KEY` or `UNIQUE` diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/helpers.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/helpers.go index a6761ebbee24..2990b8acc6c0 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/helpers.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/helpers.go @@ -30,6 +30,11 @@ import ( func qualifiedName(b BuildCtx, id catid.DescID) string { _, _, ns := scpb.FindNamespace(b.QueryByID(id)) + if ns == nil { + // Function descriptors don't have namespace. So we need to handle this + // special case here. + return qualifiedFunctionName(b, id) + } _, _, sc := scpb.FindNamespace(b.QueryByID(ns.SchemaID)) _, _, db := scpb.FindNamespace(b.QueryByID(ns.DatabaseID)) if db == nil { @@ -41,6 +46,16 @@ func qualifiedName(b BuildCtx, id catid.DescID) string { return db.Name + "." + sc.Name + "." + ns.Name } +func qualifiedFunctionName(b BuildCtx, id catid.DescID) string { + elts := b.QueryByID(id) + _, _, fnName := scpb.FindFunctionName(elts) + _, _, objParent := scpb.FindObjectParent(elts) + _, _, scName := scpb.FindNamespace(b.QueryByID(objParent.ParentSchemaID)) + _, _, scParent := scpb.FindSchemaParent(b.QueryByID(objParent.ParentSchemaID)) + _, _, dbName := scpb.FindNamespace(b.QueryByID(scParent.ParentDatabaseID)) + return dbName.Name + "." + scName.Name + "." + fnName.Name +} + func simpleName(b BuildCtx, id catid.DescID) string { _, _, ns := scpb.FindNamespace(b.QueryByID(id)) return ns.Name @@ -204,6 +219,8 @@ func dropCascadeDescriptor(b BuildCtx, id catid.DescID) { dropCascadeDescriptor(next, t.TypeID) case *scpb.CompositeType: dropCascadeDescriptor(next, t.TypeID) + case *scpb.FunctionBody: + dropCascadeDescriptor(next, t.FunctionID) case *scpb.Column, *scpb.ColumnType, *scpb.SecondaryIndexPartial: // These only have type references. break diff --git a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/process.go b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/process.go index a99164a142a2..1747fd0a7f8d 100644 --- a/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/process.go +++ b/pkg/sql/schemachanger/scbuild/internal/scbuildstmt/process.go @@ -103,6 +103,7 @@ var supportedStatements = map[reflect.Type]supportedStatement{ reflect.TypeOf((*tree.CommentOnIndex)(nil)): {fn: CommentOnIndex, on: true, minSupportedClusterVersion: clusterversion.V22_2Start}, reflect.TypeOf((*tree.CommentOnConstraint)(nil)): {fn: CommentOnConstraint, on: true, minSupportedClusterVersion: clusterversion.V22_2Start}, reflect.TypeOf((*tree.DropIndex)(nil)): {fn: DropIndex, on: true, minSupportedClusterVersion: clusterversion.V23_1Start}, + reflect.TypeOf((*tree.DropFunction)(nil)): {fn: DropFunction, on: true, minSupportedClusterVersion: clusterversion.V23_1Start}, } func init() { diff --git a/pkg/sql/schemachanger/scbuild/testdata/drop_function b/pkg/sql/schemachanger/scbuild/testdata/drop_function new file mode 100644 index 000000000000..ed694de7c4a3 --- /dev/null +++ b/pkg/sql/schemachanger/scbuild/testdata/drop_function @@ -0,0 +1,43 @@ +setup +CREATE TABLE t( + a INT PRIMARY KEY, + b INT, + C INT, + INDEX t_idx_b(b), + INDEX t_idx_c(c) +); +CREATE SEQUENCE sq1; +CREATE VIEW v AS SELECT a FROM t; +CREATE TYPE notmyworkday AS ENUM ('Monday', 'Tuesday'); +CREATE FUNCTION f(a notmyworkday) RETURNS INT IMMUTABLE LANGUAGE SQL AS $$ + SELECT a FROM t; + SELECT b FROM t@t_idx_b; + SELECT c FROM t@t_idx_c; + SELECT a FROM v; + SELECT nextval('sq1'); +$$; +---- + +build +DROP FUNCTION f; +---- +- [[Owner:{DescID: 109}, ABSENT], PUBLIC] + {descriptorId: 109, owner: root} +- [[UserPrivileges:{DescID: 109, Name: admin}, ABSENT], PUBLIC] + {descriptorId: 109, privileges: "2", userName: admin} +- [[UserPrivileges:{DescID: 109, Name: root}, ABSENT], PUBLIC] + {descriptorId: 109, privileges: "2", userName: root} +- [[Function:{DescID: 109}, ABSENT], PUBLIC] + {functionId: 109, params: [{class: {class: IN}, name: a, type: {closedTypeIds: [107, 108], type: {family: EnumFamily, oid: 100107, udtMetadata: {arrayTypeOid: 100108}}}}], returnType: {type: {family: IntFamily, oid: 20, width: 64}}} +- [[ObjectParent:{DescID: 109, ReferencedDescID: 101}, ABSENT], PUBLIC] + {objectId: 109, parentSchemaId: 101} +- [[FunctionName:{DescID: 109}, ABSENT], PUBLIC] + {functionId: 109, name: f} +- [[FunctionVolatility:{DescID: 109}, ABSENT], PUBLIC] + {functionId: 109, volatility: {volatility: IMMUTABLE}} +- [[FunctionLeakProof:{DescID: 109}, ABSENT], PUBLIC] + {functionId: 109} +- [[FunctionNullInputBehavior:{DescID: 109}, ABSENT], PUBLIC] + {functionId: 109, nullInputBehavior: {nullInputBehavior: CALLED_ON_NULL_INPUT}} +- [[FunctionBody:{DescID: 109}, ABSENT], PUBLIC] + {body: "SELECT a FROM defaultdb.public.t;\nSELECT b FROM defaultdb.public.t@t_idx_b;\nSELECT c FROM defaultdb.public.t@t_idx_c;\nSELECT a FROM defaultdb.public.v;\nSELECT nextval(105:::REGCLASS);", functionId: 109, lang: {lang: SQL}, usesSequenceIds: [105], usesTables: [{columnIds: [1], tableId: 104}, {columnIds: [2], indexId: 2, tableId: 104}, {columnIds: [3], indexId: 3, tableId: 104}], usesTypeIds: [107, 108], usesViews: [{columnIds: [1], viewId: 106}]} diff --git a/pkg/sql/schemachanger/scdecomp/testdata/function b/pkg/sql/schemachanger/scdecomp/testdata/function index b83bb4d9d958..30581174ff11 100644 --- a/pkg/sql/schemachanger/scdecomp/testdata/function +++ b/pkg/sql/schemachanger/scdecomp/testdata/function @@ -77,12 +77,12 @@ ElementState: Status: PUBLIC - UserPrivileges: descriptorId: 110 - privileges: 2 + privileges: "2" userName: admin Status: PUBLIC - UserPrivileges: descriptorId: 110 - privileges: 2 + privileges: "2" userName: root Status: PUBLIC - ObjectParent: diff --git a/pkg/sql/schemachanger/scdeps/sctestdeps/BUILD.bazel b/pkg/sql/schemachanger/scdeps/sctestdeps/BUILD.bazel index deb9e209c24c..e21ab526efed 100644 --- a/pkg/sql/schemachanger/scdeps/sctestdeps/BUILD.bazel +++ b/pkg/sql/schemachanger/scdeps/sctestdeps/BUILD.bazel @@ -26,6 +26,7 @@ go_library( "//pkg/sql/catalog/dbdesc", "//pkg/sql/catalog/descbuilder", "//pkg/sql/catalog/descpb", + "//pkg/sql/catalog/funcdesc", "//pkg/sql/catalog/nstree", "//pkg/sql/catalog/schemadesc", "//pkg/sql/catalog/tabledesc", diff --git a/pkg/sql/schemachanger/scdeps/sctestdeps/test_deps.go b/pkg/sql/schemachanger/scdeps/sctestdeps/test_deps.go index 58f97ffb570f..570588105451 100644 --- a/pkg/sql/schemachanger/scdeps/sctestdeps/test_deps.go +++ b/pkg/sql/schemachanger/scdeps/sctestdeps/test_deps.go @@ -27,6 +27,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/catalog/catpb" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descbuilder" "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" + "github.com/cockroachdb/cockroach/pkg/sql/catalog/funcdesc" "github.com/cockroachdb/cockroach/pkg/sql/catalog/nstree" "github.com/cockroachdb/cockroach/pkg/sql/catalog/schemadesc" "github.com/cockroachdb/cockroach/pkg/sql/catalog/typedesc" @@ -1150,15 +1151,27 @@ func (s *TestState) AddTableForStatsRefresh(id descpb.ID) { func (s *TestState) ResolveFunction( ctx context.Context, name *tree.UnresolvedName, path tree.SearchPath, ) (*tree.ResolvedFunctionDefinition, error) { - // TODO(chengxiong): add UDF support for test. - fn, err := name.ToFunctionName() + fnName, err := name.ToFunctionName() if err != nil { return nil, err } - fd, err := tree.GetBuiltinFuncDefinitionOrFail(fn, path) + fd, err := tree.GetBuiltinFuncDefinition(fnName, path) if err != nil { return nil, err } + if fd != nil { + return fd, nil + } + + _, sc := s.mayResolvePrefix(fnName.ObjectNamePrefix) + scDesc, err := catalog.AsSchemaDescriptor(sc) + if err != nil { + return nil, err + } + fd, found := scDesc.GetResolvedFuncDefinition(fnName.Object()) + if !found { + return nil, errors.Newf("function %s not found", fnName.String()) + } return fd, nil } @@ -1166,18 +1179,34 @@ func (s *TestState) ResolveFunction( func (s *TestState) ResolveFunctionByOID( ctx context.Context, oid oid.Oid, ) (string, *tree.Overload, error) { - // TODO(chengxiong): add UDF support for test. - name, ok := tree.OidToBuiltinName[oid] - if !ok { + if !funcdesc.IsOIDUserDefinedFunc(oid) { + name, ok := tree.OidToBuiltinName[oid] + if !ok { + return "", nil, errors.Newf("function %d not found", oid) + } + funcDef := tree.FunDefs[name] + for _, o := range funcDef.Definition { + if o.Oid == oid { + return funcDef.Name, o, nil + } + } return "", nil, errors.Newf("function %d not found", oid) } - funcDef := tree.FunDefs[name] - for _, o := range funcDef.Definition { - if o.Oid == oid { - return funcDef.Name, o, nil - } + + fnID := funcdesc.UserDefinedFunctionOIDToID(oid) + desc, err := s.mustReadImmutableDescriptor(fnID) + if err != nil { + return "", nil, err + } + fnDesc, err := catalog.AsFunctionDescriptor(desc) + if err != nil { + return "", nil, err + } + ol, err := fnDesc.ToOverload() + if err != nil { + return "", nil, err } - return "", nil, errors.Newf("function %d not found", oid) + return fnDesc.GetName(), ol, nil } // ZoneConfigGetter implement scexec.Dependencies. diff --git a/pkg/sql/schemachanger/scexec/scmutationexec/eventlog.go b/pkg/sql/schemachanger/scexec/scmutationexec/eventlog.go index f7e282f5400c..158ead023564 100644 --- a/pkg/sql/schemachanger/scexec/scmutationexec/eventlog.go +++ b/pkg/sql/schemachanger/scexec/scmutationexec/eventlog.go @@ -76,6 +76,8 @@ func asEventPayload( case *scpb.TableComment, *scpb.ColumnComment, *scpb.IndexComment, *scpb.ConstraintComment, *scpb.DatabaseComment, *scpb.SchemaComment: return asCommentEventPayload(ctx, fullName, e, targetStatus, m, true /* isNullComment */) + case *scpb.Function: + return &eventpb.DropFunction{FunctionName: fullName}, nil } } switch e := e.(type) { diff --git a/pkg/sql/schemachanger/scexec/scmutationexec/index.go b/pkg/sql/schemachanger/scexec/scmutationexec/index.go index 0412c086fe4e..c3d5b0895831 100644 --- a/pkg/sql/schemachanger/scexec/scmutationexec/index.go +++ b/pkg/sql/schemachanger/scexec/scmutationexec/index.go @@ -486,3 +486,19 @@ func (m *visitor) RemoveColumnFromIndex(ctx context.Context, op scop.RemoveColum } return nil } + +func (m *visitor) RemoveObjectParent(ctx context.Context, op scop.RemoveObjectParent) error { + obj, err := m.s.CheckOutDescriptor(ctx, op.ObjectID) + if err != nil { + return err + } + switch obj.DescriptorType() { + case catalog.Function: + sc, err := m.checkOutSchema(ctx, op.ParentSchemaID) + if err != nil { + return err + } + sc.RemoveFunction(obj.GetName(), obj.GetID()) + } + return nil +} diff --git a/pkg/sql/schemachanger/scop/mutation.go b/pkg/sql/schemachanger/scop/mutation.go index 8a9ac0cc057e..4e75059990f7 100644 --- a/pkg/sql/schemachanger/scop/mutation.go +++ b/pkg/sql/schemachanger/scop/mutation.go @@ -710,3 +710,9 @@ type RemoveColumnFromIndex struct { Ordinal uint32 InvertedKind catpb.InvertedIndexColumnKind } + +type RemoveObjectParent struct { + mutationOp + ObjectID descpb.ID + ParentSchemaID descpb.ID +} diff --git a/pkg/sql/schemachanger/scop/mutation_visitor_generated.go b/pkg/sql/schemachanger/scop/mutation_visitor_generated.go index 6a5a22ec930a..323e82da8e7c 100644 --- a/pkg/sql/schemachanger/scop/mutation_visitor_generated.go +++ b/pkg/sql/schemachanger/scop/mutation_visitor_generated.go @@ -106,6 +106,7 @@ type MutationVisitor interface { RefreshStats(context.Context, RefreshStats) error AddColumnToIndex(context.Context, AddColumnToIndex) error RemoveColumnFromIndex(context.Context, RemoveColumnFromIndex) error + RemoveObjectParent(context.Context, RemoveObjectParent) error } // Visit is part of the MutationOp interface. @@ -527,3 +528,8 @@ func (op AddColumnToIndex) Visit(ctx context.Context, v MutationVisitor) error { func (op RemoveColumnFromIndex) Visit(ctx context.Context, v MutationVisitor) error { return v.RemoveColumnFromIndex(ctx, op) } + +// Visit is part of the MutationOp interface. +func (op RemoveObjectParent) Visit(ctx context.Context, v MutationVisitor) error { + return v.RemoveObjectParent(ctx, op) +} diff --git a/pkg/sql/schemachanger/scplan/internal/opgen/BUILD.bazel b/pkg/sql/schemachanger/scplan/internal/opgen/BUILD.bazel index 59018a261628..e8eca0824a36 100644 --- a/pkg/sql/schemachanger/scplan/internal/opgen/BUILD.bazel +++ b/pkg/sql/schemachanger/scplan/internal/opgen/BUILD.bazel @@ -28,6 +28,13 @@ go_library( "opgen_enum_type.go", "opgen_enum_type_value.go", "opgen_foreign_key_constraint.go", + "opgen_function.go", + "opgen_function_body.go", + "opgen_function_leakproof.go", + "opgen_function_name.go", + "opgen_function_null_input.go", + "opgen_function_param_default.go", + "opgen_function_volatility.go", "opgen_index_column.go", "opgen_index_comment.go", "opgen_index_data.go", diff --git a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_function.go b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_function.go new file mode 100644 index 000000000000..d76ef63a6c15 --- /dev/null +++ b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_function.go @@ -0,0 +1,63 @@ +// Copyright 2023 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package opgen + +import ( + "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scop" + "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scpb" +) + +func init() { + opRegistry.register((*scpb.Function)(nil), + toPublic( + scpb.Status_ABSENT, + equiv(scpb.Status_DROPPED), + to(scpb.Status_TXN_DROPPED, + emit(func(this *scpb.Function) *scop.NotImplemented { + return notImplemented(this) + }), + ), + to(scpb.Status_PUBLIC, + emit(func(this *scpb.Function) *scop.NotImplemented { + return notImplemented(this) + }), + ), + ), + toAbsent( + scpb.Status_PUBLIC, + to(scpb.Status_TXN_DROPPED, + emit(func(this *scpb.Function, md *opGenContext) *scop.MarkDescriptorAsSyntheticallyDropped { + return &scop.MarkDescriptorAsSyntheticallyDropped{ + DescriptorID: this.FunctionID, + } + }), + ), + to(scpb.Status_DROPPED, + revertible(false), + emit(func(this *scpb.Function) *scop.MarkDescriptorAsDropped { + return &scop.MarkDescriptorAsDropped{ + DescriptorID: this.FunctionID, + } + }), + ), + to(scpb.Status_ABSENT, + emit(func(this *scpb.Function, md *opGenContext) *scop.LogEvent { + return newLogEventOp(this, md) + }), + emit(func(this *scpb.Function) *scop.DeleteDescriptor { + return &scop.DeleteDescriptor{ + DescriptorID: this.FunctionID, + } + }), + ), + ), + ) +} diff --git a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_body.go b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_body.go new file mode 100644 index 000000000000..52a726782773 --- /dev/null +++ b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_body.go @@ -0,0 +1,60 @@ +// Copyright 2023 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package opgen + +import ( + "github.com/cockroachdb/cockroach/pkg/sql/catalog/descpb" + "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scop" + "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scpb" +) + +func init() { + opRegistry.register((*scpb.FunctionBody)(nil), + toPublic( + scpb.Status_ABSENT, + to(scpb.Status_PUBLIC, + emit(func(this *scpb.FunctionBody) *scop.NotImplemented { + return notImplemented(this) + }), + ), + ), + toAbsent( + scpb.Status_PUBLIC, + to(scpb.Status_ABSENT, + emit(func(this *scpb.FunctionBody) *scop.RemoveBackReferenceInTypes { + if len(this.UsesTypeIDs) == 0 { + return nil + } + return &scop.RemoveBackReferenceInTypes{ + BackReferencedDescriptorID: this.FunctionID, + TypeIDs: this.UsesTypeIDs, + } + }), + emit(func(this *scpb.FunctionBody) *scop.RemoveBackReferencesInRelations { + var relationIDs []descpb.ID + for _, ref := range this.UsesTables { + relationIDs = append(relationIDs, ref.TableID) + } + for _, ref := range this.UsesViews { + relationIDs = append(relationIDs, ref.ViewID) + } + relationIDs = append(relationIDs, this.UsesSequenceIDs...) + if len(relationIDs) == 0 { + return nil + } + return &scop.RemoveBackReferencesInRelations{ + BackReferencedID: this.FunctionID, + RelationIDs: relationIDs, + } + })), + ), + ) +} diff --git a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_leakproof.go b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_leakproof.go new file mode 100644 index 000000000000..5a7e4711c39c --- /dev/null +++ b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_leakproof.go @@ -0,0 +1,37 @@ +// Copyright 2023 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package opgen + +import ( + "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scop" + "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scpb" +) + +func init() { + opRegistry.register((*scpb.FunctionLeakProof)(nil), + toPublic( + scpb.Status_ABSENT, + to(scpb.Status_PUBLIC, + emit(func(this *scpb.FunctionLeakProof) *scop.NotImplemented { + return notImplemented(this) + }), + ), + ), + toAbsent( + scpb.Status_PUBLIC, + to(scpb.Status_ABSENT, + emit(func(this *scpb.FunctionLeakProof) *scop.NotImplemented { + return notImplemented(this) + }), + ), + ), + ) +} diff --git a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_name.go b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_name.go new file mode 100644 index 000000000000..d392cd954886 --- /dev/null +++ b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_name.go @@ -0,0 +1,37 @@ +// Copyright 2023 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package opgen + +import ( + "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scop" + "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scpb" +) + +func init() { + opRegistry.register((*scpb.FunctionName)(nil), + toPublic( + scpb.Status_ABSENT, + to(scpb.Status_PUBLIC, + emit(func(this *scpb.FunctionName) *scop.NotImplemented { + return notImplemented(this) + }), + ), + ), + toAbsent( + scpb.Status_PUBLIC, + to(scpb.Status_ABSENT, + emit(func(this *scpb.FunctionName) *scop.NotImplemented { + return notImplemented(this) + }), + ), + ), + ) +} diff --git a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_null_input.go b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_null_input.go new file mode 100644 index 000000000000..a5787b684c62 --- /dev/null +++ b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_null_input.go @@ -0,0 +1,37 @@ +// Copyright 2023 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package opgen + +import ( + "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scop" + "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scpb" +) + +func init() { + opRegistry.register((*scpb.FunctionNullInputBehavior)(nil), + toPublic( + scpb.Status_ABSENT, + to(scpb.Status_PUBLIC, + emit(func(this *scpb.FunctionNullInputBehavior) *scop.NotImplemented { + return notImplemented(this) + }), + ), + ), + toAbsent( + scpb.Status_PUBLIC, + to(scpb.Status_ABSENT, + emit(func(this *scpb.FunctionNullInputBehavior) *scop.NotImplemented { + return notImplemented(this) + }), + ), + ), + ) +} diff --git a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_param_default.go b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_param_default.go new file mode 100644 index 000000000000..bb467a5e33d7 --- /dev/null +++ b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_param_default.go @@ -0,0 +1,39 @@ +// Copyright 2023 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package opgen + +import ( + "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scop" + "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scpb" +) + +func init() { + opRegistry.register((*scpb.FunctionParamDefaultExpression)(nil), + toPublic( + scpb.Status_ABSENT, + to(scpb.Status_PUBLIC, + // TODO(chengxiong): add operations when default value is supported. + emit(func(this *scpb.FunctionParamDefaultExpression) *scop.NotImplemented { + return notImplemented(this) + }), + ), + ), + toAbsent( + scpb.Status_PUBLIC, + to(scpb.Status_ABSENT, + // TODO(chengxiong): add operations when default value is supported. + emit(func(this *scpb.FunctionParamDefaultExpression) *scop.NotImplemented { + return notImplemented(this) + }), + ), + ), + ) +} diff --git a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_volatility.go b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_volatility.go new file mode 100644 index 000000000000..f6ed74e89d08 --- /dev/null +++ b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_function_volatility.go @@ -0,0 +1,37 @@ +// Copyright 2023 The Cockroach Authors. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package opgen + +import ( + "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scop" + "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scpb" +) + +func init() { + opRegistry.register((*scpb.FunctionVolatility)(nil), + toPublic( + scpb.Status_ABSENT, + to(scpb.Status_PUBLIC, + emit(func(this *scpb.FunctionVolatility) *scop.NotImplemented { + return notImplemented(this) + }), + ), + ), + toAbsent( + scpb.Status_PUBLIC, + to(scpb.Status_ABSENT, + emit(func(this *scpb.FunctionVolatility) *scop.NotImplemented { + return notImplemented(this) + }), + ), + ), + ) +} diff --git a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_object_parent.go b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_object_parent.go index 781b54d6fc7c..755135e44bd5 100644 --- a/pkg/sql/schemachanger/scplan/internal/opgen/opgen_object_parent.go +++ b/pkg/sql/schemachanger/scplan/internal/opgen/opgen_object_parent.go @@ -30,6 +30,12 @@ func init() { to(scpb.Status_ABSENT, // TODO(postamar): remove revertibility constraint when possible revertible(false), + emit(func(this *scpb.ObjectParent) *scop.RemoveObjectParent { + return &scop.RemoveObjectParent{ + ObjectID: this.ObjectID, + ParentSchemaID: this.ParentSchemaID, + } + }), ), ), ) diff --git a/pkg/sql/schemachanger/scplan/internal/rules/helpers.go b/pkg/sql/schemachanger/scplan/internal/rules/helpers.go index 01e7523ba26d..53a8acbf6963 100644 --- a/pkg/sql/schemachanger/scplan/internal/rules/helpers.go +++ b/pkg/sql/schemachanger/scplan/internal/rules/helpers.go @@ -245,7 +245,7 @@ func forEachElement(fn func(element scpb.Element) error) error { func IsDescriptor(e scpb.Element) bool { switch e.(type) { case *scpb.Database, *scpb.Schema, *scpb.Table, *scpb.View, *scpb.Sequence, - *scpb.AliasType, *scpb.EnumType, *scpb.CompositeType: + *scpb.AliasType, *scpb.EnumType, *scpb.CompositeType, *scpb.Function: return true } return false @@ -323,6 +323,11 @@ func getExpression(element scpb.Element) (*scpb.Expression, error) { return nil, nil } return &e.Expression, nil + case *scpb.FunctionParamDefaultExpression: + if e == nil { + return nil, nil + } + return &e.Expression, nil } return nil, errors.AssertionFailedf("element %T does not have an embedded scpb.Expression", element) } diff --git a/pkg/sql/schemachanger/scplan/internal/rules/op_drop.go b/pkg/sql/schemachanger/scplan/internal/rules/op_drop.go index dab2cdc0150b..5dc89870fd23 100644 --- a/pkg/sql/schemachanger/scplan/internal/rules/op_drop.go +++ b/pkg/sql/schemachanger/scplan/internal/rules/op_drop.go @@ -240,6 +240,10 @@ func init() { (*scpb.UserPrivileges)(nil), (*scpb.EnumTypeValue)(nil), (*scpb.TablePartitioning)(nil), + (*scpb.FunctionName)(nil), + (*scpb.FunctionVolatility)(nil), + (*scpb.FunctionLeakProof)(nil), + (*scpb.FunctionNullInputBehavior)(nil), ), joinOnDescID(desc, dep, descID), diff --git a/pkg/sql/schemachanger/scplan/internal/rules/testdata/deprules b/pkg/sql/schemachanger/scplan/internal/rules/testdata/deprules index 1d57723c9e37..01774bc7ab2f 100644 --- a/pkg/sql/schemachanger/scplan/internal/rules/testdata/deprules +++ b/pkg/sql/schemachanger/scplan/internal/rules/testdata/deprules @@ -11,7 +11,7 @@ columnInSwappedInPrimaryIndex($index-column, $index, $table-id, $column-id, $ind - sourceIndexIsSet($index) descriptorIsNotBeingDropped($element): not-join: - - $descriptor[Type] IN ['*scpb.Database', '*scpb.Schema', '*scpb.View', '*scpb.Sequence', '*scpb.Table', '*scpb.EnumType', '*scpb.AliasType', '*scpb.CompositeType'] + - $descriptor[Type] IN ['*scpb.Database', '*scpb.Schema', '*scpb.View', '*scpb.Sequence', '*scpb.Table', '*scpb.EnumType', '*scpb.AliasType', '*scpb.CompositeType', '*scpb.Function'] - joinTarget($descriptor, $descriptor-target) - joinOnDescID($descriptor, $element, $id) - $descriptor-target[TargetStatus] = ABSENT @@ -2047,7 +2047,7 @@ deprules kind: PreviousTransactionPrecedence to: absent-node query: - - $dropped[Type] IN ['*scpb.Database', '*scpb.Schema', '*scpb.View', '*scpb.Sequence', '*scpb.Table', '*scpb.EnumType', '*scpb.AliasType', '*scpb.CompositeType'] + - $dropped[Type] IN ['*scpb.Database', '*scpb.Schema', '*scpb.View', '*scpb.Sequence', '*scpb.Table', '*scpb.EnumType', '*scpb.AliasType', '*scpb.CompositeType', '*scpb.Function'] - $dropped[DescID] = $_ - $dropped[Self] = $absent - toAbsent($dropped-target, $absent-target) @@ -2060,7 +2060,7 @@ deprules kind: PreviousStagePrecedence to: dropped-node query: - - $txn_dropped[Type] IN ['*scpb.Database', '*scpb.Schema', '*scpb.View', '*scpb.Sequence', '*scpb.Table', '*scpb.EnumType', '*scpb.AliasType', '*scpb.CompositeType'] + - $txn_dropped[Type] IN ['*scpb.Database', '*scpb.Schema', '*scpb.View', '*scpb.Sequence', '*scpb.Table', '*scpb.EnumType', '*scpb.AliasType', '*scpb.CompositeType', '*scpb.Function'] - $txn_dropped[DescID] = $_ - $txn_dropped[Self] = $dropped - toAbsent($txn_dropped-target, $dropped-target) @@ -2073,8 +2073,8 @@ deprules kind: Precedence to: dependent-node query: - - $descriptor[Type] IN ['*scpb.Database', '*scpb.Schema', '*scpb.View', '*scpb.Sequence', '*scpb.Table', '*scpb.EnumType', '*scpb.AliasType', '*scpb.CompositeType'] - - $dependent[Type] IN ['*scpb.ColumnFamily', '*scpb.TableComment', '*scpb.RowLevelTTL', '*scpb.TableZoneConfig', '*scpb.TablePartitioning', '*scpb.TableLocalityGlobal', '*scpb.TableLocalityPrimaryRegion', '*scpb.TableLocalitySecondaryRegion', '*scpb.TableLocalityRegionalByRow', '*scpb.ColumnName', '*scpb.ColumnType', '*scpb.ColumnDefaultExpression', '*scpb.ColumnOnUpdateExpression', '*scpb.SequenceOwner', '*scpb.ColumnComment', '*scpb.IndexName', '*scpb.IndexPartitioning', '*scpb.SecondaryIndexPartial', '*scpb.IndexComment', '*scpb.IndexColumn', '*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment', '*scpb.Namespace', '*scpb.Owner', '*scpb.UserPrivileges', '*scpb.DatabaseRegionConfig', '*scpb.DatabaseRoleSetting', '*scpb.DatabaseComment', '*scpb.SchemaParent', '*scpb.SchemaComment', '*scpb.ObjectParent', '*scpb.EnumTypeValue', '*scpb.CompositeTypeAttrType', '*scpb.CompositeTypeAttrName'] + - $descriptor[Type] IN ['*scpb.Database', '*scpb.Schema', '*scpb.View', '*scpb.Sequence', '*scpb.Table', '*scpb.EnumType', '*scpb.AliasType', '*scpb.CompositeType', '*scpb.Function'] + - $dependent[Type] IN ['*scpb.ColumnFamily', '*scpb.TableComment', '*scpb.RowLevelTTL', '*scpb.TableZoneConfig', '*scpb.TablePartitioning', '*scpb.TableLocalityGlobal', '*scpb.TableLocalityPrimaryRegion', '*scpb.TableLocalitySecondaryRegion', '*scpb.TableLocalityRegionalByRow', '*scpb.ColumnName', '*scpb.ColumnType', '*scpb.ColumnDefaultExpression', '*scpb.ColumnOnUpdateExpression', '*scpb.SequenceOwner', '*scpb.ColumnComment', '*scpb.IndexName', '*scpb.IndexPartitioning', '*scpb.SecondaryIndexPartial', '*scpb.IndexComment', '*scpb.IndexColumn', '*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment', '*scpb.Namespace', '*scpb.Owner', '*scpb.UserPrivileges', '*scpb.DatabaseRegionConfig', '*scpb.DatabaseRoleSetting', '*scpb.DatabaseComment', '*scpb.SchemaParent', '*scpb.SchemaComment', '*scpb.ObjectParent', '*scpb.EnumTypeValue', '*scpb.CompositeTypeAttrType', '*scpb.CompositeTypeAttrName', '*scpb.FunctionName', '*scpb.FunctionVolatility', '*scpb.FunctionLeakProof', '*scpb.FunctionNullInputBehavior', '*scpb.FunctionBody', '*scpb.FunctionParamDefaultExpression'] - joinOnDescID($descriptor, $dependent, $desc-id) - toAbsent($descriptor-target, $dependent-target) - $descriptor-node[CurrentStatus] = DROPPED @@ -2087,8 +2087,8 @@ deprules kind: SameStagePrecedence to: referencing-via-attr-node query: - - $referenced-descriptor[Type] IN ['*scpb.Database', '*scpb.Schema', '*scpb.View', '*scpb.Sequence', '*scpb.Table', '*scpb.EnumType', '*scpb.AliasType', '*scpb.CompositeType'] - - $referencing-via-attr[Type] IN ['*scpb.ColumnFamily', '*scpb.TableComment', '*scpb.RowLevelTTL', '*scpb.TableZoneConfig', '*scpb.TablePartitioning', '*scpb.TableLocalityGlobal', '*scpb.TableLocalityPrimaryRegion', '*scpb.TableLocalitySecondaryRegion', '*scpb.TableLocalityRegionalByRow', '*scpb.ColumnName', '*scpb.ColumnType', '*scpb.ColumnDefaultExpression', '*scpb.ColumnOnUpdateExpression', '*scpb.SequenceOwner', '*scpb.ColumnComment', '*scpb.IndexName', '*scpb.IndexPartitioning', '*scpb.SecondaryIndexPartial', '*scpb.IndexComment', '*scpb.IndexColumn', '*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment', '*scpb.Namespace', '*scpb.Owner', '*scpb.UserPrivileges', '*scpb.DatabaseRegionConfig', '*scpb.DatabaseRoleSetting', '*scpb.DatabaseComment', '*scpb.SchemaParent', '*scpb.SchemaComment', '*scpb.ObjectParent', '*scpb.EnumTypeValue', '*scpb.CompositeTypeAttrType', '*scpb.CompositeTypeAttrName'] + - $referenced-descriptor[Type] IN ['*scpb.Database', '*scpb.Schema', '*scpb.View', '*scpb.Sequence', '*scpb.Table', '*scpb.EnumType', '*scpb.AliasType', '*scpb.CompositeType', '*scpb.Function'] + - $referencing-via-attr[Type] IN ['*scpb.ColumnFamily', '*scpb.TableComment', '*scpb.RowLevelTTL', '*scpb.TableZoneConfig', '*scpb.TablePartitioning', '*scpb.TableLocalityGlobal', '*scpb.TableLocalityPrimaryRegion', '*scpb.TableLocalitySecondaryRegion', '*scpb.TableLocalityRegionalByRow', '*scpb.ColumnName', '*scpb.ColumnType', '*scpb.ColumnDefaultExpression', '*scpb.ColumnOnUpdateExpression', '*scpb.SequenceOwner', '*scpb.ColumnComment', '*scpb.IndexName', '*scpb.IndexPartitioning', '*scpb.SecondaryIndexPartial', '*scpb.IndexComment', '*scpb.IndexColumn', '*scpb.ConstraintWithoutIndexName', '*scpb.ConstraintComment', '*scpb.Namespace', '*scpb.Owner', '*scpb.UserPrivileges', '*scpb.DatabaseRegionConfig', '*scpb.DatabaseRoleSetting', '*scpb.DatabaseComment', '*scpb.SchemaParent', '*scpb.SchemaComment', '*scpb.ObjectParent', '*scpb.EnumTypeValue', '*scpb.CompositeTypeAttrType', '*scpb.CompositeTypeAttrName', '*scpb.FunctionName', '*scpb.FunctionVolatility', '*scpb.FunctionLeakProof', '*scpb.FunctionNullInputBehavior', '*scpb.FunctionBody', '*scpb.FunctionParamDefaultExpression'] - joinReferencedDescID($referencing-via-attr, $referenced-descriptor, $desc-id) - toAbsent($referenced-descriptor-target, $referencing-via-attr-target) - $referenced-descriptor-node[CurrentStatus] = DROPPED @@ -2103,7 +2103,7 @@ deprules - $referenced-descriptor[Type] = '*scpb.Sequence' - $referenced-descriptor[DescID] = $seqID - $referencing-via-expr[ReferencedSequenceIDs] CONTAINS $seqID - - $referencing-via-expr[Type] IN ['*scpb.ColumnType', '*scpb.ColumnDefaultExpression', '*scpb.ColumnOnUpdateExpression', '*scpb.SecondaryIndexPartial'] + - $referencing-via-expr[Type] IN ['*scpb.ColumnType', '*scpb.ColumnDefaultExpression', '*scpb.ColumnOnUpdateExpression', '*scpb.SecondaryIndexPartial', '*scpb.FunctionParamDefaultExpression'] - toAbsent($referenced-descriptor-target, $referencing-via-expr-target) - $referenced-descriptor-node[CurrentStatus] = DROPPED - $referencing-via-expr-node[CurrentStatus] = ABSENT @@ -2117,7 +2117,7 @@ deprules - $referenced-descriptor[Type] IN ['*scpb.EnumType', '*scpb.AliasType', '*scpb.CompositeType'] - $referenced-descriptor[DescID] = $fromDescID - $referencing-via-type[ReferencedTypeIDs] CONTAINS $fromDescID - - $referencing-via-type[Type] IN ['*scpb.ColumnType', '*scpb.ColumnDefaultExpression', '*scpb.ColumnOnUpdateExpression', '*scpb.SecondaryIndexPartial'] + - $referencing-via-type[Type] IN ['*scpb.ColumnType', '*scpb.ColumnDefaultExpression', '*scpb.ColumnOnUpdateExpression', '*scpb.SecondaryIndexPartial', '*scpb.FunctionParamDefaultExpression'] - toAbsent($referenced-descriptor-target, $referencing-via-type-target) - $referenced-descriptor-node[CurrentStatus] = DROPPED - $referencing-via-type-node[CurrentStatus] = ABSENT @@ -2128,7 +2128,7 @@ deprules kind: SameStagePrecedence to: data-node query: - - $database[Type] IN ['*scpb.Database', '*scpb.Schema', '*scpb.View', '*scpb.Sequence', '*scpb.Table', '*scpb.EnumType', '*scpb.AliasType', '*scpb.CompositeType'] + - $database[Type] IN ['*scpb.Database', '*scpb.Schema', '*scpb.View', '*scpb.Sequence', '*scpb.Table', '*scpb.EnumType', '*scpb.AliasType', '*scpb.CompositeType', '*scpb.Function'] - $data[Type] = '*scpb.DatabaseData' - joinOnDescID($database, $data, $db-id) - toAbsent($database-target, $data-target) @@ -2838,7 +2838,7 @@ deprules kind: SameStagePrecedence to: data-node query: - - $table[Type] IN ['*scpb.Database', '*scpb.Schema', '*scpb.View', '*scpb.Sequence', '*scpb.Table', '*scpb.EnumType', '*scpb.AliasType', '*scpb.CompositeType'] + - $table[Type] IN ['*scpb.Database', '*scpb.Schema', '*scpb.View', '*scpb.Sequence', '*scpb.Table', '*scpb.EnumType', '*scpb.AliasType', '*scpb.CompositeType', '*scpb.Function'] - $data[Type] = '*scpb.TableData' - joinOnDescID($table, $data, $table-id) - toAbsent($table-target, $data-target) diff --git a/pkg/sql/schemachanger/scplan/internal/rules/testdata/oprules b/pkg/sql/schemachanger/scplan/internal/rules/testdata/oprules index c27c9a5b7883..86170b99dfa7 100644 --- a/pkg/sql/schemachanger/scplan/internal/rules/testdata/oprules +++ b/pkg/sql/schemachanger/scplan/internal/rules/testdata/oprules @@ -11,7 +11,7 @@ columnInSwappedInPrimaryIndex($index-column, $index, $table-id, $column-id, $ind - sourceIndexIsSet($index) descriptorIsNotBeingDropped($element): not-join: - - $descriptor[Type] IN ['*scpb.Database', '*scpb.Schema', '*scpb.View', '*scpb.Sequence', '*scpb.Table', '*scpb.EnumType', '*scpb.AliasType', '*scpb.CompositeType'] + - $descriptor[Type] IN ['*scpb.Database', '*scpb.Schema', '*scpb.View', '*scpb.Sequence', '*scpb.Table', '*scpb.EnumType', '*scpb.AliasType', '*scpb.CompositeType', '*scpb.Function'] - joinTarget($descriptor, $descriptor-target) - joinOnDescID($descriptor, $element, $id) - $descriptor-target[TargetStatus] = ABSENT @@ -164,8 +164,8 @@ oprules - name: skip element removal ops on descriptor drop from: dep-node query: - - $desc[Type] IN ['*scpb.Database', '*scpb.Schema', '*scpb.View', '*scpb.Sequence', '*scpb.Table', '*scpb.EnumType', '*scpb.AliasType', '*scpb.CompositeType'] - - $dep[Type] IN ['*scpb.ColumnFamily', '*scpb.Owner', '*scpb.UserPrivileges', '*scpb.EnumTypeValue', '*scpb.TablePartitioning'] + - $desc[Type] IN ['*scpb.Database', '*scpb.Schema', '*scpb.View', '*scpb.Sequence', '*scpb.Table', '*scpb.EnumType', '*scpb.AliasType', '*scpb.CompositeType', '*scpb.Function'] + - $dep[Type] IN ['*scpb.ColumnFamily', '*scpb.Owner', '*scpb.UserPrivileges', '*scpb.EnumTypeValue', '*scpb.TablePartitioning', '*scpb.FunctionName', '*scpb.FunctionVolatility', '*scpb.FunctionLeakProof', '*scpb.FunctionNullInputBehavior'] - joinOnDescID($desc, $dep, $desc-id) - joinTarget($desc, $desc-target) - $desc-target[TargetStatus] = ABSENT diff --git a/pkg/sql/schemachanger/scplan/testdata/alter_table_drop_column b/pkg/sql/schemachanger/scplan/testdata/alter_table_drop_column index 2e771563c3d7..c3034b559f8f 100644 --- a/pkg/sql/schemachanger/scplan/testdata/alter_table_drop_column +++ b/pkg/sql/schemachanger/scplan/testdata/alter_table_drop_column @@ -214,7 +214,11 @@ PostCommitPhase stage 7 of 7 with 1 ValidationType op *scop.ValidateIndex IndexID: 3 TableID: 107 +<<<<<<< HEAD PostCommitNonRevertiblePhase stage 1 of 3 with 25 MutationType ops +======= +PostCommitNonRevertiblePhase stage 1 of 3 with 27 MutationType ops +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) transitions: [[Column:{DescID: 107, ColumnID: 2}, ABSENT], WRITE_ONLY] -> DELETE_ONLY [[IndexColumn:{DescID: 107, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT @@ -274,6 +278,14 @@ PostCommitNonRevertiblePhase stage 1 of 3 with 25 MutationType ops BackReferencedID: 108 RelationIDs: - 107 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 108 + *scop.RemoveObjectParent + ObjectID: 108 + ParentSchemaID: 101 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.RemoveDroppedColumnType ColumnID: 2 TableID: 108 @@ -1173,7 +1185,11 @@ PostCommitPhase stage 7 of 7 with 1 ValidationType op *scop.ValidateIndex IndexID: 3 TableID: 107 +<<<<<<< HEAD PostCommitNonRevertiblePhase stage 1 of 3 with 26 MutationType ops +======= +PostCommitNonRevertiblePhase stage 1 of 3 with 28 MutationType ops +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) transitions: [[Column:{DescID: 107, ColumnID: 3}, ABSENT], WRITE_ONLY] -> DELETE_ONLY [[IndexColumn:{DescID: 107, ColumnID: 1, IndexID: 1}, ABSENT], PUBLIC] -> ABSENT @@ -1233,6 +1249,14 @@ PostCommitNonRevertiblePhase stage 1 of 3 with 26 MutationType ops BackReferencedID: 108 RelationIDs: - 107 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 108 + *scop.RemoveObjectParent + ObjectID: 108 + ParentSchemaID: 101 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.RemoveDroppedColumnType ColumnID: 2 TableID: 108 diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_database b/pkg/sql/schemachanger/scplan/testdata/drop_database index 41a40a3f39e7..a09c6009d6ae 100644 --- a/pkg/sql/schemachanger/scplan/testdata/drop_database +++ b/pkg/sql/schemachanger/scplan/testdata/drop_database @@ -96,7 +96,11 @@ StatementPhase stage 1 of 1 with 14 MutationType ops DescriptorID: 116 *scop.MarkDescriptorAsSyntheticallyDropped DescriptorID: 117 +<<<<<<< HEAD PreCommitPhase stage 1 of 1 with 91 MutationType ops +======= +PreCommitPhase stage 1 of 1 with 109 MutationType ops +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) transitions: [[Namespace:{DescID: 104, Name: db1, ReferencedDescID: 0}, ABSENT], PUBLIC] -> ABSENT [[Owner:{DescID: 104}, ABSENT], PUBLIC] -> ABSENT @@ -331,8 +335,23 @@ PreCommitPhase stage 1 of 1 with 91 MutationType ops SchemaID: 106 *scop.MarkDescriptorAsDropped DescriptorID: 107 +<<<<<<< HEAD *scop.MarkDescriptorAsDropped DescriptorID: 110 +======= + *scop.RemoveAllTableComments + TableID: 107 + *scop.RemoveObjectParent + ObjectID: 107 + ParentSchemaID: 105 + *scop.MarkDescriptorAsDropped + DescriptorID: 110 + *scop.RemoveAllTableComments + TableID: 110 + *scop.RemoveObjectParent + ObjectID: 110 + ParentSchemaID: 105 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.RemoveColumnDefaultExpression ColumnID: 3 TableID: 110 @@ -343,10 +362,19 @@ PreCommitPhase stage 1 of 1 with 91 MutationType ops - 107 *scop.MarkDescriptorAsDropped DescriptorID: 108 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 108 + *scop.RemoveObjectParent + ObjectID: 108 + ParentSchemaID: 106 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.MarkDescriptorAsDropped DescriptorID: 109 *scop.RemoveTableComment TableID: 109 +<<<<<<< HEAD *scop.LogEvent Element: TableComment: @@ -361,6 +389,11 @@ PreCommitPhase stage 1 of 1 with 91 MutationType ops SourceElementID: 6 SubWorkID: 1 TargetStatus: 1 +======= + *scop.RemoveObjectParent + ObjectID: 109 + ParentSchemaID: 106 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.RemoveColumnDefaultExpression ColumnID: 3 TableID: 109 @@ -375,12 +408,28 @@ PreCommitPhase stage 1 of 1 with 91 MutationType ops BackReferencedID: 111 RelationIDs: - 109 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 111 + *scop.RemoveObjectParent + ObjectID: 111 + ParentSchemaID: 106 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.MarkDescriptorAsDropped DescriptorID: 112 *scop.RemoveBackReferencesInRelations BackReferencedID: 112 RelationIDs: - 111 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 112 + *scop.RemoveObjectParent + ObjectID: 112 + ParentSchemaID: 106 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.MarkDescriptorAsDropped DescriptorID: 113 *scop.RemoveBackReferencesInRelations @@ -388,16 +437,38 @@ PreCommitPhase stage 1 of 1 with 91 MutationType ops RelationIDs: - 111 - 112 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 113 + *scop.RemoveObjectParent + ObjectID: 113 + ParentSchemaID: 106 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.MarkDescriptorAsDropped DescriptorID: 114 *scop.RemoveBackReferencesInRelations BackReferencedID: 114 RelationIDs: - 112 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 114 + *scop.RemoveObjectParent + ObjectID: 114 + ParentSchemaID: 106 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.MarkDescriptorAsDropped DescriptorID: 115 + *scop.RemoveObjectParent + ObjectID: 115 + ParentSchemaID: 106 *scop.MarkDescriptorAsDropped DescriptorID: 116 + *scop.RemoveObjectParent + ObjectID: 116 + ParentSchemaID: 106 *scop.MarkDescriptorAsDropped DescriptorID: 117 *scop.RemoveBackReferenceInTypes @@ -409,6 +480,14 @@ PreCommitPhase stage 1 of 1 with 91 MutationType ops BackReferencedID: 117 RelationIDs: - 114 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 117 + *scop.RemoveObjectParent + ObjectID: 117 + ParentSchemaID: 106 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.DrainDescriptorName Namespace: DescriptorID: 104 diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_function b/pkg/sql/schemachanger/scplan/testdata/drop_function new file mode 100644 index 000000000000..fe1f91a99708 --- /dev/null +++ b/pkg/sql/schemachanger/scplan/testdata/drop_function @@ -0,0 +1,160 @@ +setup +CREATE TABLE t( + a INT PRIMARY KEY, + b INT, + C INT, + INDEX t_idx_b(b), + INDEX t_idx_c(c) +); +CREATE SEQUENCE sq1; +CREATE VIEW v AS SELECT a FROM t; +CREATE TYPE notmyworkday AS ENUM ('Monday', 'Tuesday'); +CREATE FUNCTION f(a notmyworkday) RETURNS INT IMMUTABLE LANGUAGE SQL AS $$ + SELECT a FROM t; + SELECT b FROM t@t_idx_b; + SELECT c FROM t@t_idx_c; + SELECT a FROM v; + SELECT nextval('sq1'); +$$; +---- + +ops +DROP FUNCTION f; +---- +StatementPhase stage 1 of 1 with 1 MutationType op + transitions: + [[Function:{DescID: 109}, ABSENT], PUBLIC] -> TXN_DROPPED + ops: + *scop.MarkDescriptorAsSyntheticallyDropped + DescriptorID: 109 +PreCommitPhase stage 1 of 1 with 11 MutationType ops + transitions: + [[Owner:{DescID: 109}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 109, Name: admin}, ABSENT], PUBLIC] -> ABSENT + [[UserPrivileges:{DescID: 109, Name: root}, ABSENT], PUBLIC] -> ABSENT + [[Function:{DescID: 109}, ABSENT], TXN_DROPPED] -> DROPPED + [[ObjectParent:{DescID: 109, ReferencedDescID: 101}, ABSENT], PUBLIC] -> ABSENT + [[FunctionName:{DescID: 109}, ABSENT], PUBLIC] -> ABSENT + [[FunctionVolatility:{DescID: 109}, ABSENT], PUBLIC] -> ABSENT + [[FunctionLeakProof:{DescID: 109}, ABSENT], PUBLIC] -> ABSENT + [[FunctionNullInputBehavior:{DescID: 109}, ABSENT], PUBLIC] -> ABSENT + [[FunctionBody:{DescID: 109}, ABSENT], PUBLIC] -> ABSENT + ops: + *scop.MarkDescriptorAsDropped + DescriptorID: 109 + *scop.RemoveObjectParent + ObjectID: 109 + ParentSchemaID: 101 + *scop.RemoveBackReferenceInTypes + BackReferencedDescriptorID: 109 + TypeIDs: + - 107 + - 108 + *scop.RemoveBackReferencesInRelations + BackReferencedID: 109 + RelationIDs: + - 104 + - 104 + - 104 + - 106 + - 105 + *scop.SetJobStateOnDescriptor + DescriptorID: 104 + Initialize: true + *scop.SetJobStateOnDescriptor + DescriptorID: 105 + Initialize: true + *scop.SetJobStateOnDescriptor + DescriptorID: 106 + Initialize: true + *scop.SetJobStateOnDescriptor + DescriptorID: 107 + Initialize: true + *scop.SetJobStateOnDescriptor + DescriptorID: 108 + Initialize: true + *scop.SetJobStateOnDescriptor + DescriptorID: 109 + Initialize: true + *scop.CreateSchemaChangerJob + Authorization: + UserName: root + DescriptorIDs: + - 104 + - 105 + - 106 + - 107 + - 108 + - 109 + JobID: 1 + NonCancelable: true + RunningStatus: PostCommitNonRevertiblePhase stage 1 of 1 with 2 MutationType ops pending + Statements: + - statement: DROP FUNCTION f + redactedstatement: DROP FUNCTION ‹""›.‹""›.‹f› + statementtag: DROP FUNCTION +PostCommitNonRevertiblePhase stage 1 of 1 with 9 MutationType ops + transitions: + [[Function:{DescID: 109}, ABSENT], DROPPED] -> ABSENT + ops: + *scop.LogEvent + Element: + Function: + functionId: 109 + params: + - class: + class: IN + name: a + type: + closedTypeIds: + - 107 + - 108 + type: + family: EnumFamily + oid: 100107 + udtMetadata: + arrayTypeOid: 100108 + returnType: + type: + family: IntFamily + oid: 20 + width: 64 + EventBase: + Authorization: + UserName: root + Statement: DROP FUNCTION ‹""›.‹""›.‹f› + StatementTag: DROP FUNCTION + TargetMetadata: + SourceElementID: 1 + SubWorkID: 1 + TargetStatus: 1 + *scop.DeleteDescriptor + DescriptorID: 109 + *scop.RemoveJobStateFromDescriptor + DescriptorID: 104 + JobID: 1 + *scop.RemoveJobStateFromDescriptor + DescriptorID: 105 + JobID: 1 + *scop.RemoveJobStateFromDescriptor + DescriptorID: 106 + JobID: 1 + *scop.RemoveJobStateFromDescriptor + DescriptorID: 107 + JobID: 1 + *scop.RemoveJobStateFromDescriptor + DescriptorID: 108 + JobID: 1 + *scop.RemoveJobStateFromDescriptor + DescriptorID: 109 + JobID: 1 + *scop.UpdateSchemaChangerJob + DescriptorIDsToRemove: + - 104 + - 105 + - 106 + - 107 + - 108 + - 109 + IsNonCancelable: true + JobID: 1 diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_index b/pkg/sql/schemachanger/scplan/testdata/drop_index index 5bfdc90da279..199e9e30e454 100644 --- a/pkg/sql/schemachanger/scplan/testdata/drop_index +++ b/pkg/sql/schemachanger/scplan/testdata/drop_index @@ -651,7 +651,11 @@ StatementPhase stage 1 of 1 with 1 MutationType op ops: *scop.MarkDescriptorAsSyntheticallyDropped DescriptorID: 105 +<<<<<<< HEAD PreCommitPhase stage 1 of 1 with 10 MutationType ops +======= +PreCommitPhase stage 1 of 1 with 12 MutationType ops +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) transitions: [[IndexColumn:{DescID: 104, ColumnID: 2, IndexID: 8}, ABSENT], PUBLIC] -> ABSENT [[IndexColumn:{DescID: 104, ColumnID: 3, IndexID: 8}, ABSENT], PUBLIC] -> ABSENT @@ -678,6 +682,14 @@ PreCommitPhase stage 1 of 1 with 10 MutationType ops BackReferencedID: 105 RelationIDs: - 104 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 105 + *scop.RemoveObjectParent + ObjectID: 105 + ParentSchemaID: 101 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.MakePublicSecondaryIndexWriteOnly IndexID: 8 TableID: 104 @@ -994,7 +1006,11 @@ StatementPhase stage 1 of 1 with 1 MutationType op ops: *scop.MarkDescriptorAsSyntheticallyDropped DescriptorID: 107 +<<<<<<< HEAD PreCommitPhase stage 1 of 1 with 12 MutationType ops +======= +PreCommitPhase stage 1 of 1 with 14 MutationType ops +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) transitions: [[IndexColumn:{DescID: 106, ColumnID: 2, IndexID: 2}, ABSENT], PUBLIC] -> ABSENT [[IndexColumn:{DescID: 106, ColumnID: 3, IndexID: 2}, ABSENT], PUBLIC] -> ABSENT @@ -1030,6 +1046,14 @@ PreCommitPhase stage 1 of 1 with 12 MutationType ops BackReferencedID: 107 RelationIDs: - 106 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 107 + *scop.RemoveObjectParent + ObjectID: 107 + ParentSchemaID: 101 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.RemoveColumnDefaultExpression ColumnID: 2 TableID: 107 diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_owned_by b/pkg/sql/schemachanger/scplan/testdata/drop_owned_by index 5a9c65764c5e..e56f08b69466 100644 --- a/pkg/sql/schemachanger/scplan/testdata/drop_owned_by +++ b/pkg/sql/schemachanger/scplan/testdata/drop_owned_by @@ -66,7 +66,11 @@ StatementPhase stage 1 of 1 with 9 MutationType ops DescriptorID: 112 *scop.MarkDescriptorAsSyntheticallyDropped DescriptorID: 113 +<<<<<<< HEAD PreCommitPhase stage 1 of 1 with 57 MutationType ops +======= +PreCommitPhase stage 1 of 1 with 71 MutationType ops +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) transitions: [[UserPrivileges:{DescID: 100, Name: r}, ABSENT], PUBLIC] -> ABSENT [[Namespace:{DescID: 105, Name: s, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT @@ -207,8 +211,23 @@ PreCommitPhase stage 1 of 1 with 57 MutationType ops User: r *scop.MarkDescriptorAsDropped DescriptorID: 106 +<<<<<<< HEAD *scop.MarkDescriptorAsDropped DescriptorID: 109 +======= + *scop.RemoveAllTableComments + TableID: 106 + *scop.RemoveObjectParent + ObjectID: 106 + ParentSchemaID: 101 + *scop.MarkDescriptorAsDropped + DescriptorID: 109 + *scop.RemoveAllTableComments + TableID: 109 + *scop.RemoveObjectParent + ObjectID: 109 + ParentSchemaID: 101 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.RemoveColumnDefaultExpression ColumnID: 3 TableID: 109 @@ -219,8 +238,23 @@ PreCommitPhase stage 1 of 1 with 57 MutationType ops - 106 *scop.MarkDescriptorAsDropped DescriptorID: 107 +<<<<<<< HEAD + *scop.MarkDescriptorAsDropped + DescriptorID: 108 +======= + *scop.RemoveAllTableComments + TableID: 107 + *scop.RemoveObjectParent + ObjectID: 107 + ParentSchemaID: 105 *scop.MarkDescriptorAsDropped DescriptorID: 108 + *scop.RemoveAllTableComments + TableID: 108 + *scop.RemoveObjectParent + ObjectID: 108 + ParentSchemaID: 105 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.RemoveColumnDefaultExpression ColumnID: 3 TableID: 108 @@ -235,10 +269,24 @@ PreCommitPhase stage 1 of 1 with 57 MutationType ops BackReferencedID: 110 RelationIDs: - 108 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 110 + *scop.RemoveObjectParent + ObjectID: 110 + ParentSchemaID: 105 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.MarkDescriptorAsDropped DescriptorID: 111 + *scop.RemoveObjectParent + ObjectID: 111 + ParentSchemaID: 105 *scop.MarkDescriptorAsDropped DescriptorID: 112 + *scop.RemoveObjectParent + ObjectID: 112 + ParentSchemaID: 105 *scop.MarkDescriptorAsDropped DescriptorID: 113 *scop.RemoveBackReferenceInTypes @@ -250,6 +298,14 @@ PreCommitPhase stage 1 of 1 with 57 MutationType ops BackReferencedID: 113 RelationIDs: - 110 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 113 + *scop.RemoveObjectParent + ObjectID: 113 + ParentSchemaID: 105 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.DrainDescriptorName Namespace: DatabaseID: 100 diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_schema b/pkg/sql/schemachanger/scplan/testdata/drop_schema index 801e26c30043..48ac2251b334 100644 --- a/pkg/sql/schemachanger/scplan/testdata/drop_schema +++ b/pkg/sql/schemachanger/scplan/testdata/drop_schema @@ -1126,7 +1126,11 @@ StatementPhase stage 1 of 1 with 10 MutationType ops DescriptorID: 112 *scop.MarkDescriptorAsSyntheticallyDropped DescriptorID: 113 +<<<<<<< HEAD PreCommitPhase stage 1 of 1 with 69 MutationType ops +======= +PreCommitPhase stage 1 of 1 with 83 MutationType ops +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) transitions: [[Namespace:{DescID: 104, Name: sc1, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT [[Owner:{DescID: 104}, ABSENT], PUBLIC] -> ABSENT @@ -1286,10 +1290,19 @@ PreCommitPhase stage 1 of 1 with 69 MutationType ops SchemaID: 104 *scop.MarkDescriptorAsDropped DescriptorID: 105 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 105 + *scop.RemoveObjectParent + ObjectID: 105 + ParentSchemaID: 104 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.MarkDescriptorAsDropped DescriptorID: 106 *scop.RemoveTableComment TableID: 106 +<<<<<<< HEAD *scop.LogEvent Element: TableComment: @@ -1304,6 +1317,11 @@ PreCommitPhase stage 1 of 1 with 69 MutationType ops SourceElementID: 2 SubWorkID: 1 TargetStatus: 1 +======= + *scop.RemoveObjectParent + ObjectID: 106 + ParentSchemaID: 104 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.RemoveColumnDefaultExpression ColumnID: 3 TableID: 106 @@ -1318,12 +1336,28 @@ PreCommitPhase stage 1 of 1 with 69 MutationType ops BackReferencedID: 107 RelationIDs: - 106 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 107 + *scop.RemoveObjectParent + ObjectID: 107 + ParentSchemaID: 104 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.MarkDescriptorAsDropped DescriptorID: 108 *scop.RemoveBackReferencesInRelations BackReferencedID: 108 RelationIDs: - 107 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 108 + *scop.RemoveObjectParent + ObjectID: 108 + ParentSchemaID: 104 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.MarkDescriptorAsDropped DescriptorID: 109 *scop.RemoveBackReferencesInRelations @@ -1331,16 +1365,38 @@ PreCommitPhase stage 1 of 1 with 69 MutationType ops RelationIDs: - 107 - 108 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 109 + *scop.RemoveObjectParent + ObjectID: 109 + ParentSchemaID: 104 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.MarkDescriptorAsDropped DescriptorID: 110 *scop.RemoveBackReferencesInRelations BackReferencedID: 110 RelationIDs: - 108 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 110 + *scop.RemoveObjectParent + ObjectID: 110 + ParentSchemaID: 104 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.MarkDescriptorAsDropped DescriptorID: 111 + *scop.RemoveObjectParent + ObjectID: 111 + ParentSchemaID: 104 *scop.MarkDescriptorAsDropped DescriptorID: 112 + *scop.RemoveObjectParent + ObjectID: 112 + ParentSchemaID: 104 *scop.MarkDescriptorAsDropped DescriptorID: 113 *scop.RemoveBackReferenceInTypes @@ -1352,6 +1408,14 @@ PreCommitPhase stage 1 of 1 with 69 MutationType ops BackReferencedID: 113 RelationIDs: - 110 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 113 + *scop.RemoveObjectParent + ObjectID: 113 + ParentSchemaID: 104 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.DrainDescriptorName Namespace: DatabaseID: 100 diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_sequence b/pkg/sql/schemachanger/scplan/testdata/drop_sequence index 8202c21c5dda..3f341dbb22b6 100644 --- a/pkg/sql/schemachanger/scplan/testdata/drop_sequence +++ b/pkg/sql/schemachanger/scplan/testdata/drop_sequence @@ -11,7 +11,11 @@ StatementPhase stage 1 of 1 with 1 MutationType op ops: *scop.MarkDescriptorAsSyntheticallyDropped DescriptorID: 104 +<<<<<<< HEAD PreCommitPhase stage 1 of 1 with 4 MutationType ops +======= +PreCommitPhase stage 1 of 1 with 6 MutationType ops +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) transitions: [[Namespace:{DescID: 104, Name: sq1, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT [[Owner:{DescID: 104}, ABSENT], PUBLIC] -> ABSENT @@ -22,6 +26,14 @@ PreCommitPhase stage 1 of 1 with 4 MutationType ops ops: *scop.MarkDescriptorAsDropped DescriptorID: 104 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 104 + *scop.RemoveObjectParent + ObjectID: 104 + ParentSchemaID: 101 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.DrainDescriptorName Namespace: DatabaseID: 100 @@ -89,7 +101,11 @@ StatementPhase stage 1 of 1 with 1 MutationType op ops: *scop.MarkDescriptorAsSyntheticallyDropped DescriptorID: 104 +<<<<<<< HEAD PreCommitPhase stage 1 of 1 with 10 MutationType ops +======= +PreCommitPhase stage 1 of 1 with 12 MutationType ops +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) transitions: [[Namespace:{DescID: 104, Name: sq1, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT [[Owner:{DescID: 104}, ABSENT], PUBLIC] -> ABSENT @@ -102,6 +118,14 @@ PreCommitPhase stage 1 of 1 with 10 MutationType ops ops: *scop.MarkDescriptorAsDropped DescriptorID: 104 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 104 + *scop.RemoveObjectParent + ObjectID: 104 + ParentSchemaID: 101 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.RemoveColumnDefaultExpression ColumnID: 2 TableID: 105 diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_table b/pkg/sql/schemachanger/scplan/testdata/drop_table index 0df7f00756e6..225b184ad59e 100644 --- a/pkg/sql/schemachanger/scplan/testdata/drop_table +++ b/pkg/sql/schemachanger/scplan/testdata/drop_table @@ -56,7 +56,11 @@ StatementPhase stage 1 of 1 with 3 MutationType ops DescriptorID: 110 *scop.MarkDescriptorAsSyntheticallyDropped DescriptorID: 111 +<<<<<<< HEAD PreCommitPhase stage 1 of 1 with 47 MutationType ops +======= +PreCommitPhase stage 1 of 1 with 45 MutationType ops +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) transitions: [[Namespace:{DescID: 109, Name: shipments, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT [[Owner:{DescID: 109}, ABSENT], PUBLIC] -> ABSENT @@ -139,6 +143,7 @@ PreCommitPhase stage 1 of 1 with 47 MutationType ops DescriptorID: 109 *scop.RemoveTableComment TableID: 109 +<<<<<<< HEAD *scop.LogEvent Element: TableComment: @@ -153,6 +158,11 @@ PreCommitPhase stage 1 of 1 with 47 MutationType ops SourceElementID: 1 SubWorkID: 1 TargetStatus: 1 +======= + *scop.RemoveObjectParent + ObjectID: 109 + ParentSchemaID: 101 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.RemoveColumnDefaultExpression ColumnID: 1 TableID: 109 @@ -233,12 +243,28 @@ PreCommitPhase stage 1 of 1 with 47 MutationType ops TargetStatus: 1 *scop.MarkDescriptorAsDropped DescriptorID: 110 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 110 + *scop.RemoveObjectParent + ObjectID: 110 + ParentSchemaID: 101 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.MarkDescriptorAsDropped DescriptorID: 111 *scop.RemoveBackReferencesInRelations BackReferencedID: 111 RelationIDs: - 109 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 111 + *scop.RemoveObjectParent + ObjectID: 111 + ParentSchemaID: 101 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.DrainDescriptorName Namespace: DatabaseID: 100 @@ -1283,7 +1309,11 @@ StatementPhase stage 1 of 1 with 1 MutationType op ops: *scop.MarkDescriptorAsSyntheticallyDropped DescriptorID: 114 +<<<<<<< HEAD PreCommitPhase stage 1 of 1 with 20 MutationType ops +======= +PreCommitPhase stage 1 of 1 with 22 MutationType ops +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) transitions: [[Namespace:{DescID: 114, Name: greeter, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT [[Owner:{DescID: 114}, ABSENT], PUBLIC] -> ABSENT @@ -1324,6 +1354,14 @@ PreCommitPhase stage 1 of 1 with 20 MutationType ops ops: *scop.MarkDescriptorAsDropped DescriptorID: 114 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 114 + *scop.RemoveObjectParent + ObjectID: 114 + ParentSchemaID: 101 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.RemoveColumnDefaultExpression ColumnID: 1 TableID: 114 diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_type b/pkg/sql/schemachanger/scplan/testdata/drop_type index 120eb4329b48..4727edda4a9a 100644 --- a/pkg/sql/schemachanger/scplan/testdata/drop_type +++ b/pkg/sql/schemachanger/scplan/testdata/drop_type @@ -15,7 +15,7 @@ StatementPhase stage 1 of 1 with 2 MutationType ops DescriptorID: 104 *scop.MarkDescriptorAsSyntheticallyDropped DescriptorID: 105 -PreCommitPhase stage 1 of 1 with 7 MutationType ops +PreCommitPhase stage 1 of 1 with 9 MutationType ops transitions: [[Namespace:{DescID: 104, Name: typ, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT [[Owner:{DescID: 104}, ABSENT], PUBLIC] -> ABSENT @@ -35,8 +35,14 @@ PreCommitPhase stage 1 of 1 with 7 MutationType ops ops: *scop.MarkDescriptorAsDropped DescriptorID: 104 + *scop.RemoveObjectParent + ObjectID: 104 + ParentSchemaID: 101 *scop.MarkDescriptorAsDropped DescriptorID: 105 + *scop.RemoveObjectParent + ObjectID: 105 + ParentSchemaID: 101 *scop.DrainDescriptorName Namespace: DatabaseID: 100 @@ -213,7 +219,7 @@ StatementPhase stage 1 of 1 with 2 MutationType ops DescriptorID: 106 *scop.MarkDescriptorAsSyntheticallyDropped DescriptorID: 107 -PreCommitPhase stage 1 of 1 with 9 MutationType ops +PreCommitPhase stage 1 of 1 with 11 MutationType ops transitions: [[Namespace:{DescID: 106, Name: ctyp, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT [[Owner:{DescID: 106}, ABSENT], PUBLIC] -> ABSENT @@ -239,8 +245,14 @@ PreCommitPhase stage 1 of 1 with 9 MutationType ops ElementType: scpb.CompositeTypeAttrName *scop.NotImplemented ElementType: scpb.CompositeTypeAttrName + *scop.RemoveObjectParent + ObjectID: 106 + ParentSchemaID: 101 *scop.MarkDescriptorAsDropped DescriptorID: 107 + *scop.RemoveObjectParent + ObjectID: 107 + ParentSchemaID: 101 *scop.DrainDescriptorName Namespace: DatabaseID: 100 diff --git a/pkg/sql/schemachanger/scplan/testdata/drop_view b/pkg/sql/schemachanger/scplan/testdata/drop_view index 1bd8f4932c86..99475436e6f0 100644 --- a/pkg/sql/schemachanger/scplan/testdata/drop_view +++ b/pkg/sql/schemachanger/scplan/testdata/drop_view @@ -15,7 +15,11 @@ StatementPhase stage 1 of 1 with 1 MutationType op ops: *scop.MarkDescriptorAsSyntheticallyDropped DescriptorID: 105 +<<<<<<< HEAD PreCommitPhase stage 1 of 1 with 9 MutationType ops +======= +PreCommitPhase stage 1 of 1 with 11 MutationType ops +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) transitions: [[Namespace:{DescID: 105, Name: v1, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT [[Owner:{DescID: 105}, ABSENT], PUBLIC] -> ABSENT @@ -39,6 +43,14 @@ PreCommitPhase stage 1 of 1 with 9 MutationType ops BackReferencedID: 105 RelationIDs: - 104 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 105 + *scop.RemoveObjectParent + ObjectID: 105 + ParentSchemaID: 101 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.DrainDescriptorName Namespace: DatabaseID: 100 @@ -288,7 +300,11 @@ StatementPhase stage 1 of 1 with 5 MutationType ops DescriptorID: 108 *scop.MarkDescriptorAsSyntheticallyDropped DescriptorID: 111 +<<<<<<< HEAD PreCommitPhase stage 1 of 1 with 45 MutationType ops +======= +PreCommitPhase stage 1 of 1 with 55 MutationType ops +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) transitions: [[Namespace:{DescID: 105, Name: v1, ReferencedDescID: 100}, ABSENT], PUBLIC] -> ABSENT [[Owner:{DescID: 105}, ABSENT], PUBLIC] -> ABSENT @@ -387,12 +403,28 @@ PreCommitPhase stage 1 of 1 with 45 MutationType ops BackReferencedID: 105 RelationIDs: - 104 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 105 + *scop.RemoveObjectParent + ObjectID: 105 + ParentSchemaID: 101 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.MarkDescriptorAsDropped DescriptorID: 106 *scop.RemoveBackReferencesInRelations BackReferencedID: 106 RelationIDs: - 105 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 106 + *scop.RemoveObjectParent + ObjectID: 106 + ParentSchemaID: 101 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.MarkDescriptorAsDropped DescriptorID: 107 *scop.RemoveBackReferencesInRelations @@ -400,12 +432,28 @@ PreCommitPhase stage 1 of 1 with 45 MutationType ops RelationIDs: - 105 - 106 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 107 + *scop.RemoveObjectParent + ObjectID: 107 + ParentSchemaID: 101 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.MarkDescriptorAsDropped DescriptorID: 108 *scop.RemoveBackReferencesInRelations BackReferencedID: 108 RelationIDs: - 106 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 108 + *scop.RemoveObjectParent + ObjectID: 108 + ParentSchemaID: 101 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.MarkDescriptorAsDropped DescriptorID: 111 *scop.RemoveBackReferenceInTypes @@ -417,6 +465,14 @@ PreCommitPhase stage 1 of 1 with 45 MutationType ops BackReferencedID: 111 RelationIDs: - 108 +<<<<<<< HEAD +======= + *scop.RemoveAllTableComments + TableID: 111 + *scop.RemoveObjectParent + ObjectID: 111 + ParentSchemaID: 101 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) *scop.DrainDescriptorName Namespace: DatabaseID: 100 diff --git a/pkg/sql/schemachanger/screl/attr.go b/pkg/sql/schemachanger/screl/attr.go index 68a50141b17e..1ac8c0bcbd74 100644 --- a/pkg/sql/schemachanger/screl/attr.go +++ b/pkg/sql/schemachanger/screl/attr.go @@ -338,6 +338,27 @@ var elementSchemaOptions = []rel.SchemaOption{ rel.EntityMapping(t((*scpb.TablePartitioning)(nil)), rel.EntityAttr(DescID, "TableID"), ), + rel.EntityMapping(t((*scpb.Function)(nil)), + rel.EntityAttr(DescID, "FunctionID"), + ), + rel.EntityMapping(t((*scpb.FunctionName)(nil)), + rel.EntityAttr(DescID, "FunctionID"), + ), + rel.EntityMapping(t((*scpb.FunctionVolatility)(nil)), + rel.EntityAttr(DescID, "FunctionID"), + ), + rel.EntityMapping(t((*scpb.FunctionLeakProof)(nil)), + rel.EntityAttr(DescID, "FunctionID"), + ), + rel.EntityMapping(t((*scpb.FunctionNullInputBehavior)(nil)), + rel.EntityAttr(DescID, "FunctionID"), + ), + rel.EntityMapping(t((*scpb.FunctionBody)(nil)), + rel.EntityAttr(DescID, "FunctionID"), + ), + rel.EntityMapping(t((*scpb.FunctionParamDefaultExpression)(nil)), + rel.EntityAttr(DescID, "FunctionID"), + ), } // Schema is the schema exported by this package covering the elements of scpb. diff --git a/pkg/sql/schemachanger/screl/scalars.go b/pkg/sql/schemachanger/screl/scalars.go index 241f344ff7d4..e74a44f9d1e2 100644 --- a/pkg/sql/schemachanger/screl/scalars.go +++ b/pkg/sql/schemachanger/screl/scalars.go @@ -120,7 +120,9 @@ func MinVersion(el scpb.Element) clusterversion.Key { return clusterversion.V23_1 case *scpb.IndexColumn, *scpb.EnumTypeValue, *scpb.TableZoneConfig: return clusterversion.V22_2UseDelRangeInGCJob - case *scpb.DatabaseData, *scpb.TableData, *scpb.IndexData, *scpb.TablePartitioning: + case *scpb.DatabaseData, *scpb.TableData, *scpb.IndexData, *scpb.TablePartitioning, + *scpb.Function, *scpb.FunctionName, *scpb.FunctionVolatility, *scpb.FunctionLeakProof, + *scpb.FunctionNullInputBehavior, *scpb.FunctionBody, *scpb.FunctionParamDefaultExpression: return clusterversion.V23_1 default: panic(errors.AssertionFailedf("unknown element %T", el)) diff --git a/pkg/sql/schemachanger/sctest/cumulative.go b/pkg/sql/schemachanger/sctest/cumulative.go index b91a0dfeaa34..741773e433a5 100644 --- a/pkg/sql/schemachanger/sctest/cumulative.go +++ b/pkg/sql/schemachanger/sctest/cumulative.go @@ -676,6 +676,7 @@ FROM SELECT descriptor_id, create_statement FROM crdb_internal.create_schema_statements UNION ALL SELECT descriptor_id, create_statement FROM crdb_internal.create_statements UNION ALL SELECT descriptor_id, create_statement FROM crdb_internal.create_type_statements + UNION ALL SELECT function_id as descriptor_id, create_statement FROM crdb_internal.create_function_statements ) WHERE descriptor_id IN (SELECT id FROM system.namespace) ORDER BY diff --git a/pkg/sql/schemachanger/sctest_generated_test.go b/pkg/sql/schemachanger/sctest_generated_test.go index 90d219265fc6..e22cc464c4a8 100644 --- a/pkg/sql/schemachanger/sctest_generated_test.go +++ b/pkg/sql/schemachanger/sctest_generated_test.go @@ -445,6 +445,31 @@ func TestRollback_drop_column_with_index(t *testing.T) { defer log.Scope(t).Close(t) sctest.Rollback(t, "pkg/sql/schemachanger/testdata/end_to_end/drop_column_with_index", sctest.SingleNodeCluster) } +func TestEndToEndSideEffects_drop_function(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + sctest.EndToEndSideEffects(t, "pkg/sql/schemachanger/testdata/end_to_end/drop_function", sctest.SingleNodeCluster) +} +func TestExecuteWithDMLInjection_drop_function(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + sctest.ExecuteWithDMLInjection(t, "pkg/sql/schemachanger/testdata/end_to_end/drop_function", sctest.SingleNodeCluster) +} +func TestGenerateSchemaChangeCorpus_drop_function(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + sctest.GenerateSchemaChangeCorpus(t, "pkg/sql/schemachanger/testdata/end_to_end/drop_function", sctest.SingleNodeCluster) +} +func TestPause_drop_function(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + sctest.Pause(t, "pkg/sql/schemachanger/testdata/end_to_end/drop_function", sctest.SingleNodeCluster) +} +func TestRollback_drop_function(t *testing.T) { + defer leaktest.AfterTest(t)() + defer log.Scope(t).Close(t) + sctest.Rollback(t, "pkg/sql/schemachanger/testdata/end_to_end/drop_function", sctest.SingleNodeCluster) +} func TestEndToEndSideEffects_drop_index_hash_sharded_index(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) diff --git a/pkg/sql/schemachanger/testdata/end_to_end/drop_function b/pkg/sql/schemachanger/testdata/end_to_end/drop_function new file mode 100644 index 000000000000..09494c99d1e4 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/end_to_end/drop_function @@ -0,0 +1,292 @@ +setup +CREATE TABLE t( + a INT PRIMARY KEY, + b INT, + C INT, + INDEX t_idx_b(b), + INDEX t_idx_c(c) +); +CREATE SEQUENCE sq1; +CREATE VIEW v AS SELECT a FROM t; +CREATE TYPE notmyworkday AS ENUM ('Monday', 'Tuesday'); +CREATE FUNCTION f(a notmyworkday) RETURNS INT IMMUTABLE LANGUAGE SQL AS $$ + SELECT a FROM t; + SELECT b FROM t@t_idx_b; + SELECT c FROM t@t_idx_c; + SELECT a FROM v; + SELECT nextval('sq1'); +$$; +CREATE TABLE t2(a notmyworkday); +---- +... ++object {100 101 t} -> 104 ++object {100 101 sq1} -> 105 ++object {100 101 v} -> 106 ++object {100 101 notmyworkday} -> 107 ++object {100 101 _notmyworkday} -> 108 ++object {100 101 t2} -> 110 + +test +DROP FUNCTION f; +---- +begin transaction #1 +# begin StatementPhase +checking for feature: DROP FUNCTION +increment telemetry for sql.schema.drop_function +## StatementPhase stage 1 of 1 with 1 MutationType op +add synthetic descriptor #109: + ... + id: 109 + lang: SQL + - modificationTime: {} + + modificationTime: + + wallTime: "1640995200000000001" + name: f + nullInputBehavior: CALLED_ON_NULL_INPUT + ... + oid: 20 + width: 64 + + state: DROP + version: "1" + volatility: IMMUTABLE +# end StatementPhase +# begin PreCommitPhase +## PreCommitPhase stage 1 of 1 with 11 MutationType ops +upsert descriptor #101 + schema: + - functions: + - f: + - overloads: + - - argTypes: + - - family: EnumFamily + - oid: 100107 + - udtMetadata: + - arrayTypeOid: 100108 + - id: 109 + - returnType: + - family: IntFamily + - oid: 20 + - width: 64 + id: 101 + modificationTime: {} + ... + withGrantOption: "2" + version: 2 + - version: "2" + + version: "3" +upsert descriptor #104 + ... + createAsOfTime: + wallTime: "1640995200000000000" + + declarativeSchemaChangerState: + + authorization: + + userName: root + + jobId: "1" + dependedOnBy: + - columnIds: + - 1 + id: 106 + - - columnIds: + - - 1 + - id: 109 + - - columnIds: + - - 2 + - id: 109 + - indexId: 2 + - - columnIds: + - - 3 + - id: 109 + - indexId: 3 + families: + - columnIds: + ... + time: {} + unexposedParentSchemaId: 101 + - version: "3" + + version: "4" +upsert descriptor #105 + ... + createAsOfTime: + wallTime: "1640995200000000000" + - dependedOnBy: + - - byId: true + - id: 109 + + declarativeSchemaChangerState: + + authorization: + + userName: root + + jobId: "1" + families: + - columnIds: + ... + start: "1" + unexposedParentSchemaId: 101 + - version: "2" + + version: "3" +upsert descriptor #106 + ... + createAsOfTime: + wallTime: "1640995200000000000" + - dependedOnBy: + - - columnIds: + - - 1 + - id: 109 + + declarativeSchemaChangerState: + + authorization: + + userName: root + + jobId: "1" + dependsOn: + - 104 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "2" + + version: "3" + viewQuery: SELECT a FROM defaultdb.public.t +upsert descriptor #107 + type: + arrayTypeId: 108 + + declarativeSchemaChangerState: + + authorization: + + userName: root + + jobId: "1" + enumMembers: + - logicalRepresentation: Monday + ... + version: 2 + referencingDescriptorIds: + - - 109 + - 110 + - version: "3" + + version: "4" +upsert descriptor #108 + ... + family: ArrayFamily + oid: 100108 + + declarativeSchemaChangerState: + + authorization: + + userName: root + + jobId: "1" + id: 108 + kind: ALIAS + ... + version: 2 + referencingDescriptorIds: + - - 109 + - 110 + - version: "3" + + version: "4" +upsert descriptor #109 + function: + + declarativeSchemaChangerState: + + authorization: + + userName: root + + currentStatuses: + + jobId: "1" + + relevantStatements: + + - statement: + + redactedStatement: DROP FUNCTION ‹""›.‹""›.‹f› + + statement: DROP FUNCTION f + + statementTag: DROP FUNCTION + + targetRanks: + + targets: + dependsOn: + - 104 + ... + oid: 20 + width: 64 + - version: "1" + + state: DROP + + version: "2" + volatility: IMMUTABLE +create job #1 (non-cancelable: true): "DROP FUNCTION \"\".\"\".f" + descriptor IDs: [104 105 106 107 108 109] +# end PreCommitPhase +commit transaction #1 +notified job registry to adopt jobs: [1] +# begin PostCommitPhase +begin transaction #2 +commit transaction #2 +begin transaction #3 +## PostCommitNonRevertiblePhase stage 1 of 1 with 9 MutationType ops +upsert descriptor #104 + ... + createAsOfTime: + wallTime: "1640995200000000000" + - declarativeSchemaChangerState: + - authorization: + - userName: root + - jobId: "1" + dependedOnBy: + - columnIds: + ... + time: {} + unexposedParentSchemaId: 101 + - version: "4" + + version: "5" +upsert descriptor #105 + ... + createAsOfTime: + wallTime: "1640995200000000000" + - declarativeSchemaChangerState: + - authorization: + - userName: root + - jobId: "1" + families: + - columnIds: + ... + start: "1" + unexposedParentSchemaId: 101 + - version: "3" + + version: "4" +upsert descriptor #106 + ... + createAsOfTime: + wallTime: "1640995200000000000" + - declarativeSchemaChangerState: + - authorization: + - userName: root + - jobId: "1" + dependsOn: + - 104 + ... + time: {} + unexposedParentSchemaId: 101 + - version: "3" + + version: "4" + viewQuery: SELECT a FROM defaultdb.public.t +upsert descriptor #107 + type: + arrayTypeId: 108 + - declarativeSchemaChangerState: + - authorization: + - userName: root + - jobId: "1" + enumMembers: + - logicalRepresentation: Monday + ... + referencingDescriptorIds: + - 110 + - version: "4" + + version: "5" +upsert descriptor #108 + ... + family: ArrayFamily + oid: 100108 + - declarativeSchemaChangerState: + - authorization: + - userName: root + - jobId: "1" + id: 108 + kind: ALIAS + ... + referencingDescriptorIds: + - 110 + - version: "4" + + version: "5" +delete descriptor #109 +write *eventpb.DropFunction to event log: DROP FUNCTION ‹""›.‹""›.‹f› +update progress of schema change job #1: "all stages completed" +set schema change job #1 to non-cancellable +updated schema change job #1 descriptor IDs to [] +commit transaction #3 +# end PostCommitPhase diff --git a/pkg/sql/schemachanger/testdata/end_to_end/drop_index_with_materialized_view_dep b/pkg/sql/schemachanger/testdata/end_to_end/drop_index_with_materialized_view_dep index ec0351b82087..b49c36934b5c 100644 --- a/pkg/sql/schemachanger/testdata/end_to_end/drop_index_with_materialized_view_dep +++ b/pkg/sql/schemachanger/testdata/end_to_end/drop_index_with_materialized_view_dep @@ -52,7 +52,12 @@ add synthetic descriptor #106: ... # end StatementPhase # begin PreCommitPhase +<<<<<<< HEAD ## PreCommitPhase stage 1 of 1 with 12 MutationType ops +======= +## PreCommitPhase stage 1 of 1 with 14 MutationType ops +delete all comments for table descriptor 106 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) delete object namespace entry {100 101 v3} -> 106 upsert descriptor #105 ... diff --git a/pkg/sql/schemachanger/testdata/end_to_end/drop_table b/pkg/sql/schemachanger/testdata/end_to_end/drop_table index 8a08c5aa0a3c..6c81e54de350 100644 --- a/pkg/sql/schemachanger/testdata/end_to_end/drop_table +++ b/pkg/sql/schemachanger/testdata/end_to_end/drop_table @@ -39,6 +39,10 @@ add synthetic descriptor #107: # end StatementPhase # begin PreCommitPhase ## PreCommitPhase stage 1 of 1 with 12 MutationType ops +<<<<<<< HEAD +======= +delete all comments for table descriptor 107 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) delete object namespace entry {104 106 t} -> 107 upsert descriptor #107 ... diff --git a/pkg/sql/schemachanger/testdata/explain/drop_function b/pkg/sql/schemachanger/testdata/explain/drop_function new file mode 100644 index 000000000000..fda409d19558 --- /dev/null +++ b/pkg/sql/schemachanger/testdata/explain/drop_function @@ -0,0 +1,69 @@ +/* setup */ +CREATE TABLE t( + a INT PRIMARY KEY, + b INT, + C INT, + INDEX t_idx_b(b), + INDEX t_idx_c(c) +); +CREATE SEQUENCE sq1; +CREATE VIEW v AS SELECT a FROM t; +CREATE TYPE notmyworkday AS ENUM ('Monday', 'Tuesday'); +CREATE FUNCTION f(a notmyworkday) RETURNS INT IMMUTABLE LANGUAGE SQL AS $$ + SELECT a FROM t; + SELECT b FROM t@t_idx_b; + SELECT c FROM t@t_idx_c; + SELECT a FROM v; + SELECT nextval('sq1'); +$$; +CREATE TABLE t2(a notmyworkday); + +/* test */ +EXPLAIN (ddl) DROP FUNCTION f; +---- +Schema change plan for DROP FUNCTION ‹""›.‹""›.‹f›; + ├── StatementPhase + │ └── Stage 1 of 1 in StatementPhase + │ ├── 1 element transitioning toward ABSENT + │ │ └── PUBLIC → TXN_DROPPED Function:{DescID: 109} + │ └── 1 Mutation operation + │ └── MarkDescriptorAsSyntheticallyDropped {"DescriptorID":109} + ├── PreCommitPhase + │ └── Stage 1 of 1 in PreCommitPhase + │ ├── 10 elements transitioning toward ABSENT + │ │ ├── PUBLIC → ABSENT Owner:{DescID: 109} + │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 109, Name: admin} + │ │ ├── PUBLIC → ABSENT UserPrivileges:{DescID: 109, Name: root} + │ │ ├── TXN_DROPPED → DROPPED Function:{DescID: 109} + │ │ ├── PUBLIC → ABSENT ObjectParent:{DescID: 109, ReferencedDescID: 101} + │ │ ├── PUBLIC → ABSENT FunctionName:{DescID: 109} + │ │ ├── PUBLIC → ABSENT FunctionVolatility:{DescID: 109} + │ │ ├── PUBLIC → ABSENT FunctionLeakProof:{DescID: 109} + │ │ ├── PUBLIC → ABSENT FunctionNullInputBehavior:{DescID: 109} + │ │ └── PUBLIC → ABSENT FunctionBody:{DescID: 109} + │ └── 11 Mutation operations + │ ├── MarkDescriptorAsDropped {"DescriptorID":109} + │ ├── RemoveObjectParent {"ObjectID":109,"ParentSchemaID":101} + │ ├── RemoveBackReferenceInTypes {"BackReferencedDescriptorID":109} + │ ├── RemoveBackReferencesInRelations {"BackReferencedID":109} + │ ├── SetJobStateOnDescriptor {"DescriptorID":104,"Initialize":true} + │ ├── SetJobStateOnDescriptor {"DescriptorID":105,"Initialize":true} + │ ├── SetJobStateOnDescriptor {"DescriptorID":106,"Initialize":true} + │ ├── SetJobStateOnDescriptor {"DescriptorID":107,"Initialize":true} + │ ├── SetJobStateOnDescriptor {"DescriptorID":108,"Initialize":true} + │ ├── SetJobStateOnDescriptor {"DescriptorID":109,"Initialize":true} + │ └── CreateSchemaChangerJob {"NonCancelable":true,"RunningStatus":"PostCommitNonRev..."} + └── PostCommitNonRevertiblePhase + └── Stage 1 of 1 in PostCommitNonRevertiblePhase + ├── 1 element transitioning toward ABSENT + │ └── DROPPED → ABSENT Function:{DescID: 109} + └── 9 Mutation operations + ├── LogEvent {"TargetStatus":1} + ├── DeleteDescriptor {"DescriptorID":109} + ├── RemoveJobStateFromDescriptor {"DescriptorID":104} + ├── RemoveJobStateFromDescriptor {"DescriptorID":105} + ├── RemoveJobStateFromDescriptor {"DescriptorID":106} + ├── RemoveJobStateFromDescriptor {"DescriptorID":107} + ├── RemoveJobStateFromDescriptor {"DescriptorID":108} + ├── RemoveJobStateFromDescriptor {"DescriptorID":109} + └── UpdateSchemaChangerJob {"IsNonCancelable":true,"RunningStatus":"all stages compl..."} diff --git a/pkg/sql/schemachanger/testdata/explain/drop_index_with_materialized_view_dep b/pkg/sql/schemachanger/testdata/explain/drop_index_with_materialized_view_dep index 4b2b31e3ccc4..97237c69514f 100644 --- a/pkg/sql/schemachanger/testdata/explain/drop_index_with_materialized_view_dep +++ b/pkg/sql/schemachanger/testdata/explain/drop_index_with_materialized_view_dep @@ -49,9 +49,17 @@ Schema change plan for DROP INDEX ‹defaultdb›.‹public›.‹v2›@‹idx │ │ ├── PUBLIC → ABSENT IndexColumn:{DescID: 106, ColumnID: 1, IndexID: 1} │ │ ├── VALIDATED → ABSENT PrimaryIndex:{DescID: 106, IndexID: 1, ConstraintID: 1} │ │ └── PUBLIC → ABSENT IndexName:{DescID: 106, Name: v3_pkey, IndexID: 1} +<<<<<<< HEAD │ └── 12 Mutation operations │ ├── MarkDescriptorAsDropped {"DescriptorID":106} │ ├── RemoveBackReferencesInRelations {"BackReferencedID":106} +======= + │ └── 14 Mutation operations + │ ├── MarkDescriptorAsDropped {"DescriptorID":106} + │ ├── RemoveBackReferencesInRelations {"BackReferencedID":106} + │ ├── RemoveAllTableComments {"TableID":106} + │ ├── RemoveObjectParent {"ObjectID":106,"ParentSchemaID":101} +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) │ ├── RemoveColumnDefaultExpression {"ColumnID":2,"TableID":106} │ ├── MakePublicSecondaryIndexWriteOnly {"IndexID":2,"TableID":105} │ ├── DrainDescriptorName {"Namespace":{"DatabaseID":100,"DescriptorID":106,"Name":"v3","SchemaID":101}} diff --git a/pkg/sql/schemachanger/testdata/explain/drop_table b/pkg/sql/schemachanger/testdata/explain/drop_table index fc01d308bd10..58e16f0f24ca 100644 --- a/pkg/sql/schemachanger/testdata/explain/drop_table +++ b/pkg/sql/schemachanger/testdata/explain/drop_table @@ -55,8 +55,13 @@ Schema change plan for DROP TABLE ‹db›.‹sc›.‹t›; │ │ └── PUBLIC → ABSENT IndexName:{DescID: 107, Name: t_pkey, IndexID: 1} │ └── 12 Mutation operations │ ├── MarkDescriptorAsDropped {"DescriptorID":107} +<<<<<<< HEAD │ ├── RemoveTableComment {"TableID":107} │ ├── LogEvent {"TargetStatus":1} +======= + │ ├── RemoveAllTableComments {"TableID":107} + │ ├── RemoveObjectParent {"ObjectID":107,"ParentSchemaID":106} +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) │ ├── RemoveColumnDefaultExpression {"ColumnID":3,"TableID":107} │ ├── DrainDescriptorName {"Namespace":{"DatabaseID":104,"DescriptorID":107,"Name":"t","SchemaID":106}} │ ├── MakeDeleteOnlyColumnAbsent {"ColumnID":1,"TableID":107} diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/drop_function b/pkg/sql/schemachanger/testdata/explain_verbose/drop_function new file mode 100644 index 000000000000..7b370d35b24f --- /dev/null +++ b/pkg/sql/schemachanger/testdata/explain_verbose/drop_function @@ -0,0 +1,276 @@ +/* setup */ +CREATE TABLE t( + a INT PRIMARY KEY, + b INT, + C INT, + INDEX t_idx_b(b), + INDEX t_idx_c(c) +); +CREATE SEQUENCE sq1; +CREATE VIEW v AS SELECT a FROM t; +CREATE TYPE notmyworkday AS ENUM ('Monday', 'Tuesday'); +CREATE FUNCTION f(a notmyworkday) RETURNS INT IMMUTABLE LANGUAGE SQL AS $$ + SELECT a FROM t; + SELECT b FROM t@t_idx_b; + SELECT c FROM t@t_idx_c; + SELECT a FROM v; + SELECT nextval('sq1'); +$$; +CREATE TABLE t2(a notmyworkday); + +/* test */ +EXPLAIN (ddl, verbose) DROP FUNCTION f; +---- +• Schema change plan for DROP FUNCTION ‹""›.‹""›.‹f›; +│ +├── • StatementPhase +│ │ +│ └── • Stage 1 of 1 in StatementPhase +│ │ +│ ├── • 1 element transitioning toward ABSENT +│ │ │ +│ │ └── • Function:{DescID: 109} +│ │ PUBLIC → TXN_DROPPED +│ │ +│ └── • 1 Mutation operation +│ │ +│ └── • MarkDescriptorAsSyntheticallyDropped +│ DescriptorID: 109 +│ +├── • PreCommitPhase +│ │ +│ └── • Stage 1 of 1 in PreCommitPhase +│ │ +│ ├── • 10 elements transitioning toward ABSENT +│ │ │ +│ │ ├── • Owner:{DescID: 109} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from DROPPED Function:{DescID: 109} +│ │ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ │ +│ │ │ └── • skip PUBLIC → ABSENT operations +│ │ │ rule: "skip element removal ops on descriptor drop" +│ │ │ +│ │ ├── • UserPrivileges:{DescID: 109, Name: admin} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from DROPPED Function:{DescID: 109} +│ │ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ │ +│ │ │ └── • skip PUBLIC → ABSENT operations +│ │ │ rule: "skip element removal ops on descriptor drop" +│ │ │ +│ │ ├── • UserPrivileges:{DescID: 109, Name: root} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from DROPPED Function:{DescID: 109} +│ │ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ │ +│ │ │ └── • skip PUBLIC → ABSENT operations +│ │ │ rule: "skip element removal ops on descriptor drop" +│ │ │ +│ │ ├── • Function:{DescID: 109} +│ │ │ │ TXN_DROPPED → DROPPED +│ │ │ │ +│ │ │ └── • PreviousStagePrecedence dependency from TXN_DROPPED Function:{DescID: 109} +│ │ │ rule: "descriptor TXN_DROPPED before DROPPED" +│ │ │ +│ │ ├── • ObjectParent:{DescID: 109, ReferencedDescID: 101} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ └── • Precedence dependency from DROPPED Function:{DescID: 109} +│ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ +│ │ ├── • FunctionName:{DescID: 109} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from DROPPED Function:{DescID: 109} +│ │ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ │ +│ │ │ └── • skip PUBLIC → ABSENT operations +│ │ │ rule: "skip element removal ops on descriptor drop" +│ │ │ +│ │ ├── • FunctionVolatility:{DescID: 109} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from DROPPED Function:{DescID: 109} +│ │ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ │ +│ │ │ └── • skip PUBLIC → ABSENT operations +│ │ │ rule: "skip element removal ops on descriptor drop" +│ │ │ +│ │ ├── • FunctionLeakProof:{DescID: 109} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from DROPPED Function:{DescID: 109} +│ │ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ │ +│ │ │ └── • skip PUBLIC → ABSENT operations +│ │ │ rule: "skip element removal ops on descriptor drop" +│ │ │ +│ │ ├── • FunctionNullInputBehavior:{DescID: 109} +│ │ │ │ PUBLIC → ABSENT +│ │ │ │ +│ │ │ ├── • Precedence dependency from DROPPED Function:{DescID: 109} +│ │ │ │ rule: "descriptor drop right before dependent element removal" +│ │ │ │ +│ │ │ └── • skip PUBLIC → ABSENT operations +│ │ │ rule: "skip element removal ops on descriptor drop" +│ │ │ +│ │ └── • FunctionBody:{DescID: 109} +│ │ │ PUBLIC → ABSENT +│ │ │ +│ │ └── • Precedence dependency from DROPPED Function:{DescID: 109} +│ │ rule: "descriptor drop right before dependent element removal" +│ │ +│ └── • 11 Mutation operations +│ │ +│ ├── • MarkDescriptorAsDropped +│ │ DescriptorID: 109 +│ │ +│ ├── • RemoveObjectParent +│ │ ObjectID: 109 +│ │ ParentSchemaID: 101 +│ │ +│ ├── • RemoveBackReferenceInTypes +│ │ BackReferencedDescriptorID: 109 +│ │ TypeIDs: +│ │ - 107 +│ │ - 108 +│ │ +│ ├── • RemoveBackReferencesInRelations +│ │ BackReferencedID: 109 +│ │ RelationIDs: +│ │ - 104 +│ │ - 104 +│ │ - 104 +│ │ - 106 +│ │ - 105 +│ │ +│ ├── • SetJobStateOnDescriptor +│ │ DescriptorID: 104 +│ │ Initialize: true +│ │ +│ ├── • SetJobStateOnDescriptor +│ │ DescriptorID: 105 +│ │ Initialize: true +│ │ +│ ├── • SetJobStateOnDescriptor +│ │ DescriptorID: 106 +│ │ Initialize: true +│ │ +│ ├── • SetJobStateOnDescriptor +│ │ DescriptorID: 107 +│ │ Initialize: true +│ │ +│ ├── • SetJobStateOnDescriptor +│ │ DescriptorID: 108 +│ │ Initialize: true +│ │ +│ ├── • SetJobStateOnDescriptor +│ │ DescriptorID: 109 +│ │ Initialize: true +│ │ +│ └── • CreateSchemaChangerJob +│ Authorization: +│ UserName: root +│ DescriptorIDs: +│ - 104 +│ - 105 +│ - 106 +│ - 107 +│ - 108 +│ - 109 +│ JobID: 1 +│ NonCancelable: true +│ RunningStatus: PostCommitNonRevertiblePhase stage 1 of 1 with 2 MutationType ops pending +│ Statements: +│ - statement: DROP FUNCTION f +│ redactedstatement: DROP FUNCTION ‹""›.‹""›.‹f› +│ statementtag: DROP FUNCTION +│ +└── • PostCommitNonRevertiblePhase + │ + └── • Stage 1 of 1 in PostCommitNonRevertiblePhase + │ + ├── • 1 element transitioning toward ABSENT + │ │ + │ └── • Function:{DescID: 109} + │ │ DROPPED → ABSENT + │ │ + │ └── • PreviousTransactionPrecedence dependency from DROPPED Function:{DescID: 109} + │ rule: "descriptor DROPPED in transaction before removal" + │ + └── • 9 Mutation operations + │ + ├── • LogEvent + │ Element: + │ Function: + │ functionId: 109 + │ params: + │ - class: + │ class: IN + │ name: a + │ type: + │ closedTypeIds: + │ - 107 + │ - 108 + │ type: + │ family: EnumFamily + │ oid: 100107 + │ udtMetadata: + │ arrayTypeOid: 100108 + │ returnType: + │ type: + │ family: IntFamily + │ oid: 20 + │ width: 64 + │ EventBase: + │ Authorization: + │ UserName: root + │ Statement: DROP FUNCTION ‹""›.‹""›.‹f› + │ StatementTag: DROP FUNCTION + │ TargetMetadata: + │ SourceElementID: 1 + │ SubWorkID: 1 + │ TargetStatus: 1 + │ + ├── • DeleteDescriptor + │ DescriptorID: 109 + │ + ├── • RemoveJobStateFromDescriptor + │ DescriptorID: 104 + │ JobID: 1 + │ + ├── • RemoveJobStateFromDescriptor + │ DescriptorID: 105 + │ JobID: 1 + │ + ├── • RemoveJobStateFromDescriptor + │ DescriptorID: 106 + │ JobID: 1 + │ + ├── • RemoveJobStateFromDescriptor + │ DescriptorID: 107 + │ JobID: 1 + │ + ├── • RemoveJobStateFromDescriptor + │ DescriptorID: 108 + │ JobID: 1 + │ + ├── • RemoveJobStateFromDescriptor + │ DescriptorID: 109 + │ JobID: 1 + │ + └── • UpdateSchemaChangerJob + DescriptorIDsToRemove: + - 104 + - 105 + - 106 + - 107 + - 108 + - 109 + IsNonCancelable: true + JobID: 1 + RunningStatus: all stages completed diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_with_materialized_view_dep b/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_with_materialized_view_dep index 8e3c7852b9e2..cabd6e4521ff 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_with_materialized_view_dep +++ b/pkg/sql/schemachanger/testdata/explain_verbose/drop_index_with_materialized_view_dep @@ -358,7 +358,11 @@ EXPLAIN (ddl, verbose) DROP INDEX idx CASCADE; │ │ └── • skip PUBLIC → ABSENT operations │ │ rule: "skip index dependents removal ops on relation drop" │ │ +<<<<<<< HEAD │ └── • 12 Mutation operations +======= +│ └── • 14 Mutation operations +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) │ │ │ ├── • MarkDescriptorAsDropped │ │ DescriptorID: 106 @@ -368,6 +372,16 @@ EXPLAIN (ddl, verbose) DROP INDEX idx CASCADE; │ │ RelationIDs: │ │ - 105 │ │ +<<<<<<< HEAD +======= +│ ├── • RemoveAllTableComments +│ │ TableID: 106 +│ │ +│ ├── • RemoveObjectParent +│ │ ObjectID: 106 +│ │ ParentSchemaID: 101 +│ │ +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) │ ├── • RemoveColumnDefaultExpression │ │ ColumnID: 2 │ │ TableID: 106 diff --git a/pkg/sql/schemachanger/testdata/explain_verbose/drop_table b/pkg/sql/schemachanger/testdata/explain_verbose/drop_table index 4e4b1862cef2..60b1e1bcc005 100644 --- a/pkg/sql/schemachanger/testdata/explain_verbose/drop_table +++ b/pkg/sql/schemachanger/testdata/explain_verbose/drop_table @@ -407,6 +407,7 @@ EXPLAIN (ddl, verbose) DROP TABLE db.sc.t; │ ├── • RemoveTableComment │ │ TableID: 107 │ │ +<<<<<<< HEAD │ ├── • LogEvent │ │ Element: │ │ TableComment: @@ -421,6 +422,11 @@ EXPLAIN (ddl, verbose) DROP TABLE db.sc.t; │ │ SourceElementID: 1 │ │ SubWorkID: 1 │ │ TargetStatus: 1 +======= +│ ├── • RemoveObjectParent +│ │ ObjectID: 107 +│ │ ParentSchemaID: 106 +>>>>>>> be3b07d938 (sql/schemachanger: declarative drop function) │ │ │ ├── • RemoveColumnDefaultExpression │ │ ColumnID: 3