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 1lMyJD-00006I-JK for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Mar 2021 19:27:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lMyJC-0001Gx-Ey for pgsql-hackers@arkaria.postgresql.org; Thu, 18 Mar 2021 19:27:50 +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 1lMyJC-0001Gq-88 for pgsql-hackers@lists.postgresql.org; Thu, 18 Mar 2021 19:27:50 +0000 Received: from mail-ed1-x532.google.com ([2a00:1450:4864:20::532]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lMyJ8-0003qF-20 for pgsql-hackers@lists.postgresql.org; Thu, 18 Mar 2021 19:27:49 +0000 Received: by mail-ed1-x532.google.com with SMTP id o19so8100444edc.3 for ; Thu, 18 Mar 2021 12:27:45 -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=A4leEq1e6EGiiyoRkAF5i2DLJ30aaQ5ZcXkZeqhuFwo=; b=h+Tl3GT5jsgoUJUzhkhnl92s+dmghyNliL0ivAX/10mYpPbxwe/jLS2roPxWTa1iSV iRkkEbQ2H2IOrOUJkc/cFnV+VNyNdrB1K72k7jwROzr//uA1GuLrJCgsPojscWBdQj1j KGYmfnJCldyBMKTbOiDVauEyWdReRzw4LTG3JJ9WUe8jETssTr6XELRW6fo+lblAQTjf P9r3DRAmlkVqkAmCKltdFbY5cScBjrC6e+lT5VGlySyKM/UnEoE9YOhlu6BUJwt2fKu1 32TACutBuVfwxiT3f+JDnYcVZ8lOaFXfF+XTAefEFXj7NJ0zQy/nBmpV61I/wZI/Wo6Q LPZQ== 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=A4leEq1e6EGiiyoRkAF5i2DLJ30aaQ5ZcXkZeqhuFwo=; b=XUxwCyCedF6PyD7M5/i6LtJeclQpGes6L5lyU8OZRdf9DI6GI43h19lQweNJXgO9qt 3c1uvpbVqy1MkW1ZEJsLtzsybS/ylfxttsh8nwPb5kUtBAGVurtuoOzNbrU/U/KtHYjH jRCklUSRT7IZD+JUYH5G2qBikJCJSwlmd3C3ia8huTqzjHyAiSh8w8rBdwSI3c5icCK2 6ZyEuFSRaUO96rhF91A9GaKxxfYiZj/z3NQZM/XtAleOj7eMfBh92B1NANpGqSBcXdUn R/AFp4ZUd0DzAw66Tbxhhy05fbPYbKV3EooHXoOjMLcxZL+r+ERodHQk0aEiQTrvEvt3 CXzg== X-Gm-Message-State: AOAM531mogF9ya1Qgtt947DLYiSgcizU7799e9BxaR0MnfFzoFOUXUH9 r+YzDC+vC/SnQrIH88RCe46sRJq19deo1613uljUA7MqCHI2Fbk0Min3PXb7hMUdbzABp+Kx11C bAiO4u42cTq/VQE0hQgK+M/AAzdF1pThkEEhU6mRbkCOiuZ5+IqXZ3oS7ABrTT8N+VGfb7Ud7dw mCph7Mt0AFefRJEWrlS4BT+ogC1p7uaJ1QGYzs1kwHIJNEnFzfw6cw3/5kXjmC X-Google-Smtp-Source: ABdhPJzPob9yl10UaNfZlhm9fAI/A86pmkPceK/CCPWVRA6E8ci4FKvvh/98siPtN42z0R7QTzhIvA== X-Received: by 2002:a05:6402:22f6:: with SMTP id dn22mr5476128edb.214.1616095663536; Thu, 18 Mar 2021 12:27:43 -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 t15sm2792878edw.84.2021.03.18.12.27.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 18 Mar 2021 12:27:42 -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> <7137947a-87be-d04a-bf91-f42e47520daa@enterprisedb.com> Message-ID: <35077b31-2d62-1e31-0e2e-ddb52d590b73@enterprisedb.com> Date: Thu, 18 Mar 2021 20:27:40 +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: <7137947a-87be-d04a-bf91-f42e47520daa@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/18/21 6:25 PM, Tomas Vondra wrote: > 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. > Hmmm, this seems to fail on lapwing with this error: parse_agg.c: In function 'expand_grouping_sets': parse_agg.c:1851:23: error: value computed is not used [-Werror=unused-value] cc1: all warnings being treated as errors That line is this: foreach_delete_current(result, cell); and I don't see how any of the values close by could be unused ... The only possibility I can think of is some sort of issue in the old-ish gcc release (4.7.2). regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company