Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nX4uS-0000lO-MY for pgsql-hackers@arkaria.postgresql.org; Wed, 23 Mar 2022 17:36:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nX4uR-0005KQ-EV for pgsql-hackers@arkaria.postgresql.org; Wed, 23 Mar 2022 17:36:35 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nX4uR-0005KF-5c for pgsql-hackers@lists.postgresql.org; Wed, 23 Mar 2022 17:36:35 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nX4uO-0003qp-Uc for pgsql-hackers@postgresql.org; Wed, 23 Mar 2022 17:36:34 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 22NHaTFH2770447; Wed, 23 Mar 2022 13:36:29 -0400 From: Tom Lane To: Robert Haas cc: Peter Eisentraut , Simon Riggs , PostgreSQL Hackers Subject: Re: Parameter for planner estimate of recursive queries In-reply-to: References: <91533bcd-c3a3-5844-7449-43aceede2117@enterprisedb.com> Comments: In-reply-to Robert Haas message dated "Fri, 28 Jan 2022 09:07:32 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2770445.1648056989.1@sss.pgh.pa.us> Date: Wed, 23 Mar 2022 13:36:29 -0400 Message-ID: <2770446.1648056989@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Robert Haas writes: > On Tue, Jan 25, 2022 at 4:44 AM Peter Eisentraut > wrote: >> On the one hand, this smells like a planner hint. But on the other >> hand, it doesn't look like we will come up with proper graph-aware >> selectivity estimation system any time soon, so just having all graph >> OLTP queries suck until then because the planner hint is hardcoded >> doesn't seem like a better solution. So I think this setting can be ok. > I agree. It's a bit lame, but seems pretty harmless, and I can't see > us realistically doing a lot better with any reasonable amount of > work. Yeah, agreed on all counts. The thing that makes it lame is that there's no reason to expect that the same multiplier is good for every recursive query done in an installation, or even in a session. One could imagine dealing with that by adding custom syntax to WITH, as we have already done once: WITH RECURSIVE cte1 AS SCALE 1.0 (SELECT ... But I *really* hesitate to go there, mainly because once we do something like that we can't ever undo it. I think Simon's proposal is a reasonable low-effort compromise. Some nitpicks: * The new calculation needs clamp_row_est(), since the float GUC could be fractional or even zero. * Do we want to prevent the GUC value from being zero? It's not very sensible, plus I think we might want to reserve that value to mean "use the built-in calculation", in case we ever do put in some smarter logic here. But I'm not sure what a reasonable non-zero lower bound would be. * The proposed docs claim that a smaller setting works by biasing the planner towards fast-start plans, but I don't think I believe that explanation. I'd venture that we want text more along the lines of "This may help the planner choose the most appropriate method for joining the work table to the query's other tables". regards, tom lane