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 1vR1S5-004Slr-16 for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Dec 2025 05:00:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vR1S4-000Vdl-0U for pgsql-hackers@arkaria.postgresql.org; Thu, 04 Dec 2025 05:00:24 +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.96) (envelope-from ) id 1vR1S3-000Vdd-2F for pgsql-hackers@lists.postgresql.org; Thu, 04 Dec 2025 05:00:24 +0000 Received: from mail-qt1-x842.google.com ([2607:f8b0:4864:20::842]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1vR1S1-0032ty-1l for pgsql-hackers@lists.postgresql.org; Thu, 04 Dec 2025 05:00:23 +0000 Received: by mail-qt1-x842.google.com with SMTP id d75a77b69052e-4ee1fca7a16so4803611cf.3 for ; Wed, 03 Dec 2025 21:00:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764824421; x=1765429221; 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=2j397XWOMNUlnNtkt0YjH2LNR+tTX5kYyjNE9tBvPUI=; b=PMZOKWPQ0DoE3ezm6cBlSuXLlwGarsD5kshSMpTR7DRmCQPPKA4qW9SFzsM+Vkg8r+ j55o6yboyOHTc1jWtV3+SpwBqEXAfKh3b9BW+wHGa8uxYz3VBUADUfjHkjmF3qDphCf0 v1wHkIro5R1jSAQEJn0ItYwzVpSzpLg0zDOkrPdkFNqeZ6SijJy+UA1pME1dfGcUC5vj 2YFQfxbuAfAmqN2b8cD4Z16zhOA8eLityegNKNzkuSRPfOe+s1Y3WnVuNlnLP2/ZwQpi JwtUtETUlWRX4W6h1R5Fjhb4/9fnsJGtfjIm74G9avtcC3m+c9z6YdC6rRInH7He32fp lvIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764824421; x=1765429221; 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=2j397XWOMNUlnNtkt0YjH2LNR+tTX5kYyjNE9tBvPUI=; b=XKTMEWETEwOdy1F9pE73HUxwwhUV5P9rhhElfay/PEaBsSQo9npBNmoHWXwhkEL92w KjurowWzW2D1cWbUbH5bBcfKCfND5fkYIw+KQuIiTpSrJAZA2fy4mtiev83T9OcKS9x8 y6SpMnf4x5udSUx68jan7q6gqIhk2Vd4iomcKRwdDi6td7at9oO19YQH3OeJICSse/TX N6kOUdg6B6QpByyCEqRvvgAITXQlUCWIRHShINUfHWza92pjAAv83NDb9kPRo0zmXSeL GYst931Wkl3k9cGctFVjHuUsSSg65974d8rDxzkP6axRNnOcSGWvYynrHHqNVy+boL00 KbVg== X-Forwarded-Encrypted: i=1; AJvYcCXBMEADq2hw+mzyztv97T1H9mNaq0gHHhRfC5spAjfzdpa7gHOlSN96Wwsk2foyJ3NiHkcha7FK3oTy6nnh@lists.postgresql.org X-Gm-Message-State: AOJu0YwyzVaSOgC8kBeo5uuLv7OIjMBZKXFusjVmXndYgsFFNGJymfVR yNcCbPabdU4qMMcnleCXKCZbg5KhkgolWnZK2O1KaOg6oHYLQdOop4piomAkrTtd4pmmZPxp3E1 Re7owCa+HHizzFqMmYXMd66YK6Av2gY4= X-Gm-Gg: ASbGncuWxE8noDympGmPdsmmlPj0nCEaCyPOhw/QGJlOuwdEIPbZa1GliMo/FoeQgoV 1NneINWW1mteaYeiAtlVbsgED1CC98SsFjFhWt4SSbxPPylSzoPlBQvMiyrmOm0C4bKpHxHQW1d CM6Xvtrt1sVh70d/BfSMRcQXn2gdo60pTQlLetQQxpHXu9SlxyP4kM7n+8RUQQKoTuN4o7kBloY zvldov2D4Sgs7iXr8YHpwABgr2K4UrJ7bEQgdKor1IoFNKUqTnHqHRy+8mMoQ0l6oWxSr5201Eu hzai2LMKjCtboU0U1kkx4My+z5RZ62QVFDnX3+l5NiOmu16QLQuA+VYTlX0PKd4qt7Y5dvHS/FM 859b8g41ebQIA07c= X-Google-Smtp-Source: AGHT+IE6v0p3Egs8KywhVSCXQ9r6FrqZfksTklfsxw7sommvOC09kAu44+Z/FRDxxtLkjhnu2O6EPRgBl0yrXch3dPo= X-Received: by 2002:a05:622a:189f:b0:4ee:2508:3934 with SMTP id d75a77b69052e-4f023aacd3emr25841381cf.67.1764824421468; Wed, 03 Dec 2025 21:00:21 -0800 (PST) MIME-Version: 1.0 References: <28f47336-84e2-445e-8216-d1ce7d3ddc3e@iki.fi> In-Reply-To: From: John Naylor Date: Thu, 4 Dec 2025 12:00:10 +0700 X-Gm-Features: AWmQ_bnolB71EgKsfvYJ2hfRthxuPOHqj-l5Osym4X6rjXwE1NSwMm8zboS_wAs Message-ID: Subject: Re: Support loser tree for k-way merge To: Sami Imseih Cc: cca5507 , 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:14=E2=80=AFAM Sami Imseih wr= ote: > Can we drive the decision for what to do based on optimizer > stats, i.e. n_distinct and row counts? Not sure what the calculation woul= d > be specifically, but something else to consider. It's happened multiple times before that someone proposes a change that makes sorting faster on some inputs, but turns out to regress on low cardinality (I've done it myself). It seems to be pretty hard not to regress that case. Occasionally the author proposes to take optimizer stats into account, and that was rejected because cardinality stats are often wildly wrong. Further, underestimation is far more common than overestimation, in which case IIUC the planner would just continue to choose the existing heap method. > We can still provide the GUC to override the optimizer decisions, > but at least the optimizer, given up-to-date stats, may get it right most > of the time. I don't have much faith that people will properly set a GUC whose effects depends on the input characteristics and memory settings. The new method might be a better overall trade-off, but we'd need some more comprehensive measurements to know what we're dealing with. -- John Naylor Amazon Web Services