Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xRFaH-00000000pBr-1Q8d for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Nov 2026 21:10:21 +0000 Received: from localhost ([127.0.0.1]:37384 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xRFaF-0000000Cu9Z-48LT for pgsql-bugs@arkaria.postgresql.org; Wed, 11 Nov 2026 21:10:20 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]:43110) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xRFYi-0000000CrZD-0tNe for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 21:08:44 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xRFYh-00000000QzS-1iji for pgsql-bugs@lists.postgresql.org; Wed, 11 Nov 2026 21:08:43 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 6ABL8eIO3410602; Wed, 11 Nov 2026 16:08:40 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 sss.pgh.pa.us 6ABL8eIO3410602 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sss.pgh.pa.us; s=default; t=1794431321; bh=WsL3hb5MdOqP54uLGvFjgtDBeBKvt5zSy8RtsrRjp40=; h=From:To:cc:Subject:In-reply-to:References:Date:From; b=uDKDNIUWBchPQFD27168YxmnAlLFXtt9h1f1dqKlGpAN/mgN1j18N7GX3Amw3mnJy kS5m4qpMxD8CkCgqOQtsC09Jxd+6z2xM8MYrBFo32BN8RVtrqpfywVGmn0cEcGm2Y2 T0CMubz0Fz8V/rt8jPaZN+mQTnGLQ0obT5FDzBd0= From: Tom Lane To: shihao zhong cc: 303677365@qq.com, pgsql-bugs@lists.postgresql.org, Guofenglinux Subject: Re: BUG #19834: eager aggregation still evaluates volatile join clauses when the volatile function is inside a SubPl In-reply-to: References: <19834-234b62f9071e6fd8@postgresql.org> Comments: In-reply-to shihao zhong message dated "Mon, 09 Nov 2026 00:16:41 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3410600.1794431320.1@sss.pgh.pa.us> Date: Wed, 11 Nov 2026 16:08:40 -0500 Message-ID: <3410601.1794431320@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk shihao zhong 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