Re: Indexing a Boolean or Null column?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "D(dot) Dante Lorenso" <dante(at)lorenso(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Indexing a Boolean or Null column?
Date: 2004-01-04 04:26:52
Message-ID: 17336.1073190412@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

"D. Dante Lorenso" <dante(at)lorenso(dot)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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Christopher Kings-Lynne 2004-01-04 04:32:36 Re: Indexing a Boolean or Null column?
Previous Message D. Dante Lorenso 2004-01-04 01:18:34 Indexing a Boolean or Null column?