postgresql/src/backend/utils
Tom Lane 3d351d916b 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
2020-08-30 12:21:51 -04:00
..
adt Move codes for pg_backend_memory_contexts from mmgr/mcxt.c to adt/mcxtfuncs.c. 2020-08-26 10:51:31 +09:00
cache Redefine pg_class.reltuples to be -1 before the first VACUUM or ANALYZE. 2020-08-30 12:21:51 -04:00
error Add %P to log_line_prefix for parallel group leader 2020-08-03 13:38:48 +09:00
fmgr Fix -Wcast-function-type warnings 2020-07-14 19:55:25 +02:00
hash Improve programmer docs for simplehash and dynahash. 2020-08-01 12:16:15 +12:00
init Fix postmaster's behavior during smart shutdown. 2020-08-14 13:26:57 -04:00
mb Fix conversion table generator scripts. 2020-07-22 16:50:03 +12:00
misc Rename VariableCacheData.nextFullXid to nextXid. 2020-08-11 12:07:14 -07:00
mmgr Move codes for pg_backend_memory_contexts from mmgr/mcxt.c to adt/mcxtfuncs.c. 2020-08-26 10:51:31 +09:00
resowner Improve performance of "simple expressions" in PL/pgSQL. 2020-03-26 18:58:57 -04:00
sort Extend the BufFile interface. 2020-08-26 07:36:43 +05:30
time snapshot scalability: cache snapshots using a xact completion counter. 2020-08-17 21:08:30 -07:00
.gitignore Rearrange makefile rules for running Gen_fmgrtab.pl. 2018-05-03 17:54:18 -04:00
Gen_dummy_probes.pl Update copyrights for 2020 2020-01-01 12:21:45 -05:00
Gen_dummy_probes.sed Update copyrights for 2020 2020-01-01 12:21:45 -05:00
Gen_fmgrtab.pl Use perl warnings pragma consistently 2020-04-13 11:55:45 -04:00
Makefile Update copyrights for 2020 2020-01-01 12:21:45 -05:00
errcodes.txt Make SQL/JSON error code names match SQL standard 2020-04-30 09:34:54 +02:00
generate-errcodes.pl Update copyrights for 2020 2020-01-01 12:21:45 -05:00
probes.d Update copyrights for 2020 2020-01-01 12:21:45 -05:00