Move I/O before the index_update_stats() buffer lock region.

Noah Misch <noah@leadboat.com>

Commit: 6d5b4031b927328e548088ebcc24781223b3b803
Author: Noah Misch <noah@leadboat.com>
Date: 2024-11-02T16:05:04Z
Releases: 15.9
Move I/O before the index_update_stats() buffer lock region.

Commit a07e03fd8fa7daf4d1356f7cb501ffe784ea6257 enlarged the work done
here under the pg_class heap buffer lock.  Two preexisting actions are
best done before holding that lock.  Both RelationGetNumberOfBlocks()
and visibilitymap_count() do I/O, and the latter might exclusive-lock a
visibility map buffer.  Moving these reduces contention and risk of
undetected LWLock deadlock.  Back-patch to v12, like that commit.

Discussion: https://postgr.es/m/20241031200139.b4@rfd.leadboat.com

Files

PathChange+/−
src/backend/catalog/index.c modified +36 −18

Discussion