Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bf136cf

Browse files
committed
Only skip pages marked as clean in the visibility map, if the last 32
pages were marked as clean as well. The idea is to avoid defeating OS readahead by skipping a page here and there, and also makes it less likely that we miss an opportunity to advance relfrozenxid, for the sake of only a few skipped pages.
1 parent c079090 commit bf136cf

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/backend/commands/vacuumlazy.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*
3030
*
3131
* 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 $
3333
*
3434
*-------------------------------------------------------------------------
3535
*/
@@ -74,6 +74,12 @@
7474
*/
7575
#define LAZY_ALLOC_TUPLES MaxHeapTuplesPerPage
7676

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+
7783
typedef struct LVRelStats
7884
{
7985
/* hasindex = true means two-pass strategy; false means one-pass */
@@ -271,6 +277,7 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
271277
int i;
272278
PGRUsage ru0;
273279
Buffer vmbuffer = InvalidBuffer;
280+
BlockNumber all_visible_streak;
274281

275282
pg_rusage_init(&ru0);
276283

@@ -292,6 +299,7 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
292299

293300
lazy_space_alloc(vacrelstats, nblocks);
294301

302+
all_visible_streak = 0;
295303
for (blkno = 0; blkno < nblocks; blkno++)
296304
{
297305
Buffer buf;
@@ -309,17 +317,30 @@ lazy_scan_heap(Relation onerel, LVRelStats *vacrelstats,
309317

310318
/*
311319
* 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.
313328
*/
314329
if (!scan_all)
315330
{
316331
all_visible_according_to_vm =
317332
visibilitymap_test(onerel, blkno, &vmbuffer);
318333
if (all_visible_according_to_vm)
319334
{
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+
}
322341
}
342+
else
343+
all_visible_streak = 0;
323344
}
324345

325346
vacuum_delay_point();

0 commit comments

Comments
 (0)