Re: Cardinality estimate of the inner relation - Mailing list pgsql-performance

From Andrei Lepikhov
Subject Re: Cardinality estimate of the inner relation
Date
Msg-id dfb633b2-6e7b-453a-a2ed-a3a32d34bdd6@gmail.com
Whole thread Raw
In response to Cardinality estimate of the inner relation  (Frédéric Yhuel <frederic.yhuel@dalibo.com>)
Responses Re: Cardinality estimate of the inner relation
List pgsql-performance
On 22/11/2024 22:53, Frédéric Yhuel wrote:
> My colleague Christophe Courtois and I have been trying to fix a bad 
> plan for one of Dalibo's clients. It is a (probably well-known) problem 
> with skewed data and a parameterized Nested Loop with an underestimation 
> of the cardinality of the inner relation.
> 
> Here is a test case (the script to create and populate the two tables is 
> at the end):
Thanks for the case provided!

I wonder if data science has invented a statistic or selectivity 
estimation technique that could tackle your case in general. As I see, 
we should touch the table of products to realise which specific ID has 
the product named 'Babar'.
I can imagine the trick when you build MCV on (id, name) and have a 
chance to find this popular ID, cache it, and use it during join clause 
estimation later. But it seems too expensive to do the same for 
arbitrary incoming queries.

If you want a workaround, such cases fit query-driven techniques. Among 
open-source ones, I can point your attention to the AQO extension 
(honestly, designed under my command). It can save information about an 
estimation error and correct the query next time.

In an enterprise-grade area, you can pick the sr_plan extension, which 
is designed to store the plan for a specific query (you can choose 
parameterisation on your own) and spread it globally across all 
instances' backends.

-- 
regards, Andrei Lepikhov




pgsql-performance by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: could not send data to client: Connection reset by peer
Next
From: Andrei Lepikhov
Date:
Subject: Re: Performance of Query 60 on TPC-DS Benchmark