Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rILWK-007zpJ-4u for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Dec 2023 04:27:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rILWI-001EsI-IH for pgsql-hackers@arkaria.postgresql.org; Wed, 27 Dec 2023 04:27:50 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rILWI-001Es9-7s for pgsql-hackers@lists.postgresql.org; Wed, 27 Dec 2023 04:27:50 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rILWA-00CO2s-M6 for pgsql-hackers@lists.postgresql.org; Wed, 27 Dec 2023 04:27:48 +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 3BR4Rd172422165; Tue, 26 Dec 2023 23:27:39 -0500 From: Tom Lane To: Alexander Korotkov cc: Andrei Lepikhov , PostgreSQL Developers , Tomas Vondra , Teodor Sigaev , David Rowley , "a.rybakina" , =?UTF-8?B?0JHQtdC70Y/Qu9C+0LIg0JTQsNC80LjRgCDQndCw0LjQu9C10LLQuNGH?= Subject: Re: POC: GROUP BY optimization In-reply-to: References: <721b3ff9-f214-f5d4-86c7-bae515bbec18@enterprisedb.com> <7bea462e-8c3e-0f8c-c7d5-f4daa12f3baf@postgrespro.ru> <9af89543-3d17-4c98-59de-1daa5bceeb06@enterprisedb.com> <9408e450-60c6-6fbc-d5c4-467bb0abfe67@postgrespro.ru> <44472925-f6c6-e8de-6f72-0451458532c4@enterprisedb.com> <7a80a207-5e8e-b80c-476c-2d290b0526e9@enterprisedb.com> <65941e87-86c1-c09c-8ad5-8e102aebe8ee@enterprisedb.com> <7256159a-bb83-7ef3-c9c9-b2188a29aaf8@postgrespro.ru> <60610df1-c32f-ebdf-e58c-7a664431f452@enterprisedb.com> <9acd27e9-3372-4d78-b9bc-73e407b8a007@postgrespro.ru> <2414422.1703647404@sss.pgh.pa.us> Comments: In-reply-to Alexander Korotkov message dated "Wed, 27 Dec 2023 06:15:22 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2422163.1703651259.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Tue, 26 Dec 2023 23:27:39 -0500 Message-ID: <2422164.1703651259@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Alexander Korotkov writes: > On Wed, Dec 27, 2023 at 5:23 AM Tom Lane wrote: >> I think it's a fool's errand to even try to separate different sort >> column orderings by cost. > Besides sorting column orderings by cost, this patch also tries to > match GROUP BY pathkeys to input pathkeys and ORDER BY pathkeys. Do > you think there is a chance for the second part if we leave the cost > part aside? I think it's definitely reasonable to try to match up available orderings, because that doesn't really require fine distinctions of cost: either it matches or it doesn't. Eliminating a sort step entirely is clearly a win. (Incremental sort complicates this though. I doubt our cost model for incremental sorts is any good either, so I am not eager to rely on that more heavily.) regards, tom lane