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 1v2V0d-004Zqg-Fy for pgsql-hackers@arkaria.postgresql.org; Sat, 27 Sep 2025 13:30:43 +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 1v2V0a-00A7wS-2S for pgsql-hackers@arkaria.postgresql.org; Sat, 27 Sep 2025 13:30:40 +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 1v2V0Z-00A7wJ-5F for pgsql-hackers@lists.postgresql.org; Sat, 27 Sep 2025 13:30:40 +0000 Received: from fhigh-b7-smtp.messagingengine.com ([202.12.124.158]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1v2V0W-000OaP-1Z for pgsql-hackers@postgresql.org; Sat, 27 Sep 2025 13:30:39 +0000 Received: from phl-compute-06.internal (phl-compute-06.internal [10.202.2.46]) by mailfhigh.stl.internal (Postfix) with ESMTP id 6055A7A0134; Sat, 27 Sep 2025 09:30:33 -0400 (EDT) Received: from phl-mailfrontend-02 ([10.202.2.163]) by phl-compute-06.internal (MEProxy); Sat, 27 Sep 2025 09:30:33 -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=1758979833; x=1759066233; bh=kuQbmny7wbdE7PjWMyc0wVBIUjc59Swk HijS0l7fVFM=; b=PwxLjsFMjHQtJe2IgF7v7/vKItfJn8itsNzM35iiRjBSqqrY Y/laT79SmRsmFphWtWWMNcw8Mf58V29yyeNc3ECZ+x/teWd9aorxNgGUuIaFT4dA 9YVuI3dVk9Cr7bN3MhoJ+6ys3HTkFABOzs0UgtBCweDYQfeHaZHb6n6vfMNleUJv gc+bm9R6qqOtXWhIpr2FFzL90GcZCe9kgIxt0/sEkcRe9xmdCo8f6pCgRLUnU2Zr PtYNmXOgKLb3a/vwMnv5VtZuTluPwMhQpKDb2xtfNiv5kEOoxusJ0dr9sp8Cqd04 xU/K4zkmja90inlThygX0TS0Fh/rP4ETqLkNmw== 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=1758979833; x= 1759066233; bh=kuQbmny7wbdE7PjWMyc0wVBIUjc59SwkHijS0l7fVFM=; b=k F2ieHKvCW3L1YDpUX4ZCUsdzAvzmUWJHEigclUqJ+/gdufoMyLBFj8MzXvimtrAL k5KfbY/M4Ud4J+fFfk1iAcCZORg/AUf/oESTZpjc+HHaQLznlki+QYlptZ52hx2f blNFbbOzXQInAY+pFrUkRc6n+txBjcsQZEazWjZBDfG1RVnQs2Uypn9lGHsW/yxJ s61eP4RWul58neRm3PBbhiasSUCoDvgpOZByBJ416y0zWeeW5bPQ6+eOJvwHZDc2 8gVqlQkkhaJnYurVfc+i9s7ZD32dCQKPkrANfTzc90ovsMufP/0fqhCeDwZ4kTiS zlyPSKT7aHja2zWfexx+g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtdeggdejvdefjecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefkffggfgfuvfevfhfhjggtgfesthejredttddvjeenucfhrhhomheprfgvthgvrhcu gfhishgvnhhtrhgruhhtuceophgvthgvrhesvghishgvnhhtrhgruhhtrdhorhhgqeenuc ggtffrrghtthgvrhhnpefgjedthfekfedtuefgieelheetleejgefhueeltdfhueetvdff udekfeejhfegheenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpehpvghtvghrsegvihhsvghnthhrrghuthdrohhrghdpnhgspghrtghpthhtohep hedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtohepthhglhesshhsshdrphhghhdrph grrdhushdprhgtphhtthhopehpghhsqhhlqdhhrggtkhgvrhhssehpohhsthhgrhgvshhq lhdrohhrghdprhgtphhtthhopegurghvihgurdhgrdhjohhhnhhsthhonhesghhmrghilh drtghomhdprhgtphhtthhopegurghvihgusehpghhguhhruhdrnhgvthdprhgtphhtthho pehpohhsthhgrhgvshesjhgvlhhtvghfrdhnlh X-ME-Proxy: Feedback-ID: ie0a040ee:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 27 Sep 2025 09:30:31 -0400 (EDT) Message-ID: <87b40ca1-f935-4d71-9edb-9d9f1053cb45@eisentraut.org> Date: Sat, 27 Sep 2025 15:30:29 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] GROUP BY ALL To: Tom Lane Cc: pgsql-hackers , "David G. Johnston" , David Christensen , Jelte Fennema-Nio References: <931747.1721687375@sss.pgh.pa.us> <634aca95-6db5-4beb-b18d-67e65582817f@eisentraut.org> <4054709.1758895915@sss.pgh.pa.us> <3d01eb20-d587-4dec-9261-0c92240ce546@eisentraut.org> <4174779.1758917912@sss.pgh.pa.us> Content-Language: en-US From: Peter Eisentraut In-Reply-To: <4174779.1758917912@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 22:18, Tom Lane wrote: > Got it, mostly. There is an edge case, though: what if there are no > candidate grouping items? I see these test cases in David's patch: > > +-- oops all aggregates > +EXPLAIN (COSTS OFF) SELECT COUNT(a), SUM(b) FROM t1 GROUP BY ALL; > + QUERY PLAN > +---------------------- > + Aggregate > + -> Seq Scan on t1 > +(2 rows) > + > +-- empty column list > +EXPLAIN (COSTS OFF) SELECT FROM t1 GROUP BY ALL; > + QUERY PLAN > +---------------- > + Seq Scan on t1 > +(1 row) > > That is, in such cases the patch behaves as if there were no GROUP BY > clause at all, which seems kinda dubious. Should this be an error, > and if not what's it supposed to do? These should resolve to GROUP BY (). > Also, what about window functions in the tlist? > (I didn't stop to figure out why this isn't giving the same error, but > maybe it's an order-of-checks thing.) In any case: should this give > "window functions are not allowed in GROUP BY", or should the > window-function-containing tlist item be silently skipped by GROUP BY > ALL? Trying to make it work is surely not the right answer. Hmm, I don't know. The syntactic transformation talks about select list elements that "do not directly contain an ", but that can also appear as part of , so the syntactic transformation might appear to apply only to some types of window functions, which doesn't make sense to me. I don't know what a sensible behavior should be here. Maybe in this first patch version just reject use of GROUP BY ALL if you find any window functions in the select list.