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.94.2) (envelope-from ) id 1v2V9q-004bFX-H2 for pgsql-hackers@arkaria.postgresql.org; Sat, 27 Sep 2025 13:40:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1v2V9o-00AC7n-He for pgsql-hackers@arkaria.postgresql.org; Sat, 27 Sep 2025 13:40:13 +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.94.2) (envelope-from ) id 1v2V9o-00AC7f-8F for pgsql-hackers@lists.postgresql.org; Sat, 27 Sep 2025 13:40:12 +0000 Received: from fhigh-b8-smtp.messagingengine.com ([202.12.124.159]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1v2V9m-000OeY-1w for pgsql-hackers@postgresql.org; Sat, 27 Sep 2025 13:40:12 +0000 Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfhigh.stl.internal (Postfix) with ESMTP id 386EB7A010F; Sat, 27 Sep 2025 09:40:08 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-01.internal (MEProxy); Sat, 27 Sep 2025 09:40:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eisentraut.org; h=cc:cc:content-transfer-encoding:content-type:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:subject:subject:to:to; s=fm1; t=1758980408; x=1759066808; bh=t5l0ij8MA4kQyJx2vqP0FwAIy1nFO5DD KrlRd5CNo/M=; b=EMU/X69PgBahU9a8VvpNVxdbI4emoMnkUwGr7PflUllRNVqd AFqGVvLZpahFh7w/jkxCAY0HjufDkNKipIBFOSJIHfye2tkug92T6IlIbip3b7SC a2JqZFtELRK17f4qsZJD31X2UqnrSoUZLPHxyZ2idW3Mp8hOtLSVqUn2VZ3j0cn7 MnuVl1Je1HDrRwa2BjFfm/HG/d1nFm8mKxnFkRUgEsCuZhJGA/1pTfoTok2V9FvN Yt+9pnKotPUA8w7WXkKxJQMY4s8Lh859LvHPht/pf64C7kdLe9i6l2eyHP3JtK1+ OEMg20nkeATzagNTkAxUqKOwBUuyyDiwx50ieA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1758980408; x= 1759066808; bh=t5l0ij8MA4kQyJx2vqP0FwAIy1nFO5DDKrlRd5CNo/M=; b=d acZaZ3iJHtcSPr32Wsp+DYbAz3HR4Y6+W4AGI9AguQLrZrmzn/T1X/Hd/miO1oLi ycIxEY1B3IT/qdtRaPGnqrVRyMYumLQ4qEf0Ew1xvhnHHCILDUt3UlXLS+4yluoR GSzMCQY3r3Ufr1LV0VUXmc65WqCZybSUkn2iqo+rsZezTpRMItlR/lDfrcjhSmSN mD3GaAkStY8nCV1ADmwXogad/ExZfeQTd7iVa/fdIgpKQLCvzv8LctWnQOAPsQZb KDW+YdS6dybrJZVniCLWlhq3alvMtVom4HcCRBOOwyjpqk5a35zg7Wgv/TVfwbN2 t6YvnTB+arDKvfUSFZ9Og== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdejvdeflecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefkffggfgfuvfevfhfhjggtgfesthejredttddvjeenucfhrhhomheprfgvthgvrhcu gfhishgvnhhtrhgruhhtuceophgvthgvrhesvghishgvnhhtrhgruhhtrdhorhhgqeenuc ggtffrrghtthgvrhhnpefgjedthfekfedtuefgieelheetleejgefhueeltdfhueetvdff udekfeejhfegheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehpvghtvghrsegvihhsvghnthhrrghuthdrohhrghdpnhgspghrtghpthhtohep iedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepthhglhesshhsshdrphhghhdrph grrdhushdprhgtphhtthhopegurghvihgusehpghhguhhruhdrnhgvthdprhgtphhtthho peiggehmmhhmseihrghnuggvgidqthgvrghmrdhruhdprhgtphhtthhopehpghhsqhhlqd hhrggtkhgvrhhssehpohhsthhgrhgvshhqlhdrohhrghdprhgtphhtthhopegurghvihgu rdhgrdhjohhhnhhsthhonhesghhmrghilhdrtghomhdprhgtphhtthhopehpohhsthhgrh gvshesjhgvlhhtvghfrdhnlh X-ME-Proxy: Feedback-ID: ie0a040ee:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 27 Sep 2025 09:40:06 -0400 (EDT) Message-ID: Date: Sat, 27 Sep 2025 15:40:05 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] GROUP BY ALL To: Tom Lane , David Christensen Cc: Andrey Borodin , pgsql-hackers , "David G. Johnston" , Jelte Fennema-Nio References: <4D2047B0-E8D8-472B-B7E8-61206B1E6AFA@yandex-team.ru> <4083063.1758902694@sss.pgh.pa.us> <4085064.1758903815@sss.pgh.pa.us> Content-Language: en-US From: Peter Eisentraut In-Reply-To: <4085064.1758903815@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 26.09.25 18:23, Tom Lane wrote: > No, I think the correct behavior would have to be to descend into > SubLinks to see if they contain any aggregates belonging to the > outer query level. > > However (looks around) we do already have that code. > See contain_aggs_of_level. (contain_agg_clause is essentially > a simplified version that is okay to use in the planner because > it's already gotten rid of sublinks.) > > What mainly concerns me at this point is whether we've identified > aggregate levels at the point in parsing where you want to run this. > I have a bit of a worry that that might interact with grouping. > Presumably the SQL committee thought about that, so it's probably > soluble, but ... The language used in the standard at the moment is the select list elements that "do not directly contain an ", where "directly contain" is a term of art that means "contains without an intervening instance of , , or that is not an ". So it means not to look into subqueries. Note that in standard SQL, the GROUP BY clause can only contain plain column references, not expressions, so this question is kind of moot in that context, because the query would be invalid no matter whether you transform the GROUP BY ALL to group by the subquery or not. For this first patch version, I suggest you reject the use of GROUP BY ALL if you find a subquery in the select list, unless you have an unambiguous better solution. (It was discussed to relax this restriction, so this discussion is useful to collect some questions related to that.)