Fix thinko in previous patch to always update pg_class.reltuples/relpages.
authorTom Lane <[email protected]>
Sun, 19 Jun 2011 18:01:05 +0000 (14:01 -0400)
committerTom Lane <[email protected]>
Sun, 19 Jun 2011 18:01:05 +0000 (14:01 -0400)
I mis-simplified the test where ANALYZE decided if it could get away
without doing anything: under the new regime, that's never allowed.  Per
bug #6068 from Jeff Janes.  Back-patch to 8.4, just like previous patch.

src/backend/commands/analyze.c

index 16169788576a479157900f9475c80c9744db0e1f..1e77752118c3eda3f97239b73c4e6b12de12c18a 100644 (file)
@@ -114,7 +114,6 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt, BufferAccessStrategy bstrategy)
        Relation   *Irel;
        int                     nindexes;
        bool            hasindex;
-       bool            analyzableindex;
        VacAttrStats **vacattrstats;
        AnlIndexData *indexdata;
        int                     targrows,
@@ -300,7 +299,6 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt, BufferAccessStrategy bstrategy)
        vac_open_indexes(onerel, AccessShareLock, &nindexes, &Irel);
        hasindex = (nindexes > 0);
        indexdata = NULL;
-       analyzableindex = false;
        if (hasindex)
        {
                indexdata = (AnlIndexData *) palloc0(nindexes * sizeof(AnlIndexData));
@@ -347,10 +345,7 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt, BufferAccessStrategy bstrategy)
                                                thisdata->vacattrstats[tcnt] =
                                                        examine_attribute(Irel[ind], i + 1);
                                                if (thisdata->vacattrstats[tcnt] != NULL)
-                                               {
                                                        tcnt++;
-                                                       analyzableindex = true;
-                                               }
                                        }
                                }
                                thisdata->attr_cnt = tcnt;
@@ -358,16 +353,11 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt, BufferAccessStrategy bstrategy)
                }
        }
 
-       /*
-        * Quit if no analyzable columns.
-        */
-       if (attr_cnt <= 0 && !analyzableindex)
-               goto cleanup;
-
        /*
         * Determine how many rows we need to sample, using the worst case from
         * all analyzable columns.      We use a lower bound of 100 rows to avoid
-        * possible overflow in Vitter's algorithm.
+        * possible overflow in Vitter's algorithm.  (Note: that will also be
+        * the target in the corner case where there are no analyzable columns.)
         */
        targrows = 100;
        for (i = 0; i < attr_cnt; i++)
@@ -477,9 +467,6 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt, BufferAccessStrategy bstrategy)
                }
        }
 
-       /* We skip to here if there were no analyzable columns */
-cleanup:
-
        /* If this isn't part of VACUUM ANALYZE, let index AMs do cleanup */
        if (!vacstmt->vacuum)
        {