Utilize the visibility map in autovacuum, too. There was an oversight in
authorHeikki Linnakangas <heikki@enterprisedb.com>
Thu, 4 Dec 2008 11:42:24 +0000 (11:42 +0000)
committerHeikki Linnakangas <heikki@enterprisedb.com>
Thu, 4 Dec 2008 11:42:24 +0000 (11:42 +0000)
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.

src/backend/commands/vacuumlazy.c
src/backend/nodes/copyfuncs.c
src/backend/nodes/equalfuncs.c
src/backend/parser/gram.y
src/backend/postmaster/autovacuum.c
src/include/nodes/parsenodes.h

index fd2429a3dfe4a492847ea167055e9a8ca497063e..475c38a8d04bb77b9963ea749aafb3720dabaa8b 100644 (file)
@@ -143,7 +143,6 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
        BlockNumber possibly_freeable;
        PGRUsage        ru0;
        TimestampTz starttime = 0;
-       bool            scan_all;
 
        pg_rusage_init(&ru0);
 
@@ -169,15 +168,9 @@ lazy_vacuum_rel(Relation onerel, VacuumStmt *vacstmt,
        /* Open all indexes of the relation */
        vac_open_indexes(onerel, RowExclusiveLock, &nindexes, &Irel);
        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 */
-       lazy_scan_heap(onerel, vacrelstats, Irel, nindexes, scan_all);
+       lazy_scan_heap(onerel, vacrelstats, Irel, nindexes, vacstmt->scan_all);
 
        /* Done with indexes */
        vac_close_indexes(nindexes, Irel, NoLock);
index eb7ab4d666a0611feb3df5d4d4e1e5f8aa6c974e..c7751fc391b8992e24e15fa984ebe4219094a8c0 100644 (file)
@@ -2771,6 +2771,7 @@ _copyVacuumStmt(VacuumStmt *from)
        COPY_SCALAR_FIELD(analyze);
        COPY_SCALAR_FIELD(verbose);
        COPY_SCALAR_FIELD(freeze_min_age);
+       COPY_SCALAR_FIELD(scan_all);
        COPY_NODE_FIELD(relation);
        COPY_NODE_FIELD(va_cols);
 
index d4c57bbacfb56a8b7c2838704d6b451e9504927c..86a032ffbd2ccd4e8c39752409d9e331c5fbb5a9 100644 (file)
@@ -1436,6 +1436,7 @@ _equalVacuumStmt(VacuumStmt *a, VacuumStmt *b)
        COMPARE_SCALAR_FIELD(analyze);
        COMPARE_SCALAR_FIELD(verbose);
        COMPARE_SCALAR_FIELD(freeze_min_age);
+       COMPARE_SCALAR_FIELD(scan_all);
        COMPARE_NODE_FIELD(relation);
        COMPARE_NODE_FIELD(va_cols);
 
index 85f4616878728a918b8133599794f6707785f75f..1aab75c4138f073b195a5fc1ec3be33716e676ec 100644 (file)
@@ -5837,6 +5837,7 @@ VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
                                        n->analyze = false;
                                        n->full = $2;
                                        n->freeze_min_age = $3 ? 0 : -1;
+                                       n->scan_all = $3;
                                        n->verbose = $4;
                                        n->relation = NULL;
                                        n->va_cols = NIL;
@@ -5849,6 +5850,7 @@ VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
                                        n->analyze = false;
                                        n->full = $2;
                                        n->freeze_min_age = $3 ? 0 : -1;
+                                       n->scan_all = $3;
                                        n->verbose = $4;
                                        n->relation = $5;
                                        n->va_cols = NIL;
@@ -5860,6 +5862,7 @@ VacuumStmt: VACUUM opt_full opt_freeze opt_verbose
                                        n->vacuum = true;
                                        n->full = $2;
                                        n->freeze_min_age = $3 ? 0 : -1;
+                                       n->scan_all = $3;
                                        n->verbose |= $4;
                                        $$ = (Node *)n;
                                }
index 8d8947f36ed1d55b350e48b8b728cec6b753887c..2c68779b2354aed3734575f5d763e815b1e7995e 100644 (file)
@@ -2649,6 +2649,7 @@ autovacuum_do_vac_analyze(autovac_table *tab,
        vacstmt.full = false;
        vacstmt.analyze = tab->at_doanalyze;
        vacstmt.freeze_min_age = tab->at_freeze_min_age;
+       vacstmt.scan_all = tab->at_wraparound;
        vacstmt.verbose = false;
        vacstmt.relation = NULL;        /* not used since we pass a relid */
        vacstmt.va_cols = NIL;
index bb71ac199daeebbeb5beb73fb04fa3145717beb0..df19f7ee8f646d360f2a9b0898f2fd10de5ad08e 100644 (file)
@@ -1966,6 +1966,7 @@ typedef struct VacuumStmt
        bool            full;                   /* do FULL (non-concurrent) vacuum */
        bool            analyze;                /* do ANALYZE step */
        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 */
        RangeVar   *relation;           /* single table to process, or NULL */
        List       *va_cols;            /* list of column names, or NIL for all */