Re: Indexing a Boolean or Null column?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Indexing a Boolean or Null column?
Дата
Msg-id 17336.1073190412@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Indexing a Boolean or Null column?  ("D. Dante Lorenso" <dante@lorenso.com>)
Список pgsql-performance
"D. Dante Lorenso" <dante@lorenso.com> writes:
> Does it make sense to have an index on data_is_active?

Hard to say.  You weren't very clear about what fraction of the table
rows you expect to have data_is_active = true.  If that's a very small
fraction, then an index might be worthwhile.

However, I'd suggest using a partial index that merges the is_active
test with some other useful behavior.  For example, if this is a
common pattern:

>     SELECT *
>     FROM table
>     WHERE data_lookup_key = 'pear'
>     AND data_is_active IS TRUE;

then what you really want is

CREATE INDEX myindex ON table (data_lookup_key) WHERE data_is_active IS TRUE;

> I bet this is in a FAQ somewhere.  Can you point me in the right
> direction?

See the docs on partial indexes.

            regards, tom lane

В списке pgsql-performance по дате отправления:

Предыдущее
От: "D. Dante Lorenso"
Дата:
Сообщение: Indexing a Boolean or Null column?
Следующее
От: Christopher Kings-Lynne
Дата:
Сообщение: Re: Indexing a Boolean or Null column?