postgresql/src/backend/access
Peter Geoghegan d004147eb3 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:56 -07:00
..
brin Fix many typos and inconsistencies 2019-07-01 10:00:23 +09:00
common Represent Lists as expansible arrays, not chains of cons-cells. 2019-07-15 13:41:58 -04:00
gin Fix inconsistencies and typos in the tree 2019-07-16 13:23:53 +09:00
gist Avoid using lcons and list_delete_first where it's easy to do so. 2019-07-17 11:15:34 -04:00
hash Fix more typos and inconsistencies in the tree 2019-06-17 16:13:16 +09:00
heap tableam: Provide helper functions for relation sizing. 2019-07-08 14:51:53 -04:00
index Update comment 2019-06-27 15:57:14 +02:00
nbtree Fix nbtree metapage cache upgrade bug. 2019-07-18 13:22:56 -07:00
rmgrdesc Use appendStringInfoString and appendPQExpBufferStr where possible 2019-07-04 13:01:13 +12:00
spgist Fix inconsistencies and typos in the tree 2019-07-16 13:23:53 +09:00
table tableam: Provide helper functions for relation sizing. 2019-07-08 14:51:53 -04:00
tablesample Phase 2 pgindent run for v12. 2019-05-22 13:04:48 -04:00
transam Fix inconsistencies and typos in the tree 2019-07-16 13:23:53 +09:00
Makefile Introduce access/{table.h, relation.h}, for generic functions from heapam.h. 2019-01-21 10:51:36 -08:00