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 1qMS74-002RFW-UZ for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Jul 2023 11:46:30 +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 1qMS73-005uX3-6A for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Jul 2023 11:46:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qMS72-005uTX-S2 for pgsql-hackers@lists.postgresql.org; Thu, 20 Jul 2023 11:46:28 +0000 Received: from mail-ej1-x634.google.com ([2a00:1450:4864:20::634]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qMS6y-000dhX-AA for pgsql-hackers@lists.postgresql.org; Thu, 20 Jul 2023 11:46:27 +0000 Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-992f6d7c7fbso124604566b.3 for ; Thu, 20 Jul 2023 04:46:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1689853582; x=1690458382; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=WPaiBCjk9xN7arQUkCoXLv6Vap2VYUNmu+GFke9aLw0=; b=XA/c7tv7neBYmOMmRwQuaRE0u6c75mzV/RkvgR6/yjW/jfSdh2GzqOJzYeSCQURaJ9 yYfx353PUHZb/2KFcHZ7uySvX7LzP3xjctrAuuQ5q5xN2hrl8tqIoJGn2+68ZZtcf89G v/Ig5i4ogGkAvPRXCelx+/RTNvs31KJSjV6x5JHJIB5ndW0x0GOSr2HI2JhmNxp3jmwj HFXGwA3yYWh3UWjyxusGe5qKNRxUT9A9xrTDONJBZHeAdu0Na0oWPkjkl1GHHUbjcvkY rnwA+tUtWpGVvMQGFAsxGefzgCDGMyVQMc9cdp81fCI9Fj2iV2qAuKTzRxmPyfjhYPni zcxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689853582; x=1690458382; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WPaiBCjk9xN7arQUkCoXLv6Vap2VYUNmu+GFke9aLw0=; b=gP9GaLXL3b/IWCtVQ2bJCLvaqNCW9MBx1GTw98AJJFAT8kemXJQLybqqBovyL9AJLI WgbdBfCps9E7f1jHnnrLYZZ13FCj9s6eeFcNZCM+7USb8NRjuQa43/NUah9sw2S0Q6kR OUqcQNHTaTiQhPmN74o6zK5zu5riS6jnZvCvg4kyAYsU7pl5qN2FBUpq/LVQCq15R+zq 2k7DU/JTknNEaOCd7h3LG8TEYsXmROOKDceu4oyYMLTiq3Uj4mLeQkDrkqDy9ARrUSo/ kJtNs40aLjsutaiyb0cMpXTichrcjthDkvtG8N/nil5lEEZMCSMI2zcW74E/dImnMmBN Ni0w== X-Gm-Message-State: ABy/qLYag3s8xZ6ICTkORzbPWsaznXoPqGmLQwxA6mwg5a60l6bB2DzZ K43nqAy9BRzC0eaXJiVnSnuNWg== X-Google-Smtp-Source: APBJJlGQ7cLPN/NNd5FgnuziDn6aMjlIRx1j8hJB1YwRBRrC7jgRrTPi3o8LKGv39iIXzM6c63Vhfw== X-Received: by 2002:a17:907:7e9a:b0:987:16c6:6ff3 with SMTP id qb26-20020a1709077e9a00b0098716c66ff3mr5478746ejc.38.1689853582567; Thu, 20 Jul 2023 04:46:22 -0700 (PDT) Received: from [10.137.0.17] (static-84-42-175-93.bb.vodafone.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id va6-20020a17090711c600b00992c4103cb5sm580244ejb.129.2023.07.20.04.46.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 20 Jul 2023 04:46:22 -0700 (PDT) Message-ID: <60610df1-c32f-ebdf-e58c-7a664431f452@enterprisedb.com> Date: Thu, 20 Jul 2023 13:46:19 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Subject: Re: POC: GROUP BY optimization Content-Language: en-US To: Andrey Lepikhov , PostgreSQL Developers , Tom Lane Cc: Zhihong Yu , Teodor Sigaev , Tomas Vondra , David Rowley , "a.rybakina" , =?UTF-8?B?0JHQtdC70Y/Qu9C+0LIg0JTQsNC80LjRgCDQndCw0LjQu9C10LLQuNGH?= References: <006667af-fc50-0627-4be7-5d9cf665219f@enterprisedb.com> <4ee5b15c-1ce0-59c7-8d4a-a1fd68ee0d12@postgrespro.ru> <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> From: Tomas Vondra In-Reply-To: <7256159a-bb83-7ef3-c9c9-b2188a29aaf8@postgrespro.ru> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 7/20/23 08:37, Andrey Lepikhov wrote: > On 3/10/2022 21:56, Tom Lane wrote: >> Revert "Optimize order of GROUP BY keys". >> >> This reverts commit db0d67db2401eb6238ccc04c6407a4fd4f985832 and >> several follow-on fixes. >> ... >> Since we're hard up against the release deadline for v15, let's >> revert these changes for now.  We can always try again later. > > It may be time to restart the project. As a first step, I rebased the > patch on the current master. It wasn't trivial because of some latest > optimizations (a29eab, 1349d27 and 8d83a5d). > Now, Let's repeat the review and rewrite the current path according to > the reasons uttered in the revert commit. I think the fundamental task is to make the costing more reliable, and the commit message 443df6e2db points out a couple challenges in this area. Not sure how feasible it is to address enough of them ... 1) procost = 1.0 - I guess we could make this more realistic by doing some microbenchmarks and tuning the costs for the most expensive cases. 2) estimating quicksort comparisons - This relies on ndistinct estimates, and I'm not sure how much more reliable we can make those. Probably not much :-( Not sure what to do about this, the only thing I can think of is to track "reliability" of the estimates and only do the reordering if we have high confidence in the estimates. That means we'll miss some optimization opportunities, but it should limit the risk. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company