pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-sql@postgresql.org
Subject: Indexing on a boolean field?
Date: Mon, 15 Jun 1998 11:33:16 -0400
Message-ID: <1691.897924796@sss.pgh.pa.us> (raw)

Can anyone suggest to me a better way to handle this?

I want to be able to select out the elements of a table that have
a TRUE value in a boolean field "flag".  (Basically the flag means
the record hasn't been processed yet.)  I can do something like

	SELECT * FROM table WHERE flag = 't';

However, the table is going to get large, and most of the elements
will have flag = 'f' as transaction history accumulates.  It looks
to me like a select done as above will have to be processed by scanning
the whole table; that's not going to do.

I thought of creating an index on the flag field, but soon found that
you can't do it in Postgres (there's no operator for index on boolean).
In any case, I doubt that btree or hash indexes would work well with
only two distinct data values.

Another possibility is to keep the not-yet-processed records in a
separate table, but that seems pretty ugly as well; especially since
I sometimes want to see both processed and unprocessed records.

Has anyone got some advice on how to approach this problem?

			regards, tom lane



view thread (2+ messages)  latest in thread

Message-ID: <1691.897924796@sss.pgh.pa.us>
Permalink:  ../1691.897924796@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1691.897924796@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 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-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: Indexing on a boolean field?
  In-Reply-To: <1691.897924796@sss.pgh.pa.us>
  References: <1691.897924796@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