Re: ORDER BY and NULLs

From: Greg Stark <gsstark(at)mit(dot)edu>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: mailreg(at)numerixtechnology(dot)de, Greg Stark <gsstark(at)mit(dot)edu>, pgsql-sql(at)postgresql(dot)org
Subject: Re: ORDER BY and NULLs
Date: 2004-09-20 00:51:35
Message-ID: 874qltkbjc.fsf@stark.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> writes:

> > The paragraph continues:
> > "If the SELECT command included the clause WHERE phone NOT NULL,
> > PostgreSQL could use the index to satisfy the ORDER BY clause.
> > An index that covers optional (NOT NULL) columns will not be used to
> > speed table joins either."
>
> My goodness, it seems to be a veritable fount of misinformation :-(
>
> I wonder how much of this is stuff that is true for Oracle and they just
> assumed it carried over?

The first part is true for Oracle. You have to add the WHERE phone NOT NULL to
convince Oracle it can use an index. Or just make the column NOT NULL to begin
with I think.

However as far as I recall the second part is not true. Oracle is smart enough
to realize that an equijoin clause implies NOT NULL and therefore allows it to
use the index.

(This may have all changed in Oracle 9+. The last I saw of Oracle was 8i)

I wonder if they just tried explain on a bunch of queries and noticed that
postgres wasn't using an index for SELECT * FROM foo ORDER BY bar and came up
with explanations for the patterns they saw?

--
greg

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Worik 2004-09-20 01:04:02 Re: How to check postgres running or not ?
Previous Message Worik 2004-09-20 00:34:59 Re: How to check postgres running or not ?