Re: simple join query runs very slowly

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: simple join query runs very slowly
Дата
Msg-id 26439.1080329833@sss.pgh.pa.us
обсуждение исходный текст
Ответ на simple join query runs very slowly  (rdnews@dahlsys.com (Roger Dahl))
Список pgsql-general
rdnews@dahlsys.com (Roger Dahl) writes:
> select b.name,
> from boxes b
> inner join item_box_maps m on m.box_id = b.id
> inner join items i on m.id = m.item_id
> where i.name = 'hammer';

You didn't say which PG version you are running, but I bet it is one
that strictly follows the JOIN syntax order.  Try flipping the order of
the JOIN clauses:

select b.name,
from boxes b
inner join items i on m.id = m.item_id
inner join item_box_maps m on m.box_id = b.id
where i.name = 'hammer';

There is more about this in the Performance Tips section of the docs.

            regards, tom lane

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

Предыдущее
От: Eric Ridge
Дата:
Сообщение: pg 7.3, cursors, and prepared queries
Следующее
От: Ron St-Pierre
Дата:
Сообщение: Re: [NOVICE] Simple list tables question