diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2008-12-17 09:15:03 +0000 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2008-12-17 09:15:03 +0000 |
commit | dcf8409985f4db00bfb4c365792e39b70688318e (patch) | |
tree | 861a18486b7ed9b3ab02074502aa905bcaa03a8c /src/backend/commands/analyze.c | |
parent | 5a90bc1fbe829e04d319388b54b76c7a0fe36b58 (diff) | |
download | postgresql-dcf8409985f4db00bfb4c365792e39b70688318e.tar.gz postgresql-dcf8409985f4db00bfb4c365792e39b70688318e.zip |
Don't reset pg_class.reltuples and relpages in VACUUM, if any pages were
skipped. We could update relpages anyway, but it seems better to only
update it together with reltuples, because we use the reltuples/relpages
ratio in the planner. Also don't update n_live_tuples in pgstat.
ANALYZE in VACUUM ANALYZE now needs to update pg_class, if the
VACUUM-phase didn't do so. Added some boolean-passing to let analyze_rel
know if it should update pg_class or not.
I also moved the relcache invalidation (to update rd_targblock) from
vac_update_relstats to where RelationTruncate is called, because
vac_update_relstats is not called for partial vacuums anymore. It's more
obvious to send the invalidation close to the truncation that requires it.
Per report by Ned T. Crigler.
Diffstat (limited to 'src/backend/commands/analyze.c')
-rw-r--r-- | src/backend/commands/analyze.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/src/backend/commands/analyze.c b/src/backend/commands/analyze.c index 2b3af54ff05..a636720f110 100644 --- a/src/backend/commands/analyze.c +++ b/src/backend/commands/analyze.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.129 2008/12/13 19:13:44 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/commands/analyze.c,v 1.130 2008/12/17 09:15:02 heikki Exp $ * *------------------------------------------------------------------------- */ @@ -101,10 +101,18 @@ static bool std_typanalyze(VacAttrStats *stats); /* * analyze_rel() -- analyze one relation + * + * If update_reltuples is true, we update reltuples and relpages columns + * in pg_class. Caller should pass false if we're part of VACUUM ANALYZE, + * and the VACUUM didn't skip any pages. We only have an approximate count, + * so we don't want to overwrite the accurate values already inserted by the + * VACUUM in that case. VACUUM always scans all indexes, however, so the + * pg_class entries for indexes are never updated if we're part of VACUUM + * ANALYZE. */ void analyze_rel(Oid relid, VacuumStmt *vacstmt, - BufferAccessStrategy bstrategy) + BufferAccessStrategy bstrategy, bool update_reltuples) { Relation onerel; int attr_cnt, @@ -364,7 +372,7 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt, * autovacuum code doesn't go nuts trying to get stats about a * zero-column table. */ - if (!vacstmt->vacuum) + if (update_reltuples) pgstat_report_analyze(onerel, 0, 0); goto cleanup; } @@ -455,18 +463,24 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt, } /* - * If we are running a standalone ANALYZE, update pages/tuples stats in - * pg_class. We know the accurate page count from the smgr, but only an - * approximate number of tuples; therefore, if we are part of VACUUM - * ANALYZE do *not* overwrite the accurate count already inserted by - * VACUUM. The same consideration applies to indexes. + * Update pages/tuples stats in pg_class. */ - if (!vacstmt->vacuum) + if (update_reltuples) { vac_update_relstats(onerel, RelationGetNumberOfBlocks(onerel), totalrows, hasindex, InvalidTransactionId); + /* report results to the stats collector, too */ + pgstat_report_analyze(onerel, totalrows, totaldeadrows); + } + /* + * Same for indexes. Vacuum always scans all indexes, so if we're part of + * VACUUM ANALYZE, don't overwrite the accurate count already inserted by + * VACUUM. + */ + if (!vacstmt->vacuum) + { for (ind = 0; ind < nindexes; ind++) { AnlIndexData *thisdata = &indexdata[ind]; @@ -477,9 +491,6 @@ analyze_rel(Oid relid, VacuumStmt *vacstmt, RelationGetNumberOfBlocks(Irel[ind]), totalindexrows, false, InvalidTransactionId); } - - /* report results to the stats collector, too */ - pgstat_report_analyze(onerel, totalrows, totaldeadrows); } /* We skip to here if there were no analyzable columns */ |