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 1oe99U-0000SH-1m for pgsql-hackers@arkaria.postgresql.org; Fri, 30 Sep 2022 06:05: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 1oe99S-0005rW-VF for pgsql-hackers@arkaria.postgresql.org; Fri, 30 Sep 2022 06:05:34 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oe99S-0005rM-JU for pgsql-hackers@lists.postgresql.org; Fri, 30 Sep 2022 06:05:34 +0000 Received: from mx.zeyos.com ([88.99.153.70]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oe99Q-0003m2-Jx for pgsql-hackers@lists.postgresql.org; Fri, 30 Sep 2022 06:05:34 +0000 Received: from mx.zeyos.com (localhost [127.0.0.1]) by mx.zeyos.com (Postfix) with ESMTP id DDFDF619EF for ; Fri, 30 Sep 2022 08:05:31 +0200 (CEST) Authentication-Results: mx.zeyos.com (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=zeyos.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=zeyos.com; h= content-transfer-encoding:content-type:content-type:mime-version :references:in-reply-to:message-id:to:from:from:subject:subject :date:date; s=dkim; t=1664517931; x=1665381932; bh=3jGM6moNOTtLO e9sQkyrxXjox3k1j9ctQ3fIy4GSzT4=; b=qjbC0jyUG6d/ZLjFAiN7IgespDMaM 7uIjy53F5E6SqEzV9bkG+oHoRyC4lDRYlFR+1Af9LBCy5nhzy1OTUDgcrmGDsMo3 i3WyxqpvPJpnba/CcaWZGYgEsWnSV05SMjgn12AOMU2nFZDBHcQzPAWTvDtyrljq gVxE1IgEcjOHY4= X-Virus-Scanned: Debian amavisd-new at mx.zeyos.com Received: from mx.zeyos.com ([127.0.0.1]) by mx.zeyos.com (mx.zeyos.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id QQ36kK0riHDj for ; Fri, 30 Sep 2022 08:05:31 +0200 (CEST) Received: from cloud.zeyos.com (static.182.82.88.23.clients.your-server.de [23.88.82.182]) by mx.zeyos.com (Postfix) with ESMTPSA id 98907619E0; Fri, 30 Sep 2022 08:05:31 +0200 (CEST) Date: Fri, 30 Sep 2022 08:05:31 +0200 Subject: Re: disfavoring unparameterized nested loops From: Benjamin Coutu To: Peter Geoghegan , Bruce Momjian Cc: PostgreSQL Hackers , Tom Lane , Robert Haas , David Rowley Message-ID: <998dbfc19d75a74f725d@zeyos.com> In-Reply-To: References: MIME-Version: 1.0 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 > Right. But that seems fraught with difficulty. I suspect that the > costs that the planner attributes to each plan often aren't very > reliable in any absolute sense, even when everything is working very > well by every available metric. Even a very noisy cost model with > somewhat inaccurate selectivity estimates will often pick the cheapest > plan, or close enough.=0A=0ASure, the absolute cost of a complex plan wil= l always be inaccurate at best.=0AMy point is that we can be very confident= in the cardinalities of base tables. As the paper states in "3.1. Estimate= s for Base Tables":=0A=0A"The median q-error is close to the optimal value = of 1 for all systems,=0Aindicating that the majority of all selections are = estimated correctly."=0A=0AThanks to the statistics will practically never = be off by an order of magnitude when estimating base table cardinalities.= =0A=0AThe paper also clearly shows (and that certainly coincides with my ex= perience) that those cardinality underestimations grow exponentially as the= y propagate up the join tree.=0A=0AGiven the research I'd stipulate that at= any given level of the join tree, the current depth is a reasonable indica= tor of underestimation. Taking that into account (even if only to mitigate = nested loops on higher levels) is IMV a principled approach, and not necess= eraly a hack.=0A=0AObviously having something like error bars as proposed b= y Tom would be even better and perhaps more general, but that is on a whole= different level in terms of complexity and I certainly have no idea how we= would easily get there.