| From: | Andrey Borodin <x4mmm(at)yandex-team(dot)ru> |
|---|---|
| To: | Dilip Kumar <dilipbalaut(at)gmail(dot)com> |
| Cc: | simon(dot)tenbusch(at)cloudelevator(dot)de, PostgreSQL mailing lists <pgsql-bugs(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: BUG #19779: Backend SIGSEGV in UPDATE with FOR UPDATE CTE joined to UNION ALL subquery |
| Date: | 2026-11-21 13:37:50 |
| Message-ID: | AD2838BC-404E-46A2-B462-E7F211F92C85@yandex-team.ru |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
Hi Dilip,
I found a wrong-result case that remains with the guard. Using the same
two-row table as your example, have session 1 update both ids and keep
the transaction open:
BEGIN;
UPDATE t SET id = -id;
Then run this in session 2, and commit session 1 after it blocks:
SELECT o.i, q.* FROM (VALUES (1), (2)) o(i)
CROSS JOIN LATERAL (
SELECT t.id, t.val, u.id AS uid FROM t
JOIN (
SELECT id FROM t WHERE id > 0
UNION ALL
SELECT -id FROM t WHERE (SELECT o.i OFFSET 0) = o.i
) u ON t.id = u.id
FOR UPDATE OF t
) q;
With the guard this returns three rows, missing (2, -2, 'a', -2).
Replacing (SELECT o.i OFFSET 0) with o.i returns all four rows.
The parent's InitPlan slot already has execPlan == NULL, but its value
is still 1 from the previous LATERAL iteration. EPQ has computed 2 for
the current iteration. The next reset copies the parent's 1 over it.
So checking whether the parent has evaluated the parameter is not
enough: this output belongs to the recheck plan's own execution.
I tried copying only the recheck plan's extParam inputs in both
EvalPlanQualStart() and EvalPlanQualBegin(). ExecSetParamPlanMulti()
already evaluates external InitPlan outputs before the copy. Locally
produced values stay in the child.
With this change, both your original example and this one match their
reference queries. Do you see any inputs outside extParam that EPQ
needs to copy?
Thank you!
Best regards, Andrey Borodin.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Raja Sai pranav | 2026-11-21 13:55:45 | Re: BUG #19875: Foreign-key self-update rejects an accepted implicit I/O cast |
| Previous Message | Dean Rasheed | 2026-11-21 12:31:08 | Re: BUG #19912: MERGE NOT MATCHED BY SOURCE sees stale source values after concurrent update (EPQ) |