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 1vdhEq-003aks-17 for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Jan 2026 04:03:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vdhEo-00HL61-2Z for pgsql-hackers@arkaria.postgresql.org; Thu, 08 Jan 2026 04:03:07 +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 1vdhEo-00HL5s-1a for pgsql-hackers@lists.postgresql.org; Thu, 08 Jan 2026 04:03:07 +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 1vdhEm-005Cnt-11 for pgsql-hackers@lists.postgresql.org; Thu, 08 Jan 2026 04:03:06 +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 608432251892153; Wed, 7 Jan 2026 23:03:02 -0500 From: Tom Lane To: Richard Guo cc: Eric Ridge , Pg Hackers Subject: Re: Fwd: pg18 bug? SELECT query doesn't work In-reply-to: References: <7900964C-F99E-481E-BEE5-4338774CEB9F@gmail.com> <1607957.1767725532@sss.pgh.pa.us> <1654153.1767753474@sss.pgh.pa.us> <1752324.1767805242@sss.pgh.pa.us> Comments: In-reply-to Richard Guo message dated "Thu, 08 Jan 2026 12:23:36 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1892151.1767844982.1@sss.pgh.pa.us> Date: Wed, 07 Jan 2026 23:03:02 -0500 Message-ID: <1892152.1767844982@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Richard Guo writes: > The underlying expression of a join alias Var can only be a Var > (potentially coerced) from one of the join's input rels, or a COALESCE > expression containing the two input Vars. Therefore, it should not be > able to contain SRFs or volatile functions, and thus we do not need to > expand it beforehand. [ itch... ] That statement is false in general, because subquery pullup within the subquery can replace a sub-subquery's output Vars with expressions. It might be okay for this purpose, as I think we'd not pull up if the sub-subquery's output expressions are volatile or SRFs. These assumptions had better be well commented though. The larger point here is that this behavior is all recursive, and we can happily end with an expression that's been pulled up several levels; we'd better make sure the right checks happen. So I'm a little bit distressed that planner.c's invocations of flatten_group_exprs are not at all analogous to its usage of flatten_join_alias_vars. The latter pattern has a couple of decades of usage to lend credence to the assumption that it's correct. flatten_group_exprs, um, not so much. It may be fine, given the fact that grouping Vars can appear within much less of the query than join aliases. But in view of the present bug, I'm feeling nervous. regards, tom lane