Re: Slow 3 Table Join with v bad row estimate

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Slow 3 Table Join with v bad row estimate
Дата
Msg-id 2570.1447167809@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Slow 3 Table Join with v bad row estimate  (David Osborne <david@qcode.co.uk>)
Ответы Re: Slow 3 Table Join with v bad row estimate  (David Osborne <david@qcode.co.uk>)
Список pgsql-performance
David Osborne <david@qcode.co.uk> writes:
> We have 3 different ways we have to do the final X join condition (we use 3
> subqueries UNIONed together), but the one causing the issues is:

> (o.branch_code || o.po_number = replace(ss.order_no,' ',''))

> ... So we can see straight away that the outer Nested loop expects 1 row, and
> gets 53595. This isn't going to help the planner pick the most efficient
> plan I suspect.

> I've tried increasing default_statistics_target to the max and re analysing
> all the tables involved but this does not help the estimate.
> I suspect it's due to the join being based on functional result meaning any
> stats are ignored?

Yeah, the planner is not nearly smart enough to draw any useful
conclusions about the selectivity of that clause from standard statistics.
What you might try doing is creating functional indexes on the two
subexpressions:

create index on branch_purchase_order ((branch_code || po_number));
create index on stocksales_ib (replace(order_no,' ',''));

(actually it looks like you've already got the latter one) and then
re-ANALYZING.  I'm not necessarily expecting that the planner will
actually choose to use these indexes in its plan; but their existence
will prompt ANALYZE to gather stats about the expression results,
and that should at least let the planner draw more-accurate conclusions
about the selectivity of the equality constraint.

            regards, tom lane


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

Предыдущее
От: David Osborne
Дата:
Сообщение: Slow 3 Table Join with v bad row estimate
Следующее
От: David Osborne
Дата:
Сообщение: Re: Slow 3 Table Join with v bad row estimate