pgsql: Fix another empty nbtree index SSI race.

From: Peter Geoghegan <pg(at)bowt(dot)ie>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix another empty nbtree index SSI race.
Date: 2026-07-25 16:01:57
Message-ID: E1wnep3-00000000GoI-3cQB@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix another empty nbtree index SSI race.

Commit f9b7fc65 fixed a race when predicate-locking completely empty
btrees: without a buffer lock held, a matching key could be inserted
between _bt_search and the PredicateLockRelation call, so the scan would
miss concurrently inserted tuples while the writer wouldn't see the
reader's predicate lock. That commit only fixed _bt_first's _bt_search
path, though. Scans without useful insertion scan keys return early
from _bt_first via _bt_endpoint, which still didn't recheck if the
relation was empty.

To fix, add handling to _bt_endpoint that is analogous to the handling
added to _bt_search by commit f9b7fc65.

Author: Peter Geoghegan <pg(at)bowt(dot)ie>
Discussion: https://postgr.es/m/CAH2-WzkNoTn3yXY0iGkSuavJ+sL8EROf+kitW+_2v2tJVWuKmA@mail.gmail.com
Backpatch-through: 14

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/2aa3c6d1fceecd94b1f605f0c62884cb686e67ed

Modified Files
--------------
src/backend/access/nbtree/nbtsearch.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Álvaro Herrera 2026-07-25 17:17:22 pgsql: Add missing PGDLLIMPORT marker
Previous Message Fujii Masao 2026-07-25 10:14:19 pgsql: psql: Allow pg_read_all_stats to see database size in \l+