Re: Handling large number of OR/IN conditions

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Handling large number of OR/IN conditions
Дата
Msg-id 26355.1241216329@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Handling large number of OR/IN conditions  (Steve Atkins <steve@blighty.com>)
Список pgsql-general
Steve Atkins <steve@blighty.com> writes:
> On May 1, 2009, at 2:42 PM, David Wall wrote:
>> Does anybody know if PG will perform better with the table join
>> instead of evaluating the series of OR/IN?  The OR/IN has to be
>> parsed, but the comparisons may be faster than the table join.

> It used to be that populating and then joining with a temporary table
> was faster than using IN (1, 3, 5, 7, 9, 11, 13) for all but the
> smallest sets. That's no longer true, and IN() is pretty good.

> I'd still use a temporary table myself, though. It's cleaner and
> easier to populate one than to cleanly produce a statement with a
> variable number of identifiers in it. And you can reuse it for
> multiple reports, join against it different ways and so on. Also you
> can populate it either from your UI or by selecting from the
> relationships table suggested above (create temporary table foo as
> select peon from reports where overlord in ('bob', 'ben', 'jerry) ),
> and still run the same reports against it.

Possibly worth noting: if you're depending on the quality of join plans
involving such a table, it's worth doing an ANALYZE against it after
you populate it.  (Autovacuum won't do that for you, because it can't
access temp tables.)

            regards, tom lane

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

Предыдущее
От: Thomas Kellerer
Дата:
Сообщение: Re: Possible to prevent transaction abort?
Следующее
От: Adam B
Дата:
Сообщение: Re: Possible to prevent transaction abort?