Re: Would an index benefit select ... order by?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: rihad <rihad(at)mail(dot)ru>
Cc: pgsql-general(at)postgresql(dot)org, andreas(dot)kretschmer(at)schollglas(dot)com
Subject: Re: Would an index benefit select ... order by?
Date: 2007-11-04 16:09:01
Message-ID: 14070.1194192541@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

rihad <rihad(at)mail(dot)ru> writes:
> You mean Postgres wouldn't *always* use created_at's index with such
> access patterns on a big table (even if one exists):

> select * from foo order by created_at desc;

No, it wouldn't necessarily, and that's a good thing. A full-table
indexscan can often be slower than a sort because of inefficient disk
access patterns. The planner will estimate the cost of each possibility
and pick the one that looks cheaper.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-11-04 16:15:05 Re: COPY ... FROM and index usage
Previous Message Lew 2007-11-04 15:46:36 Re: What makes a Postgres DBA?