pgsql: Fix a missed case in code for "moving average" estimate of reltu
От | Tom Lane |
---|---|
Тема | pgsql: Fix a missed case in code for "moving average" estimate of reltu |
Дата | |
Msg-id | [email protected] обсуждение исходный текст |
Список | pgsql-committers |
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. Branch ------ REL8_4_STABLE Details ------- http://git.postgresql.org/pg/commitdiff/201646d16f87f2720e337269004ae0340a695aa9 Modified Files -------------- src/backend/commands/vacuum.c | 6 +++- src/backend/commands/vacuumlazy.c | 40 ++++++++++++++++++++++++++++------- src/backend/utils/cache/relcache.c | 4 +- 3 files changed, 38 insertions(+), 12 deletions(-)
В списке pgsql-committers по дате отправления: