From ca4c0fbb862297bb6053970267c3a6e7a6362cca Mon Sep 17 00:00:00 2001 From: aykutbozkurt Date: Mon, 10 Jul 2023 11:30:25 +0300 Subject: [PATCH] add tests --- .../commands/create_distributed_table.c | 3 -- .../distributed/commands/dependencies.c | 8 +++- .../regress/expected/multi_schema_support.out | 47 +++++++++++++++++++ src/test/regress/sql/multi_schema_support.sql | 28 +++++++++++ 4 files changed, 82 insertions(+), 4 deletions(-) diff --git a/src/backend/distributed/commands/create_distributed_table.c b/src/backend/distributed/commands/create_distributed_table.c index 86f8037bf46..8810e6db90d 100644 --- a/src/backend/distributed/commands/create_distributed_table.c +++ b/src/backend/distributed/commands/create_distributed_table.c @@ -1316,9 +1316,6 @@ CreateCitusTable(Oid relationId, CitusTableType tableType, bool skip_validation = true; ExecuteForeignKeyCreateCommandList(originalForeignKeyRecreationCommands, skip_validation); - - /* track the creation of the distributed table in the current transaction */ - AddTableToCurrentDistObjects(relationId); } diff --git a/src/backend/distributed/commands/dependencies.c b/src/backend/distributed/commands/dependencies.c index 0dc0eb73bac..3e387f71940 100644 --- a/src/backend/distributed/commands/dependencies.c +++ b/src/backend/distributed/commands/dependencies.c @@ -162,7 +162,7 @@ ResetDistObjects(void) /* - * HasAnyDepInTxDistObjects decides if any distributed object is created in the current + * HasAnyDepInTxDistObjects decides if any object in given list is created in the current * transaction. */ bool @@ -310,6 +310,12 @@ EnsureDependenciesExistOnAllNodes(const ObjectAddress *target) */ MarkObjectDistributedViaSuperUser(dependency); } + + /* track the creation of the distributed table in the current transaction */ + if (target->classId == RelationRelationId) + { + AddTableToCurrentDistObjects(target->objectId); + } } diff --git a/src/test/regress/expected/multi_schema_support.out b/src/test/regress/expected/multi_schema_support.out index f39f5f2b1c7..1889552db46 100644 --- a/src/test/regress/expected/multi_schema_support.out +++ b/src/test/regress/expected/multi_schema_support.out @@ -1384,6 +1384,53 @@ BEGIN; ALTER SCHEMA bar RENAME TO foo; ROLLBACK; +-- verify that Citus uses current user's metadata connection to propagate table deps since sc1, which is one of the deps of table s1, is created in the same transaction. +BEGIN; + CREATE SCHEMA sc1; + CREATE SEQUENCE sc1.seq; + CREATE TABLE sc1.s1(id int default(nextval('sc1.seq'))); + SELECT create_distributed_table('sc1.s1','id'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +COMMIT; +DROP SCHEMA sc1 CASCADE; +NOTICE: drop cascades to 2 other objects +DETAIL: drop cascades to sequence sc1.seq +drop cascades to table sc1.s1 +-- verify that Citus uses current user's metadata connection to propagate table deps since seq1, which is one of the deps of table s1, is created in the same transaction. +CREATE SCHEMA sc1; +BEGIN; + CREATE SEQUENCE sc1.seq1; + CREATE TABLE sc1.s1(id int default(nextval('sc1.seq1'))); + SELECT create_distributed_table('sc1.s1','id'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +COMMIT; +DROP SCHEMA sc1 CASCADE; +NOTICE: drop cascades to 2 other objects +DETAIL: drop cascades to sequence sc1.seq1 +drop cascades to table sc1.s1 +-- verify that Citus uses superuser outside connection to propagate table deps since noneof the table's deps is created in the same transaction. +SET citus.enable_metadata_sync TO off; +CREATE SCHEMA sc1; +SET citus.enable_metadata_sync TO on; +BEGIN; + CREATE TABLE sc1.s1(id int); + SELECT create_distributed_table('sc1.s1','id'); + create_distributed_table +--------------------------------------------------------------------- + +(1 row) + +COMMIT; +DROP SCHEMA sc1 CASCADE; +NOTICE: drop cascades to table sc1.s1 -- Clean up the created schema SET client_min_messages TO WARNING; SELECT pg_identify_object_as_address(classid, objid, objsubid) FROM pg_catalog.pg_dist_object diff --git a/src/test/regress/sql/multi_schema_support.sql b/src/test/regress/sql/multi_schema_support.sql index 7ca60162ef0..21a13a9184e 100644 --- a/src/test/regress/sql/multi_schema_support.sql +++ b/src/test/regress/sql/multi_schema_support.sql @@ -983,6 +983,34 @@ BEGIN; ALTER SCHEMA bar RENAME TO foo; ROLLBACK; +-- verify that Citus uses current user's metadata connection to propagate table deps since sc1, which is one of the deps of table s1, is created in the same transaction. +BEGIN; + CREATE SCHEMA sc1; + CREATE SEQUENCE sc1.seq; + CREATE TABLE sc1.s1(id int default(nextval('sc1.seq'))); + SELECT create_distributed_table('sc1.s1','id'); +COMMIT; +DROP SCHEMA sc1 CASCADE; + +-- verify that Citus uses current user's metadata connection to propagate table deps since seq1, which is one of the deps of table s1, is created in the same transaction. +CREATE SCHEMA sc1; +BEGIN; + CREATE SEQUENCE sc1.seq1; + CREATE TABLE sc1.s1(id int default(nextval('sc1.seq1'))); + SELECT create_distributed_table('sc1.s1','id'); +COMMIT; +DROP SCHEMA sc1 CASCADE; + +-- verify that Citus uses superuser outside connection to propagate table deps since noneof the table's deps is created in the same transaction. +SET citus.enable_metadata_sync TO off; +CREATE SCHEMA sc1; +SET citus.enable_metadata_sync TO on; +BEGIN; + CREATE TABLE sc1.s1(id int); + SELECT create_distributed_table('sc1.s1','id'); +COMMIT; +DROP SCHEMA sc1 CASCADE; + -- Clean up the created schema SET client_min_messages TO WARNING;