pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: D. Dante Lorenso <dante@lorenso.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Indexing a Boolean or Null column?
Date: Sat, 03 Jan 2004 23:26:52 -0500
Message-ID: <17336.1073190412@sss.pgh.pa.us> (raw)
In-Reply-To: <3FF769EA.7090508@lorenso.com>
References: <3FF769EA.7090508@lorenso.com>

"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



view thread (8+ messages)  latest in thread

Message-ID: <17336.1073190412@sss.pgh.pa.us>
Permalink:  ../17336.1073190412@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/17336.1073190412@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: tgl@sss.pgh.pa.us, dante@lorenso.com
  Subject: Re: Indexing a Boolean or Null column?
  In-Reply-To: <17336.1073190412@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox