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 1rv96O-009zFF-Ax for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Apr 2024 05:05:29 +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 1rv96N-00A3Tb-BI for pgsql-hackers@arkaria.postgresql.org; Fri, 12 Apr 2024 05:05:27 +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 1rv96M-00A3Pl-TU for pgsql-hackers@lists.postgresql.org; Fri, 12 Apr 2024 05:05:27 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by makus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rv96J-002SJA-Jb for pgsql-hackers@lists.postgresql.org; Fri, 12 Apr 2024 05:05:25 +0000 Received: from [172.30.0.166] (unknown [172.30.0.166]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: a.lepikhov@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id B71D3E20EA3; Fri, 12 Apr 2024 08:05:16 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1712898319; bh=3GFa/6IaSdySYWXn/+jLvEXibazaoCVX6Ly4r/4MnUU=; h=Message-ID:Date:User-Agent:Subject:To:Cc:References:From: In-Reply-To:From; b=AM/dAyI6BZw6COCVjQ/MeSfJvPh/IV5SdEVFRfSkzNAL79yco8aHwHWvafEsjMx7Y bJl+BWphvVkDTacXS5IO1ev0CwxkrLBmLcOExUy4hiXN3GSTQKm+Gx8lbCqnZOPLf8 SfeGOH35uLxFyMp6H3yawMJGReU32jVWJEhvnoEVjfUoTllhSljUNkouEQ11bAWj6l 0L+dBhcysMPpSVPENFmpS5LeQpzyJFMDqeHjEHBWoJWWP0XExSvsEiBcVos4bD8jg0 jPkoIzBDeIMBB6DhHPHlUjEss1ISPyAx71y1AqOZR78Jd9+eOKgU8DpBmtdV3S90G7 sF3eGAnRkh/GA== Message-ID: <8f06a452-55f7-4b72-bb9f-c1f3df44b94b@postgrespro.ru> Date: Fri, 12 Apr 2024 12:05:14 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: POC: GROUP BY optimization To: Tom Lane , Alexander Korotkov Cc: Richard Guo , Pavel Borisov , vignesh C , PostgreSQL Developers , Tomas Vondra , Teodor Sigaev , David Rowley , "a.rybakina" References: <3046975.1706839355@sss.pgh.pa.us> <890ed877-e2c0-448a-93b8-b07ccf3a2b37@postgrespro.ru> <266850.1712879082@sss.pgh.pa.us> Content-Language: en-US From: Andrei Lepikhov Organization: Postgres Professional In-Reply-To: <266850.1712879082@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/12/24 06:44, Tom Lane wrote: > If this patch were producing better results I'd be more excited > about putting more work into it. But on the basis of what I'm > seeing right now, I think maybe we ought to give up on it. First, thanks for the deep review - sometimes, only a commit gives us a chance to get such observation :))). On a broader note, introducing automatic group-by-order choosing is a step towards training the optimiser to handle poorly tuned incoming queries. While it's true that this may initially impact performance, it's crucial to weigh the potential benefits. So, beforehand, we should agree: Is it worth it? If yes, I would say I see how often hashing doesn't work in grouping. Sometimes because of estimation errors, sometimes because grouping already has sorted input, sometimes in analytical queries when planner doesn't have enough memory for hashing. In analytical cases, the only way to speed up queries sometimes is to be smart with features like IncrementalSort and this one. About low efficiency. Remember the previous version of the GROUP-BY optimisation - we disagreed on operator costs and the cost model in general. In the current version, we went the opposite - adding small features step-by-step. The current commit contains an integral part of the feature and is designed for safely testing the approach and adding more profitable parts like choosing group-by-order according to distinct values or unique indexes on grouping columns. I have passed through the code being steered by the issues explained in detail. I see seven issues. Two of them definitely should be scrutinised right now, and I'm ready to do that. -- regards, Andrei Lepikhov Postgres Professional