pgsql: Initialize read stream before fetching metapage in hash bulk-del

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Initialize read stream before fetching metapage in hash bulk-del
Date: 2026-08-05 07:57:17
Message-ID: E1wrWV3-00000000Gyt-0yFt@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Initialize read stream before fetching metapage in hash bulk-deletion

hashbulkdelete() fetched the relcache's cached hash metapage before
calling read_stream_begin_relation(). During the read stream
initialization, relation lookups may process pending relcache
invalidation messages, which could cause the cached metapage to be
invalidated before the read stream uses it, leading to the failure of a
VACUUM bulk-deletion for a hash index.

This commit reworks the order of hashbulkdelete() so as its read stream
is initialized before fetching the cached metapage, so as pending
invalidation messages do not interfere with the relation scan.

Issue introduced by bfa3c4f106b1.

Author: Mikhail Nikalayeu <mihailnikalayeu(at)gmail(dot)com>
Reviewed-by: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
Reviewed-by: Nazir Bilal Yavuz <byavuz81(at)gmail(dot)com>
Reviewed-by: Xuneng Zhou <xunengzhou(at)gmail(dot)com>
Discussion: https://postgr.es/m/CADzfLwVEJ2_7ioX3ZSB1P7qXW40ghUy_ZCzeFvhDLoa_3Muztg@mail.gmail.com
Backpatch-through: 19

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/ca86d7439b1947e97d0d86036f29ebc5cb0397aa

Modified Files
--------------
src/backend/access/hash/hash.c | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2026-08-05 08:57:43 pgsql: Disallow aggregates, window functions, and SRFs in GRAPH_TABLE C
Previous Message Peter Eisentraut 2026-08-05 06:47:26 pgsql: More tab-completion for DROP PROPERTY GRAPH