Re: Order by and index

From: Jonathan Tse <dev(at)tsez(dot)net>
To: pgsql-novice(at)postgresql(dot)org
Subject: Re: Order by and index
Date: 2005-10-07 02:34:48
Message-ID: 4345DEC8.7060105@tsez.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Hi Tom,

Thanks for your reply, making us aware of the way that postgresql's
query plan.

One more question, I got an index on ownerid , but postgresql 8.03
still cannot use index to execute the following sql:

select ownerid,count(ownerid) from t_post group by ownerid order by
ownerid limit 100

Why is that? Is 8.1 more capable to use the index? Thanks a lot.

Best regards,
Jonathan Tse

Tom Lane wrote:

>Jonathan Tse <dev(at)tsez(dot)net> writes:
>
>
>> It is good. However, if I execute the following query:
>>
>>
>
>
>
>> select * from t_post where ownerid = 2
>> order by t_stamp
>>
>>
>
>
>
>> The query planner doesn't use the index for sorting.
>>
>>
>
>Try "order by ownerid, t_stamp".
>
>Postgres 8.1 will recognize that the where clause makes it OK to
>consider the ORDER BY as matching the index order, but existing
>releases do not know that.
>
> regards, tom lane
>
>

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2005-10-07 03:23:12 Re: Order by and index
Previous Message Bruno Wolff III 2005-10-07 00:32:33 Re: create table as problem