agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Peter Geoghegan <pg@bowt.ie>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix nbtree skip array parallel alloc accounting.
Date: Wed, 29 Apr 2026 15:23:36 +0000
Message-ID: <E1wI6lD-003LOS-2m@gemulon.postgresql.org> (raw)

Fix nbtree skip array parallel alloc accounting.

btestimateparallelscan neglected to add btps_arrElems[] space overhead
for skip array scan keys that were later output by nbtree preprocessing.
Skip arrays don't actually need to use this space, but a scan with a
subsequent SAOP array will need to subscript btps_arrElems[] using a
simple so->arrayKeys[]-wise offset.  so->arrayKeys[] has entries for
both kinds of arrays.

As a result of this oversight, it was possible for an index scan with a
skip array and a lower-order SAOP array to write past the allocated
shared memory boundary when storing the SAOP array's cur_elem.  In
practice the problem seems to be limited to scans with many skipped
index columns, since our general approach to estimating the amount of
shared memory that will be required is fairly conservative.

To fix, have btestimateparallelscan request an extra sizeof(int) space
for key columns that might require a skip array later on.

Oversight in commit 92fe23d9, which added the nbtree skip scan
optimization.

Author: Siddharth Kothari <sidkot@google.com>
Discussion: https://postgr.es/m/CAGCUe0Lwk3C0qdkBa+OLpYc7yXwW=pbaz8Sju4xMXEQAmyp+5g@mail.gmail.com
Backpatch-through: 18

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/748d871b7cb08302ef312b665bd64012f19fc16c

Modified Files
--------------
src/backend/access/nbtree/nbtree.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)



view thread (2+ messages)

Message-ID: <E1wI6lD-003LOS-2m@gemulon.postgresql.org>
Permalink:  ../E1wI6lD-003LOS-2m@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wI6lD-003LOS-2m@gemulon.postgresql.org

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: pg@bowt.ie, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix nbtree skip array parallel alloc accounting.
  In-Reply-To: <E1wI6lD-003LOS-2m@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox