Re: ORDER BY and NULLs

From: T E Schmitz <mailreg(at)numerixtechnology(dot)de>
To: Greg Stark <gsstark(at)mit(dot)edu>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-sql(at)postgresql(dot)org
Subject: Re: ORDER BY and NULLs
Date: 2004-09-19 20:22:23
Message-ID: 414DEA7F.6050100@numerixtechnology.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello Greg,

Greg Stark wrote:

> T E Schmitz <mailreg(at)numerixtechnology(dot)de> writes:
>
>>Quote: "PostgreSQL will not index NULL values. Because an index will never
>>include NULL values, it cannot be used to satisfy the ORDER BY clause of a
>>query that returns all rows in a table."
>
>
> You should just cross out that whole section. It's just flatly wrong.
> I had always assumed it was just people bringing assumptions over from Oracle
> where it is true. Perhaps this book is to blame for some of the confusion.
> Which book is it?

PostgreSQL by Korry Douglas + Susan Douglas, ISBN 0-7357-1257-3; Feb 2003

> Postgres indexes NULLs. It can use them for ORDER BY clauses.
>
> Where it cannot use them is to satisfy "WHERE foo IS NULL" or "WHERE foo IS
> NOT NULL" constraints though. That's an implementation detail, but it can be
> worked around with partial indexes.

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."

--

Regards/Gruß,

Tarlika Elisabeth Schmitz

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2004-09-19 20:30:29 Re: ORDER BY and NULLs
Previous Message Tom Lane 2004-09-19 19:00:08 Re: ORDER BY and NULLs