From fc307afdc44d6e2127f6b0ba9befd0d56246d5a1 Mon Sep 17 00:00:00 2001 From: Burak Velioglu Date: Sun, 16 Jan 2022 15:42:54 +0300 Subject: [PATCH] Use function to get table command list and fix isolation test --- .../distributed/commands/dependencies.c | 52 ++++++++++++------- ...lation_ensure_dependency_activate_node.out | 32 ++++++++---- 2 files changed, 56 insertions(+), 28 deletions(-) diff --git a/src/backend/distributed/commands/dependencies.c b/src/backend/distributed/commands/dependencies.c index 1296cb1ff..156f06136 100644 --- a/src/backend/distributed/commands/dependencies.c +++ b/src/backend/distributed/commands/dependencies.c @@ -32,6 +32,7 @@ typedef bool (*AddressPredicate)(const ObjectAddress *); static int ObjectAddressComparator(const void *a, const void *b); static List * GetDependencyCreateDDLCommands(const ObjectAddress *dependency); +static List *GetCitusTableDDLCommandList(Oid relationId); static List * FilterObjectAddressListByPredicate(List *objectAddressList, AddressPredicate predicate); @@ -240,27 +241,14 @@ GetDependencyCreateDDLCommands(const ObjectAddress *dependency) relKind == RELKIND_FOREIGN_TABLE) { Oid relationId = dependency->objectId; + List *commandList = NIL; + if (IsCitusTable(relationId) && !IsTableOwnedByExtension(relationId)) { - /* skip table metadata creation when the Citus table is owned by an extension */ - List *commandList = NIL; - List *tableDDLCommands = GetFullTableCreationCommands(relationId, - WORKER_NEXTVAL_SEQUENCE_DEFAULTS); - - TableDDLCommand *tableDDLCommand = NULL; - foreach_ptr(tableDDLCommand, tableDDLCommands) - { - Assert(CitusIsA(tableDDLCommand, TableDDLCommand)); - commandList = lappend(commandList, GetTableDDLCommand( - tableDDLCommand)); - } - - List *sequenceDependencyCommandList = SequenceDependencyCommandList( - dependency->objectId); - commandList = list_concat(commandList, sequenceDependencyCommandList); - - return commandList; + commandList = GetCitusTableDDLCommandList(relationId); } + + return commandList; } if (relKind == RELKIND_SEQUENCE) @@ -351,6 +339,34 @@ GetDependencyCreateDDLCommands(const ObjectAddress *dependency) } +/* + * GetCitusTableDDLCommandList returns the list of commands to create citus table + * including the commands to associate sequences with table. + */ +static List * +GetCitusTableDDLCommandList(Oid relationId) +{ + List *commandList = NIL; + List *tableDDLCommands = GetFullTableCreationCommands(relationId, + WORKER_NEXTVAL_SEQUENCE_DEFAULTS); + + TableDDLCommand *tableDDLCommand = NULL; + foreach_ptr(tableDDLCommand, tableDDLCommands) + { + Assert(CitusIsA(tableDDLCommand, TableDDLCommand)); + commandList = lappend(commandList, GetTableDDLCommand(tableDDLCommand)); + } + + /* + * Get commands to associate sequences with dependencies + */ + List *sequenceDependencyCommandList = SequenceDependencyCommandList(relationId); + commandList = list_concat(commandList, sequenceDependencyCommandList); + + return commandList; +} + + /* * ReplicateAllDependenciesToNode replicate all previously marked objects to a worker * node. The function also sets clusterHasDistributedFunction if there are any diff --git a/src/test/regress/expected/isolation_ensure_dependency_activate_node.out b/src/test/regress/expected/isolation_ensure_dependency_activate_node.out index b137a56fb..c7d836b63 100644 --- a/src/test/regress/expected/isolation_ensure_dependency_activate_node.out +++ b/src/test/regress/expected/isolation_ensure_dependency_activate_node.out @@ -118,7 +118,8 @@ pg_identify_object_as_address (database,{regression},{}) (role,{postgres},{}) (schema,{public},{}) -(3 rows) +(table,"{public,t1}",{}) +(4 rows) count --------------------------------------------------------------------- @@ -310,7 +311,8 @@ pg_identify_object_as_address (database,{regression},{}) (role,{postgres},{}) (schema,{public},{}) -(3 rows) +(table,"{public,t1}",{}) +(4 rows) count --------------------------------------------------------------------- @@ -502,7 +504,8 @@ pg_identify_object_as_address (database,{regression},{}) (role,{postgres},{}) (schema,{public},{}) -(3 rows) +(table,"{public,t1}",{}) +(4 rows) count --------------------------------------------------------------------- @@ -690,7 +693,8 @@ pg_identify_object_as_address (role,{postgres},{}) (schema,{myschema},{}) (schema,{public},{}) -(4 rows) +(table,"{myschema,t1}",{}) +(5 rows) count --------------------------------------------------------------------- @@ -884,7 +888,8 @@ pg_identify_object_as_address (role,{postgres},{}) (schema,{myschema},{}) (schema,{public},{}) -(4 rows) +(table,"{myschema,t1}",{}) +(5 rows) count --------------------------------------------------------------------- @@ -1078,7 +1083,8 @@ pg_identify_object_as_address (role,{postgres},{}) (schema,{myschema},{}) (schema,{public},{}) -(4 rows) +(table,"{myschema,t1}",{}) +(5 rows) count --------------------------------------------------------------------- @@ -1272,7 +1278,8 @@ pg_identify_object_as_address (role,{postgres},{}) (schema,{myschema},{}) (schema,{public},{}) -(4 rows) +(table,"{myschema,t1}",{}) +(5 rows) count --------------------------------------------------------------------- @@ -1480,7 +1487,9 @@ pg_identify_object_as_address (role,{postgres},{}) (schema,{myschema},{}) (schema,{public},{}) -(4 rows) +(table,"{myschema,t1}",{}) +(table,"{myschema,t2}",{}) +(6 rows) count --------------------------------------------------------------------- @@ -1697,7 +1706,9 @@ pg_identify_object_as_address (schema,{myschema},{}) (schema,{myschema2},{}) (schema,{public},{}) -(5 rows) +(table,"{myschema,t1}",{}) +(table,"{myschema2,t2}",{}) +(7 rows) count --------------------------------------------------------------------- @@ -2251,8 +2262,9 @@ pg_identify_object_as_address (role,{postgres},{}) (schema,{myschema},{}) (schema,{public},{}) +(table,"{myschema,t1}",{}) (type,{myschema.tt1},{}) -(5 rows) +(6 rows) count ---------------------------------------------------------------------