Fix assertions with RI triggers in heap_update and heap_delete.
If the tuple being updated is not visible to the crosscheck snapshot, we return TM_Updated but the assertions would not hold in that case. Move them to before the cross-check. Fixes bug #17893. Backpatch to all supported versions. Author: Alexander Lakhin Backpatch-through: 12 Discussion: https://www.postgresql.org/message-id/17893-35847009eec517b5%40postgresql.org
This commit is contained in:
parent
3a95d2c242
commit
59c62a21f2
@ -2918,13 +2918,7 @@ l1:
|
|||||||
result = TM_Deleted;
|
result = TM_Deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (crosscheck != InvalidSnapshot && result == TM_Ok)
|
/* sanity check the result HeapTupleSatisfiesUpdate() and the logic above */
|
||||||
{
|
|
||||||
/* Perform additional check for transaction-snapshot mode RI updates */
|
|
||||||
if (!HeapTupleSatisfiesVisibility(&tp, crosscheck, buffer))
|
|
||||||
result = TM_Updated;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result != TM_Ok)
|
if (result != TM_Ok)
|
||||||
{
|
{
|
||||||
Assert(result == TM_SelfModified ||
|
Assert(result == TM_SelfModified ||
|
||||||
@ -2934,6 +2928,17 @@ l1:
|
|||||||
Assert(!(tp.t_data->t_infomask & HEAP_XMAX_INVALID));
|
Assert(!(tp.t_data->t_infomask & HEAP_XMAX_INVALID));
|
||||||
Assert(result != TM_Updated ||
|
Assert(result != TM_Updated ||
|
||||||
!ItemPointerEquals(&tp.t_self, &tp.t_data->t_ctid));
|
!ItemPointerEquals(&tp.t_self, &tp.t_data->t_ctid));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (crosscheck != InvalidSnapshot && result == TM_Ok)
|
||||||
|
{
|
||||||
|
/* Perform additional check for transaction-snapshot mode RI updates */
|
||||||
|
if (!HeapTupleSatisfiesVisibility(&tp, crosscheck, buffer))
|
||||||
|
result = TM_Updated;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result != TM_Ok)
|
||||||
|
{
|
||||||
tmfd->ctid = tp.t_data->t_ctid;
|
tmfd->ctid = tp.t_data->t_ctid;
|
||||||
tmfd->xmax = HeapTupleHeaderGetUpdateXid(tp.t_data);
|
tmfd->xmax = HeapTupleHeaderGetUpdateXid(tp.t_data);
|
||||||
if (result == TM_SelfModified)
|
if (result == TM_SelfModified)
|
||||||
@ -3563,16 +3568,7 @@ l2:
|
|||||||
result = TM_Deleted;
|
result = TM_Deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (crosscheck != InvalidSnapshot && result == TM_Ok)
|
/* Sanity check the result HeapTupleSatisfiesUpdate() and the logic above */
|
||||||
{
|
|
||||||
/* Perform additional check for transaction-snapshot mode RI updates */
|
|
||||||
if (!HeapTupleSatisfiesVisibility(&oldtup, crosscheck, buffer))
|
|
||||||
{
|
|
||||||
result = TM_Updated;
|
|
||||||
Assert(!ItemPointerEquals(&oldtup.t_self, &oldtup.t_data->t_ctid));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result != TM_Ok)
|
if (result != TM_Ok)
|
||||||
{
|
{
|
||||||
Assert(result == TM_SelfModified ||
|
Assert(result == TM_SelfModified ||
|
||||||
@ -3582,6 +3578,17 @@ l2:
|
|||||||
Assert(!(oldtup.t_data->t_infomask & HEAP_XMAX_INVALID));
|
Assert(!(oldtup.t_data->t_infomask & HEAP_XMAX_INVALID));
|
||||||
Assert(result != TM_Updated ||
|
Assert(result != TM_Updated ||
|
||||||
!ItemPointerEquals(&oldtup.t_self, &oldtup.t_data->t_ctid));
|
!ItemPointerEquals(&oldtup.t_self, &oldtup.t_data->t_ctid));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (crosscheck != InvalidSnapshot && result == TM_Ok)
|
||||||
|
{
|
||||||
|
/* Perform additional check for transaction-snapshot mode RI updates */
|
||||||
|
if (!HeapTupleSatisfiesVisibility(&oldtup, crosscheck, buffer))
|
||||||
|
result = TM_Updated;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result != TM_Ok)
|
||||||
|
{
|
||||||
tmfd->ctid = oldtup.t_data->t_ctid;
|
tmfd->ctid = oldtup.t_data->t_ctid;
|
||||||
tmfd->xmax = HeapTupleHeaderGetUpdateXid(oldtup.t_data);
|
tmfd->xmax = HeapTupleHeaderGetUpdateXid(oldtup.t_data);
|
||||||
if (result == TM_SelfModified)
|
if (result == TM_SelfModified)
|
||||||
|
@ -1453,8 +1453,8 @@ table_multi_insert(Relation rel, TupleTableSlot **slots, int nslots,
|
|||||||
* TM_BeingModified (the last only possible if wait == false).
|
* TM_BeingModified (the last only possible if wait == false).
|
||||||
*
|
*
|
||||||
* In the failure cases, the routine fills *tmfd with the tuple's t_ctid,
|
* In the failure cases, the routine fills *tmfd with the tuple's t_ctid,
|
||||||
* t_xmax, and, if possible, and, if possible, t_cmax. See comments for
|
* t_xmax, and, if possible, t_cmax. See comments for struct
|
||||||
* struct TM_FailureData for additional info.
|
* TM_FailureData for additional info.
|
||||||
*/
|
*/
|
||||||
static inline TM_Result
|
static inline TM_Result
|
||||||
table_tuple_delete(Relation rel, ItemPointer tid, CommandId cid,
|
table_tuple_delete(Relation rel, ItemPointer tid, CommandId cid,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user