Re: Optimising queries involving unions

Список
Период
Сортировка
От Tom Lane
Тема Re: Optimising queries involving unions
Дата
Msg-id 3339.1117126434@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Optimising queries involving unions  (Sam Mason)
Ответы Re: Optimising queries involving unions  (Sam Mason)
Список pgsql-performance
Дерево обсуждения
Optimising queries involving unions  (Sam Mason, )
 Re: Optimising queries involving unions  (Tom Lane, )
  Re: Optimising queries involving unions  (Sam Mason, )
   Re: Optimising queries involving unions  (Tom Lane, )
 Re: Optimising queries involving unions  ("Marc Mamin", )
Sam Mason <> writes:
> Here's a bad example:

>   SELECT u.txt
>   FROM smalltable t, (
>     SELECT id, txt FROM largetable1
>     UNION ALL
>     SELECT id, txt FROM largetable2) u
>   WHERE t.id = u.id
>     AND t.foo = 'bar';

> I was hoping that "smalltable" would get moved up into the union,
> but it doesn't at the moment and the database does a LOT of extra
> work.

I'm afraid we're a long way away from being able to do that; the
parse/plan representation of UNION wasn't chosen with an eye to
being able to optimize it at all :-(.  We can push restriction
clauses down into a union, but we can't do much with join clauses,
because they necessarily refer to tables that don't even exist
within the sub-query formed by the UNION.

It'd be nice to fix this someday, but don't hold your breath ...

            regards, tom lane

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

Предыдущее
От: Dawid Kuroczko
Дата:
Сообщение: Re: slow queries, possibly disk io
Следующее
От: Christopher Kings-Lynne
Дата:
Сообщение: Re: slow queries, possibly disk io