Re: Indexing a Boolean or Null column? - Mailing list pgsql-performance

From Tom Lane
Subject Re: Indexing a Boolean or Null column?
Date
Msg-id 17336.1073190412@sss.pgh.pa.us
Whole thread Raw
In response to Indexing a Boolean or Null column?  ("D. Dante Lorenso" <dante@lorenso.com>)
List pgsql-performance
"D. Dante Lorenso" <dante@lorenso.com> writes:
> Does it make sense to have an index on data_is_active?

Hard to say.  You weren't very clear about what fraction of the table
rows you expect to have data_is_active = true.  If that's a very small
fraction, then an index might be worthwhile.

However, I'd suggest using a partial index that merges the is_active
test with some other useful behavior.  For example, if this is a
common pattern:

>     SELECT *
>     FROM table
>     WHERE data_lookup_key = 'pear'
>     AND data_is_active IS TRUE;

then what you really want is

CREATE INDEX myindex ON table (data_lookup_key) WHERE data_is_active IS TRUE;

> I bet this is in a FAQ somewhere.  Can you point me in the right
> direction?

See the docs on partial indexes.

            regards, tom lane

pgsql-performance by date:

Previous
From: "D. Dante Lorenso"
Date:
Subject: Indexing a Boolean or Null column?
Next
From: Christopher Kings-Lynne
Date:
Subject: Re: Indexing a Boolean or Null column?