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 1wNP7E-000mVQ-1r for pgsql-hackers@arkaria.postgresql.org; Thu, 14 May 2026 06:00:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wNP7C-00AzCj-31 for pgsql-hackers@arkaria.postgresql.org; Thu, 14 May 2026 06:00:11 +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 1wNP7C-00AzCa-1c for pgsql-hackers@lists.postgresql.org; Thu, 14 May 2026 06:00:10 +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.98.2) (envelope-from ) id 1wNP7A-00000000U5e-1T4G for pgsql-hackers@lists.postgresql.org; Thu, 14 May 2026 06:00:09 +0000 Received: by mail-qt1-x842.google.com with SMTP id d75a77b69052e-50e5c7eb565so73730651cf.3 for ; Wed, 13 May 2026 23:00:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1778738408; cv=none; d=google.com; s=arc-20240605; b=LMEXPplZTvE1MCb5tzg/ft5kkfmEaeoHTaKqigo7YubqFzgVtihf3oSDWBL0XI9SBf I6gtETuZtlaQAmZeH6NwYYYHroFz/CnU/HBgU16yQFQKjgxax1vz9EYQGiidZcwuBPaz LfbOafSoJw3KTB8wSEdTRIL77oggBn0bGEAUxmCEOKF2hM97nZDxLPEtm8HxLaQqoXkR MsMQglRnqMxy2g0TO1Rp1LST9Ysd1CJYXInfLy0lGHNsxY0BFuPTtpkWY0kOL5KzSnDn BtVPm873vHqTE0Ki13mFKO9DnB+ifWvLp1v04GmYYOh0KWB7K52b8/7ePC3yimMdV8LS PdLw== 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=oi+Z3VuN2Mmpp1PtLRAz4ck2U6ndDj+OUO/cij/jRw8=; fh=IAnh03USMWUBJA6jU2NiPMXhu5B6s76DeKKqYbqShnc=; b=fXYjXQbcJO8l49YCk/h/c1FtcDENiH3EBvOXSfpiZD59NmwEqmJWhB3uqRcA4vdjyk gCPE5gulj0eAOyvJcDvIR6Uuy0WJxLNLtqdVSSA7GN+Iodoe0zGI1gYG5WL4jbtJCoyh EKxHDY/TcVSYj8ULxZ2uSxFqghhzmCOMewjqEvv/6MQhb2LVnc9hV0JVBhvELcl7yctL qRPNnFaj7mCcTuRGIV4ltDcF7TpsKkjWdphsud6jX6+HGPmPXG9f0mR4KrfGlvbfhKHO YD2qlpsH6rKuN8AKc75amXJ3/Vo5IsXO+Ma6BoMMcPOTTc7UrKC5/X8Rrp9qELERT34N v4bA==; 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=1778738408; x=1779343208; 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=oi+Z3VuN2Mmpp1PtLRAz4ck2U6ndDj+OUO/cij/jRw8=; b=gc92bjJrSZvA5mjY0yCQGWGetd1QbnS6Ix7bRA3n91vJ9qfITGnc/5fdPO3/IlXF1n AcorVQWfitn5qv9Nl9kVs5Xf3tYfe6WRXdpc+YcbhkY5aTaldIwY8ksqPWi6gldxUiTb q7Q3SbsHDijuDHxpJBlB/C0r+sUe0qvzNW2bODgdmXxOEp8BhDbU74FlOkezjeiUteJk AOhPL/YULUUePWKtVdhWdzAtNvTu4lrGRY5ZpAhTalj/gMhPkWW4ajWSs2YN4ucY6y// NJi4MRECHuUccPyoB1ZolZ6qEaRtxPi0OiHZVWCj5WSRwCUVtRShdhRRfyWkBQKfIVrD DDQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778738408; x=1779343208; 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=oi+Z3VuN2Mmpp1PtLRAz4ck2U6ndDj+OUO/cij/jRw8=; b=nGvq75ajXq/V3ByUTEeVFt9EOsBq7bZDSrqVXAKTiNiCY1rXUXh3UvpeUeZdtR2oay 0qYQpb2iil0wPX6br1+kl6WNC+yfEhIOGJEoSu58dSCCTvtxPaMj3XpAq2oUo2TxmcsU WxpUSznke0Qqg5toaBDRYTDj2D003mfat0VDB3TsKm45WrVP56tlDJFEwGJqV3y3yXOs lYtiz2lcSK4f7vkxRpgIJeXMI8/UFPpkaR5NocrnB33u7blK5uv3Wn46N+kIU2OJbuhr j2UXd4xcRPs3nj7/DNQ7C44fi0tNUEfjiq/cujSMG2CymFfvzw8mxnNlNUcV7nWK8drD zvpw== X-Forwarded-Encrypted: i=1; AFNElJ/VL+6FSx/ZVomLudgkc3t5N/ou7QRKkqCzPMS9TPTR45Gd04TTugDR5rWTHxI3PYFvNA56xYkPgO9GrXqT@lists.postgresql.org X-Gm-Message-State: AOJu0YzqMsnJgirGJkeR4614LiclP6XxHPnOv6TJpG31iFu8mzL0AHRC A+aVBM++41C5M0vyUSSPzlNmV2AF+7uZhNmByANnRJ9jBNoCNw0eGXCNU+udSSvNraYzvrd8Yhz 1h1C8Gh1E9LCAi3cKLgigl+ZlCRiZGvI= X-Gm-Gg: Acq92OGQZBDh7D2wPG8RBbWZ5jvNHJqelh36tSWNEAyZbv+sTIByLZPNAT/WidIhUwC lGqahuOJucNEhURuCNll3k6rrzUBrtt0oo48/3fNTH7jbXm/Hidgpe9Lih53uPt2wwHz3DzVjpB aTrLewA2PexEdO73Md0wusbFZtWyGKv4dDct3Xv1Hni4n1hjfC4bsu/2N/uile0P+JuaQhLT2xa nwN3S6oTNdONuudGr2CDraXiLzxwRBhgMkgmgay8C9nPdzrVyKizqtsBN4rcksRzaqLxG9aWshW 1Xj95HnTCuc46Ta1DWr2WDIbTMTV2swAPrYoJDTmxMoecTtCkiGlyTRoh4BHngyDuYbOWfKEXWH LuiCwB52ShDLdmHzvto+4nhoUSJy2j5Uks/GB4A== X-Received: by 2002:a05:622a:1a97:b0:510:138e:b83c with SMTP id d75a77b69052e-5162f58ae21mr90463321cf.33.1778738407987; Wed, 13 May 2026 23:00:07 -0700 (PDT) MIME-Version: 1.0 References: <3FF63E99-AB4F-41A9-BC78-AAB28823FBD0@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> <8e9509d3-b6a3-4604-bd26-8777386de216@vondra.me> In-Reply-To: <8e9509d3-b6a3-4604-bd26-8777386de216@vondra.me> From: John Naylor Date: Thu, 14 May 2026 12:59:55 +0700 X-Gm-Features: AVHnY4IXtLmHU3YIcwb8Ra3NBM81GB7vpJtO5SpxZzt-TLGCzi7RuAG9IwuJtCw Message-ID: Subject: Re: Add a greedy join search algorithm to handle large join problems To: Tomas Vondra Cc: Chengpeng Yan , 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 Wed, May 13, 2026 at 6:54=E2=80=AFPM Tomas Vondra wrot= e: > > On 5/13/26 06:34, John Naylor wrote: > > On Tue, May 12, 2026 at 8:42=E2=80=AFPM Tomas Vondra = wrote: > >> To got to the GEQO/GOO code, people have to adjust the limits, so that > >> (join_collapse_limit >=3D geqo_threshold). AFAIK almost no one does th= at, > >> so most join problems are smaller that geqo_threshold and so handled b= y > >> regular DP (for smaller subproblems). > >> > >> But let's say someone adjusts the GUCs, gets to GOO, and it handles a > >> prefix of the problem using the DP approach. How is that different fro= m > >> keeping the (join_collapse_limit < geqo_threshold) and not even gettin= g > >> to GOO? Why not to just leave join_collapse_limit to a low value? > > > > One flavor of the second idea above (found in the literature) is to > > start with DP, and after some new GUC limit (under the hood: # of > > times calling make_join_rel), pick one of the incomplete subproblems > > and finish with a heuristic search. It switches strategy on the fly, > > rather than choosing upfront. That's the difference from now, although > > I'm not sure offhand how join_collase_limit chooses its subproblems > > out of the bigger problem. > > > > Not sure, for two reasons. > > How often do we expect this to be used? AFAIK GEQO is not used very > often in practice, because geqo_threshold is so much higher than > join_collapse_limit. So even huge joins get divided into problems > handled by DP. We might invest a lot of time and complexity into > something that gets used extremely rarely ... That's a risk to keep in mind. In cases where planning time is a substantial part of the runtime (like in your thread on OLTP star joins), a user could lower the threshold for greedy search, since it's fast. That's not an option currently because GEQO is slow. With a dynamic strategy, I imagine join_collapse_limit would mean something different (one technique in the literature is to refine the greedy output on subproblems of size 4-7), or be replaced with a different tuning knob. Anyway, these questions reinforce that this is potential follow-up work. > Also, couldn't this easily lead to unpredictable planning behavior? Say > the budget relies on counting "make_join_rel" calls, or something like > that. Then someone adds or removes an index on one of the tables, and we > suddenly start to consider fewer/more candidate orders. Or maybe someone > refactors the code a little bit, moving the calls. And suddenly, we hit > the threshold at a different place. But maybe it's OK for a heuristics? That's a good question. -- John Naylor Amazon Web Services