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 1lKrHu-0007EJ-8y for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Mar 2021 23:33:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lKrHt-0002RR-6k for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Mar 2021 23:33:45 +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 1lKrHs-0002PU-Vs for pgsql-hackers@lists.postgresql.org; Fri, 12 Mar 2021 23:33:44 +0000 Received: from mail-ed1-x52c.google.com ([2a00:1450:4864:20::52c]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lKrHo-0008Ia-K5 for pgsql-hackers@lists.postgresql.org; Fri, 12 Mar 2021 23:33:44 +0000 Received: by mail-ed1-x52c.google.com with SMTP id i61so10282719edd.7 for ; Fri, 12 Mar 2021 15:33:40 -0800 (PST) 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=DJTUHqqtbX/86B+eAEDe8855jcsvyqhibQ/Xi9DVh5I=; b=Wo/tX6v+eQa0X7MIDs74jzP97WLeI4ezu6/LI6p7kIIjbCn05swgn2uwXEuWkGdxJg X0svZrJ69XjdnX2IH7Z/Dcgc7tpnFJDAT+JYxt70FIpMPj9xvibsVXqYs5fRe68xAcq1 qBqKzVTxEKk1mlwWrijgqw+Cro2VcKAbeSg6CJXcwAZ4/NaXoEyXPAV1aru89P3oJr9C jQW9iBZTktbTrqqmX6H0/i18OHYqOpp/0aiDFlgDzA0tBohCPMs9ylqpb5mUtx/xH/pj yJB3o7JdYf9IqdfHXK850QViug5Mdw+8d8IuEkMdvf0wtoPHcxlRS3w14y+yoFKyzUfV MwvA== 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=DJTUHqqtbX/86B+eAEDe8855jcsvyqhibQ/Xi9DVh5I=; b=gFtmcczVg+oPAH7aK84j4s1gTSE5sQMo10u/vneQwzCDfKNabqDellYK7RjvffrpZe 9Puyp4gTy7ViPqb3GKiTR61zrLnyU5eDPA7yywB5xVIGq5IRC9YPUevCGCIfr7JOGtYH N5dzZMPc63wDndAFvzkiA/4Rm2nrm2Nml74i3mIMKaTh5y0Cr6czTWtx0PxR6zx5uEfx s/NO8q64sZnnXc3Qfp84jZrrmDw02A/XyOWtqvIvQA+auxahOLybR5YlnD/QkEARwwwO uQmbInO+sdeBjCz18SpRVtQ0+7dsgjRjRJQNTD665VAsIvsljuF8Hv9Fm/kOlPacUFe9 BfPw== X-Gm-Message-State: AOAM533hWmXIFUZE13esyPIrGyAXVGsctkuIyjMTOXrJrxM4qbhekNQp XLriyAGoy50V1C1takLDcceKtlAoVZeHzCHLkUW3HgxlfILycGArzhkn9nD3jBdHCxj5lQ2M+KK 8gsTkdkT7lP5UDUXIaIITTl6BUbAw/Q3UDiN3Sg8L3k/MCk3YF8GXo2lZKZhKwJTfCfSqUaMhjD 4NcStluB/ypgZqoWeOA/ceUwxcfZD1eSV+DPl3avthU4l85rbe7yD3 X-Google-Smtp-Source: ABdhPJwLD34ubvyF//OXE01YW2ZncaP4QRB9R9Yyf12XWJUwee/2K3E+PXTnkfxvObqL+1yqvB4ftw== X-Received: by 2002:a05:6402:b41:: with SMTP id bx1mr17275031edb.69.1615592019652; Fri, 12 Mar 2021 15:33:39 -0800 (PST) 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 q20sm3430095ejs.41.2021.03.12.15.33.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 12 Mar 2021 15:33:38 -0800 (PST) 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> From: Tomas Vondra Message-ID: Date: Sat, 13 Mar 2021 00:33:36 +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: <4294e82f-a134-5dbb-d9d6-03d72dce2e1e@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 Hi Vik, The patch seems quite ready, I have just two comments. 1) Shouldn't this add another for DISTINCT, somewhere in the documentation? Now the index points just to the SELECT DISTINCT part. 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. 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. 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. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company