From 51ab536eededa7113f18fc533a3ea38c12849a60 Mon Sep 17 00:00:00 2001 From: Onur Tirtir Date: Thu, 24 Dec 2020 17:10:15 +0300 Subject: [PATCH] Consider fkey graph invalidations due to CREATE TABLE cmds too --- .../distributed/commands/utility_hook.c | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/backend/distributed/commands/utility_hook.c b/src/backend/distributed/commands/utility_hook.c index 13be409a4..bf46d2bc8 100644 --- a/src/backend/distributed/commands/utility_hook.c +++ b/src/backend/distributed/commands/utility_hook.c @@ -524,6 +524,24 @@ multi_ProcessUtility(PlannedStmt *pstmt, /* * Post process for ddl statements */ + + if (IsA(parsetree, CreateStmt)) + { + CreateStmt *createStatement = (CreateStmt *) parsetree; + + PostprocessCreateTableStmt(createStatement, queryString); + } + + /* + * Re-forming the foreign key graph relies on the command being executed + * on the local table first. However, in order to decide whether the + * command leads to an invalidation, we need to check before the command + * is being executed since we read pg_constraint table. Thus, we maintain a + * local flag and do the invalidation after multi_ProcessUtility, + * before ExecuteDistributedDDLJob(). + */ + InvalidateForeignKeyGraphForDDL(); + if (EnableDDLPropagation) { if (ops && ops->postprocess) @@ -547,13 +565,6 @@ multi_ProcessUtility(PlannedStmt *pstmt, } } - if (IsA(parsetree, CreateStmt)) - { - CreateStmt *createStatement = (CreateStmt *) parsetree; - - PostprocessCreateTableStmt(createStatement, queryString); - } - /* * We only process ALTER TABLE ... ATTACH PARTITION commands in the function below * and distribute the partition if necessary. @@ -890,16 +901,6 @@ static void PostStandardProcessUtility(Node *parsetree) { DecrementUtilityHookCountersIfNecessary(parsetree); - - /* - * Re-forming the foreign key graph relies on the command being executed - * on the local table first. However, in order to decide whether the - * command leads to an invalidation, we need to check before the command - * is being executed since we read pg_constraint table. Thus, we maintain a - * local flag and do the invalidation after multi_ProcessUtility, - * before ExecuteDistributedDDLJob(). - */ - InvalidateForeignKeyGraphForDDL(); }