Re: Does not use index on query using "field is null"?

From: Vick Khera <vivek(at)khera(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Does not use index on query using "field is null"?
Date: 2010-11-10 13:35:04
Message-ID: AANLkTimbLZ6c55QAOKez8FqgwQOEQ5v+2owj=1yn3FSJ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2010/11/10 Bjørn T Johansen <btj(at)havleik(dot)no>:
> select * from table where field is null
>
> And when I run explain, it tells me that it uses seq scan... Is this because pg thinks that seq scan is as fast as using indexes or because using index on "is null" queries does
> not work?
>

Does the table have *lots* of NULLs in that column? If the index is
not very selective, it may choose to use a seq scan since it will
result in fewer I/O ops. This decision will be based on the relative
values of random_page_cost and seq_page_cost, and probably the
effective_cache_size as well.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2010-11-10 15:00:43 Re: Does not use index on query using "field is null"?
Previous Message Bjørn T Johansen 2010-11-10 12:07:49 Does not use index on query using "field is null"?