Skip to content

Commit 81fbbfe

Browse files
committed
Fix bugs in SSI tuple locking.
1. In heap_hot_search_buffer(), the PredicateLockTuple() call is passed wrong offset number. heapTuple->t_self is set to the tid of the first tuple in the chain that's visited, not the one actually being read. 2. CheckForSerializableConflictIn() uses the tuple's t_ctid field instead of t_self to check for exiting predicate locks on the tuple. If the tuple was updated, but the updater rolled back, t_ctid points to the aborted dead tuple. Reported by Hannu Krosing. Backpatch to 9.1.
1 parent 0b109c8 commit 81fbbfe

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/backend/access/heap/heapam.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -1688,6 +1688,8 @@ heap_hot_search_buffer(ItemPointer tid, Relation relation, Buffer buffer,
16881688
at_chain_start = first_call;
16891689
skip = !first_call;
16901690

1691+
heapTuple->t_self = *tid;
1692+
16911693
/* Scan through possible multiple members of HOT-chain */
16921694
for (;;)
16931695
{
@@ -1717,7 +1719,7 @@ heap_hot_search_buffer(ItemPointer tid, Relation relation, Buffer buffer,
17171719
heapTuple->t_data = (HeapTupleHeader) PageGetItem(dp, lp);
17181720
heapTuple->t_len = ItemIdGetLength(lp);
17191721
heapTuple->t_tableOid = RelationGetRelid(relation);
1720-
heapTuple->t_self = *tid;
1722+
ItemPointerSetOffsetNumber(&heapTuple->t_self, offnum);
17211723

17221724
/*
17231725
* Shouldn't see a HEAP_ONLY tuple at chain start.

src/backend/storage/lmgr/predicate.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -4279,8 +4279,8 @@ CheckForSerializableConflictIn(Relation relation, HeapTuple tuple,
42794279
SET_PREDICATELOCKTARGETTAG_TUPLE(targettag,
42804280
relation->rd_node.dbNode,
42814281
relation->rd_id,
4282-
ItemPointerGetBlockNumber(&(tuple->t_data->t_ctid)),
4283-
ItemPointerGetOffsetNumber(&(tuple->t_data->t_ctid)));
4282+
ItemPointerGetBlockNumber(&(tuple->t_self)),
4283+
ItemPointerGetOffsetNumber(&(tuple->t_self)));
42844284
CheckTargetForConflictsIn(&targettag);
42854285
}
42864286

0 commit comments

Comments
 (0)