Re: Order by and index

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jonathan Tse <dev(at)tsez(dot)net>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Order by and index
Date: 2005-10-07 03:23:12
Message-ID: 28676.1128655392@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Jonathan Tse <dev(at)tsez(dot)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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Michael Fuhr 2005-10-07 07:56:39 Re: Currval function won't work
Previous Message Jonathan Tse 2005-10-07 02:34:48 Re: Order by and index