Using index for IS NULL query

От: Andrus
Тема: Using index for IS NULL query
Дата: ,
Msg-id: gfcprb$m40$1@news.hub.org
(см: обсуждение, исходный текст)
Ответы: Re: Using index for IS NULL query  (Tom Lane)
Re: Using index for IS NULL query  (Andreas Kretschmer)
Re: Using index for IS NULL query  (Tomas Vondra)
Список: pgsql-performance

Скрыть дерево обсуждения

Using index for IS NULL query  ("Andrus", )
 Re: Using index for IS NULL query  (Tom Lane, )
  Re: Using index for IS NULL query  (Andreas Kretschmer, )
  Re: Using index for IS NULL query  (Matthew Wakeling, )
 Re: Using index for IS NULL query  (Andreas Kretschmer, )
 Re: Using index for IS NULL query  (Tomas Vondra, )
  Re: Using index for IS NULL query  ("Vladimir Sitnikov", )
   Re: Using index for IS NULL query  ("Scott Marlowe", )
   Re: Using index for IS NULL query  (Tomas Vondra, )
  Index usage with sub select or inner joins  ("Julien Theulier", )
   Re: Index usage with sub select or inner joins  (Joshua Tolley, )
    Re: Index usage with sub select or outer joins  ("Julien Theulier", )

Index is not used for

 is null

condition:

create index  makse_dokumnr_idx on makse(dokumnr);
explain select
     sum( summa)
   from MAKSE
   where  dokumnr is null

"Aggregate  (cost=131927.95..131927.96 rows=1 width=10)"
"  ->  Seq Scan on makse  (cost=0.00..131927.94 rows=1 width=10)"
"        Filter: (dokumnr IS NULL)"



Table makse contains 1200000 rows and about 800 rows with dokumnr is null so
using index is much faster that seq scan.
How to fix ?

Andrus.

"PostgreSQL 8.1.4 on i686-pc-linux-gnu, compiled by GCC
i686-pc-linux-gnu-gcc (GCC) 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0,
pie-8.7.9)"



В списке pgsql-performance по дате сообщения:

От: Tom Lane
Дата:
Сообщение: Re: Oddity with view (now with test case)
От: Matthew Wakeling
Дата:
Сообщение: Re: Using index for IS NULL query