Re: Indexing a boolean

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Kris Kiger <kris(at)musicrebellion(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: Indexing a boolean
Date: 2003-08-21 21:13:07
Message-ID: 20030821211307.GA7194@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Thu, Aug 21, 2003 at 15:47:39 -0500,
Kris Kiger <kris(at)musicrebellion(dot)com> wrote:
> I would appreciate it if I could get some thoughts on indexing a field
> with only two values? For example, I have a table with a few million
> rows in it. All items in this table are broken up into two categories
> using 'T' or 'F'. It seems logical to me that an index on this field
> would create two logical 'buckets', so that one could say, "I want all
> 'T' values", or "I want all 'F' values" and merely have to look in the
> appropriate bucket, rather than have to perform a sequential scan
> through three million items every time a request is made based on 'T' or
> 'F'. If I were to create an index on a char(1) field that contains only
> values of 'T' or 'F', would the query analyzer override the use of this
> index? How does Postgres address this problem and what are all of your
> thoughts on this issue? I appreciate the help!

You probably don't want to use an index unless one of the two values
is much more common than the other. In that case you want to use a partial
index on the rare condition.

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Tom Lane 2003-08-21 22:05:07 Re: This table won't use INDEX until I DUMP/RESTORE it ?
Previous Message Kris Kiger 2003-08-21 20:47:39 Indexing a boolean