From cd5213abeee0eb56496bc79f2c22d39fcf59b680 Mon Sep 17 00:00:00 2001 From: Murat Tuncer Date: Wed, 23 Jan 2019 15:06:00 +0300 Subject: [PATCH] Set sequential mode execution GUC for alter partitioned table PG recently started propagating foreign key constraints to partition tables. This came with a select query to validate the the constaint. We are already setting sequential mode execution for this command. In order for validation select query to respect this setting we need to explicitly set the GUC. This commit also handles detach partition part. --- src/backend/distributed/commands/table.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/backend/distributed/commands/table.c b/src/backend/distributed/commands/table.c index b507c8ca5..a687931aa 100644 --- a/src/backend/distributed/commands/table.c +++ b/src/backend/distributed/commands/table.c @@ -1185,6 +1185,26 @@ SetupExecutionModeForAlterTable(Oid relationId, AlterTableCmd *command) { executeSequentially = true; } + + /* + * Postgres performs additional selects when creating constraints + * on partitioned tables. We need to set execution mode to + * sequential for the select query so that ddl connections + * we open does not fail due to previous select. + */ + if (executeSequentially && PartitionedTable(relationId)) + { + SetLocalMultiShardModifyModeToSequential(); + } + } + } + else if (alterTableType == AT_DetachPartition) + { + /* check if there are foreign constraints to reference tables */ + if (HasForeignKeyToReferenceTable(relationId)) + { + executeSequentially = true; + SetLocalMultiShardModifyModeToSequential(); } }