Query plan change with multiple elements in IN clause

Поиск
Список
Период
Сортировка
От Mathieu De Zutter
Тема Query plan change with multiple elements in IN clause
Дата
Msg-id CAH7GKCzV_ZSBodUaT9ui406o-0Ak9WNHWW=yCMThj8CE_QJXQQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: Query plan change with multiple elements in IN clause  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-performance
Hi all,

I'm migrating a web application to an ORM framework (Doctrine) so I need a new way to get statistics about entities into the application without importing all data, only the results (e.g. load total number of children instead of loading all children into the application and counting it afterwards). My current solution is to create a view for those statistics and map it to an (read-only) entity in my application. This view is joined with the table containing the entities on which I need statistics.

The entity table is called 'work'. The view containing statistical information about works is called wps2.

The problem is that this join is performing very badly when more than one work is involved. It chooses a plan that is orders of magnitude slower.

I have attached
- The (simplified) table definitions
- The (simplified) view 
- Two queries with explain analyze plan: "IN (1)" => fast, "IN (1,3)" => slow
- postgresql.conf

I do not understand why the planner does not consider the nested loop in the second case, like it does in the first case.

Can anyone help me?

Thanks.

Kind regards,
Mathieu
Вложения

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

Предыдущее
От: Bastiaan Olij
Дата:
Сообщение: Optimising views
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Query plan change with multiple elements in IN clause