| From: | Bjorn Pagen <hello(at)bjornpagen(dot)com> |
|---|---|
| To: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | [PATCH] pg_plan_advice: NESTED_LOOP_MEMOIZE advice can fail |
| Date: | 2026-11-28 06:26:32 |
| Message-ID: | CAARz7_hYt1STWZ45V_JM-Azu1mp7=9KHAVjMrS0_0jojGn=8QA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi,
NESTED_LOOP_MEMOIZE advice can come back "matched, failed" even though
the planner could have done the join that way:
CREATE TABLE o (id int PRIMARY KEY, k int);
CREATE TABLE i (a int, b int, PRIMARY KEY (a, b));
INSERT INTO o SELECT g, g FROM generate_series(1, 1000) g;
INSERT INTO i SELECT g, g FROM generate_series(1, 1000) g;
VACUUM ANALYZE o, i;
LOAD 'pg_plan_advice';
SET pg_plan_advice.advice = 'NESTED_LOOP_MEMOIZE(i)';
EXPLAIN (COSTS OFF)
SELECT * FROM o JOIN i ON i.b = o.k AND i.a = 1 WHERE
https://www.google.com/url?q=http://o.id&source=gmail&ust=1795933592081000&sa=E
= 5;
Nested Loop
Disabled: true
Join Filter: (i.b = o.k)
-> Index Scan using o_pkey on o
Index Cond: (id = 5)
-> Index Only Scan using i_pkey on i
Index Cond: (a = 1)
Supplied Plan Advice:
NESTED_LOOP_MEMOIZE(i) /* matched, failed */
Both ways of scanning i, with and without b = o.k as an index
condition, are estimated at one row and the same cost. So add_path()
keeps only the unparameterized one, and there's nothing left to put a
Memoize on top of. (dc47beacaa fixed a similar-looking failure, but
there the path existed.)
The attached patch adds PGS_CONSIDER_UNPARAMETERIZED, which disables a
rel's unparameterized paths the way PGS_CONSIDER_NONPARTIAL disables
its non-partial ones. pg_plan_advice clears it for the relation that
NESTED_LOOP_MEMOIZE names. add_path() isn't touched.
This doesn't fix NESTED_LOOP_PLAIN(i), which gives the same join
filter here and reports "matched". That's the case we ran into. I
think it needs advice that says whether the inner scan is
parameterized, which Robert mentioned as a possibility in [1].
Thanks,
Bjorn Pagen
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Keep-parameterized-paths-for-NESTED_LOOP_MEMOIZE-.patch | text/x-patch | 17.7 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Bjorn Pagen | 2026-11-28 06:30:46 | Re: [PATCH] pg_plan_advice: NESTED_LOOP_MEMOIZE advice can fail |
| Previous Message | Andrey Borodin | 2026-11-28 05:26:35 | Re: Set 1s WaitLatch timeout if standby limit has expired in ResolveRecoveryConflictWithBufferPin |