From: Tom Lane Date: Tue, 22 May 2012 23:42:05 +0000 (-0400) Subject: Ensure that seqscans check for interrupts at least once per page. X-Git-Tag: REL9_2_BETA2~43 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ed962fd712bbc0836437c8f789d9152aca5711b5;p=postgresql Ensure that seqscans check for interrupts at least once per page. 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. --- diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c index 0d6fe3f0ac..0c67156390 100644 --- a/src/backend/access/heap/heapam.c +++ b/src/backend/access/heap/heapam.c @@ -222,6 +222,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);