pgsql: Fix VACUUM so that it always updates pg_class.reltuples/relpages

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Fix VACUUM so that it always updates pg_class.reltuples/relpages
Дата
Msg-id E1QR9gu-0005AX-8p@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Fix VACUUM so that it always updates pg_class.reltuples/relpages.

When we added the ability for vacuum to skip heap pages by consulting the
visibility map, we made it just not update the reltuples/relpages
statistics if it skipped any pages.  But this could leave us with extremely
out-of-date stats for a table that contains any unchanging areas,
especially for TOAST tables which never get processed by ANALYZE.  In
particular this could result in autovacuum making poor decisions about when
to process the table, as in recent report from Florian Helmberger.  And in
general it's a bad idea to not update the stats at all.  Instead, use the
previous values of reltuples/relpages as an estimate of the tuple density
in unvisited pages.  This approach results in a "moving average" estimate
of reltuples, which should converge to the correct value over multiple
VACUUM and ANALYZE cycles even when individual measurements aren't very
good.

This new method for updating reltuples is used by both VACUUM and ANALYZE,
with the result that we no longer need the grotty interconnections that
caused ANALYZE to not update the stats depending on what had happened
in the parent VACUUM command.

Also, fix the logic for skipping all-visible pages during VACUUM so that it
looks ahead rather than behind to decide what to do, as per a suggestion
from Greg Stark.  This eliminates useless scanning of all-visible pages at
the start of the relation or just after a not-all-visible page.  In
particular, the first few pages of the relation will not be invariably
included in the scanned pages, which seems to help in not overweighting
them in the reltuples estimate.

Back-patch to 8.4, where the visibility map was introduced.

Branch
------
REL8_4_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/b503da135ab0bdd97ac3d3f720c35854e084e525

Modified Files
--------------
src/backend/commands/analyze.c    |   45 ++++------
src/backend/commands/vacuum.c     |   98 ++++++++++++++++++----
src/backend/commands/vacuumlazy.c |  170 ++++++++++++++++++++++++-------------
src/backend/postmaster/pgstat.c   |   16 +---
src/include/commands/vacuum.h     |    8 ++-
src/include/pgstat.h              |    3 +-
6 files changed, 219 insertions(+), 121 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: pgsql: Suppress foreign data wrappers and foreign servers in partial du
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix VACUUM so that it always updates pg_class.reltuples/relpages