]> granicus.if.org Git - postgresql/commitdiff
Fix bugs in SSI tuple locking.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 7 Oct 2013 20:57:40 +0000 (23:57 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Mon, 7 Oct 2013 21:04:28 +0000 (00:04 +0300)
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.

src/backend/access/heap/heapam.c
src/backend/storage/lmgr/predicate.c

index a4ab9b4e0744324903fa0082bee939a6b37a7acd..029131bee8a4c0b4604c38d18cc7625beb8fd98a 100644 (file)
@@ -1561,6 +1561,8 @@ heap_hot_search_buffer(ItemPointer tid, Relation relation, Buffer buffer,
        at_chain_start = first_call;
        skip = !first_call;
 
+       heapTuple->t_self = *tid;
+
        /* Scan through possible multiple members of HOT-chain */
        for (;;)
        {
@@ -1590,7 +1592,7 @@ heap_hot_search_buffer(ItemPointer tid, Relation relation, Buffer buffer,
                heapTuple->t_data = (HeapTupleHeader) PageGetItem(dp, lp);
                heapTuple->t_len = ItemIdGetLength(lp);
                heapTuple->t_tableOid = relation->rd_id;
-               heapTuple->t_self = *tid;
+               ItemPointerSetOffsetNumber(&heapTuple->t_self, offnum);
 
                /*
                 * Shouldn't see a HEAP_ONLY tuple at chain start.
index 776c4b9902a050b786dfbc96ca7b302fa484ff20..4e8f7cf81a7c5f9ebf12e75bcadf9eeab8d9b738 100644 (file)
@@ -4276,8 +4276,8 @@ CheckForSerializableConflictIn(Relation relation, HeapTuple tuple,
                SET_PREDICATELOCKTARGETTAG_TUPLE(targettag,
                                                                                 relation->rd_node.dbNode,
                                                                                 relation->rd_id,
-                                                ItemPointerGetBlockNumber(&(tuple->t_data->t_ctid)),
-                                               ItemPointerGetOffsetNumber(&(tuple->t_data->t_ctid)));
+                                                                 ItemPointerGetBlockNumber(&(tuple->t_self)),
+                                                               ItemPointerGetOffsetNumber(&(tuple->t_self)));
                CheckTargetForConflictsIn(&targettag);
        }