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.96) (envelope-from ) id 1viav3-00AeSu-0m for pgsql-bugs@arkaria.postgresql.org; Wed, 21 Jan 2026 16:18:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1viav2-008930-0M for pgsql-bugs@arkaria.postgresql.org; Wed, 21 Jan 2026 16:18:56 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1viav1-00892s-2j for pgsql-bugs@lists.postgresql.org; Wed, 21 Jan 2026 16:18:56 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1viav0-001kN7-0L for pgsql-bugs@lists.postgresql.org; Wed, 21 Jan 2026 16:18:55 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 60LGIj1o2212450; Wed, 21 Jan 2026 11:18:45 -0500 From: Tom Lane To: David Rowley cc: postgresql@juneidy.wibowo.au, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19377: Query planner interesting behaviour In-reply-to: References: <19377-6797bfc0a06bf23c@postgresql.org> Comments: In-reply-to David Rowley message dated "Wed, 21 Jan 2026 21:06:51 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2212448.1769012325.1@sss.pgh.pa.us> Date: Wed, 21 Jan 2026 11:18:45 -0500 Message-ID: <2212449.1769012325@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Rowley writes: > On Tue, 13 Jan 2026 at 21:57, PG Bug reporting form > wrote: >> It's weird that in the first query postgres doesn't seem to treat >> st_makevalid($0) as a constant and I think re-evaluate st_makevalue($0) for >> every row. Is that an expected behaviour? > Yes, it's expected. We don't do anything special to try and walk up > function call chains of immutable functions for init plan parameters > to push function calls down to the init plan. Perhaps something is > possible here, but anyone proposing we change this would need to come > armed with proof that it's safe to do this. It would be a fairly hard sell, I think, because traditionally PG users have understood that a scalar sub-SELECT like this is an optimization fence. Pushing stuff across that fence is likely to break some hand-optimized queries. regards, tom lane