Re: Order by and index - Mailing list pgsql-novice

From Tom Lane
Subject Re: Order by and index
Date
Msg-id 28676.1128655392@sss.pgh.pa.us
Whole thread Raw
In response to Re: Order by and index  (Jonathan Tse <dev@tsez.net>)
List pgsql-novice
Jonathan Tse <dev@tsez.net> writes:
>     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

"Cannot"?  Or "chooses not to"?  And are you sure the choice is wrong?

A simple test case for me says that a seqscan/hashaggregate plan is
faster than an indexscan/groupaggregate plan for this sort of problem.
It'll depend on many factors, but for a query that necessarily involves
visiting every row of the table, you're seriously in error to think that
an indexscan plan must be a win.

Try playing around with enable_seqscan and related settings to see what
the alternatives really    are.

            regards, tom lane

pgsql-novice by date:

Previous
From: Jonathan Tse
Date:
Subject: Re: Order by and index
Next
From: "Bluebottle"
Date:
Subject: Currval function won't work