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 1wjMz8-0004oD-2T for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Jul 2026 20:10:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wjMz5-000oLm-1m for pgsql-hackers@arkaria.postgresql.org; Mon, 13 Jul 2026 20:10:36 +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 1wjMz5-000oLe-0V for pgsql-hackers@lists.postgresql.org; Mon, 13 Jul 2026 20:10:36 +0000 Received: from smtp.outgoing.loopia.se ([93.188.3.37]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wjMz3-000000003xJ-430K for pgsql-hackers@postgresql.org; Mon, 13 Jul 2026 20:10:35 +0000 Received: from s807.loopia.se (localhost [127.0.0.1]) by s807.loopia.se (Postfix) with ESMTP id 49D1D65BDA6 for ; Mon, 13 Jul 2026 22:10:33 +0200 (CEST) Received: from s979.loopia.se (unknown [172.22.191.5]) by s807.loopia.se (Postfix) with ESMTP id 395D865BAE7; Mon, 13 Jul 2026 22:10:33 +0200 (CEST) Received: from localhost (unknown [172.22.191.5]) by s979.loopia.se (Postfix) with ESMTP id 3781210BC425; Mon, 13 Jul 2026 22:10:33 +0200 (CEST) X-Virus-Scanned: amavis at amavis.loopia.se X-Spam-Flag: NO X-Spam-Score: -1.2 X-Spam-Level: X-Spam-Status: No, score=-1.2 tagged_above=-999 required=6.2 tests=[ALL_TRUSTED=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1] autolearn=disabled Authentication-Results: s898.loopia.se (amavis); dkim=pass (2048-bit key) header.d=yesql.se Received: from s934.loopia.se ([172.22.191.5]) by localhost (s898.loopia.se [172.22.190.17]) (amavis, port 10024) with LMTP id 3OD8bCvfcjJG; Mon, 13 Jul 2026 22:10:32 +0200 (CEST) X-Loopia-Auth: user X-Loopia-User: daniel@yesql.se X-Loopia-Originating-IP: 89.255.232.236 Received: from smtpclient.apple (customer-89-255-232-236.stosn.net [89.255.232.236]) (Authenticated sender: daniel@yesql.se) by s934.loopia.se (Postfix) with ESMTPSA id 962B7917F09; Mon, 13 Jul 2026 22:10:32 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yesql.se; s=loopiadkim1707475645; t=1783973432; bh=ALSwnfZ2x7IsDa0AK4hUgYE2T6gd5487wq2n8vsb/Lc=; h=Subject:From:In-Reply-To:Date:Cc:References:To; b=S5tHTl4b/ylqdamcZJ/YQzIHoWdZ+wRGwviyNw47EaaiJ+k4wtHvpuXUP2xhbEnpV mgLHakAJiKXefoGrKeyVv4P+s2Ao1PMapB7odUiXUF95LEj06dBoOjUFrm1d2Nnugr kHRMyvaazsH0LRO+wI/D+swtGrpSFiU/LgPbph6vilRAnEGYqzMr8hDcpZ7L9uA/IJ K9mOzlYNgDJac9JlajZZEKv/iY+9oodHk1dx8a0bO+/P/RgR8peh9Nkdr343RUmoNt Ol9mGB2TF2/COBCwmVhnR8vXylx/bymEGCm4bnkgMB0X3uqjSGokhkkxETfsh5EGgm wBvghgK/TWVvQ== Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3776.700.51.11.12\)) Subject: Re: Fix GROUP BY ALL handling of ORDER BY operator semantics From: Daniel Gustafsson In-Reply-To: <5243308F-8E5C-45AA-828C-FAD96C4F34DA@gmail.com> Date: Mon, 13 Jul 2026 22:10:22 +0200 Cc: PostgreSQL Hackers , Tom Lane Content-Transfer-Encoding: quoted-printable Message-Id: References: <5243308F-8E5C-45AA-828C-FAD96C4F34DA@gmail.com> To: Chao Li X-Mailer: Apple Mail (2.3776.700.51.11.12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On 29 Jun 2026, at 09:20, Chao Li wrote: > The fix mostly refactors the existing logic so the GROUP BY ALL path = also handles the ORDER BY sort clause. See the attached patch for = details. Thanks for the report and the patch, I am going to study it a bit more = but I have a few small comments on the patch. +/* + * Add a targetlist entry to the GROUP BY list, copying matching ORDER = BY + * operator information if available. + */ This comment is a bit light for such an important routine. The foreach = has a really great comment, I think we should move some (most?) of it to the = function comment. - *flatresult =3D lappend(*flatresult, grpc); + grouplist =3D lappend(grouplist, grpc); found =3D true; break; Now that we are in an external function, we could just return grouplist = here instead of breaking with a flag. The code outside the foreach can then = call addTargetToGroupList directly since we know that if we reach thus far = there was no match. -- Daniel Gustafsson