Re: Order by and index

Поиск
Список
Период
Сортировка
Искать
От
Josh Kupershmidt
Тема
Re: Order by and index
Дата
Msg-id
AANLkTinNUHhHOcwkjnh8PW87Yy4iXME85GSnkto8B1ic@mail.gmail.com
Ответ на
Order by and index (Mladen Gogala)
Список
Дерево обсуждения
Order by and index Mladen Gogala <mgogala@vmsinfo.com>
Re: Order by and index Josh Kupershmidt <schmiddy@gmail.com>
Re: Order by and index Mladen Gogala <mladen.gogala@vmsinfo.com>
On Fri, Aug 27, 2010 at 6:30 PM, Mladen Gogala  wrote:
> It looks like the Postgres optimizer cannot use indexes for "order by"
> conditions. The query that made me conclude this, looks like this:

It looks to me like the reason that you have that heapsort step is
because of your WHERE clause involving the "created_at" timestamp.

> explain analyze
> select "document#" from moreover_documents
> where created_at order by "document#"
> limit 10;

And your comparison showing Oracle to be faster doesn't use this WHERE clause:

> SQL> set autotrace on explain;
> SQL> select document# from (
>  2  select document# from moreover_documents
>  3  order by document#)
>  4  where rownum<=10;

Perhaps Oracle is smart enough to use indexes on "created_at" and
"document#" together to avoid a sort entirely, but your example
doesn't show this. Postgres should be able to use an Index Scan and
avoid that sort step if you don't involve "created_at":

Also, I'm not sure whether this would help in your case, but there was
some talk recently about implementing "Index Organized Tables" for
Postgres, borrowing from Oracle.

http://archives.postgresql.org/pgsql-hackers/2010-02/msg01708.php

Josh
В списке pgsql-novice по дате отправления
От: Mladen Gogala
Дата:
Сообщение: Re: COPY problem.
От: Mladen Gogala
Дата:
Сообщение: Re: Order by and index
FAQ