29
29
*
30
30
*
31
31
* IDENTIFICATION
32
- * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.117 2009/01/16 13:27:23 heikki Exp $
32
+ * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.118 2009/01/22 19:25:00 heikki Exp $
33
33
*
34
34
*-------------------------------------------------------------------------
35
35
*/
74
74
*/
75
75
#define LAZY_ALLOC_TUPLES MaxHeapTuplesPerPage
76
76
77
+ /*
78
+ * Before we consider skipping a page that's marked as clean in
79
+ * visibility map, we must've seen at least this many clean pages.
80
+ */
81
+ #define SKIP_PAGES_THRESHOLD 32
82
+
77
83
typedef struct LVRelStats
78
84
{
79
85
/* hasindex = true means two-pass strategy; false means one-pass */
@@ -271,6 +277,7 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
271
277
int i ;
272
278
PGRUsage ru0 ;
273
279
Buffer vmbuffer = InvalidBuffer ;
280
+ BlockNumber all_visible_streak ;
274
281
275
282
pg_rusage_init (& ru0 );
276
283
@@ -292,6 +299,7 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
292
299
293
300
lazy_space_alloc (vacrelstats , nblocks );
294
301
302
+ all_visible_streak = 0 ;
295
303
for (blkno = 0 ; blkno < nblocks ; blkno ++ )
296
304
{
297
305
Buffer buf ;
@@ -309,17 +317,30 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
309
317
310
318
/*
311
319
* Skip pages that don't require vacuuming according to the
312
- * visibility map.
320
+ * visibility map. But only if we've seen a streak of at least
321
+ * SKIP_PAGES_THRESHOLD pages marked as clean. Since we're reading
322
+ * sequentially, the OS should be doing readahead for us and there's
323
+ * no gain in skipping a page now and then. You need a longer run of
324
+ * consecutive skipped pages before it's worthwhile. Also, skipping
325
+ * even a single page means that we can't update relfrozenxid or
326
+ * reltuples, so we only want to do it if there's a good chance to
327
+ * skip a goodly number of pages.
313
328
*/
314
329
if (!scan_all )
315
330
{
316
331
all_visible_according_to_vm =
317
332
visibilitymap_test (onerel , blkno , & vmbuffer );
318
333
if (all_visible_according_to_vm )
319
334
{
320
- vacrelstats -> scanned_all = false;
321
- continue ;
335
+ all_visible_streak ++ ;
336
+ if (all_visible_streak >= SKIP_PAGES_THRESHOLD )
337
+ {
338
+ vacrelstats -> scanned_all = false;
339
+ continue ;
340
+ }
322
341
}
342
+ else
343
+ all_visible_streak = 0 ;
323
344
}
324
345
325
346
vacuum_delay_point ();
0 commit comments