Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wIRnw-0086jZ-2s for pgsql-bugs@arkaria.postgresql.org; Thu, 30 Apr 2026 13:51:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wIRnw-007dyj-0H for pgsql-bugs@arkaria.postgresql.org; Thu, 30 Apr 2026 13:51:48 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wI6O2-003tQP-0z for pgsql-bugs@lists.postgresql.org; Wed, 29 Apr 2026 14:59:38 +0000 Received: from mail-qv1-xf29.google.com ([2607:f8b0:4864:20::f29]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wI6Nz-00000003MQQ-3PQq for pgsql-bugs@lists.postgresql.org; Wed, 29 Apr 2026 14:59:37 +0000 Received: by mail-qv1-xf29.google.com with SMTP id 6a1803df08f44-8a1e1817db6so100371376d6.2 for ; Wed, 29 Apr 2026 07:59:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1777474774; cv=none; d=google.com; s=arc-20240605; b=cZtp2GdSS3ZRuXvn2wZaY+wVZlYyLSfj6F2tr4udoYnt6KYtxd8JfaxeByKiBAdbvs 1HXc3t1GGiaRmt59+mJ1LOjXz3NbVYNuoJr1m3ghjZEHx5omK5bf2TOm6bxbpE2aKiu/ TNmlMC5NAHqNe3rQLKLb8g0cTdUZqQXOxNCSNelTqhbKpsjyRHINUWtRsLzoQefnIb4E fq3hROfnS+X/8tol/w9D0VaaobQkkdYvmCnCN9Q/C1+vW7M5DyxfjousKzVZnJxePBBD F4VBFikYoNqMA5yZcCw5arm7suXl8pxUyocZc+yfQZA0cl1CfDH2/aGy1oMtDXXLShVB Jikg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=pz3jeHQ0N4CelFRXacrV4A0FcszK/QWpAKkEk9zEpgM=; fh=zTINfu8gCfC56YYpugIBAYt7oeuUoi4ugZ3WbOqNmlI=; b=lv3f0s4Hlncj1HO8P5FEO2ROOd3ZzMV1RKxdyBfyl9Gm0EYaclFcs29APrkzmA8b8C IHjGFNHNJiOnVErSKfE/Yyoryn3vGI1W5nKd68XGqGbCebAzo0FYnt58SfW5nsrSnCva VNmAEUX/KFyPsfj/8fbwIKfCmBUpg8uDWhjk2V7UvYmVtHUAXIIPJR22JvyYwYINB8k1 bqkwG57n+rcYcEtHIaMRaVgpZwdEcRtUt9K5LRA7BtDlPSPMvnZCrx+qFgV2rC4gkLFW gs+jQQ2QP8y3rBfLHx+WwO9+kv+9lfn+5GQV8Hh8h52wvZkl2lpX48VhIxky8tAjeknS zPhw==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1777474774; x=1778079574; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=pz3jeHQ0N4CelFRXacrV4A0FcszK/QWpAKkEk9zEpgM=; b=XmHNu5TgMa4asJuj/E93gqcbtLgsIzU/EbtXzwmwv+b9RskoxhEmZvVF8EdIK9g789 0UzmCbydRO4JDe6ceS17z2imPCeuptWrSxvng5xb6XImAuLMqLm4AnOqcnNavZEUccN7 RO9Hz7lTIDFxhP+/C1UZm69aa5fyV0TvqAkug2/MouMGH/0VXaOeXdqm46m0S9I1fHr1 HpZCQOW0ndHNX7IqlPu1kVotvwEaMusk/kQbSGltTIZSMJ+CUmvNxl5S6iLvXPSPToGV 2Zo6mt50ziHu88wBczhs35LpDPMA8uykg8vehcLGivp2oiE0VGcpiSrjfBL4ovfqQBGp r/dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777474774; x=1778079574; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=pz3jeHQ0N4CelFRXacrV4A0FcszK/QWpAKkEk9zEpgM=; b=i/iIsSmBwrkAEOLMa31c8/RWuT1ZNqjh1tFz/C+Nt41Jj8RhgNcTRnnAmUNeCSxrlB syFfub9CVqlXN66QleYTSWzhYiYhu+cAkh0qndtTCzcKiJkPbzHnR6QO8Q1FDgW6V99n 0DLXFZtWItDmBUDQhdWQyGNz4FgFU3Mfyh5v+0FjEG/uCpu737oQeO148ajfVWHYBXIR 03WFNc0EPp3GS+S3X4Gt1jIx03uilS636R3SsfAb/BFBS7KbY3jzqZswUGs6meeEiGkp DUp6d3IclGmXnzjinkH/b6EUUG03eDu6U1qUaFRu5hMAMb3SXj9Ml1VO+4Ty90p9mXBd gXTA== X-Gm-Message-State: AOJu0YxDvojZYFieszUb/282agS6JrXBlz6mbtHUjGJYy9JMM15uBg9+ 7Exp2DnVR+nTFDd9X4MhGxFPJJK2rFE6XdLcV87ELs/APGASQKGnAx746nDBmBlepZPTvnMet+u zC9gPsDyQhq1h0VbSZVRIiD4XRQaipue1rYNAoAw3 X-Gm-Gg: AeBDieuomjc0QiRKXmT2RRUaonwjs+f3GMhlUjC3AOqP6zJjG2krI5oHuJVpvFAwbLj 1U25QvkD+RAo3f5rS/uoYEMPftX+rvYEAcZiVuPfWfhqNTDslhKAgt8HI26VWCR3NTn/rS2Gu1d SOI+vo4PRjmFzh72kQVzN3AoYjHhrcY6HjWF9wRPMMjmHS9i2zls4SCp05U860JPzDsCHOtFCn2 +dXTr5nixxcr0qQM5E6hxMzAWimrnq+0IsAgG029A4apCjm5eb+Mb4lEWMJCYgVyNNHqHkmfSMS xh+yaPhMMgksqe/8AdIgEzCxwzTq3HhNTAHiDZwLadDBwUXUtPSlzGuqyPBGJR4= X-Received: by 2002:a05:6214:3116:b0:8ae:5f0f:cc80 with SMTP id 6a1803df08f44-8b3e31ca414mr118077056d6.38.1777474774024; Wed, 29 Apr 2026 07:59:34 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Siddharth Kothari Date: Wed, 29 Apr 2026 20:29:23 +0530 X-Gm-Features: AVHnY4KMM9CqcI8L-6mrao-LP3DqxyLJgsZf97M4eliVz8OlQD8obLDgX1Jimew Message-ID: Subject: Re: Fix size estimation for parallel B-Tree scans with skip arrays To: Peter Geoghegan Cc: pgsql-bugs@lists.postgresql.org, Vaibhav Jain , Madhukar , Xun Cheng Content-Type: multipart/alternative; boundary="000000000000817a5006509a9814" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000817a5006509a9814 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thank you Peter! On Wed, Apr 29, 2026 at 8:14=E2=80=AFPM Peter Geoghegan wrote: > On Wed, Apr 29, 2026 at 2:54=E2=80=AFAM Siddharth Kothari > wrote: > > Root cause: > > > > In src/backend/access/nbtree/nbtree.c, the loop in > btestimateparallelscan assumes that every index column might require a sk= ip > 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 > --000000000000817a5006509a9814 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thank you Peter!

On Wed, Apr 29, 2026= at 8:14=E2=80=AFPM Peter Geoghegan <pg@bo= wt.ie> wrote:
On Wed, Apr 29, 2026 at 2:54=E2=80=AFAM Siddharth Kothari <sidkot@google.com> w= rote:
> Root cause:
>
> In src/backend/access/nbtree/nbtree.c, the loop in btestimateparallels= can assumes that every index column might require a skip array and adds siz= eof(int) to the estimated size:
>
> However, every skip array actually needs space for its slot in the btp= s_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
--000000000000817a5006509a9814--