mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
Fix nbtree metapage cache upgrade bug.
Commit857f9c36cd
, 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 commit0a64b45152
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 commitdd299df8
. 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 commit0a64b45152
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 commit857f9c36cd
. 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.
This commit is contained in:
@ -97,12 +97,12 @@ typedef BTPageOpaqueData *BTPageOpaque;
|
||||
typedef struct BTMetaPageData
|
||||
{
|
||||
uint32 btm_magic; /* should contain BTREE_MAGIC */
|
||||
uint32 btm_version; /* should contain BTREE_VERSION */
|
||||
uint32 btm_version; /* nbtree version (always <= BTREE_VERSION) */
|
||||
BlockNumber btm_root; /* current root location */
|
||||
uint32 btm_level; /* tree level of the root page */
|
||||
BlockNumber btm_fastroot; /* current "fast" root location */
|
||||
uint32 btm_fastlevel; /* tree level of the "fast" root page */
|
||||
/* following fields are available since page version 3 */
|
||||
/* remaining fields only valid when btm_version >= BTREE_NOVAC_VERSION */
|
||||
TransactionId btm_oldest_btpo_xact; /* oldest btpo_xact among all deleted
|
||||
* pages */
|
||||
float8 btm_last_cleanup_num_heap_tuples; /* number of heap tuples
|
||||
|
Reference in New Issue
Block a user