Indexing on a boolean field? - Mailing list pgsql-sql

From Tom Lane
Subject Indexing on a boolean field?
Date
Msg-id 1691.897924796@sss.pgh.pa.us
Whole thread Raw
Responses Re: [SQL] Indexing on a boolean field?  (Herouth Maoz <herouth@oumail.openu.ac.il>)
List pgsql-sql
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

pgsql-sql by date:

Previous
From: JESUS AVILA MOLINA
Date:
Subject: Postgresql-Perl -->PQexec() -- there is no connection to the backend
Next
From: Herouth Maoz
Date:
Subject: Re: [SQL] Indexing on a boolean field?