diff --git a/pkg/sql/logictest/testdata/logic_test/create_index b/pkg/sql/logictest/testdata/logic_test/create_index index d56648f986a9..edbab9c98345 100644 --- a/pkg/sql/logictest/testdata/logic_test/create_index +++ b/pkg/sql/logictest/testdata/logic_test/create_index @@ -233,6 +233,14 @@ CREATE INDEX "'t1-esc-index'" ON "'t1-esc'"(name) subtest resume-with-diff-tenant-resume-spans +let $schema_changer_state +SELECT value FROM information_schema.session_variables where variable='experimental_use_new_schema_changer' + +# Intentionally, disable the declarative schema changer for this +# part of the test, since we are pausing jobs intentionally below. +statement ok +SET experimental_use_new_schema_changer = 'off' + statement ok SET CLUSTER SETTING jobs.registry.interval.adopt = '50ms'; @@ -300,3 +308,7 @@ succeeded statement ok SET CLUSTER SETTING jobs.registry.interval.cancel = DEFAULT; + +# Restore the schema changer state back. +statement ok +SET experimental_use_new_schema_changer = $schema_changer_state diff --git a/pkg/sql/logictest/testdata/logic_test/drop_database b/pkg/sql/logictest/testdata/logic_test/drop_database index 7e3870c6c5e7..4b9ccd0f88a3 100644 --- a/pkg/sql/logictest/testdata/logic_test/drop_database +++ b/pkg/sql/logictest/testdata/logic_test/drop_database @@ -25,6 +25,7 @@ DROP DATABASE "foo-bar" RESTRICT statement ok DROP DATABASE "foo-bar" CASCADE +skipif config local-declarative-schema query TTT SELECT name, database_name, state FROM crdb_internal.tables WHERE name = 't' ---- @@ -38,6 +39,7 @@ postgres root NULL {} NULL system node NULL {} NULL test root NULL {} NULL +skipif config local-declarative-schema query TT SELECT job_type, status FROM [SHOW JOBS] WHERE user_name = 'root' ---- @@ -219,6 +221,7 @@ CREATE TABLE constraint_db.t2 ( statement ok DROP DATABASE constraint_db CASCADE +skipif config local-declarative-schema query TTT WITH cte AS ( SELECT job_type, description, status @@ -276,7 +279,11 @@ statement ok DROP DATABASE empty query TT -SELECT job_type, status FROM [SHOW JOBS] WHERE description LIKE '%empty%' +SELECT replace(job_type, 'NEW SCHEMA CHANGE', 'SCHEMA CHANGE'), status + FROM [SHOW JOBS] + WHERE description LIKE '%empty%' + OR job_type = 'NEW SCHEMA CHANGE' + LIMIT 1 ---- SCHEMA CHANGE succeeded diff --git a/pkg/sql/logictest/testdata/logic_test/drop_table b/pkg/sql/logictest/testdata/logic_test/drop_table index 1bf8f04f0361..121a71f8ce3e 100644 --- a/pkg/sql/logictest/testdata/logic_test/drop_table +++ b/pkg/sql/logictest/testdata/logic_test/drop_table @@ -31,7 +31,17 @@ DROP TABLE a # TODO (lucy): Update this if/when we decide to change how these jobs queued by # the startup migration are handled. query TT -SELECT job_type, status FROM [SHOW JOBS] WHERE user_name = 'root' AND (job_type = 'SCHEMA CHANGE GC' OR (job_type = 'SCHEMA CHANGE' AND description != 'updating privileges')) +SELECT replace(job_type, 'NEW SCHEMA CHANGE', 'SCHEMA CHANGE'), status + FROM [SHOW JOBS] + WHERE (user_name = 'root' OR user_name = 'node') + AND ( + job_type = 'SCHEMA CHANGE GC' + OR job_type = 'NEW SCHEMA CHANGE' + OR ( + job_type = 'SCHEMA CHANGE' + AND description != 'updating privileges' + ) + ); ---- SCHEMA CHANGE succeeded SCHEMA CHANGE succeeded diff --git a/pkg/sql/logictest/testdata/logic_test/drop_type b/pkg/sql/logictest/testdata/logic_test/drop_type index f091885ac4d0..ff04a27481fb 100644 --- a/pkg/sql/logictest/testdata/logic_test/drop_type +++ b/pkg/sql/logictest/testdata/logic_test/drop_type @@ -359,7 +359,7 @@ CREATE TYPE schema_to_drop.typ AS ENUM ('a'); CREATE TABLE t (k schema_to_drop.typ PRIMARY KEY); CREATE TABLE schema_to_drop.t (k schema_to_drop.typ PRIMARY KEY); -statement error pgcode 0A000 unimplemented: cannot drop type "test.schema_to_drop.(_)*typ" because other objects \(\[test\.public\.t\]\) still depend on it +statement error pgcode 0A000 unimplemented: cannot drop type "test.schema_to_drop.(_)?typ" because other objects \(\[test\.public\.t\]\) still depend on it DROP SCHEMA schema_to_drop CASCADE; statement ok diff --git a/pkg/sql/logictest/testdata/logic_test/event_log b/pkg/sql/logictest/testdata/logic_test/event_log index 7b7fbad1c160..5358d9f87e05 100644 --- a/pkg/sql/logictest/testdata/logic_test/event_log +++ b/pkg/sql/logictest/testdata/logic_test/event_log @@ -373,15 +373,23 @@ DROP DATABASE IF EXISTS othereventlogtest CASCADE # verify event is there, and cascading table drops are logged. query IT -SELECT "reportingID", info::JSONB - 'Timestamp' - 'DescriptorID' - 'DroppedSchemaObjects' -FROM system.eventlog -WHERE "eventType" = 'drop_database' - AND info::JSONB->>'Statement' LIKE 'DROP DATABASE eventlogtest%' - AND - (json_extract_path(info::JSONB, 'DroppedSchemaObjects') @> '["eventlogtest.public.anothertesttable", "eventlogtest.public.testtable"]' OR - json_extract_path(info::JSONB, 'DroppedSchemaObjects') @> '["eventlogtest.public.testtable", "eventlogtest.public.anothertesttable"]') +SELECT "reportingID", + (info::JSONB - 'Timestamp' - 'DescriptorID') + || ( + SELECT json_build_object( + 'DroppedSchemaObjects', + json_agg(value ORDER BY value) + ) + FROM ROWS FROM ( + json_array_elements((info::JSONB)->'DroppedSchemaObjects') + ) + ) + FROM system.eventlog + WHERE "eventType" = 'drop_database' + AND info::JSONB->>'Statement' LIKE 'DROP DATABASE eventlogtest%' + ORDER BY "timestamp"; ---- -1 {"DatabaseName": "eventlogtest", "EventType": "drop_database", "Statement": "DROP DATABASE eventlogtest CASCADE", "Tag": "DROP DATABASE", "User": "root"} +1 {"DatabaseName": "eventlogtest", "DroppedSchemaObjects": ["eventlogtest.public.anothertesttable", "eventlogtest.public.testtable"], "EventType": "drop_database", "Statement": "DROP DATABASE eventlogtest CASCADE", "Tag": "DROP DATABASE", "User": "root"} query IT SELECT "reportingID", info::JSONB - 'Timestamp' - 'DescriptorID' @@ -475,6 +483,7 @@ AND info NOT LIKE '%sql.stats.automatic_collection.enabled%' AND info NOT LIKE '%sql.defaults.vectorize%' AND info NOT LIKE '%sql.testing%' AND info NOT LIKE '%sql.defaults.experimental_distsql_planning%' +AND info NOT LIKE '%sql.defaults.experimental_new_schema_changer.enabled%' ORDER BY "timestamp", info ---- 0 1 {"ApplicationName": "$ internal-optInToDiagnosticsStatReporting", "EventType": "set_cluster_setting", "SettingName": "diagnostics.reporting.enabled", "Statement": "SET CLUSTER SETTING \"diagnostics.reporting.enabled\" = true", "Tag": "SET CLUSTER SETTING", "User": "root", "Value": "true"} diff --git a/pkg/sql/logictest/testdata/logic_test/fk b/pkg/sql/logictest/testdata/logic_test/fk index 4064510ee870..1bd036ed1bb1 100644 --- a/pkg/sql/logictest/testdata/logic_test/fk +++ b/pkg/sql/logictest/testdata/logic_test/fk @@ -999,14 +999,19 @@ DELETE FROM a WHERE id > 2 statement ok DELETE FROM b WHERE id = 2 +let $a_table_id +SELECT 'a'::REGCLASS::INT::STRING + statement ok DROP TABLE a # Check proper GC job description formatting when removing FK back-references when dropping a table (#59221). query T -SELECT description FROM [SHOW JOBS] WHERE job_type = 'SCHEMA CHANGE GC' AND description LIKE 'GC for updating table "a"%' +SELECT job_type FROM [SHOW JOBS] WHERE job_type = 'SCHEMA CHANGE GC' AND + (description LIKE 'GC for updating table "a"%' OR + description = 'GC for dropping descriptor ' || $a_table_id); ---- -GC for updating table "a" after removing constraint "fk_self_id" from table "test.public.a"; DROP TABLE test.public.a +SCHEMA CHANGE GC statement ok DROP TABLE b diff --git a/pkg/sql/logictest/testdata/logic_test/information_schema b/pkg/sql/logictest/testdata/logic_test/information_schema index cad540799fc0..cd87d92b06fb 100644 --- a/pkg/sql/logictest/testdata/logic_test/information_schema +++ b/pkg/sql/logictest/testdata/logic_test/information_schema @@ -4632,9 +4632,10 @@ subtest variables ## excluding crdb_version and session_id variables as they are generated on each ## commit/session; distsql, experimental_distsql_planning and vectorize as they -## depend on distsql and vectorization turned on/off. +## depend on distsql and vectorization turned on/off. Also excluding +## experimental_use_new_schema_changer, which can be adjusted based on the mode. query TT colnames -SELECT * FROM information_schema.session_variables where variable not in ('crdb_version', 'session_id', 'distsql', 'vectorize', 'experimental_distsql_planning') +SELECT * FROM information_schema.session_variables where variable not in ('crdb_version', 'session_id', 'distsql', 'vectorize', 'experimental_distsql_planning', 'experimental_use_new_schema_changer') ---- variable value allow_prepare_as_opt_plan off @@ -4676,7 +4677,6 @@ experimental_enable_hash_sharded_indexes off experimental_enable_implicit_column_partitioning off experimental_enable_temp_tables off experimental_enable_unique_without_index_constraints on -experimental_use_new_schema_changer off extra_float_digits 0 force_savepoint_restart off foreign_key_cascades_limit 10000 diff --git a/pkg/sql/logictest/testdata/logic_test/jobs b/pkg/sql/logictest/testdata/logic_test/jobs index 5b9749bbbde7..2eb1a043329c 100644 --- a/pkg/sql/logictest/testdata/logic_test/jobs +++ b/pkg/sql/logictest/testdata/logic_test/jobs @@ -1,3 +1,4 @@ +# LogicTest: !local-declarative-schema # 3node-tenant fails due to AUTO STATS being returned in SHOW JOBS. Changing # the cluster setting to disable auto stats doesn't work: # https://github.com/cockroachdb/cockroach/issues/47918 diff --git a/pkg/sql/logictest/testdata/logic_test/schema b/pkg/sql/logictest/testdata/logic_test/schema index 09a18368865b..cc4db963404d 100644 --- a/pkg/sql/logictest/testdata/logic_test/schema +++ b/pkg/sql/logictest/testdata/logic_test/schema @@ -423,7 +423,7 @@ CREATE TYPE privs.denied AS ENUM ('denied') statement error pq: must be owner of schema "privs" ALTER SCHEMA privs RENAME TO denied -statement error must be owner of schema \"privs\" +statement error must be owner of schema privs DROP SCHEMA privs # Test the usage privilege. diff --git a/pkg/sql/logictest/testdata/logic_test/system b/pkg/sql/logictest/testdata/logic_test/system index 8661e1beac87..2e3c12c0bf02 100644 --- a/pkg/sql/logictest/testdata/logic_test/system +++ b/pkg/sql/logictest/testdata/logic_test/system @@ -1073,6 +1073,7 @@ AND name != 'sql.stats.automatic_collection.enabled' AND name NOT LIKE '%sql.defaults.vectorize%' AND name NOT LIKE '%sql.testing%' AND name NOT LIKE '%sql.defaults.experimental_distsql_planning%' +AND name NOT LIKE '%sql.defaults.experimental_new_schema_changer.enabled%' ORDER BY name ---- cluster.secret @@ -1108,7 +1109,7 @@ SELECT name, value FROM system.settings WHERE name NOT IN ('version', 'sql.defaults.distsql', 'cluster.secret', 'sql.stats.automatic_collection.enabled', 'sql.defaults.vectorize', - 'sql.defaults.experimental_distsql_planning') + 'sql.defaults.experimental_distsql_planning', 'sql.defaults.experimental_new_schema_changer.enabled') ORDER BY name ---- diagnostics.reporting.enabled true diff --git a/pkg/sql/logictest/testdata/logic_test/views b/pkg/sql/logictest/testdata/logic_test/views index 48e360fbccce..2e96b6bcbcb9 100644 --- a/pkg/sql/logictest/testdata/logic_test/views +++ b/pkg/sql/logictest/testdata/logic_test/views @@ -1205,12 +1205,20 @@ DROP table t1nest CASCADE # Validate the objects being dropped query IT -SELECT "reportingID", info::JSONB - 'Timestamp' - 'DescriptorID' - 'CascadeDroppedViews' -FROM system.eventlog -WHERE "eventType" in ('drop_view', 'drop_table') AND -(json_extract_path(info::JSONB, 'CascadeDroppedViews') @> '["db2.public.v3nest", "db2.public.v2nest", "db2.public.v1nest"]' OR - json_extract_path(info::JSONB, 'CascadeDroppedViews') @> '["db2.public.v1nest", "db2.public.v2nest", "db2.public.v3nest"]') -ORDER BY "timestamp" DESC, info -LIMIT 1 +SELECT "reportingID", + (info::JSONB - 'Timestamp' - 'DescriptorID') + || ( + SELECT json_build_object( + 'CascadeDroppedViews', + json_agg(value ORDER BY value) + ) + FROM ROWS FROM ( + json_array_elements((info::JSONB)->'CascadeDroppedViews') + ) + ) + FROM system.eventlog + WHERE "eventType" IN ('drop_view', 'drop_table') + ORDER BY "timestamp" DESC + LIMIT 1; ---- - 1 {"EventType": "drop_table", "Statement": "DROP TABLE db2.public.t1nest CASCADE", "TableName": "db2.public.t1nest", "Tag": "DROP TABLE", "User": "root"} +1 {"CascadeDroppedViews": ["db2.public.v1nest", "db2.public.v2nest", "db2.public.v3nest"], "EventType": "drop_table", "Statement": "DROP TABLE db2.public.t1nest CASCADE", "TableName": "db2.public.t1nest", "Tag": "DROP TABLE", "User": "root"} diff --git a/pkg/sql/schemachanger/scbuild/BUILD.bazel b/pkg/sql/schemachanger/scbuild/BUILD.bazel index 452d4687cc85..ad07949f16f1 100644 --- a/pkg/sql/schemachanger/scbuild/BUILD.bazel +++ b/pkg/sql/schemachanger/scbuild/BUILD.bazel @@ -25,6 +25,7 @@ go_library( "//pkg/sql/parser", "//pkg/sql/pgwire/pgcode", "//pkg/sql/pgwire/pgerror", + "//pkg/sql/privilege", "//pkg/sql/schemachanger/scbuild/internal/scbuildstmt", "//pkg/sql/schemachanger/scpb", "//pkg/sql/schemachanger/screl", diff --git a/pkg/sql/sem/tree/BUILD.bazel b/pkg/sql/sem/tree/BUILD.bazel index b2a614beff07..ae65107e5e7a 100644 --- a/pkg/sql/sem/tree/BUILD.bazel +++ b/pkg/sql/sem/tree/BUILD.bazel @@ -85,6 +85,7 @@ go_library( "role_spec.go", "run_control.go", "schedule.go", + "schema_feature_name.go", "scrub.go", "select.go", "set.go",