Re: ORDER BY and NULLs - Mailing list pgsql-sql

From Greg Stark
Subject Re: ORDER BY and NULLs
Date
Msg-id 874qltkbjc.fsf@stark.xeocode.com
Whole thread Raw
In response to Re: ORDER BY and NULLs  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: ORDER BY and NULLs
List pgsql-sql
Tom Lane <tgl@sss.pgh.pa.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



pgsql-sql by date:

Previous
From: Worik
Date:
Subject: Re: How to check postgres running or not ?
Next
From: Worik
Date:
Subject: Re: How to check postgres running or not ?