Re: Using index for IS NULL query
От
Tomas Vondra
Тема
Re: Using index for IS NULL query
Дата
Msg-id
4919F2C6.4000303@fuzzy.cz
Ответ на
Using index for IS NULL query (Andrus)
Список
Дерево обсуждения
Using index for IS NULL query "Andrus" <kobruleht2@hot.ee>
Re: Using index for IS NULL query Tom Lane <tgl@sss.pgh.pa.us>
Re: Using index for IS NULL query Andreas Kretschmer <akretschmer@spamfence.net>
Re: Using index for IS NULL query Matthew Wakeling <matthew@flymine.org>
Re: Using index for IS NULL query Andreas Kretschmer <akretschmer@spamfence.net>
Re: Using index for IS NULL query Tomas Vondra <tv@fuzzy.cz>
Index usage with sub select or inner joins "Julien Theulier" <julien@squidsolutions.com>
Re: Index usage with sub select or inner joins Joshua Tolley <eggyknap@gmail.com>
Re: Index usage with sub select or outer joins "Julien Theulier" <julien@squidsolutions.com>
Re: Using index for IS NULL query "Vladimir Sitnikov" <sitnikov.vladimir@gmail.com>
Re: Using index for IS NULL query Tomas Vondra <tv@fuzzy.cz>
Re: Using index for IS NULL query "Scott Marlowe" <scott.marlowe@gmail.com>
> 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 ? Yes, NULL values are not stored in the index, but you may create functional index on (CASE WHEN dokumnr IS NULL THEN -1 ELSE dokumnr END) and then use the same expression in the WHERE clause. You may replace the '-1' value by something that's not used in the dokumnr column. regards Tomas
В списке pgsql-performance по дате отправления