Re: Need help with optimising simple query

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Need help with optimising simple query
Дата
Msg-id 9715.1531146227@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Need help with optimising simple query  (Nandakumar M <m.nanda92@gmail.com>)
Ответы Re: Need help with optimising simple query  (Nandakumar M <m.nanda92@gmail.com>)
Список pgsql-performance
Nandakumar M <m.nanda92@gmail.com> writes:
> I am having a query that has an order by and a limit clause. The
> column on which I am doing order by is indexed (default b tree index).
> However the index is not being used. On tweaking the query a bit I
> found that when I use left join index is not used whereas when I use
> inner join the index is used.

The reason the index isn't being used is that the sort order the query
requests isn't the same as the order provided by the index.  Here:

> performance_test=# explain analyze select * from parent left join
> child on parent.child_id = child.id order by child.name limit 10;

you're asking to sort by a column that will include null values for
child.name anywhere that there's a parent row without a match for
child_id.  Those rows aren't even represented in the index on child.name,
much less placed in the right order.

            regards, tom lane


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

Предыдущее
От: Nandakumar M
Дата:
Сообщение: Need help with optimising simple query
Следующее
От: Nandakumar M
Дата:
Сообщение: Re: Need help with optimising simple query