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 1uFUhB-0054VQ-1n for pgsql-bugs@arkaria.postgresql.org; Thu, 15 May 2025 09:16:05 +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 1uFUh8-00DIT9-HF for pgsql-bugs@arkaria.postgresql.org; Thu, 15 May 2025 09:16:02 +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 1uFUh8-00DIT1-8c for pgsql-bugs@lists.postgresql.org; Thu, 15 May 2025 09:16:02 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uFUh5-001thf-2D for pgsql-bugs@lists.postgresql.org; Thu, 15 May 2025 09:16:01 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-441d1ed82faso5468315e9.0 for ; Thu, 15 May 2025 02:16:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747300558; x=1747905358; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=EZgV0/9SV5Z5Q42wb1A2QaKPauo4adPKpIeknUjb068=; b=PFG7O1jYEjJq/+JJ/z7NJy+5oH92T/oPxmFeZ0o5nnZ6LuY/b1C6RRA8+zPXSQJyOf xpt9xjdCBqQjMHmfFoObOcsTQVjij8zZA4lB+yAMyekgW6JZUmm3l8xXauBecC5tG0Ux e4VWHKSgyBAc1Tuc1vhRj9toAuOs9jt4bC7WxSsOdDirWILAgJG0tShL8HUKhgxc3tEp Rz/20pEj/XCv1jtkOsKeL2FlrjeriuFJQ0+KkN2ypw1HRYso8kS0vXQSYloTY0jC4bzM 70nV9GMgjCdMEOV9nUjwsNH3qqDL3fdabbjLAX6ZpZpyX/PAvhy1dYw5yoS9t/aOMSWh HsPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747300558; x=1747905358; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=EZgV0/9SV5Z5Q42wb1A2QaKPauo4adPKpIeknUjb068=; b=H2iqt9zo1h8c9vZK9bd0Z7/ut71vmgt3C4Cgrs3sGfzyI+PdsP/lt5BPJt7mGicCoY QFELrxXGfz3VoaBq0X0icCdsQkMnD+S5S1847G4FVdk/2IaPW1U/LNL7n+GjId2hHJIv P/jSQHewVtfSR59H/h4OKGjvyLpWlsSFMX49M4o4RmOstTydG/QWjAEHJiGEhTNTanyO WOu3QEyQrKC4WpDmmNiepsd6YTTE2ybq1adZ2zsSOiZMzqpPb5/b1KdERKNfIK0Ra25T I0UyKR3y2LhJFFuSeOikMZyV9yetkumhVqMhBLU4q1BBxH8zrGbVUu9UbRv5Vl69yZ2T zcbA== X-Gm-Message-State: AOJu0YwEBS9izHzIrJN3a17KEDFNofQjfNJHF1pjXJp+bBHxAcBW36FK NIpZuXZg05Aq3EtBtmAIl/xowE30sDYjTU9t4rQgoIVENiKrRnoG X-Gm-Gg: ASbGnct36nBOv9T9oRYwJcdiAjPE9uxLiaRD/zw1zDMch59fjCe8wPlyV63JeT/pQAl +TkwgL535dEJySGz/7PK3YTQ4wSZ0l/YHohGG8qPRjXync87+v8KBwU5YEDhnlu6AXksElQtJH2 xHjmQWdov981ba1A2JncYa4uP5JfDMYmZ38HiglveMKHANaldVgRF8xJycvRBPrm4WCp01Ds3b3 nPvAZISCymodo0BMS+h28scHRlAJYm0TO1Dx42r/xkm9jegAMXHXJDm5pDJkP7rgZHqt6wYcZVW l1oJ1w39Qdxpko2xL6xsQ5QENEVQb4yccbQkRB8XI5TGN+FceSy5SASaLSbHl98= X-Google-Smtp-Source: AGHT+IFsUZ/FXMWH/G2lxnRU4JJUhgQ8ZsATfzxgX1RYeL4saVDwtWzHn7QKTmGNGwG/DNd8WKY4Zw== X-Received: by 2002:a05:6000:40ce:b0:3a1:fc5b:7389 with SMTP id ffacd0b85a97d-3a35371ebe5mr1518579f8f.2.1747300557869; Thu, 15 May 2025 02:15:57 -0700 (PDT) Received: from [192.168.15.111] ([80.251.191.198]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a1f57de0b2sm22471330f8f.19.2025.05.15.02.15.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 15 May 2025 02:15:57 -0700 (PDT) Message-ID: <52f073ae-7fb0-40a1-9a29-e5a68199baf1@gmail.com> Date: Thu, 15 May 2025 11:15:56 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #18927: Poor query plan - HashAggregate is more than twice as fast but at a higher cost To: Dilip Kumar , =?UTF-8?B?6JCn6bi/6aqP?= <23031212454@stu.xidian.edu.cn> Cc: pgsql-bugs@lists.postgresql.org References: <18927-95043e0792441d50@postgresql.org> <21222aa8.36d.196cde41666.Coremail.23031212454@stu.xidian.edu.cn> Content-Language: en-US From: Andrei Lepikhov In-Reply-To: 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 15/5/2025 10:45, Dilip Kumar wrote: > However, during further investigation, I hadn't increased > hash_mem_multiplier. Instead, I forced the use of hash aggregation by > disabling other options with SET enable_incremental_sort = off; and > SET enable_sort = off;. Even without adjusting hash_mem_multiplier, > the HashAggregate was significantly cheaper than GroupAggregate. Are > these points that we are overestimating the cost of the hash > aggregate? Not sure, might need to dig further down, but one thing to > note is that the planner cost shows a hash aggregate with 2x costlier > than the group aggregate[1][2], whereas the actual execution shows > that the hash aggregate is 4x faster than the group aggregate. One more thing to consider: I see four grouping columns. The cost model of hash aggregate includes the number of columns. Sort-based grouping doesn't take it into account. In the case of full join, when many tuples are generated on the fly, it may impact somehow. -- regards, Andrei Lepikhov