Received: from sss.sss.pgh.pa.us (sss.pgh.pa.us [206.210.65.6]) by hub.org (8.8.8/8.7.5) with ESMTP id LAA18109 for ; Mon, 15 Jun 1998 11:33:22 -0400 (EDT) Received: from sss.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.sss.pgh.pa.us (8.8.5/8.8.5) with ESMTP id LAA01694 for ; Mon, 15 Jun 1998 11:33:16 -0400 (EDT) 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> From: Tom Lane 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