| From: | Ishjaap Singh <ishjaap(dot)singh07(at)gmail(dot)com> |
|---|---|
| To: | Kirill Reshke <reshkekirill(at)gmail(dot)com> |
| Cc: | 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-01 16:22:57 |
| Message-ID: | CA+Y2BmfyjLbUYog=qDK_dD--Ge4b3NSesR_3RkLjgrq=EqaCZA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
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 |
|---|---|---|
| v1-0001-Simplify-identical-index-expressions-only-once-in.patch | application/octet-stream | 7.4 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Kirill Reshke | 2026-12-01 16:57:09 | Re: JIT inlining: "tupdesc reference ... is not owned by resource owner Portal" (inlined code uses a cloned tupdesc_resowner_desc) |
| Previous Message | Tom Lane | 2026-12-01 15:14:53 | Re: BUG #19963: INNER JOIN ON qual evaluated as scan filter even when the inner input is empty |