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 1vIrcx-0008Zj-19 for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Nov 2025 16:53:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vIrcv-0073U4-0S for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Nov 2025 16:53:53 +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 1vIrcu-0073Tw-2Z for pgsql-bugs@lists.postgresql.org; Tue, 11 Nov 2025 16:53:52 +0000 Received: from relay3-d.mail.gandi.net ([217.70.183.195]) by makus.postgresql.org with smtp (Exim 4.96) (envelope-from ) id 1vIrcs-006ZuQ-2L for pgsql-bugs@lists.postgresql.org; Tue, 11 Nov 2025 16:53:51 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 55879201C5; Tue, 11 Nov 2025 16:53:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=postgresfriends.org; s=gm1; t=1762880028; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mzVVnC1XZqswNEHRnLwoRYJVgz8twtb5Fn/DgLv4lCc=; b=cgd2X/iATbLgrA15zhOR4HXTXJQt+dB+wA5rl3ExMJ4g7txnb3s09dwIalr4OJFBLo0Z3R tFde6avzz145eknoFCosdFpsNfBEM71x8AGukC8Ys+yO9sjUPv1/I/BCJ5/sS4up+CT1x3 y1tpk2MC96VUn0iqnU7Z9OMgGH0DXloA8ufd5SUdvDU6rEP8dnMW1gIUiOScgoqxF1HV1c zybL3kHZciKYWWVlpNEUD65MSRoqydKRfbi2hinInSnwRIanH77gFDWh/IiApMp7IoWp/M sv7cyJLKFLCAUPOHTs1XKHrK+QZyM9ubS7Ph1IXBRa2NfwQELcBTjcZOcUDzgA== Message-ID: Date: Tue, 11 Nov 2025 17:53:45 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #19106: Potential regression with CTE materialization planning in Postgres 18 To: Tom Lane Cc: Kamil Monicz , pgsql-bugs@lists.postgresql.org, Peter Eisentraut 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> <2184532.1762874669@sss.pgh.pa.us> Content-Language: en-US From: Vik Fearing In-Reply-To: <2184532.1762874669@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-GND-State: clean X-GND-Score: -100 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggddvtddujedvucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefkffggfgfuvfevfhfhjggtgfesthekredttddvjeenucfhrhhomhepgghikhcuhfgvrghrihhnghcuoehvihhksehpohhsthhgrhgvshhfrhhivghnughsrdhorhhgqeenucggtffrrghtthgvrhhnpedutdevfeelgedvuddtjefhhfelhefhveehieelhfegtedtuefhtdffgedvgfetffenucfkphepkeehrddvvdelrdeiiedrkeegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepkeehrddvvdelrdeiiedrkeegpdhhvghloheplgdutddrtddruddrvddvngdpmhgrihhlfhhrohhmpehvihhksehpohhsthhgrhgvshhfrhhivghnughsrdhorhhgpdhnsggprhgtphhtthhopeegpdhrtghpthhtohepthhglhesshhsshdrphhghhdrphgrrdhushdprhgtphhtthhopehkrghmihhlsehmohhnihgtiidruggvvhdprhgtphhtthhopehpghhsqhhlqdgsuhhgsheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhgpdhrtghpthhtohepphgvthgvrhesvghishgvnhhtrhgruhhtrdhorhhg X-GND-Sasl: vik@postgresfriends.org List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 11/11/2025 16:24, Tom Lane wrote: > 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 function> shall not contain a > or a . > > The predecessor text in SQL99 says > > 4) The simply contained in specification> shall not contain a > or a . > > I don't think replacing with moved the > goalposts at all, but maybe I'm missing something. I don't think you are.  I was missing that you can't get to without going through (or a window) so I did not see that rule. I had a rummage through the archives but couldn't easily find the paper introducing aggregates so I can't see what the justification for that rule was. This language was not in 1989 but is in 1992. It may just be a case of "this is what we've implemented so this is what we are specifying." >> ... 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. Thank you for the explanation. -- Vik Fearing