1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-30 21:42:05 +03:00

Allow using the updated tuple while moving it to a different partition.

An update that causes the tuple to be moved to a different partition was
missing out on re-constructing the to-be-updated tuple, based on the latest
tuple in the update chain.  Instead, it's simply deleting the latest tuple
and inserting a new tuple in the new partition based on the old tuple.
Commit 2f17844104 didn't consider this case, so some of the updates were
getting lost.

In passing, change the argument order for output parameter in ExecDelete
and add some commentary about it.

Reported-by: Pavan Deolasee
Author: Amit Khandekar, with minor changes by me
Reviewed-by: Dilip Kumar, Amit Kapila and Alvaro Herrera
Backpatch-through: 11
Discussion: https://postgr.es/m/CAJ3gD9fRbEzDqdeDq1jxqZUb47kJn+tQ7=Bcgjc8quqKsDViKQ@mail.gmail.com
This commit is contained in:
Amit Kapila
2018-07-12 12:51:39 +05:30
parent edc6b41bd4
commit 40ca70ebcc
7 changed files with 213 additions and 22 deletions

View File

@ -2726,11 +2726,19 @@ ExecASDeleteTriggers(EState *estate, ResultRelInfo *relinfo,
false, NULL, NULL, NIL, NULL, transition_capture);
}
/*
* Execute BEFORE ROW DELETE triggers.
*
* True indicates caller can proceed with the delete. False indicates caller
* need to suppress the delete and additionally if requested, we need to pass
* back the concurrently updated tuple if any.
*/
bool
ExecBRDeleteTriggers(EState *estate, EPQState *epqstate,
ResultRelInfo *relinfo,
ItemPointer tupleid,
HeapTuple fdw_trigtuple)
HeapTuple fdw_trigtuple,
TupleTableSlot **epqslot)
{
TriggerDesc *trigdesc = relinfo->ri_TrigDesc;
bool result = true;
@ -2747,6 +2755,18 @@ ExecBRDeleteTriggers(EState *estate, EPQState *epqstate,
LockTupleExclusive, &newSlot);
if (trigtuple == NULL)
return false;
/*
* If the tuple was concurrently updated and the caller of this
* function requested for the updated tuple, skip the trigger
* execution.
*/
if (newSlot != NULL && epqslot != NULL)
{
*epqslot = newSlot;
heap_freetuple(trigtuple);
return false;
}
}
else
trigtuple = fdw_trigtuple;