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.96) (envelope-from ) id 1vbsbP-00FIbO-0U for pgsql-hackers@arkaria.postgresql.org; Sat, 03 Jan 2026 03:46:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vbsbN-00C45x-0d for pgsql-hackers@arkaria.postgresql.org; Sat, 03 Jan 2026 03:46:53 +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.96) (envelope-from ) id 1vbsbM-00C45o-2s for pgsql-hackers@lists.postgresql.org; Sat, 03 Jan 2026 03:46:53 +0000 Received: from smtp.outgoing.loopia.se ([93.188.3.37]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vbsbL-004BUQ-0j for pgsql-hackers@lists.postgresql.org; Sat, 03 Jan 2026 03:46:53 +0000 Received: from s807.loopia.se (localhost [127.0.0.1]) by s807.loopia.se (Postfix) with ESMTP id A2D00517393 for ; Sat, 03 Jan 2026 04:46:50 +0100 (CET) Received: from s980.loopia.se (unknown [172.22.191.5]) by s807.loopia.se (Postfix) with ESMTP id 8DA8D516F3B; Sat, 03 Jan 2026 04:46:50 +0100 (CET) Received: from localhost (unknown [172.22.191.5]) by s980.loopia.se (Postfix) with ESMTP id 8AEDC220156C; Sat, 03 Jan 2026 04:46:50 +0100 (CET) X-Virus-Scanned: amavis at amavis.loopia.se X-Spam-Flag: NO X-Spam-Score: -1.2 X-Spam-Level: X-Spam-Status: No, score=-1.2 tagged_above=-999 required=6.2 tests=[ALL_TRUSTED=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1] autolearn=disabled Authentication-Results: s471.loopia.se (amavis); dkim=pass (2048-bit key) header.d=proxel.se Received: from s981.loopia.se ([172.22.191.6]) by localhost (s471.loopia.se [172.22.190.35]) (amavis, port 10024) with LMTP id PeSkBf8oo_x0; Sat, 3 Jan 2026 04:46:50 +0100 (CET) X-Loopia-Auth: user X-Loopia-User: andreas@proxel.se X-Loopia-Originating-IP: 147.28.75.140 Received: from [192.168.0.121] (customer-147-28-75-140.stosn.net [147.28.75.140]) (Authenticated sender: andreas@proxel.se) by s981.loopia.se (Postfix) with ESMTPSA id F1E1C22B1668; Sat, 03 Jan 2026 04:46:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proxel.se; s=loopiadkim1707418970; t=1767412010; bh=5tTYhwcGxl3dMl1fbXPCfmuojeFflrCHwE6sfAw2x9c=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=n9ulHCqUrL3kvWVeuWqsWYMdvIZuT/TTWitzffxOfsEb67nTgkzAoizHunHxa4Gk4 Rax/iujaei/Li6czrW1PMt2KNmYN0zkkwJPqfCogk39IbIzSpWclRr6g9/x6oLNQLP Bj46ur1i+PwG77pzhbz+FMtKoMVegmfPrKFLmPFmeG03gUV+nVAtXiUODN+ZF3sWjJ KzSQN/1Urh6jFh6ZmpAL2BdWt/87m2Wpxzeyk5kVAFB08ygFedAD/uNwD0kNPXLLaj okaJcRKT7uyekjyR8S3tuTkmg/AXn2u97MiMswONLcv3qOV+2gcJKjtK5K9nC7gulo CMClpn/z4mezw== Message-ID: <69012ece-1907-4d70-ac1a-db7897bac865@proxel.se> Date: Sat, 3 Jan 2026 04:46:49 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Support loser tree for k-way merge To: cca5507 , John Naylor Cc: Sami Imseih , Heikki Linnakangas , pgsql-hackers References: <28f47336-84e2-445e-8216-d1ce7d3ddc3e@iki.fi> From: Andreas Karlsson Content-Language: en-US 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 12/8/25 7:46 AM, cca5507 wrote: > For heap, it reduces one tuple comparison if the keys are same and increase one if not. > For loser tree, it reduces many tuple comparisons (maybe tree's height - 1?) if the keys > are same and increase one if not. The bad case is all keys are different, so we still need > to decide when to use the fast path, it's hard I think. My suggestion is that you start with trying to find some cases where we get regressions and measure how big these regressions are and if there are any clear cutoffs where we can use a simple heuristic to select algorithm. One thought I have is that pre-sorted input could be slower with loser than with heap but since I am unfamiliar with loser trees I could be wrong. Andreas