From f1b4c771ea74f42447dccaed42ffcdcccf3aa694 Mon Sep 17 00:00:00 2001 From: Robert Haas Date: Wed, 4 Jan 2017 14:36:34 -0500 Subject: Fix reporting of constraint violations for table partitioning. After a tuple is routed to a partition, it has been converted from the root table's row type to the partition's row type. ExecConstraints needs to report the failure using the original tuple and the parent's tuple descriptor rather than the ones for the selected partition. Amit Langote --- src/backend/executor/nodeModifyTable.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/backend/executor/nodeModifyTable.c') diff --git a/src/backend/executor/nodeModifyTable.c b/src/backend/executor/nodeModifyTable.c index aa364707f8d..4692427e600 100644 --- a/src/backend/executor/nodeModifyTable.c +++ b/src/backend/executor/nodeModifyTable.c @@ -262,7 +262,7 @@ ExecInsert(ModifyTableState *mtstate, Relation resultRelationDesc; Oid newId; List *recheckIndexes = NIL; - TupleTableSlot *oldslot = NULL; + TupleTableSlot *oldslot = slot; /* * get the heap tuple out of the tuple table slot, making sure we have a @@ -328,7 +328,6 @@ ExecInsert(ModifyTableState *mtstate, * point on, until we're finished dealing with the partition. * Use the dedicated slot for that. */ - oldslot = slot; slot = mtstate->mt_partition_tuple_slot; Assert(slot != NULL); ExecSetSlotDescriptor(slot, RelationGetDescr(partrel)); @@ -434,7 +433,7 @@ ExecInsert(ModifyTableState *mtstate, * Check the constraints of the tuple */ if (resultRelationDesc->rd_att->constr || resultRelInfo->ri_PartitionCheck) - ExecConstraints(resultRelInfo, slot, estate); + ExecConstraints(resultRelInfo, slot, oldslot, estate); if (onconflict != ONCONFLICT_NONE && resultRelInfo->ri_NumIndices > 0) { @@ -579,10 +578,6 @@ ExecInsert(ModifyTableState *mtstate, { resultRelInfo = saved_resultRelInfo; estate->es_result_relation_info = resultRelInfo; - - /* Switch back to the slot corresponding to the root table */ - Assert(oldslot != NULL); - slot = oldslot; } /* @@ -994,10 +989,12 @@ lreplace:; resultRelInfo, slot, estate); /* - * Check the constraints of the tuple + * Check the constraints of the tuple. Note that we pass the same + * slot for the orig_slot argument, because unlike ExecInsert(), no + * tuple-routing is performed here, hence the slot remains unchanged. */ if (resultRelationDesc->rd_att->constr || resultRelInfo->ri_PartitionCheck) - ExecConstraints(resultRelInfo, slot, estate); + ExecConstraints(resultRelInfo, slot, slot, estate); /* * replace the heap tuple -- cgit v1.2.3