Re: Is there value in having optimizer stats for joins/foreignkeys?

Поиск
Список
Период
Сортировка
От Andrei Lepikhov
Тема Re: Is there value in having optimizer stats for joins/foreignkeys?
Дата
Msg-id 3c477f2f-10e4-4705-bb21-90ccbe67e9d2@gmail.com
обсуждение исходный текст
Ответ на Re: Is there value in having optimizer stats for joins/foreignkeys?  (Tomas Vondra <tomas@vondra.me>)
Ответы Re: Is there value in having optimizer stats for joins/foreignkeys?
Список pgsql-hackers
On 1/2/26 17:39, Tomas Vondra wrote:
> We can't simply store an opaque VIEW, and build the stats by simply
> executing it (and sampling the results). The whole premise of extended
> stats is that people define them to fix incorrect estimates. And with
> incorrect estimates the plan may be terrible, and the VIEW may not even
> complete.

Ok, I got the point.
I think linking to a join or foreign key seems restrictive. In my mind, 
extended statistics may go the following way:

CREATE STATISTICS abc_stat ON (t1.x,t2.y,t3.z) FROM t1,t2,t3;

Suppose t1.x,t2.y, and t3.z have a common equality operator.

Here we can build statistics on (t1.x = t2.y), (t1.x = t3.z), (t2.y = 
t3.z), and potentially (t1.x = t2.y = t3.z).

But I don't frequently detect problems with JOIN estimation using a 
single join clause. Usually, we have problems with (I) join trees 
(clauses spread across joins) and (II) a single multi-clause join.
We can't solve (I) here (kinda statistics on a VIEW might help, I 
think), but may ease (II) using:

CREATE STATISTICS abc_stat ON ((t1.x=t2.x),(t1.y=t2.y)) FROM t1,t2;

or even more bravely:

CREATE STATISTICS abc_stat ON ((t1.x=t2.x),(t1.y=t2.y)) FROM t1,t2
WHERE (t1.z <> t2.z);

-- 
regards, Andrei Lepikhov,
pgEdge



В списке pgsql-hackers по дате отправления: