| From: | Manu <manuelreyesbravo(at)gmail(dot)com> |
|---|---|
| To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
| Cc: | Kirill Reshke <reshkekirill(at)gmail(dot)com>, Tender Wang <tndrwang(at)gmail(dot)com>, Richard Guo <guofenglinux(at)gmail(dot)com>, idrissaajalloh(at)gmail(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Subject: | Re: BUG #19861: Self-join elimination drops a VOLATILE predicate and changes the query result |
| Date: | 2026-12-06 04:26:50 |
| Message-ID: | 179653121085.2547965.13229330238494156597@gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
On Sat, 5 Dec 2026 at 22:03, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> I want to push back hard against the idea that we promise anything
> about "how many times or in which order" qual clauses run; see the
> explicit documentation to the contrary in [1].
>
> [1] https://www.postgresql.org/docs/current/sql-expressions.html#SYNTAX-EXPRESS-EVAL
Fair enough. My test counted calls, which is a stricter rule than
the documented one, and I should not have used it to argue for v3.
> It might be appropriate to avoid dropping duplicate clauses if they
> are volatile, but I do not think that we should expend any great
> complexity or a lot of planner cycles on it.
The attached patch does only that: one more condition at the
list_member() test in fixup_selfjoin_quals(), so
contain_volatile_functions() runs only on a qual that has already
turned out to be a duplicate. replace_selfjoin_qual(), which it
calls first, already leaves volatile clauses alone; the patch says
the same about duplicates in the header comment.
In my test SJE removes the same joins as on master, and the plan of
the reported query keeps both calls. regress and isolation pass on
8d90516d76d. The patch also applies to REL_18_STABLE and
REL_19_STABLE, where the reported query loses a call the same way,
and regress and isolation pass there too.
Tender, if you would rather fold this into your patch, please do.
Regards,
Manu
| Attachment | Content-Type | Size |
|---|---|---|
| v4-0001-Keep-volatile-duplicate-quals-in-self-join-elimi.patch | text/x-patch | 4.3 KB |
| From | Date | Subject | |
|---|---|---|---|
| Previous Message | Tom Lane | 2026-12-06 04:08:09 | Re: BUG #19861: Self-join elimination drops a VOLATILE predicate and changes the query result |