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 1oO8Jn-0007Ck-R2 for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Aug 2022 01:58:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oO8Jm-0000fp-K0 for pgsql-hackers@arkaria.postgresql.org; Wed, 17 Aug 2022 01:58:02 +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 1oO8Jm-0000fb-5t for pgsql-hackers@lists.postgresql.org; Wed, 17 Aug 2022 01:58:02 +0000 Received: from mail-io1-xd34.google.com ([2607:f8b0:4864:20::d34]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oO8Jj-00088M-Ga for pgsql-hackers@lists.postgresql.org; Wed, 17 Aug 2022 01:58:01 +0000 Received: by mail-io1-xd34.google.com with SMTP id h78so4537091iof.13 for ; Tue, 16 Aug 2022 18:57:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:from:to:cc; bh=D2NDPVrD/4+zxlxOoZPy6cJ8b740/dDvl+WQtKFHZts=; b=UBN4eDJycjcIPUytAM5oK8fsz/OM/K4cZFxtv/QpJsL/csAgu/Nmr6GrLGN3p+lh+d h/b5pl3BEEr8+0Vh95ueqwaH4IQpC4i6cPSFIkE9EcDj6j/u437e5N6834GEjBIQ9rr1 By+PT2A9r/Wib28QYvqZinKoIoVS4uMukCB5eFMn2u6Da8fAUj7r3YKypFK9ratRgP4W NfAEZ1xIlbu2aE6aZ6TRtQDXHmcm/YxH53hAo3hXz9KmJWBo/btuZKyGwvo8KDEaXSvy +97Bw3j9qwV/XjqdLPiv2OD1VvAImV3F2jZVpJ6nRY/ORLKXOvvTjLXJagayP5jMZ194 W7xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc; bh=D2NDPVrD/4+zxlxOoZPy6cJ8b740/dDvl+WQtKFHZts=; b=wfSR9xoO5rQIy4JgvsiTitMahwo1sDHgJ2gBM+Dm42G9pKy9k6BLO9aVXbuK0KBSrv u6/qVleNVi1rG7Eb/O+H6GivCpPRb+n43OnKQCOWauViVZweo8Bwd00ztrJjJW3ZSTij cjlvXSsirmQoSFxwTR0SbWlMUr+DMu/3IlDrtt+rZnOBuy1J4kt9dR1OToEn1x0b0Q+E zJzaQI7LvlT1qhyy+Vk7G52UHBSBjO4+CkKSyLkTBLk7q/lWi2MROLhfwBja0+jrL/5c leuKOGlq5FSshVCqVDQka9fao6X4ckmDhAFd7HmUEScoTR+JdmOHUY6aNL55MdnzCrII wvyw== X-Gm-Message-State: ACgBeo2nQeG5dgawVXq4lWHRxKUG0N1ufppCm5ihd14Ed3XkwKQ3THvC FWFvgIVg6lD9wfs+1vSR3LfeGA== X-Google-Smtp-Source: AA6agR513Iao8rBY0hNdOjWSpSmE9BadfSJnzL2ZZ25yLTVYrnl/18l0ZjcmJ9Q1MzmMu0NnTnM3+g== X-Received: by 2002:a05:6638:1644:b0:343:ee62:89fa with SMTP id a4-20020a056638164400b00343ee6289famr7901817jat.54.1660701477628; Tue, 16 Aug 2022 18:57:57 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id q23-20020a05663810d700b0034365a5b178sm5091948jad.54.2022.08.16.18.57.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 16 Aug 2022 18:57:57 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id C404A8006D0; Tue, 16 Aug 2022 20:57:55 -0500 (CDT) Date: Tue, 16 Aug 2022 20:57:55 -0500 From: Justin Pryzby To: David Rowley Cc: Tom Lane , Richard Guo , Ronan Dunklau , pgsql-hackers@lists.postgresql.org, Ranier Vilela Subject: Re: Add proper planner support for ORDER BY / DISTINCT aggregates Message-ID: <20220817015755.GB26426@telsasoft.com> References: <3163474.aeNJFYEL58@aivenronan> <1138716.1659282591@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Aug 02, 2022 at 11:21:04PM +1200, David Rowley wrote: > I've now pushed the patch. I've not studied the patch at all. But in a few places, it removes the locally-computed group_pathkeys: - List *group_pathkeys = root->group_pathkeys; However it doesn't do that here: /* * Instead of operating directly on the input relation, we can * consider finalizing a partially aggregated path. */ if (partially_grouped_rel != NULL) { foreach(lc, partially_grouped_rel->pathlist) { ListCell *lc2; Path *path = (Path *) lfirst(lc); Path *path_original = path; List *pathkey_orderings = NIL; List *group_pathkeys = root->group_pathkeys; I noticed because that creates a new shadow variable, which seems accidental. make src/backend/optimizer/plan/planner.o COPT=-Wshadow=compatible-local src/backend/optimizer/plan/planner.c:6642:14: warning: declaration of ‘group_pathkeys’ shadows a previous local [-Wshadow=compatible-local] 6642 | List *group_pathkeys = root->group_pathkeys; | ^~~~~~~~~~~~~~ src/backend/optimizer/plan/planner.c:6438:12: note: shadowed declaration is here 6438 | List *group_pathkeys; -- Justin