From: Tom Lane <tgl@sss.pgh.pa.us>
To: shihao zhong <zhong950419@gmail.com>
Cc: 303677365@qq.com, pgsql-bugs@lists.postgresql.org, Guofenglinux <guofenglinux@gmail.com>
Subject: Re: BUG #19834: eager aggregation still evaluates volatile join clauses when the volatile function is inside a SubPl
Date: Wed, 11 Nov 2026 16:08:40 -0500
Message-ID: <3410601.1794431320@sss.pgh.pa.us> (raw)
In-Reply-To: <CAGRkXqTtO9ahgZ_aXTpWW_5xOohjvkzLY-+3aqvDPd++=wVDYg@mail.gmail.com>
References: <19834-234b62f9071e6fd8@postgresql.org>
<CAGRkXqTtO9ahgZ_aXTpWW_5xOohjvkzLY-+3aqvDPd++=wVDYg@mail.gmail.com>
shihao zhong <zhong950419@gmail.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, zhong950419@gmail.com, guofenglinux@gmail.com
Subject: Re: BUG #19834: eager aggregation still evaluates volatile join clauses when the volatile function is inside a SubPl
In-Reply-To: <3410601.1794431320@sss.pgh.pa.us>
References: <19834-234b62f9071e6fd8@postgresql.org> <CAGRkXqTtO9ahgZ_aXTpWW_5xOohjvkzLY-+3aqvDPd++=wVDYg@mail.gmail.com> <3410601.1794431320@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox