Re: Indexing null dates - Mailing list pgsql-general

From Greg Stark
Subject Re: Indexing null dates
Date
Msg-id 87ekqj5nms.fsf@stark.xeocode.com
Whole thread Raw
In response to Re: Indexing null dates  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-general
Bruce Momjian <pgman@candle.pha.pa.us> writes:

> Yes, nifty.  CREATE INDEX docs updated with:
>
> +    <literal>NULL</> values are not indexed by default.  The best way
> +    to index <literal>NULL</> values is to create a partial index using
> +    an <literal>IS NULL</> comparison.  <literal>IS NULL</> is more
> +    of a function call than a value comparison, and this is why a partial
> +    index works.

Uh, this is wrong.

NULLs are indexed. It's just that IS NULL cannot take advantage of it due to
technical details. These are NOT the same thing.

Saying "NULLs are not indexed" will confuse people because it will make them
think that they're not present in the index at all which is what Oracle does.

That has real consequences on queries. The most obvious being that

 SELECT * FROM foo ORDER BY bar

cannot take advantage of an index on bar. Oracle programmers are accustomed to
having to had a "WHERE bar IS NOT NULL" or else live with the full table scan
and sort.

--
greg

pgsql-general by date:

Previous
From: Andreas
Date:
Subject: Re: plan-reading extensive tutorial?
Next
From: Tom Lane
Date:
Subject: Re: Indexing null dates