pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tobias Brox <tobias@nordicbet.com>
To: pgsql-performance@postgresql.org
Subject: Index on a NULL-value
Date: Tue, 31 May 2005 11:02:07 +0800
Message-ID: <20050531030207.GD26100@tobias.exoweb.net> (raw)

I read in the manual today:

  Indexes are not used for IS NULL clauses by default. The best way to use
  indexes in such cases is to create a partial index using an IS NULL
  predicate.
  
This is from the documentation for PostgreSQL 8.  I did not find anything
equivalent in the 7.4.8-documentation.
  
I wasn't aware of this until it became an issue :-) Well, so I follow the
tip but in vain.  Reduced and reproduced like this in PostgreSQL 7.4.7:

test=# create table mock(a int, b int);
CREATE TABLE
test=# create index b_is_null on mock((b IS NULL));
CREATE INDEX
test=# insert into mock values (10,20);
INSERT 70385040 1
test=# insert into mock values (20,30);
INSERT 70385041 1
test=# insert into mock values (30, NULL);
INSERT 70385042 1
test=# set enable_seqscan=off; 
SET
test=# explain select * from mock where b is NULL;
                             QUERY PLAN                             
--------------------------------------------------------------------
 Seq Scan on mock (cost=100000000.00..100000020.00 rows=6 width=8)
   Filter: (b IS NULL)
(2 rows)

vacuum analyze also didn't help to recognize the index ;-)

Any tips?  Rewrite the application to not use NULL-values?  Hide under
bedclothes and hope the problem goes away?  Install more memory in the
server? :-)

-- 
Tobias Brox, Beijing



view thread (12+ messages)  latest in thread

Message-ID: <20050531030207.GD26100@tobias.exoweb.net>
Permalink:  ../20050531030207.GD26100@tobias.exoweb.net/
Also on:    postgresql.org/message-id/20050531030207.GD26100@tobias.exoweb.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tobias@nordicbet.com
  Subject: Re: Index on a NULL-value
  In-Reply-To: <20050531030207.GD26100@tobias.exoweb.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox