Re: Query plan different depending on the value of where filter

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Query plan different depending on the value of where filter
Дата
Msg-id 6847.1374080649@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Query plan different depending on the value of where filter  ("Looby, Denis" <denis.looby@hp.com>)
Список pgsql-general
"Looby, Denis" <denis.looby@hp.com> writes:
> What I don't understand is why the plan is different just because the group_id = has changed value?
> Does the planner have some statistical info on the contents of non-indexed rows?

Of course.  In this case it knows that a nestloop would be a loser
because many rows would be fetched from the outer table.

> I don't quite understand why this plan executes the sequential scan once, whereas the slow one does it 5001 times,
whichI believe is the main source of the difference. 

In the hash join case, it builds the hash table, discovers that it's
empty (because there are no rows with type = 2), and concludes that it
need not scan the outer relation.  This is a corner case that the
planner doesn't try to account for because it couldn't be predicted
reliably.  I wouldn't get too excited about it if I were you, because
presumably the case isn't going to happen all that much in production
either (else why are you bothering with the query?).

Personally I'd suggest getting rid of the
WHERE outer_tab.outer_key = inner_tab_1.key_to
clause, which is entirely redundant with the IN condition and is
preventing the planner from seeing that it could optimize the IN
into a semijoin.

            regards, tom lane


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

Предыдущее
От: "Looby, Denis"
Дата:
Сообщение: Query plan different depending on the value of where filter
Следующее
От: rox
Дата:
Сообщение: What are my options to avoid a Row Exclusive/RowShareLock conflict/ is there a better way?