postgresql/src/include
Peter Geoghegan 6523f2ed34 Fix nbtree metapage cache upgrade bug.
Commit 857f9c36cd, which taught nbtree VACUUM to avoid unnecessary
index scans, bumped the nbtree version number from 2 to 3, while adding
the ability for nbtree indexes to be upgraded on-the-fly.  Various
assertions that assumed that an nbtree index was always on version 2 had
to be changed to accept any supported version (version 2 or 3 on
Postgres 11).

However, a few assertions were missed in the initial commit, all of
which were in code paths that cache a local copy of the metapage
metadata, where the index had been expected to be on the current version
(no longer version 2) as a generic sanity check.  Rather than simply
update the assertions, follow-up commit 0a64b45152 intentionally made
the metapage caching code update the per-backend cached metadata version
without changing the on-disk version at the same time.  This could even
happen when the planner needed to determine the height of a B-Tree for
costing purposes.  The assertions only fail on Postgres v12 when
upgrading from v10, because they were adjusted to use the authoritative
shared memory metapage by v12's commit dd299df8.

To fix, remove the cache-only upgrade mechanism entirely, and update the
assertions themselves to accept any supported version (go back to using
the cached version in v12).  The fix is almost a full revert of commit
0a64b45152 on the v11 branch.

VACUUM only considers the authoritative metapage, and never bothers with
a locally cached version, whereas everywhere else isn't interested in
the metapage fields that were added by commit 857f9c36cd.  It seems
unlikely that this bug has affected any user on v11.

Reported-By: Christoph Berg
Bug: #15896
Discussion: https://postgr.es/m/15896-5b25e260fdb0b081%40postgresql.org
Backpatch: 11-, where VACUUM was taught to avoid unnecessary index scans.
2019-07-18 13:22:53 -07:00
..
access Fix nbtree metapage cache upgrade bug. 2019-07-18 13:22:53 -07:00
bootstrap Rationalize handling of array type names in bootstrap data. 2018-04-17 18:29:11 -04:00
catalog Move CloneForeignKeyConstraints to tablecmds.c 2019-01-18 14:57:49 -03:00
commands Move CloneForeignKeyConstraints to tablecmds.c 2019-01-18 14:57:49 -03:00
common Fix detection of passwords hashed with MD5 or SCRAM-SHA-256 2019-04-23 15:43:32 +09:00
datatype Update copyright for 2018 2018-01-02 23:30:12 -05:00
executor Restructure creation of run-time pruning steps. 2019-05-17 19:44:19 -04:00
fe_utils Ensure schema qualification in pg_restore DISABLE/ENABLE TRIGGER commands. 2018-08-17 17:12:21 -04:00
foreign Allow insert and update tuple routing and COPY for foreign tables. 2018-04-06 19:22:03 -04:00
jit Fix LLVM related headers to compile standalone (to fix cpluspluscheck). 2019-01-28 18:14:45 -08:00
lib simplehash: Add support for resetting a hashtable's contents. 2019-02-09 01:05:50 -08:00
libpq Fix detection of passwords hashed with MD5 or SCRAM-SHA-256 2019-04-23 15:43:32 +09:00
mb Fix a boatload of typos in C comments. 2018-04-01 15:01:28 -04:00
nodes Remove misleading comment from pathnodes.h. 2019-06-25 09:20:36 +12:00
optimizer Avoid sharing PARAM_EXEC slots between different levels of NestLoop. 2019-01-11 15:54:08 -05:00
parser Fix INSERT ON CONFLICT UPDATE through a view that isn't just SELECT *. 2018-08-04 19:38:58 -04:00
partitioning Restructure creation of run-time pruning steps. 2019-05-17 19:44:19 -04:00
port Fix misc typos, mostly in comments. 2018-07-18 16:17:42 +03:00
portability Update copyright for 2018 2018-01-02 23:30:12 -05:00
postmaster Add comment explaining BGWORKER_BYPASS_ALLOWCONN 2018-04-23 10:31:22 +02:00
regex Update copyright for 2018 2018-01-02 23:30:12 -05:00
replication Mark ReplicationSlotCtl as PGDLLIMPORT. 2019-06-13 10:53:17 -04:00
rewrite Revert MERGE patch 2018-04-12 11:22:56 +01:00
snowball Update copyright for 2018 2018-01-02 23:30:12 -05:00
statistics Update copyright for 2018 2018-01-02 23:30:12 -05:00
storage Fix spinlock assembly code for MIPS so it works on MIPS r6. 2019-06-22 20:31:50 -04:00
tcop Fix event triggers for partitioned tables 2018-10-06 19:17:46 -03:00
tsearch Post-feature-freeze pgindent run. 2018-04-26 14:47:16 -04:00
utils Don't read fields of a misaligned ExpandedObjectHeader or AnyArrayType. 2019-06-30 17:34:20 -07:00
.gitignore Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
c.h Allow btree comparison functions to return INT_MIN. 2018-10-05 16:01:29 -04:00
fmgr.h Add expression compilation support to LLVM JIT provider. 2018-03-22 14:45:59 -07:00
funcapi.h Support INOUT arguments in procedures 2018-03-14 12:07:28 -04:00
getaddrinfo.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
getopt_long.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
Makefile Install JIT related headers. 2019-01-28 13:53:43 -08:00
miscadmin.h Allow group access on PGDATA 2018-04-07 17:45:39 -04:00
pg_config.h.in Avoid thread-safety problem in ecpglib. 2019-01-21 23:18:58 -05:00
pg_config.h.win32 Stamp 11.4. 2019-06-17 17:15:30 -04:00
pg_config_ext.h.in Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_ext.h.win32 Autoconfiscate selection of 64-bit int type for 64-bit large object API. 2012-10-07 21:52:43 -04:00
pg_config_manual.h Improve description of DEFAULT_XLOG_SEG_SIZE in pg_config.h 2018-12-29 08:24:47 +09:00
pg_getopt.h Use our own getopt() on OpenBSD. 2019-01-18 15:06:26 -05:00
pg_trace.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
pgstat.h Rearrange pgstat_bestart() to avoid failures within its critical section. 2019-05-11 21:27:13 -04:00
pgtar.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
pgtime.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
port.h Fix misc typos in comments. 2019-01-23 13:43:41 +02:00
postgres.h Detoast plpgsql variables if they might live across a transaction boundary. 2018-05-16 14:56:52 -04:00
postgres_ext.h Phase 2 of pgindent updates. 2017-06-21 15:19:25 -04:00
postgres_fe.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
rusagestub.h Update copyright for 2018 2018-01-02 23:30:12 -05:00
windowapi.h Update copyright for 2018 2018-01-02 23:30:12 -05:00