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 1vIqEV-00GVpY-2v for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Nov 2025 15:24:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vIqET-006fn2-1d for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Nov 2025 15:24:33 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vIqET-006fmt-0o for pgsql-bugs@lists.postgresql.org; Tue, 11 Nov 2025 15:24:33 +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.96) (envelope-from ) id 1vIqER-006ZJn-1r for pgsql-bugs@lists.postgresql.org; Tue, 11 Nov 2025 15:24:32 +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 5ABFOTmv2184533; Tue, 11 Nov 2025 10:24:29 -0500 From: Tom Lane To: Vik Fearing cc: Kamil Monicz , pgsql-bugs@lists.postgresql.org, Peter Eisentraut Subject: Re: BUG #19106: Potential regression with CTE materialization planning in Postgres 18 In-reply-to: <36c1f631-f65f-4bb8-90af-9fafdb683547@postgresfriends.org> References: <19106-9dd3668a0734cd72@postgresql.org> <1650412.1762703636@sss.pgh.pa.us> <1886977.1762794560@sss.pgh.pa.us> <1980046.1762808758@sss.pgh.pa.us> <36c1f631-f65f-4bb8-90af-9fafdb683547@postgresfriends.org> Comments: In-reply-to Vik Fearing message dated "Tue, 11 Nov 2025 16:16:06 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2184531.1762874669.1@sss.pgh.pa.us> Date: Tue, 11 Nov 2025 10:24:29 -0500 Message-ID: <2184532.1762874669@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Vik Fearing writes: > On 10/11/2025 22:05, Tom Lane wrote: >> I looked at the SQL standard for possible guidance and found none: >> they disallow subqueries altogether within aggregate arguments, >> so they need not consider such cases. > I am not seeing that restriction in the standard. Maybe I'm misunderstanding what I read, but in SQL:2021 6.9 SR1 says If specifies a , then the simply contained in the shall not contain a or a . The predecessor text in SQL99 says 4) The simply contained in shall not contain a or a . I don't think replacing with moved the goalposts at all, but maybe I'm missing something. > ... MATERIALIZEDing either or both CTEs > has no effect, which I find strange. The fundamental problem is that the parser is mis-assigning agglevelsup; given that, the planner is very likely to get confused no matter what other details there are. regards, tom lane