Re: [SQL] Optimizing ORDER BY with indexes?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dirk Lutzebaeck <lutzeb(at)aeccom(dot)com>
Cc: pgsql-sql(at)postgreSQL(dot)org
Subject: Re: [SQL] Optimizing ORDER BY with indexes?
Date: 2000-01-14 15:18:16
Message-ID: 29405.947863096@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Dirk Lutzebaeck <lutzeb(at)aeccom(dot)com> writes:
> Reading about indexes in the Bowman SQL book I think a
> _clustered index_ is needed for the problem above.
> Does Postgresql support these?

It's there, but (1) the clustering operation itself isn't really
production-grade code (it tends to drop auxiliary data about the table),
and (2) the optimizer doesn't make any allowance in its estimates for
recently clustered indexes, so it might fail to choose an indexscan when
that would actually be the best way to do things.

I've been thinking about fixing (2), but the problem is to know how long
ago the cluster operation was done --- updates to the table will
gradually destroy the cluster order, so you really want to somehow scale
the cost estimate back towards the unordered case as more and more
updates are done following a cluster. But that'd mean keeping an update
counter, which is pretty expensive in itself.

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bruce Momjian 2000-01-14 16:37:19 Re: [SQL] Optimizing ORDER BY with indexes?
Previous Message Tom Lane 2000-01-14 15:02:33 Re: [SQL] key set delete query