Re: Index on nullable column

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Daniel Caune" <daniel(dot)caune(at)ubisoft(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Index on nullable column
Date: 2006-03-24 23:48:17
Message-ID: 12727.1143244097@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Daniel Caune" <daniel(dot)caune(at)ubisoft(dot)com> writes:
> Is an index on a nullable column useful for retrieving rows having that
> column null?

Nope, because IS NULL isn't an indexable operator.

You can make an end-run around that with a partial index, eg

create index fooi on foo(f1) where f1 is null

This can be used to satisfy queries using "where f1 is null", but it's
not any good for any other purpose.

If you often do "where f1 is null and something-about-f2",
you might get better mileage with

create index fooi on foo(f2) where f1 is null

but it's still a very specialized index.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message AKHILESH GUPTA 2006-03-25 06:36:34 regarding join
Previous Message PFC 2006-03-24 23:17:08 Re: Expressing a result set as an array (and vice versa)?