diff options
author | Robert Haas <rhaas@postgresql.org> | 2017-01-04 14:36:34 -0500 |
---|---|---|
committer | Robert Haas <rhaas@postgresql.org> | 2017-01-04 14:36:34 -0500 |
commit | f1b4c771ea74f42447dccaed42ffcdcccf3aa694 (patch) | |
tree | f1e7aa7a4b767602ff57b30dbcb459a7c86d1da5 /src/backend/executor/nodeModifyTable.c | |
parent | 3e353a7bc2dd6a9edfffe7e045c810b421f7ecc4 (diff) | |
download | postgresql-f1b4c771ea74f42447dccaed42ffcdcccf3aa694.tar.gz postgresql-f1b4c771ea74f42447dccaed42ffcdcccf3aa694.zip |
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
Diffstat (limited to 'src/backend/executor/nodeModifyTable.c')
-rw-r--r-- | src/backend/executor/nodeModifyTable.c | 15 |
1 files changed, 6 insertions, 9 deletions
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 |