]> granicus.if.org Git - postgresql/commitdiff
Don't try to set InvalidXid as page pruning hint
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Wed, 27 Nov 2013 20:47:16 +0000 (17:47 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Thu, 28 Nov 2013 14:54:25 +0000 (11:54 -0300)
If a transaction updates/deletes a tuple just before aborting, and a
concurrent transaction tries to prune the page concurrently, the pruner
may see HeapTupleSatisfiesVacuum return HEAPTUPLE_DELETE_IN_PROGRESS,
but a later call to HeapTupleGetUpdateXid() return InvalidXid.  This
would cause an assertion failure in development builds, but would be
otherwise Mostly Harmless.

Fix by checking whether the updater Xid is valid before trying to apply
it as page prune point.

Reported by Andres in 20131124000203.GA4403@alap2.anarazel.de

src/backend/access/heap/pruneheap.c

index c6e31542935b79089f26dbde069d4a29b71421f6..638ce26ef4ea04bc5e161e75f1606326527011c7 100644 (file)
@@ -466,13 +466,22 @@ heap_prune_chain(Relation relation, Buffer buffer, OffsetNumber rootoffnum,
                                break;
 
                        case HEAPTUPLE_DELETE_IN_PROGRESS:
+                               {
+                                       TransactionId   xmax;
+
+                                       /*
+                                        * This tuple may soon become DEAD.  Update the hint field
+                                        * so that the page is reconsidered for pruning in future.
+                                        * If there was a MultiXactId updater, and it aborted after
+                                        * HTSV checked, then we will get an invalid Xid here.
+                                        * There is no need for future pruning of the page in that
+                                        * case, so skip it.
+                                        */
+                                       xmax = HeapTupleHeaderGetUpdateXid(htup);
+                                       if (TransactionIdIsValid(xmax))
+                                               heap_prune_record_prunable(prstate, xmax);
+                               }
 
-                               /*
-                                * This tuple may soon become DEAD.  Update the hint field so
-                                * that the page is reconsidered for pruning in future.
-                                */
-                               heap_prune_record_prunable(prstate,
-                                                                                  HeapTupleHeaderGetUpdateXid(htup));
                                break;
 
                        case HEAPTUPLE_LIVE: