Re: Index not used with IS NULL

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Dima Tkach <dmitry(at)openratings(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Index not used with IS NULL
Date: 2003-02-17 05:46:49
Message-ID: 20030216213835.X1444-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, 16 Feb 2003, Dima Tkach wrote:

> Stephan Szabo wrote:
> > On Sat, 15 Feb 2003, Dima Tkach wrote:
> >
> >
> >>It would be a lot nicer if the default operators could handle that...
> >>Why can it not be done?
> >
> >
> > Jumping in... I usually use a partial index as a workaround. Postgresql
> > will look at a partial index whose condition is IS NULL for queries of col
> > IS NULL.
> >
>
> - create two indexes, one with predicate, and one without predicate - is
> a waste of space, because all the rows with nulls get indexed twice. The
> space may not be such an important consideration by itself, but, when
> the table is huge and heavily being updated, the overhead of having to
> keep both indexes in synch becomes significant.

Yes, this solution does double index the NULLs, but if you have alot of
NULLs you probably should be doing a seqscan to find them anyway and don't
need the index. High update frequency costs you the NULL check, which is
a little annoying, and if you've got a small number of NULL rows or the
data is clustered in some fashion (so that the index is a win) that have
lots of updates this may become significant.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rajesh Kumar Mallah 2003-02-17 07:10:57 Re: [SQL] is current_timestamp unique for a transaction?
Previous Message Tom Lane 2003-02-17 05:42:19 Re: Index not used with IS NULL