aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/cache
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2011-08-30 14:49:52 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2011-08-30 14:49:52 -0400
commit030cdaf7fb90decfd7f959aa0d67d19b5669f458 (patch)
tree2ee3ce8301c9bfd5c6cbd7448eef3e163205b5f8 /src/backend/utils/cache
parent579577320ef449442f804043a67ce5c13d679679 (diff)
downloadpostgresql-030cdaf7fb90decfd7f959aa0d67d19b5669f458.tar.gz
postgresql-030cdaf7fb90decfd7f959aa0d67d19b5669f458.zip
Fix a missed case in code for "moving average" estimate of reltuples.
It is possible for VACUUM to scan no pages at all, if the visibility map shows that all pages are all-visible. In this situation VACUUM has no new information to report about the relation's tuple density, so it wasn't changing pg_class.reltuples ... but it updated pg_class.relpages anyway. That's wrong in general, since there is no evidence to justify changing the density ratio reltuples/relpages, but it's particularly bad if the previous state was relpages=reltuples=0, which means "unknown tuple density". We just replaced "unknown" with "zero". ANALYZE would eventually recover from this, but it could take a lot of repetitions of ANALYZE to do so if the relation size is much larger than the maximum number of pages ANALYZE will scan, because of the moving-average behavior introduced by commit b4b6923e03f4d29636a94f6f4cc2f5cf6298b8c8. The only known situation where we could have relpages=reltuples=0 and yet the visibility map asserts everything's visible is immediately following a pg_upgrade. It might be advisable for pg_upgrade to try to preserve the relpages/reltuples statistics; but in any case this code is wrong on its own terms, so fix it. Per report from Sergey Koposov. Back-patch to 8.4, where the visibility map was introduced, same as the previous change.
Diffstat (limited to 'src/backend/utils/cache')
-rw-r--r--src/backend/utils/cache/relcache.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c
index 2d1fee26ed8..6026599a9bc 100644
--- a/src/backend/utils/cache/relcache.c
+++ b/src/backend/utils/cache/relcache.c
@@ -1415,8 +1415,8 @@ formrdesc(const char *relationName, Oid relationReltype,
/* formrdesc is used only for permanent relations */
relation->rd_rel->relpersistence = RELPERSISTENCE_PERMANENT;
- relation->rd_rel->relpages = 1;
- relation->rd_rel->reltuples = 1;
+ relation->rd_rel->relpages = 0;
+ relation->rd_rel->reltuples = 0;
relation->rd_rel->relkind = RELKIND_RELATION;
relation->rd_rel->relhasoids = hasoids;
relation->rd_rel->relnatts = (int16) natts;