Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lDoDy-0005HX-5Q for pgsql-hackers@arkaria.postgresql.org; Sun, 21 Feb 2021 12:52:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lDoDx-0003ii-1j for pgsql-hackers@arkaria.postgresql.org; Sun, 21 Feb 2021 12:52:33 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lDoDw-0003ia-Ic for pgsql-hackers@lists.postgresql.org; Sun, 21 Feb 2021 12:52:32 +0000 Received: from relay5-d.mail.gandi.net ([217.70.183.197]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lDoDs-0007QG-Vf for pgsql-hackers@lists.postgresql.org; Sun, 21 Feb 2021 12:52:31 +0000 X-Originating-IP: 79.88.149.14 Received: from [172.16.255.146] (14.149.88.79.rev.sfr.net [79.88.149.14]) (Authenticated sender: vik@postgresfriends.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id 99EAE1C0002 for ; Sun, 21 Feb 2021 12:52:25 +0000 (UTC) To: PostgreSQL Hackers From: Vik Fearing Subject: GROUP BY DISTINCT Message-ID: Date: Sun, 21 Feb 2021 13:52:24 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------D258B3365BDD8AD18F46455C" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------D258B3365BDD8AD18F46455C Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit When combining multiple grouping items, such as rollups and cubes, the resulting flattened grouping sets can contain duplicate items. The standard provides for this by allowing GROUP BY DISTINCT to deduplicate them prior to doing the actual work. For example: GROUP BY ROLLUP (a,b), ROLLUP (a,c) expands to the sets: (a,b,c), (a,b), (a,b), (a,c), (a), (a), (a,c), (a), () but: GROUP BY DISTINCT ROLLUP (a,b), ROLLUP (a,c) expands to just the sets: (a,b,c), (a,b), (a,c), (a), () Attached is a patch to implement this for PostgreSQL. -- Vik Fearing --------------D258B3365BDD8AD18F46455C Content-Type: text/x-patch; charset=UTF-8; name="0001-implement-GROUP-BY-DISTINCT.v01.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-implement-GROUP-BY-DISTINCT.v01.patch"