pgsql: Fix nbtree metapage cache upgrade bug. - Mailing list pgsql-committers

From Peter Geoghegan
Subject pgsql: Fix nbtree metapage cache upgrade bug.
Date
Msg-id E1hoCvi-0000Or-Tx@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Fix nbtree metapage cache upgrade bug.

Commit 857f9c36cda, 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 0a64b45152b 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
0a64b45152b 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 857f9c36cda.  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.

Branch
------
REL_11_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/6523f2ed34413ffcbee8b20d01b0101d9e7dd9c1

Modified Files
--------------
src/backend/access/nbtree/nbtpage.c | 52 +++++++------------------------------
src/backend/access/nbtree/nbtxlog.c |  2 ++
src/include/access/nbtree.h         |  4 +--
3 files changed, 13 insertions(+), 45 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Further adjust SPITupleTable to provide a public row-countfield
Next
From: Jeff Davis
Date:
Subject: pgsql: Fix daterange canonicalization for +/- infinity.