From: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
To: D. Dante Lorenso <dante@lorenso.com>
Cc: pgsql-performance@postgresql.org
Subject: Re: Indexing a Boolean or Null column?
Date: Sun, 04 Jan 2004 12:32:36 +0800
Message-ID: <3FF79764.6060805@familyhealth.com.au> (raw)
In-Reply-To: <3FF769EA.7090508@lorenso.com>
References: <3FF769EA.7090508@lorenso.com>
> Will an index on the 'data_is_active' column be used or work
> as I expect? I'm assuming that I may have a million entries
> sharing the same 'data_lookup_key' and I'll be using that to
> search for the active version of the row.
An index just on a boolean column won't be 'selective enough'. eg. The
index will only be able to choose 50% of the table - since it's faster
to do a full table scan in that case, the index won't get used.
A multi keyed index, however will work a bit better, eg an index over
(data_lookup_key, data_is_active).
That way, the index will first be able to find the correct key (which is
nicely selective) and then will be able to halve the resulting search
space to get the active ones.
BTW, you shouldn't use 'banana', 'pear', etc as the data_lookup_key, you
should make another table like this:
id name
1 banana
2 apple
3 pear
And then replace the data_lookup_key col with a column of integers that
is a foreign key to the names table - waaaaay faster to process.
Chris
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-performance@postgresql.org
Cc: chriskl@familyhealth.com.au, dante@lorenso.com
Subject: Re: Indexing a Boolean or Null column?
In-Reply-To: <3FF79764.6060805@familyhealth.com.au>
References: <3FF769EA.7090508@lorenso.com> <3FF79764.6060805@familyhealth.com.au>
* 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