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 1vSRnq-00Eq5J-1A for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Dec 2025 03:20:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vSRnn-00Ebdh-1z for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Dec 2025 03:20:43 +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 1vSRnn-00EbdZ-0u for pgsql-hackers@lists.postgresql.org; Mon, 08 Dec 2025 03:20:43 +0000 Received: from mail-qt1-x842.google.com ([2607:f8b0:4864:20::842]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vSRnl-003m6j-1G for pgsql-hackers@lists.postgresql.org; Mon, 08 Dec 2025 03:20:43 +0000 Received: by mail-qt1-x842.google.com with SMTP id d75a77b69052e-4ee158187aaso40271631cf.0 for ; Sun, 07 Dec 2025 19:20:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1765164039; x=1765768839; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=P4yL8aEbK8T5tI6UDT5b/u8Cgrb7g88Z8BxfnDSSqIU=; b=jQkczcISp7G1j5VSM3VVszdnf6N3VXT+NIL0XYpr4MOgZUHiiCPzDxzGCj4QA0H1AS yX+4ecGBAh7A8Lzw6MjczFZtzURe1B7vVLFzZCfNdeELeYcVC3q1nuMN/yEFb3DMaZob dqZPDRUE3CqX63lc7K8g+21FMBFadbDuvgDSyJz/SlKfFAz8VTSnk1Ml3a8dSnVyl4GY sMIQ/lWyhdnrXbaE8APueCQy1vtQFjZ6ic2F/Gq36R3n+lcz7nCRK19P18f5fbXYnM51 Iw5oEcDB/kiZrZonuNL3p16nbtD0QjBwJDB09YKfvT2gx4pUqLGRgxoGXn+S8+6tYmry EGkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765164039; x=1765768839; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=P4yL8aEbK8T5tI6UDT5b/u8Cgrb7g88Z8BxfnDSSqIU=; b=gZjPx+GRw3CP6GDg+xoiRzUaNYmLz42N+FvJ4tLoYDeQ5OwM6HOY9My9HKEseIBX1v PjSYWmAhyWCo0h/12LjLJ5yWZAJFEkRX3ehSGtbwMsHHeMMx/3SmChzEQxf9TUX8Av33 LViuw5KRCAe47GYzyCUTsHpxUtIeNO2/RHXgOzbbj6gd1icAiKpS+RmGoFPz8ycbyOCc ECMYI9vlDtC8JIc9pA7iNZBDUnTlteF0PKI9ZTQ3HlNIAJrg8QPPW2GJkj3mLnCJDrFT BxrzswbQ0ICk7oLgfYcM5CYvlmddT+l8/EXigcUP7sjz2nLNMJcGURqZ3+rszInVUb2B GlgQ== X-Forwarded-Encrypted: i=1; AJvYcCV7zSzhWP30keHtotZlURFRypegq1v+sxKAa9Pub01NJ3FcdxHtmRTTBRsJDJX1BRhSlvAszlB6vGesILOm@lists.postgresql.org X-Gm-Message-State: AOJu0Yx0G9IoLTpYxFWK4nP6+WOxZ2c4/6op74CUK/ifmwRAR3Did0fU mPm9EVLrRIGkQDjlTqUZvR9aLMtkgs3nobFSjUBVfJpBR0o9hlqoJnpdcwVQCC2yXievhjAinF0 XjZ4sOdhI1RdprigYP4y0rrQrj03duHQ= X-Gm-Gg: ASbGncsO+tSQBGgx0pULZCExDdAc/6vs7xgzRUtLoxHAVfy1XzBi4EyHjyL0/WtPXGx +CSOzIRX5Apqh2OI30bfY42p0Q2ofho9xfEzMWq4XLuqZ4L59Ip5fEeF40LZ3YUixYVQOSa+KTR ry/Rf8vtTjZGWoq5OLDXOv1CsQ0Glw7Qr4+wUgF94h36Q92Vpk2mi+16oAFSlTz1uMBVyfUIhTA tGbYedBTIs/1iejcFnpoTDbZYRhLhjy/JjAWtH0Hes1uzUh7PWdeGmU+mQXAMoZk+hg6sSlcUFM J8e2Oup4kM/C7HIgSUvZsdJ8ycLr/PMmx33d8o28p3em/LwLQD8BvK9BVw== X-Google-Smtp-Source: AGHT+IGrfIGTefwWj9LMcLHgDNCaDTdixj8lb10zbmUE20dg5SH2Ko6kUyCu+wQ0pSv0EkA1Hrvdlj4s3gFudWtiSpw= X-Received: by 2002:ac8:5989:0:b0:4ed:b93f:465b with SMTP id d75a77b69052e-4f03ff3e136mr90744001cf.84.1765164038905; Sun, 07 Dec 2025 19:20:38 -0800 (PST) MIME-Version: 1.0 References: <28f47336-84e2-445e-8216-d1ce7d3ddc3e@iki.fi> In-Reply-To: From: John Naylor Date: Mon, 8 Dec 2025 10:20:27 +0700 X-Gm-Features: AQt7F2q2gbMEA9_GnWXe56FsoHR-Bdhz9koxhxPtWASZpKk2wfmoS4y0xsmHd5g Message-ID: Subject: Re: Support loser tree for k-way merge To: cca5507 Cc: Sami Imseih , Heikki Linnakangas , pgsql-hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Dec 4, 2025 at 1:11=E2=80=AFPM cca5507 wrote: > I summarized the number of comparisons needed for different 'k': > > k =3D 2, heap: 1, loser tree: 1 > k =3D 3, heap: 2, loser tree: [1, 2] > k =3D 4, heap: [2, 3], loser tree: 2 > k =3D 5, heap: [2, 4], loser tree: [2, 3] > > So if k < 5, the loser tree is never worse than the heap for any input da= ta. Please explain your notation. For starters, does "comparison" refer to sortkey comparison or does it include checking for sentinel? If loser tree can't early return, why is the number not always a constant? If "k" is very small, I'm guessing the merge step is small compared to sorting the individual runs, in which case it matters less which one to use. That's just a guess, though -- we need structured testing. On Fri, Dec 5, 2025 at 11:11=E2=80=AFPM cca5507 wrote: > Can we support loser tree first and set the default value of enable_loser= _tree to off? If you, the patch author, cannot demonstrate how to choose this setting, what makes you think our users can? (That said, a temporary GUC is useful for testing) Here's a half-baked idea: If the regressions are mostly in low-cardinality inputs, is it possible to add a fast path that just checks if the current key is the same as the last one? -- John Naylor Amazon Web Services