Skip to content

Commit 9037843

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 4dd5c31 commit 9037843

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/backend/access/heap/heapam.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1561,6 +1561,8 @@ heap_hot_search_buffer(ItemPointer tid, Relation relation, Buffer buffer,
15611561
at_chain_start = first_call;
15621562
skip = !first_call;
15631563

1564+
heapTuple->t_self = *tid;
1565+
15641566
/* Scan through possible multiple members of HOT-chain */
15651567
for (;;)
15661568
{
@@ -1590,7 +1592,7 @@ heap_hot_search_buffer(ItemPointer tid, Relation relation, Buffer buffer,
15901592
heapTuple->t_data = (HeapTupleHeader) PageGetItem(dp, lp);
15911593
heapTuple->t_len = ItemIdGetLength(lp);
15921594
heapTuple->t_tableOid = relation->rd_id;
1593-
heapTuple->t_self = *tid;
1595+
ItemPointerSetOffsetNumber(&heapTuple->t_self, offnum);
15941596

15951597
/*
15961598
* 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
@@ -4276,8 +4276,8 @@ CheckForSerializableConflictIn(Relation relation, HeapTuple tuple,
42764276
SET_PREDICATELOCKTARGETTAG_TUPLE(targettag,
42774277
relation->rd_node.dbNode,
42784278
relation->rd_id,
4279-
ItemPointerGetBlockNumber(&(tuple->t_data->t_ctid)),
4280-
ItemPointerGetOffsetNumber(&(tuple->t_data->t_ctid)));
4279+
ItemPointerGetBlockNumber(&(tuple->t_self)),
4280+
ItemPointerGetOffsetNumber(&(tuple->t_self)));
42814281
CheckTargetForConflictsIn(&targettag);
42824282
}
42834283

0 commit comments

Comments
 (0)