Re: Fix size estimation for parallel B-Tree scans with skip arrays

Siddharth Kothari <sidkot@google.com>

From: Siddharth Kothari <sidkot@google.com>
To: Peter Geoghegan <pg@bowt.ie>
Cc: pgsql-bugs@lists.postgresql.org, Vaibhav Jain <jainva@google.com>, Madhukar <madhukarprasad@google.com>, Xun Cheng <xuncheng@google.com>
Date: 2026-04-29T14:59:23Z
Lists: pgsql-bugs
Thank you Peter!

On Wed, Apr 29, 2026 at 8:14 PM Peter Geoghegan <pg@bowt.ie> wrote:

> On Wed, Apr 29, 2026 at 2:54 AM Siddharth Kothari <sidkot@google.com>
> wrote:
> > Root cause:
> >
> > In src/backend/access/nbtree/nbtree.c, the loop in
> btestimateparallelscan assumes that every index column might require a skip
> array and adds sizeof(int) to the estimated size:
> >
> > However, every skip array actually needs space for its slot in the
> btps_arrElems array AND space to store its scan key's sk_flags.
>
> Your diagnosis looks correct to me. As you said, the problem is that
> we only add btps_arrElems space overhead for input scan keys -- we
> neglect to do the same for any skip array scan key that might be
> output by nbtree preprocessing later on.
>
> I'll commit this patch later today.
>
> Thanks!
> --
> Peter Geoghegan
>

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Fix nbtree skip array parallel alloc accounting.

  2. Add nbtree skip scan optimization.