]> granicus.if.org Git - postgresql/commitdiff
Ensure that seqscans check for interrupts at least once per page.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 22 May 2012 23:42:12 +0000 (19:42 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 22 May 2012 23:42:12 +0000 (19:42 -0400)
If a seqscan encounters many consecutive pages containing only dead tuples,
it can remain in the loop in heapgettup for a long time, and there was no
CHECK_FOR_INTERRUPTS anywhere in that loop.  This meant there were
real-world situations where a query would be effectively uncancelable for
long stretches.  Add a check placed to occur once per page, which should be
enough to provide reasonable response time without adding any measurable
overhead.

Report and patch by Merlin Moncure (though I tweaked it a bit).
Back-patch to all supported branches.

src/backend/access/heap/heapam.c

index cc8b45fd489410e2b1e6e16b5235bd7378949eb0..197067d4a1dac9f9993ecd4b716daa8b8045c1e6 100644 (file)
@@ -219,6 +219,13 @@ heapgetpage(HeapScanDesc scan, BlockNumber page)
                scan->rs_cbuf = InvalidBuffer;
        }
 
+       /*
+        * Be sure to check for interrupts at least once per page.  Checks at
+        * higher code levels won't be able to stop a seqscan that encounters
+        * many pages' worth of consecutive dead tuples.
+        */
+       CHECK_FOR_INTERRUPTS();
+
        /* read page using selected strategy */
        scan->rs_cbuf = ReadBufferExtended(scan->rs_rd, MAIN_FORKNUM, page,
                                                                           RBM_NORMAL, scan->rs_strategy);