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 1lMwPE-0004Cc-Kl for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Mar 2021 17:25:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lMwPD-0000Ud-Hr for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Mar 2021 17:25:55 +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 1lMwPD-0000UW-6d for pgsql-hackers@lists.postgresql.org; Thu, 18 Mar 2021 17:25:55 +0000 Received: from mail-ed1-x536.google.com ([2a00:1450:4864:20::536]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lMwPA-0001IO-Cc for pgsql-hackers@lists.postgresql.org; Thu, 18 Mar 2021 17:25:54 +0000 Received: by mail-ed1-x536.google.com with SMTP id dm8so7687414edb.2 for ; Thu, 18 Mar 2021 10:25:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=cZ27iXSLgGDKr93rXIXMaccJGgQf4NoFnETm+vSnyxM=; b=ZxMkgAvxkeCEi/Bcie+iY7yxS1l9A+nqcfsX8SroKqiZ3cgWx+RHBd5BpY6sxZLXFJ eXi2pWdYi12/1wK3yS0/Wkx8Mwngksq98CmSgvZ4PprZNjM8krKlSUN/MwsTXZ1mlT3d qzQQTX4PYKwVompSdxlIls30NW3tLS6AjmcDT1uDCLS4QFY9EbgPK/rDMQ4biDG+4jL3 9R5TR8Ln/NVb0FeALruOJmTVgqYt6DcmpjUhcCJkGw3ODHmcWbdh123Tz/G4HIaovIbw iYVCrsHz7Oe/xfTCMPqzOf+/Bh6bSNd5ATZol4bkapj905zdcqHsChDNHBUvQnM/IgRY Wdow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=cZ27iXSLgGDKr93rXIXMaccJGgQf4NoFnETm+vSnyxM=; b=k0/fm+8B3sEa+1VX2Zenfw4xPtbCiKTpKlW+UeiKuq92zWZJaE8jqrcHZKTNFQ9e1w wqX692EYfL+pq6qDHu38y3VGyZGbtZchBsOulwmtuLI6VzoJ2CGwcEaRyQNCHtFoSQGh UdNtqYRR+3KOQyGG4D8R3TXno0TSbCu5beUd4Xoa0TArbwmObcPYNvrmy0HxIGpEQIiH 6AI0H8E/yN7pMX33vstGRukpkGRfsUbzusEksEf192/HPDJiQ52Hr2CH9mu8EXcZ8HP+ 2RtRaa4ucLOkLnLJeXHW6+bd3AIeIiY8SM6P+CUuJJNSRXCk2EzsvKjv0aWYPnJPmxXL 3KsA== X-Gm-Message-State: AOAM5313qcdvg3BBxs7NIQzdTVf+RMn/2kxZfnTZaUtV37V2/GzjmJSF i4yQyQu7coUbTG3rkgMi7vLQVCtbiQ8dmTSMVaVodt35a+hNeY4HZfWTYtOAeQnkwAPHnF8uemH D87VlC9iFD+jElP47ChgmmlEtYP0R7Uc56R4cuUxRVLngJiyKCBzwCnBOR4wIhA9enT1AngBN/x Dlgvjis07jfEf5hpp1ha+dC2B5MKVoqwC7vK+77abWGK3qtTwS3Mvf X-Google-Smtp-Source: ABdhPJwfQYYi2bNYHTB1bASZEqRW8gqAR0BMHz1dduG0J5FgASrL1jEj7hZ+py6u3fEu6PhdUNz+VQ== X-Received: by 2002:a50:9ea7:: with SMTP id a36mr5110582edf.174.1616088349957; Thu, 18 Mar 2021 10:25:49 -0700 (PDT) Received: from [10.137.0.20] (ip-86-49-253-127.net.upcbroadband.cz. [86.49.253.127]) by smtp.gmail.com with ESMTPSA id w18sm2331171ejn.23.2021.03.18.10.25.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 18 Mar 2021 10:25:49 -0700 (PDT) Subject: Re: GROUP BY DISTINCT From: Tomas Vondra To: Vik Fearing , Georgios Kokolatos , pgsql-hackers@lists.postgresql.org Cc: Erik Rijkers References: <161469758801.29967.4455067072614569957.pgcf@coridan.postgresql.org> <4294e82f-a134-5dbb-d9d6-03d72dce2e1e@postgresfriends.org> <3817d5ec-f3e4-e4b9-d169-271ae5d3cbe4@postgresfriends.org> <8c44df08-bb64-3d78-da1a-d24b7c9db39d@enterprisedb.com> Message-ID: <7137947a-87be-d04a-bf91-f42e47520daa@enterprisedb.com> Date: Thu, 18 Mar 2021 18:25:47 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.0 MIME-Version: 1.0 In-Reply-To: <8c44df08-bb64-3d78-da1a-d24b7c9db39d@enterprisedb.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/16/21 3:52 PM, Tomas Vondra wrote: > > > On 3/16/21 9:21 AM, Vik Fearing wrote: >> On 3/13/21 12:33 AM, Tomas Vondra wrote: >>> Hi Vik, >>> >>> The patch seems quite ready, I have just two comments. >> >> Thanks for taking a look. >> >>> 1) Shouldn't this add another for DISTINCT, somewhere in the >>> documentation? Now the index points just to the SELECT DISTINCT part. >> >> Good idea; I never think about the index. >> >>> 2) The part in gram.y that wraps/unwraps the boolean flag as an integer, >>> in order to stash it in the group lists is rather ugly, IMHO. It forces >>> all the places handling the list to be aware of this (there are not >>> many, but still ...). And there are no other places doing (bool) intVal >>> so it's not like there's a precedent for this. >> >> There is kind of a precedent for it, I was copying off of TriggerEvents >> and func_alias_clause. >> > > I see. I was looking for "(bool) intVal" but you're right TriggerEvents > code does something similar. > >>> I think the clean solution is to make group_clause produce a struct with >>> two fields, and just use that. Not sure how invasive that will be >>> outside gram.y, though. >> >> I didn't want to create a whole new parse node for it, but Andrew Gierth >> pointed me towards SelectLimit so I did it like that and I agree it is >> much cleaner. >> > > I agree, that's much cleaner. > >>> Also, the all_or_distinct vs. distinct_or_all seems a bit error-prone. I >>> wonder if we can come up with some clearer names, describing the context >>> of those types. >> >> I turned this into an enum for ALL/DISTINCT/default and the caller can >> choose what it wants to do with default. I think that's a lot cleaner, >> too. Maybe DISTINCT ON should be changed to fit in that? I left it >> alone for now. >> > > I think DISTINCT ON is a different kind of animal, because that is a > list of expressions, not just a simple enum state. > >> I also snuck in something that all of us overlooked which is outputting >> the DISTINCT in ruleutils.c. I didn't add a test for it but that would >> have been an unfortunate bug. >> > > Oh! > >> New patch attached, rebased on 15639d5e8f. >> > > Thanks. At this point it seems fine to me, no further comments. > Pushed. Thanks for the patch. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company