From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Redefine pg_class.reltuples to be -1 before the first VACUUM or
Date: Sun, 30 Aug 2020 16:22:04 +0000
Message-ID: <E1kCQ5k-0006BR-56@gemulon.postgresql.org> (raw)
Redefine pg_class.reltuples to be -1 before the first VACUUM or ANALYZE.
Historically, we've considered the state with relpages and reltuples
both zero as indicating that we do not know the table's tuple density.
This is problematic because it's impossible to distinguish "never yet
vacuumed" from "vacuumed and seen to be empty". In particular, a user
cannot use VACUUM or ANALYZE to override the planner's normal heuristic
that an empty table should not be believed to be empty because it is
probably about to get populated. That heuristic is a good safety
measure, so I don't care to abandon it, but there should be a way to
override it if the table is indeed intended to stay empty.
Hence, represent the initial state of ignorance by setting reltuples
to -1 (relpages is still set to zero), and apply the minimum-ten-pages
heuristic only when reltuples is still -1. If the table is empty,
VACUUM or ANALYZE (but not CREATE INDEX) will override that to
reltuples = relpages = 0, and then we'll plan on that basis.
This requires a bunch of fiddly little changes, but we can get rid of
some ugly kluges that were formerly needed to maintain the old definition.
One notable point is that FDWs' GetForeignRelSize methods will see
baserel->tuples = -1 when no ANALYZE has been done on the foreign table.
That seems like a net improvement, since those methods were formerly
also in the dark about what baserel->tuples = 0 really meant. Still,
it is an API change.
I bumped catversion because code predating this change would get confused
by seeing reltuples = -1.
Discussion: https://postgr.es/m/F02298E0-6EF4-49A1-BCB6-C484794D9ACC@thebuild.com
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/3d351d916b20534f973eda760cde17d96545d4c4
Modified Files
--------------
contrib/file_fdw/file_fdw.c | 2 +-
contrib/pgstattuple/pgstatapprox.c | 3 +++
contrib/postgres_fdw/postgres_fdw.c | 7 +++----
doc/src/sgml/catalogs.sgml | 4 ++++
doc/src/sgml/fdwhandler.sgml | 3 ++-
src/backend/access/gin/ginvacuum.c | 2 +-
src/backend/access/heap/vacuumlazy.c | 38 ++++++++++++++---------------------
src/backend/access/nbtree/nbtree.c | 1 +
src/backend/access/table/tableam.c | 22 +++++++++-----------
src/backend/catalog/heap.c | 4 ++--
src/backend/catalog/index.c | 9 +++++++++
src/backend/commands/vacuum.c | 14 ++++++-------
src/backend/optimizer/path/allpaths.c | 6 +++++-
src/backend/optimizer/util/plancat.c | 11 ++++------
src/backend/postmaster/autovacuum.c | 4 ++++
src/backend/rewrite/rewriteDefine.c | 2 +-
src/backend/utils/cache/relcache.c | 4 ++--
src/include/access/genam.h | 4 ++--
src/include/catalog/catversion.h | 2 +-
src/include/catalog/pg_class.h | 4 ++--
20 files changed, 77 insertions(+), 69 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Redefine pg_class.reltuples to be -1 before the first VACUUM or
In-Reply-To: <E1kCQ5k-0006BR-56@gemulon.postgresql.org>
References: <E1kCQ5k-0006BR-56@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox