Commit 7537f52a authored by Heikki Linnakangas's avatar Heikki Linnakangas

Utilize the visibility map in autovacuum, too. There was an oversight in

the visibility map patch that because autovacuum always sets
VacuumStmt->freeze_min_age, visibility map was never used for autovacuum,
only for manually launched vacuums. This patch introduces a new scan_all
field to VacuumStmt, indicating explicitly whether the visibility map
should be used, or the whole relation should be scanned, to advance
relfrozenxid. Anti-wraparound vacuums still need to scan all pages.
parent 69b3383c
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.112 2008/12/03 13:05:22 heikki Exp $ * $PostgreSQL: pgsql/src/backend/commands/vacuumlazy.c,v 1.113 2008/12/04 11:42:23 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -143,7 +143,6 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt, ...@@ -143,7 +143,6 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
BlockNumber possibly_freeable; BlockNumber possibly_freeable;
PGRUsage ru0; PGRUsage ru0;
TimestampTz starttime = 0; TimestampTz starttime = 0;
bool scan_all;
pg_rusage_init(&ru0); pg_rusage_init(&ru0);
...@@ -169,15 +168,9 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt, ...@@ -169,15 +168,9 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
/* Open all indexes of the relation */ /* Open all indexes of the relation */
vac_open_indexes(onerel, RowExclusiveLock, &nindexes, &Irel); vac_open_indexes(onerel, RowExclusiveLock, &nindexes, &Irel);
vacrelstats->hasindex = (nindexes > 0); vacrelstats->hasindex = (nindexes > 0);
/* Should we use the visibility map or scan all pages? */
if (vacstmt->freeze_min_age != -1)
scan_all = true;
else
scan_all = false;
/* Do the vacuuming */ /* Do the vacuuming */
lazy_scan_heap(onerel, vacrelstats, Irel, nindexes, scan_all); lazy_scan_heap(onerel, vacrelstats, Irel, nindexes, vacstmt->scan_all);
/* Done with indexes */ /* Done with indexes */
vac_close_indexes(nindexes, Irel, NoLock); vac_close_indexes(nindexes, Irel, NoLock);
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.413 2008/11/24 08:46:03 petere Exp $ * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.414 2008/12/04 11:42:23 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2771,6 +2771,7 @@ _copyVacuumStmt(VacuumStmt *from) ...@@ -2771,6 +2771,7 @@ _copyVacuumStmt(VacuumStmt *from)
COPY_SCALAR_FIELD(analyze); COPY_SCALAR_FIELD(analyze);
COPY_SCALAR_FIELD(verbose); COPY_SCALAR_FIELD(verbose);
COPY_SCALAR_FIELD(freeze_min_age); COPY_SCALAR_FIELD(freeze_min_age);
COPY_SCALAR_FIELD(scan_all);
COPY_NODE_FIELD(relation); COPY_NODE_FIELD(relation);
COPY_NODE_FIELD(va_cols); COPY_NODE_FIELD(va_cols);
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.338 2008/11/24 08:46:03 petere Exp $ * $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.339 2008/12/04 11:42:24 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1436,6 +1436,7 @@ _equalVacuumStmt(VacuumStmt *a, VacuumStmt *b) ...@@ -1436,6 +1436,7 @@ _equalVacuumStmt(VacuumStmt *a, VacuumStmt *b)
COMPARE_SCALAR_FIELD(analyze); COMPARE_SCALAR_FIELD(analyze);
COMPARE_SCALAR_FIELD(verbose); COMPARE_SCALAR_FIELD(verbose);
COMPARE_SCALAR_FIELD(freeze_min_age); COMPARE_SCALAR_FIELD(freeze_min_age);
COMPARE_SCALAR_FIELD(scan_all);
COMPARE_NODE_FIELD(relation); COMPARE_NODE_FIELD(relation);
COMPARE_NODE_FIELD(va_cols); COMPARE_NODE_FIELD(va_cols);
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.641 2008/11/26 08:45:11 petere Exp $ * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.642 2008/12/04 11:42:24 heikki Exp $
* *
* HISTORY * HISTORY
* AUTHOR DATE MAJOR EVENT * AUTHOR DATE MAJOR EVENT
...@@ -5837,6 +5837,7 @@ VacuumStmt: VACUUM opt_full opt_freeze opt_verbose ...@@ -5837,6 +5837,7 @@ VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
n->analyze = false; n->analyze = false;
n->full = $2; n->full = $2;
n->freeze_min_age = $3 ? 0 : -1; n->freeze_min_age = $3 ? 0 : -1;
n->scan_all = $3;
n->verbose = $4; n->verbose = $4;
n->relation = NULL; n->relation = NULL;
n->va_cols = NIL; n->va_cols = NIL;
...@@ -5849,6 +5850,7 @@ VacuumStmt: VACUUM opt_full opt_freeze opt_verbose ...@@ -5849,6 +5850,7 @@ VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
n->analyze = false; n->analyze = false;
n->full = $2; n->full = $2;
n->freeze_min_age = $3 ? 0 : -1; n->freeze_min_age = $3 ? 0 : -1;
n->scan_all = $3;
n->verbose = $4; n->verbose = $4;
n->relation = $5; n->relation = $5;
n->va_cols = NIL; n->va_cols = NIL;
...@@ -5860,6 +5862,7 @@ VacuumStmt: VACUUM opt_full opt_freeze opt_verbose ...@@ -5860,6 +5862,7 @@ VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
n->vacuum = true; n->vacuum = true;
n->full = $2; n->full = $2;
n->freeze_min_age = $3 ? 0 : -1; n->freeze_min_age = $3 ? 0 : -1;
n->scan_all = $3;
n->verbose |= $4; n->verbose |= $4;
$$ = (Node *)n; $$ = (Node *)n;
} }
......
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.87 2008/11/12 10:10:32 heikki Exp $ * $PostgreSQL: pgsql/src/backend/postmaster/autovacuum.c,v 1.88 2008/12/04 11:42:24 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -2649,6 +2649,7 @@ autovacuum_do_vac_analyze(autovac_table *tab, ...@@ -2649,6 +2649,7 @@ autovacuum_do_vac_analyze(autovac_table *tab,
vacstmt.full = false; vacstmt.full = false;
vacstmt.analyze = tab->at_doanalyze; vacstmt.analyze = tab->at_doanalyze;
vacstmt.freeze_min_age = tab->at_freeze_min_age; vacstmt.freeze_min_age = tab->at_freeze_min_age;
vacstmt.scan_all = tab->at_wraparound;
vacstmt.verbose = false; vacstmt.verbose = false;
vacstmt.relation = NULL; /* not used since we pass a relid */ vacstmt.relation = NULL; /* not used since we pass a relid */
vacstmt.va_cols = NIL; vacstmt.va_cols = NIL;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.379 2008/11/24 08:46:04 petere Exp $ * $PostgreSQL: pgsql/src/include/nodes/parsenodes.h,v 1.380 2008/12/04 11:42:24 heikki Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1966,6 +1966,7 @@ typedef struct VacuumStmt ...@@ -1966,6 +1966,7 @@ typedef struct VacuumStmt
bool full; /* do FULL (non-concurrent) vacuum */ bool full; /* do FULL (non-concurrent) vacuum */
bool analyze; /* do ANALYZE step */ bool analyze; /* do ANALYZE step */
bool verbose; /* print progress info */ bool verbose; /* print progress info */
bool scan_all; /* force scan of all pages */
int freeze_min_age; /* min freeze age, or -1 to use default */ int freeze_min_age; /* min freeze age, or -1 to use default */
RangeVar *relation; /* single table to process, or NULL */ RangeVar *relation; /* single table to process, or NULL */
List *va_cols; /* list of column names, or NIL for all */ List *va_cols; /* list of column names, or NIL for all */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment