Skip to content

Commit

Permalink
logictest: fixes for declarative schema changer
Browse files Browse the repository at this point in the history
This commit will do a number of fixes for logictests running
under the declarative schema changer:

1) Add support for the new authorization messages from
   the declarative schema changer.
2) Update test cases to expected different jobs based on
   declarative or legacy schema changer.
3) Exclude experimental_use_new_schema_changer from tests
   checking settings.

Release note: None
  • Loading branch information
fqazi committed Jan 29, 2022
1 parent 0cf1721 commit 2eb4d32
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 26 deletions.
12 changes: 12 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/create_index
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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
9 changes: 8 additions & 1 deletion pkg/sql/logictest/testdata/logic_test/drop_database
Original file line number Diff line number Diff line change
Expand Up @@ -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'
----
Expand All @@ -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'
----
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
12 changes: 11 additions & 1 deletion pkg/sql/logictest/testdata/logic_test/drop_table
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/drop_type
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 17 additions & 8 deletions pkg/sql/logictest/testdata/logic_test/event_log
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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"}
Expand Down
9 changes: 7 additions & 2 deletions pkg/sql/logictest/testdata/logic_test/fk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/logictest/testdata/logic_test/information_schema
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/logictest/testdata/logic_test/jobs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/schema
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/logictest/testdata/logic_test/system
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
24 changes: 16 additions & 8 deletions pkg/sql/logictest/testdata/logic_test/views
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
1 change: 1 addition & 0 deletions pkg/sql/schemachanger/scbuild/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/sem/tree/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ go_library(
"role_spec.go",
"run_control.go",
"schedule.go",
"schema_feature_name.go",
"scrub.go",
"select.go",
"set.go",
Expand Down

0 comments on commit 2eb4d32

Please sign in to comment.