Re: BUG #19834: eager aggregation still evaluates volatile join clauses when the volatile function is inside a SubPl

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: shihao zhong <zhong950419(at)gmail(dot)com>
Cc: 303677365(at)qq(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org, Guofenglinux <guofenglinux(at)gmail(dot)com>
Subject: Re: BUG #19834: eager aggregation still evaluates volatile join clauses when the volatile function is inside a SubPl
Date: 2026-11-11 21:08:40
Message-ID: 3410601.1794431320@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

shihao zhong <zhong950419(at)gmail(dot)com> writes:
> Thanks for the report. This follows up on [1], where we fixed volatile
> join clauses. contain_volatile_functions() does not look into SubPlans,
> so a volatile function in a correlated sub-select still gets through.
> The query in the report does not show it, because its sub-select is
> uncorrelated and runs once as an initplan.
> The attached patch also refuses SubPlans, like we do when moving HAVING
> to WHERE. I think it should go back to 19.

I do not think this is a bug, so I don't think we should limit query
optimization to work around it (especially in such a brute-force way).
We have traditionally understood that a sub-select can be used to hide
or disable the volatility of a function. For example, these clauses
behave quite differently:

WHERE x = random()
WHERE x = (SELECT random())

So the fact that contain_volatile_functions() doesn't descend into
SubPlans is intentional, and subverting that intention in just one
place does not seem to me like a good idea.

Maybe there is something to be done here, but this bug report shows
no awareness of that context.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message surya poondla 2026-11-11 21:27:22 Re: BUG #19382: Server crash at __nss_database_lookup
Previous Message Tom Lane 2026-11-11 20:23:49 Re: BUG #19826: corr()/regr_r2() of constant input: NULL serially, 1 with partial aggregation