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 1pFSmZ-0002Bu-W2 for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Jan 2023 04:32:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pFSmY-0007sp-I1 for pgsql-hackers@arkaria.postgresql.org; Wed, 11 Jan 2023 04:32:10 +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 1pFSmY-0007sf-8p for pgsql-hackers@lists.postgresql.org; Wed, 11 Jan 2023 04:32:10 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pFSmV-0008Cc-Tg for pgsql-hackers@lists.postgresql.org; Wed, 11 Jan 2023 04:32:09 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 30B4W4Ob416297; Tue, 10 Jan 2023 23:32:04 -0500 From: Tom Lane To: David Rowley cc: Richard Guo , Dean Rasheed , Ronan Dunklau , Justin Pryzby , Pavel Luzanov , pgsql-hackers@lists.postgresql.org, Ranier Vilela Subject: Re: Add proper planner support for ORDER BY / DISTINCT aggregates In-reply-to: References: <3163474.aeNJFYEL58@aivenronan> <9f61ddbf-2989-1536-b31e-6459370a6baa@postgrespro.ru> <2202180.iZASKD2KPV@aivenlaptop> Comments: In-reply-to David Rowley message dated "Wed, 11 Jan 2023 17:12:45 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <416295.1673411524.1@sss.pgh.pa.us> Date: Tue, 10 Jan 2023 23:32:04 -0500 Message-ID: <416296.1673411524@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk David Rowley writes: > I think whatever the fix is here, we should likely ensure that the > results are consistent regardless of which Aggrefs are the presorted > ones. Perhaps the easiest way to do that, and to ensure we call the > volatile functions are called the same number of times would just be > to never choose Aggrefs with volatile functions when doing > make_pathkeys_for_groupagg(). There's existing logic in equivclass.c and other places that tries to draw very tight lines around what we'll assume about volatile sort expressions (pathkeys). It sounds like there's someplace in this recent patch that didn't get that memo. regards, tom lane