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 1wMleg-000KOP-0P for pgsql-hackers@arkaria.postgresql.org; Tue, 12 May 2026 11:52:06 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wMlee-004Yfj-32 for pgsql-hackers@arkaria.postgresql.org; Tue, 12 May 2026 11:52:05 +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 1wMlee-004YfY-1f for pgsql-hackers@lists.postgresql.org; Tue, 12 May 2026 11:52:04 +0000 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wMlec-00000000CHJ-0qsb for pgsql-hackers@lists.postgresql.org; Tue, 12 May 2026 11:52:03 +0000 Received: by mail-qt1-x841.google.com with SMTP id d75a77b69052e-51306c36c3eso49704281cf.0 for ; Tue, 12 May 2026 04:52:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1778586722; cv=none; d=google.com; s=arc-20240605; b=GxeBkM2xRNscu+ZonF+nLyiW5woKYZdrZbPrQlvJ64ZwEAp07VlP2TExUdhh3V3FmL wu6SL8nqpEt+zytu3FhZWn4lKxT3bspG+vrEHnqmy9y+WAWNMbgyE6SjXuuaVcITgO3F +RwgP9ArXpZEO8t6D2j1GqDyMUneadgnFHxgSnDIcRz/PmJpbcByoIq4A4W8dkMgCyth pSQpt1Ia4BwgAbHIBePHjWfCl+ae8oAzHcFFbx4zRw2OtUpcJvAvUZuhocu5Ft9v5oQL o/X/YXAMFlvTe8YW5qw0b5f5XPsjyByJZClGtWqnPcyu/f9CBp5cUc4kLjNKLMFbe09p Zb0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=0G7yfCsVAdf7PqwKobpIx7FGjPogTvoMLtgsSdJXLnM=; fh=9q+z6kdroI8Zf2SaEx52d8hR0mkYTJK6i/dAVg25LG0=; b=I5nsrZqNs1BYkaFvq6MsOpWN8bi7tG6JkJErwsSLPGVQJDdP3n4LIldci5UIEUs1o8 EuOoyshqzp6QK6nr7djrMGHqD7DXn2yf35AJ0KxSOfWKf/q7FL0Sp7Rb5QJEZio6gZsq 9cw1wghp7wi6f1rkMAxv8AQrn+9G4VPnbC/HA64sB9v+Lwx96CMS8/XLTpd6EKZyO/h3 h7F2KcFCvbGuWl5mRCH1hOjASRQOCrSgJVHpL+ShvCxK0qSKc+44a/fGjJkxSWbX8ukv eIQQeyxxFvoRqmf+VsGWIgey7GpqE49A2UY03idgA8wp5v514LUXHQyBHhDda8hNwlt8 uvig==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778586722; x=1779191522; 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=0G7yfCsVAdf7PqwKobpIx7FGjPogTvoMLtgsSdJXLnM=; b=SIOSYD3UboJOJLIcn3FWGT4p46lIU5ebSOjLA3weBUajbK3EKTj/460Oq/U3fmvAgn rJIrn4IA7MzD/cY4lcDURJhhtn5Ge+RdG1Ipx64OBmmwc+24bHPUGoixlsLdSZVytyCW MhkQJPKEiWmr418OM2fXBUGGBYghsahrX0QrgpFMV1xKwckXAyG5B7gEDnSZS27DVfSm r5+or2QEmTzni5XUt+GG6I4kB6iNEsdWSU4/wefM27uakavLeUJ14fXgbYyqn4jaCXii gkTzblC/06mOH8ZN3aUM2BftZw4j8FqGQrXXzCp9BDOhrbNkvHJ1cA2pjfQOQVAHipDG NG3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778586722; x=1779191522; 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=0G7yfCsVAdf7PqwKobpIx7FGjPogTvoMLtgsSdJXLnM=; b=XZ0M9A0+8u2daL/UJaVq0NfZl+JmwKQg+YReAUdGTg7wvj5+mJmgueKq95hNLhNHnb UnTomryyuV7EbGB9GJtaOE3UGMK9I4UTSQ/UyExZrVRgW5Gc8UESc3zEJMRm4dCD0tNX oJFTcAdfstwFH1A2OlxhbOlVpaqUfuJXNF7fOvGdG2JmefxldyR+zR856F1t1NW6sG2q eh5Yr4wTTBVda+D/hJ0aNmXSDuFu8d5K+pqDR+bOMtxH4tqrKDoJrYmEJU7/DMgKUM7O /3TEQlXpOHXAuynB6dVsgjAPYNx2Bh+SCdIM6B6SXIJiZtFTdhssZlcoIPclYee+9eHK AgIg== X-Forwarded-Encrypted: i=1; AFNElJ/yXzVEG5BkpJdf1r7kT16qOg4tqL84ceUYiB7P6KN1ZdliJCmxV84y/WP2viSGynOaBsd6bmQLotPGt9wu@lists.postgresql.org X-Gm-Message-State: AOJu0YywGS5u9oSYxt5hr+BlSKm8Y3witQx+fHm83tH4+/SnYl17wb0+ p5oA5SBYCjmx9jIGaNzVYGvq8TKUkuwC88aoYy57R30YhYsG9K+4QVTywgkSitBCQYH4WitCY5i j1w4UaSt1ptEmXr2xtOtiiHzlAhn+bxw= X-Gm-Gg: Acq92OEqhcdM+n7ri+bwPd3tWEGajq095vQ20L58ij1aGSCCoaGCtErLBnbnn+FPZCK XPUYNFsoYvGn3PWJwenAnOnN5co+Bi7m1IggY/q8B6d8UyTlaqXh8BaXKtweEFaKNODAsx/AIFK 8j4w1kZ32SVgYEu9GPIxxG9BxZP0x8KmdOwHyyDXdzBP8TFTnPriYk5tWQFjFTHnCpVJrehGP2A tZy17k6yH5mbRfVPPhyXTzJ30YY9Zxl0V10NiMVHbeSxIcUsOssdXahWw1TtKgEYhTfmJCQp9rx J6fKvRt6GYDyXBwc1b/G1U7eITpK2hh2ZZeyjsTlaSiHtxt5X3Jwgc3bQQmX2+kRvmgO9xxCYVm K3+xDYrjTmzOs7WUrG4bRPPII1IAFiWGpvU6aRg== X-Received: by 2002:a05:622a:153:b0:50f:b81e:c65b with SMTP id d75a77b69052e-514d226a7f8mr37026111cf.59.1778586721711; Tue, 12 May 2026 04:52:01 -0700 (PDT) MIME-Version: 1.0 References: <3FF63E99-AB4F-41A9-BC78-AAB28823FBD0@Outlook.com> <6db6d2ec-7529-4add-9a95-178fc318311d@vondra.me> <313ACE5A-CBF1-43B3-9181-10D3E8ADF424@Outlook.com> <5abd6054-413c-4f48-9172-d8b31062b266@vondra.me> <938E2286-9B0D-4F8D-A916-8E0E35D55034@Outlook.com> <982de4a4-71b6-4d1d-afe2-35b1c5d43529@vondra.me> <8927A117-A7EA-41E8-94B3-0B4F7767DA8B@outlook.com> <4383D1E9-8F01-429E-9C18-1EFE12FF9196@outlook.com> In-Reply-To: <4383D1E9-8F01-429E-9C18-1EFE12FF9196@outlook.com> From: John Naylor Date: Tue, 12 May 2026 18:51:50 +0700 X-Gm-Features: AVHnY4Ih-OWES-b-4mAOZA2biI3C-0-iOpbI4mpwDljxd3X54oJWLfwJxzUoDkM Message-ID: Subject: Re: Add a greedy join search algorithm to handle large join problems To: Chengpeng Yan Cc: Tomas Vondra , lakshmi , Pavel Stehule , "pgsql-hackers@lists.postgresql.org" , Robert Haas 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 Mon, May 11, 2026 at 9:33=E2=80=AFPM Chengpeng Yan wrote: > > On May 5, 2026, at 13:40, John Naylor wrote: > > Given that all heuristic join enumeration methods can produce > > spectacularly bad plans, the ability to influence the plan is more > > crucial with large join problems with small ones. Features should be > > orthogonal in general, and in this case, integrating well with plan > > advice seems like a strong deciding factor. > > I agree. For large joins, cardinality estimation, the cost model, and > the join-order search all interact. Even a better search method can > choose a bad plan if the cardinality estimates or cost model give it > misleading input. So the ability to tune or influence the chosen plan > becomes especially important. > > After reading more of the pg_plan_advice discussion and code, my current > understanding is that GOO should be easier than GEQO to integrate with > join order advice. Please correct me if this understanding is wrong. My > reading of the pg_plan_advice discussion is that advice can only > reliably nudge the planner towards plans it would have considered > anyway; with GEQO, not all join orders are explored, so join-order > advice can only constrain the options that the genetic search actually > considers [3][4]. I believe that's the current thinking, but note this from the plan advice README: "XXX Need to investigate whether and how well supplying advice works with G= EQO" > GOO seems to have a useful property here: candidate generation is > explicit. At each contraction step it evaluates legal pair joins, so an > advice implementation could reject or prefer candidate pairs at that > point. This does not make impossible advice feasible, and it still would > need careful integration, but it seems less dependent on whether GEQO > happened to generate a compatible join sequence. That's a reasonable hypothesis. I'm not sure what you mean by "careful integration". Would some aspects of the patch need to change? > I also noticed a statistics-sensitivity issue while rerunning the > large-query subset. I ran five rounds over the same 33 queries and the > same DP / GEQO / GOO(combined) variants. Each round refreshed statistics > before executing the measured queries. I saved the statistics snapshot > with pg_dump --statistics-only and kept the per-round result > spreadsheets; these are in round_artifacts-20260511.zip, organized as > round1 through round5. The per-run measured repetitions are > comparatively stable; the large differences below correspond to changed > plans after refreshed statistics, not just measurement noise. > > Execution-time sum: > > | round | DP ms | GEQO ms | GOO(combined) ms | > | --- | ---: | ---: | ---: | > | round1 | 41091 | 574582 | 87706 | > | round2 | 41331 | 51205 | 85038 | > | round3 | 40493 | 95580 | 85561 | > | round4 | 41464 | 99228 | 83930 | > | round5 | 41611 | 126544 | 85578 | > > GOO(combined) has the lower execution-time sum in four of the five > rounds. The exact bucket counts are not identical in every round, but > each round still has both large GOO(combined) wins and large > regressions. More importantly, GEQO varies much more across statistics > snapshots: its execution-time sum ranges from 51s to 575s, while > GOO(combined) stays in the 84s-88s range. That's an interesting finding! We'll want to keep this behavior in mind and see how reproducible it is. You mentioned you didn't want to draw any general conclusions (reasonable), but a 10x variation just from statistics does put a new perspective on the test results. > As I mentioned in the previous message, the remaining GOO(combined) > regressions fall into two groups: sometimes neither cost nor result_size > finds a good greedy candidate, and sometimes a good greedy candidate > exists but the final estimated-cost selector chooses a slower plan. > > So I am still looking at the two follow-up directions mentioned earlier, > both building on the current GOO work. One is to improve pure-GOO > candidate generation and the final selector, for example by adding more > diverse strategies and making the selector consider signals beyond final > estimated cost. The other is to use exact DP for a prefix of the problem > and fall back to GOO when the DP budget is not enough. The first > direction may need broader changes across planner or estimation-related > code, I agree we should try to avoid strategies that depend on changing other are= as. > so I am currently focusing more on the second direction and will > share the code and numbers once I have a clearer result. I've mentioned elsewhere that graceful degradation is a good property (and a prerequisite for robustness), and cliff behavior is one disadvantage of the GEQO search. However, it's not going to scale: There will always be large join problems where a heuristic search will find terrible plans, and that means severe regressions are possible, as we've seen. Further, this direction opens up another large design space that I fear will complicate testing and review, and it's already hard enough. So, the above doesn't seem like a logical next step from the data thus far. (To be clear, I think it's good future work, but that presumes getting to a first commit). To my mind, we still need more data to inform future direction. The most important things IMO are - plan advice -- My current thinking is, the plan advice aspect is the "wild card" that could immediately improve user experience with large joins. Conversely, without the ability to fix regressions, any new approach is risky. How well does plan advice work with GEQO? Does it work with GOO already or would that need additional coding? - more large join benchmarks (I see you have additional benchmarks in your repository above) -- John Naylor Amazon Web Services