Indexing on a boolean field?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Indexing on a boolean field?
Дата
Msg-id 1691.897924796@sss.pgh.pa.us
обсуждение исходный текст
Ответы Re: [SQL] Indexing on a boolean field?
Список 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 по дате отправления:

Предыдущее
От: JESUS AVILA MOLINA
Дата:
Сообщение: Postgresql-Perl -->PQexec() -- there is no connection to the backend
Следующее
От: Herouth Maoz
Дата:
Сообщение: Re: [SQL] Indexing on a boolean field?