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 1lMB49-0001xX-PG for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Mar 2021 14:53:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lMB48-0007iM-Mj for pgsql-hackers@arkaria.postgresql.org; Tue, 16 Mar 2021 14:53:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lMB48-0007iB-Cw for pgsql-hackers@lists.postgresql.org; Tue, 16 Mar 2021 14:53:00 +0000 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lMB45-00029l-Dp for pgsql-hackers@lists.postgresql.org; Tue, 16 Mar 2021 14:53:00 +0000 Received: by mail-ej1-x631.google.com with SMTP id si25so16936737ejb.1 for ; Tue, 16 Mar 2021 07:52:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=D4T1AxuiQVsLtyhwSdCOjGSIA43sWBuuOpySP8x/L9Q=; b=s+D7CcCLDHFexgwK0DhsJeFBzhOUK3AUyyZX25enkIwkdGtotM9Td489BcbVUZazaD uEA73xvSqB1dxMtTYQN3PwEhSccuS5ZKIKB/A8rYqziLP307FGJKBVyqX3B5/Pzcuj4y YwrXsFT9bUQbKM6mxy7U27eDfIwaD/PqcwmERXt2fJf85dqtulogi1Poee/rOSkwskVH j4/K6n5xChQU7THNh739ens9yY7uX0EXe4ce4D8rfzDWm/R/jneRnmZiCeRPwg7lAHFw shGcY7D5aTpFdbtzJ3FvISwoaKPYoAPnDYYb7au74uxNSkYaWTP75OZnsIhdWy5yl9Zo 54Cg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=D4T1AxuiQVsLtyhwSdCOjGSIA43sWBuuOpySP8x/L9Q=; b=HpByMcuGfCMgfaF35uzdJJBbtKurqpbf1mfpj2KyFJWPVqZZCmYrsVJtbtvVqt9ZtP sZyS8KaaqNXfLdZDebEbWE29ViKDFI596aqJiqRJ/7TY0Vc2QDwbcLIc2BxhxBR0mxKs 8HOxd6pXIjorMEJNZ1JNjfMWC9wTEeoxgt0bOILLOzgtWetr0ybEuMIOxfvUJEgnfD1s 7VZoiHTYELO9cW4oo+I9/yganrXY/5RlfDMSk+NVGZZoG3w+fipL7qTpSEuN5NsBKufl cC+RMVJJtuez4Pl3yfkLrU5/8ows2wCr/pPxBuuXcgX867D2P/Q1E6RXDItcp5CWmiCd AsbQ== X-Gm-Message-State: AOAM532Lf1l2ujItadcDBdONBvUEpghrJ9R1XTNiJaQ7E30Md6Jo5/RX PJQbou2o/2h/lp3W2G21OJmAHQABppOdl4ZpA86ATcK7DXk8surbegyBRko5oPXK2DlNcLQUR9Q n4Bh/kgEuwQwfNvdLF/qBloycc1FDYQ6fE8iS9NIsos9QJ5a1o8I0X8cKGIRlAYaCuem/jrFENS ks0S/1Ct1XoKSgMlmmJoptzqWcYEK88PFGjeWx4F4MR0yLbnU5HgB+ X-Google-Smtp-Source: ABdhPJwwGAeqqst0lof9RMmvihcjGbCX/ABQ+PslfUF1TIHNPza/xvKIdLfa1Yo4OynmMLNThW8T5A== X-Received: by 2002:a17:906:3849:: with SMTP id w9mr30521589ejc.7.1615906376436; Tue, 16 Mar 2021 07:52:56 -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 jj16sm9742576ejc.19.2021.03.16.07.52.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 Mar 2021 07:52:55 -0700 (PDT) Subject: Re: GROUP BY DISTINCT 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> From: Tomas Vondra Message-ID: <8c44df08-bb64-3d78-da1a-d24b7c9db39d@enterprisedb.com> Date: Tue, 16 Mar 2021 15:52:52 +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: <3817d5ec-f3e4-e4b9-d169-271ae5d3cbe4@postgresfriends.org> 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 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. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company