| From: | buyu zi <zibuyu423(at)gmail(dot)com> |
|---|---|
| To: | Ishjaap Singh <ishjaap(dot)singh07(at)gmail(dot)com> |
| Cc: | Kirill Reshke <reshkekirill(at)gmail(dot)com>, Nitin Motiani <nitinmotiani(at)google(dot)com>, 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-12-03 14:54:51 |
| Message-ID: | CADbAUJJpe-aVvq9onKMdCOog+jciMcmQnBydNWij2nXM_xumaA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
Hi Ishjaap,
I tried the case you mentioned where neighboring indexes have different
expressions. If the indexes alternate between two keys, each lookup
misses the previous expression even though there are only two distinct
expressions to simplify.
The attached patch applies on top of your v1. It keeps the two most
recent results and checks the cache less often after repeated misses.
With 550 partial indexes, I measured the following planning times in ms:
Index keys Unpatched master v1 + attached patch
Same key throughout 2.976 1.526
Two alternating keys 2.983 1.554
All keys distinct 3.009 2.917
Long keys differing at the end 5.877 5.920
These are medians from CPU-pinned runs with -O2 builds. The ranges
overlapped in both all-distinct cases. The EXPLAIN plans matched across
all four workloads, and make check passed on master and REL_19_STABLE.
Do you think the alternating-key case is worth covering in the fix
for 19?
Regards,
zibuyu
On Thu, Dec 3, 2026 at 10:50 PM Ishjaap Singh <ishjaap(dot)singh07(at)gmail(dot)com>
wrote:
> Hi Kirill,
>
> Here's a patch. I tried a few things first:
>
> - I started with Nitin's suggestion of checking for NOT NULL columns.
> It brought planning time back down in the original examples. When
> I made the indexed column NOT NULL, the second pass still ran.
> - A finer check fixed that too. But both checks skip the pass for an
> index like WHERE (a IS NULL) IS FALSE. Only the second pass turns
> that into a IS NOT NULL, so 19.0 uses the index for a query with
> a IS NOT NULL, and with either check it doesn't.
> - Remembering which SQL functions failed to inline fixed everything I
> tried. But it took a hash table in inline_function() and about 170
> lines in core planner code, which felt like too much for 19.
>
> The attached patch is simpler. If an index has the same expressions
> as the previous index with expressions, it reuses that result instead
> of running the second pass again, unless invalidation messages came in
> between. In both reports all 550 indexes share one key, so the second
> pass on their expressions runs once instead of 550 times. Predicates
> still get the second pass as before.
>
> Planning time in ms with 550 indexes (medians from two runs, release
> builds):
>
> 18.7 19.0 patched
> Jordan's f 0.73-0.75 2.88-2.90 0.83-0.88
> f with 41 copies of j::text 0.76-0.77 17.86-18.09 0.83-0.90
> Nitin's full_name() 0.69 2.37 0.85-0.86
> A different key per index 0.69-0.71 2.78-2.88 2.69-2.70
>
> As the last line shows, it doesn't help when neighbouring indexes have
> different expressions. With 550 long expressions that differ only at
> the end, it adds about 0.5 ms. I can post the inlining version if that
> case matters.
>
> Plans were the same as on 19.0 for about 3,200 test queries. The
> patch adds a test to predicate.sql, and make check passes on master and
> REL_19_STABLE.
>
> Regards,
> Ishjaap Singh
>
| Attachment | Content-Type | Size |
|---|---|---|
| 19936-on-top-of-v1.patch | text/x-patch | 6.8 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Fujii Masao | 2026-12-03 16:06:39 | Re: BUG #19952: psql \d+ omits nondefault replica identity for partitioned tables |
| Previous Message | buyu zi | 2026-12-03 14:47:16 | Re: BUG #19962: pg_dumpall can't produce restorable circular grants with ADMIN OPTION |