Skip to content

Commit 42c63ca

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 1c4dfd1 commit 42c63ca

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/backend/access/heap/heapam.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,6 +1555,8 @@ heap_hot_search_buffer(ItemPointer tid, Relation relation, Buffer buffer,
15551555
offnum = ItemPointerGetOffsetNumber(tid);
15561556
at_chain_start = true;
15571557

1558+
heapTuple->t_self = *tid;
1559+
15581560
/* Scan through possible multiple members of HOT-chain */
15591561
for (;;)
15601562
{
@@ -1586,6 +1588,7 @@ heap_hot_search_buffer(ItemPointer tid, Relation relation, Buffer buffer,
15861588
heapTuple.t_len = ItemIdGetLength(lp);
15871589
heapTuple.t_tableOid = relation->rd_id;
15881590
heapTuple.t_self = *tid;
1591+
ItemPointerSetOffsetNumber(&heapTuple.t_self, offnum);
15891592

15901593
/*
15911594
* Shouldn't see a HEAP_ONLY tuple at chain start.

src/backend/storage/lmgr/predicate.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4204,8 +4204,8 @@ CheckForSerializableConflictIn(Relation relation, HeapTuple tuple,
42044204
SET_PREDICATELOCKTARGETTAG_TUPLE(targettag,
42054205
relation->rd_node.dbNode,
42064206
relation->rd_id,
4207-
ItemPointerGetBlockNumber(&(tuple->t_data->t_ctid)),
4208-
ItemPointerGetOffsetNumber(&(tuple->t_data->t_ctid)));
4207+
ItemPointerGetBlockNumber(&(tuple->t_self)),
4208+
ItemPointerGetOffsetNumber(&(tuple->t_self)));
42094209
CheckTargetForConflictsIn(&targettag);
42104210
}
42114211

0 commit comments

Comments
 (0)