Re: Why is the query not using the index for sorting?

From: Thom Brown <thombrown(at)gmail(dot)com>
To: Jonathan Blitz <jblitz(at)013(dot)net>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Why is the query not using the index for sorting?
Date: 2009-11-22 13:10:26
Message-ID: bddc86150911220510rfb8f8a4jbdb90d7266cdf315@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

2009/11/22 Jonathan Blitz <jblitz(at)013(dot)net>

> I have a table with a number of columns.
>
> I perform
>
> Select *
> from table
> order by a,b
>
> There is an index on a,b which is clustered (as well as indexes on a and b
> alone).
> I have issued the cluster and anyalze commands.
>
> Nevertheless, PostgreSQL performs a Sequential Scan on the table and then
> performs a sort.
> Am I missing something?
>
> Jonathan Blitz
>

It depends on firstly the size of the table, and also the distribution of
data in columns a and b. If the stats for that table knows that the table
has a natural order (i.e. they happen to be in roughly the order you've
asked for them in), or the table isn't big enough to warrant using an index,
then it won't bother using one. It will pick whichever it believes to be
the most efficient method.

Regards

Thom

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Craig Ringer 2009-11-22 13:25:17 Re: Why is the query not using the index for sorting?
Previous Message Jonathan Blitz 2009-11-22 12:50:51 Why is the query not using the index for sorting?