Re: BUG #19936: Planning is slower on 19.0 with many partial indexes on a SQL function

From: Nitin Motiani <nitinmotiani(at)google(dot)com>
To: Ishjaap Singh <ishjaap(dot)singh07(at)gmail(dot)com>
Cc: jdimov(at)a115(dot)bg, pgsql-bugs(at)lists(dot)postgresql(dot)org, guofenglinux(at)gmail(dot)com
Subject: Re: BUG #19936: Planning is slower on 19.0 with many partial indexes on a SQL function
Date: 2026-11-30 16:39:43
Message-ID: CAH5HC96j7KKEqpEk7nBAPNc2Vbq20T5EQX0J9TZF_TuRCPWNQg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Mon, Nov 30, 2026 at 1:07 AM Ishjaap Singh <ishjaap(dot)singh07(at)gmail(dot)com> wrote:
>
> Hi,
>
> I can reproduce this, and the slowdown starts at c925ad30b04, the
> commit Jordan suspected. I compared builds at c925ad30b04 and its
> parent 04396eacd3f (GCC 13.3, -O2, assertions off, jit = off), using
> Jordan's 550-index script. Median planning time in ms, from two runs
> of ten plans per variant after a warm-up:
>
> 04396eacd3f c925ad30b04
> f(a -> 0) 0.97 4.86
> plain (a -> 0) 1.13 1.16
> f with SET search_path 1.11 1.49
>

I also noticed that it can happen with other types of queries with
immutable wrappers. One example follows.

create function full_name(first_name text, last_name text) returns
text language sql immutable return concat_ws(' ', first_name,
last_name);

With 550 per-tenant partial indexes on lower(full_name(first_name,
last_name)), planning took 1.73 ms on 18.7 and 3.85 ms on 19.0.

I'm not sure this is worth fixing, though. The extra cost is about 5
microseconds per index (based on my experiment). And it scales
linearly with the number of indexes. Therefore it only has an effect
with hundreds of indexes. The commit message for c925ad30b04 already
accepted this trade-off.

If we want to make a fix, I thought of a couple of ways but I'm not
sure if they are the right or clean fixes.

1. Record during the relcache pass if something was skipped due to the
lack of root. And skip it on the second pass in planning. We have to
be careful and cover all the places in the code where this
2. Don't record anything but explicitly check for the presence of 'not
null' columns in the second pass and skip it.

Let me know what you think.

Thanks & Regards,
Nitin Motiani
Google

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Nathan Bossart 2026-11-30 17:05:45 Re: BUG #19688: pg_dump --schema scans all sequences in PostgreSQL 18, causing severe performance regression
Previous Message Raja Sai pranav 2026-11-30 16:21:13 Re: BUG #19928: pg_upgrade fails on v18 schema with NOT NULL ... NO INHERIT and inheritance