Re: BUG #19861: Self-join elimination drops a VOLATILE predicate and changes the query result

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Manu <manuelreyesbravo(at)gmail(dot)com>
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 03:03:16
Message-ID: 373466.1796526196@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Manu <manuelreyesbravo(at)gmail(dot)com> writes:
> I also tried a narrower fix: keep a duplicate qual when it contains
> volatile functions (one condition at the list_member() test in
> fixup_selfjoin_quals()). It drops no qual, but about 2300 cases
> still differ in how many times or in which order the function runs,
> so I think v3's approach is the right one.

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]. Given that, I'm
quite prepared to dismiss this complaint as not a bug at all.
I'm also very doubtful that SJE is the only source of effects
of this kind.

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.

regards, tom lane

[1] https://www.postgresql.org/docs/current/sql-expressions.html#SYNTAX-EXPRESS-EVAL

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Kirill Reshke 2026-12-06 03:55:17 Re: BUG #19861: Self-join elimination drops a VOLATILE predicate and changes the query result
Previous Message Manu 2026-12-06 02:30:36 Re: BUG #19861: Self-join elimination drops a VOLATILE predicate and changes the query result