pgsql: Fix nbtree skip array parallel alloc accounting.

From: Peter Geoghegan <pg(at)bowt(dot)ie>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix nbtree skip array parallel alloc accounting.
Date: 2026-04-29 15:23:36
Message-ID: E1wI6lD-003LOU-2r@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(at)google(dot)com>
Discussion: https://postgr.es/m/CAGCUe0Lwk3C0qdkBa+OLpYc7yXwW=pbaz8Sju4xMXEQAmyp+5g@mail.gmail.com
Backpatch-through: 18

Branch
------
REL_18_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/1e71970d2d2bc38dd542f029098e05ab80fd8294

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

Browse pgsql-committers by date

  From Date Subject
Next Message Andrew Dunstan 2026-04-29 15:34:31 pgsql: Convert ddlutils regression tests to TAP tests.
Previous Message John Naylor 2026-04-29 09:15:19 pgsql: Cosmetic fixes for radix sort