Re: BUG #1470: Boolean expression index not used when it could be

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Sergey Koshcheyev" <sergey(dot)p(dot)k(at)hotmail(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #1470: Boolean expression index not used when it could be
Date: 2005-02-09 21:07:18
Message-ID: 20239.1107983238@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"Sergey Koshcheyev" <sergey(dot)p(dot)k(at)hotmail(dot)com> writes:
> I'm trying to optimize "is null" queries, since PgSQL doesn't index null
> values. I have found that creating an expression index on (column is null)
> could work, but it doesn't get used unless the index expression is part of a
> comparison. Could this be improved, so that (a boolean expression) is taken
> as equivalent to (a boolean expression = true)?

You would be better off to use a partial index:

create index tbl1_abc on tbl1 (somecol) where abc is null;

The advantage of this is that not only do you get the is-null filter,
but you may be able to filter on some other column(s) at the same time.
For instance if you commonly query

select ... from tbl1 where abc is null and def > 42

then making "somecol" be "def" would be a winner.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Bruce Momjian 2005-02-09 22:42:38 Re: BUG #1468: psql_dump is not backward compatible
Previous Message Joachim Schuette 2005-02-09 17:16:06 BUG #1472: Win-Installation failed due to missing access-rights