diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/executor/execPartition.c | 19 | ||||
-rw-r--r-- | src/backend/executor/nodeModifyTable.c | 14 |
2 files changed, 20 insertions, 13 deletions
diff --git a/src/backend/executor/execPartition.c b/src/backend/executor/execPartition.c index b2ee92eb155..954a96c6966 100644 --- a/src/backend/executor/execPartition.c +++ b/src/backend/executor/execPartition.c @@ -333,6 +333,13 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, estate->es_instrument); /* + * Verify result relation is a valid target for an INSERT. An UPDATE of a + * partition-key becomes a DELETE+INSERT operation, so this check is still + * required when the operation is CMD_UPDATE. + */ + CheckValidResultRel(leaf_part_rri, CMD_INSERT); + + /* * Since we've just initialized this ResultRelInfo, it's not in any list * attached to the estate as yet. Add it, so that it can be found later. * @@ -344,9 +351,6 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, lappend(estate->es_tuple_routing_result_relations, leaf_part_rri); - /* Set up information needed for routing tuples to this partition. */ - ExecInitRoutingInfo(mtstate, estate, proute, leaf_part_rri, partidx); - /* * Open partition indices. The user may have asked to check for conflicts * within this leaf partition and do "nothing" instead of throwing an @@ -489,6 +493,9 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, &mtstate->ps, RelationGetDescr(partrel)); } + /* Set up information needed for routing tuples to the partition. */ + ExecInitRoutingInfo(mtstate, estate, proute, leaf_part_rri, partidx); + /* * If there is an ON CONFLICT clause, initialize state for it. */ @@ -655,8 +662,7 @@ ExecInitPartitionInfo(ModifyTableState *mtstate, /* * ExecInitRoutingInfo - * Set up information needed for routing tuples to a leaf partition if - * routable; else abort the operation + * Set up information needed for routing tuples to a leaf partition */ void ExecInitRoutingInfo(ModifyTableState *mtstate, @@ -667,9 +673,6 @@ ExecInitRoutingInfo(ModifyTableState *mtstate, { MemoryContext oldContext; - /* Verify the partition is a valid target for INSERT */ - CheckValidResultRel(partRelInfo, CMD_INSERT); - /* * Switch into per-query memory context. */ diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index f6482f8411b..71314e73bcf 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -1700,20 +1700,24 @@ ExecPrepareTupleRouting(ModifyTableState *mtstate, partidx); /* - * Set up information needed for routing tuples to the partition if we - * didn't yet (ExecInitRoutingInfo would abort the operation if the - * partition isn't routable). + * Check whether the partition is routable if we didn't yet * * Note: an UPDATE of a partition key invokes an INSERT that moves the - * tuple to a new partition. This setup would be needed for a subplan + * tuple to a new partition. This check would be applied to a subplan * partition of such an UPDATE that is chosen as the partition to route - * the tuple to. The reason we do this setup here rather than in + * the tuple to. The reason we do this check here rather than in * ExecSetupPartitionTupleRouting is to avoid aborting such an UPDATE * unnecessarily due to non-routable subplan partitions that may not be * chosen for update tuple movement after all. */ if (!partrel->ri_PartitionReadyForRouting) + { + /* Verify the partition is a valid target for INSERT. */ + CheckValidResultRel(partrel, CMD_INSERT); + + /* Set up information needed for routing tuples to the partition. */ ExecInitRoutingInfo(mtstate, estate, proute, partrel, partidx); + } /* * Make it look like we are inserting into the partition. |