From ee502453d678c8add409a496f02605620fc4cd80 Mon Sep 17 00:00:00 2001 From: Onur Tirtir Date: Wed, 6 Jan 2021 10:44:59 +0300 Subject: [PATCH] Use InvalidateForeignKeyGraph in postprocess --- src/backend/distributed/commands/table.c | 6 ++--- .../distributed/commands/utility_hook.c | 24 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/backend/distributed/commands/table.c b/src/backend/distributed/commands/table.c index d43d88f8d..963a2250b 100644 --- a/src/backend/distributed/commands/table.c +++ b/src/backend/distributed/commands/table.c @@ -204,7 +204,7 @@ PostprocessCreateTableStmt(CreateStmt *createStatement, const char *queryString) /* invalidate foreign key cache if the table involved in any foreign key */ if ((TableReferenced(relationId) || TableReferencing(relationId))) { - MarkInvalidateForeignKeyGraph(); + InvalidateForeignKeyGraph(); } #endif @@ -263,7 +263,7 @@ PostprocessCreateTableStmtPartitionOf(CreateStmt *createStatement, const */ if ((TableReferenced(parentRelationId) || TableReferencing(parentRelationId))) { - MarkInvalidateForeignKeyGraph(); + InvalidateForeignKeyGraph(); } } @@ -353,7 +353,7 @@ PostprocessAlterTableStmtAttachPartition(AlterTableStmt *alterTableStatement, */ if ((TableReferenced(relationId) || TableReferencing(relationId))) { - MarkInvalidateForeignKeyGraph(); + InvalidateForeignKeyGraph(); } } } diff --git a/src/backend/distributed/commands/utility_hook.c b/src/backend/distributed/commands/utility_hook.c index c3275e556..c6b436d38 100644 --- a/src/backend/distributed/commands/utility_hook.c +++ b/src/backend/distributed/commands/utility_hook.c @@ -515,8 +515,6 @@ multi_ProcessUtility(PlannedStmt *pstmt, } PG_CATCH(); { - PostStandardProcessUtility(parsetree); - /* * We call MarkInvalidateForeignKeyGraph in preprocess without knowing * that if command would fail or not. However, we don't want to invalidate @@ -528,6 +526,8 @@ multi_ProcessUtility(PlannedStmt *pstmt, */ shouldInvalidateForeignKeyGraph = false; + PostStandardProcessUtility(parsetree); + PG_RE_THROW(); } PG_END_TRY(); @@ -577,16 +577,6 @@ multi_ProcessUtility(PlannedStmt *pstmt, PostprocessAlterTableStmtAttachPartition(alterTableStatement, 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(); - /* after local command has completed, finish by executing worker DDLJobs, if any */ if (ddlJobs != NIL) { @@ -912,6 +902,16 @@ 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(); }