Обсуждение: Bitmasks

Поиск
Список
Период
Сортировка

Bitmasks

От
Ivan Voras
Дата:
Can indexes be used for bit-filtering queries? For example:

create table tt (
   flags integer not null default 0,
   str   varchar
);

select * from tt where (flags & 16) != 0;

I suspected radix trees could be used for this but it seems it doesn't
work that way.

If not, is there a way of quickly filtering by such "elements of a set"
that doesn't involve creating 32 boolean fields (which would also need
to be pretty uselessly indexed separately)?

Would strings and regular expressions work?

Re: Bitmasks

От
Greg Stark
Дата:
Ivan Voras <ivoras@fer.hr> writes:

> select * from tt where (flags & 16) != 0;
>
> I suspected radix trees could be used for this but it seems it doesn't work
> that way.

You would need a gist index method to make this work. I actually worked on one
for a while and had it working. But it wasn't really finished. If there's
interest I could finish it up and put it up somewhere like pgfoundry.

> If not, is there a way of quickly filtering by such "elements of a set" that
> doesn't involve creating 32 boolean fields (which would also need to be pretty
> uselessly indexed separately)?

You could create 32 partial indexes on some other column which wouldn't really
take much more space than a single index on that other column. But that won't
let you combine them effectively as a gist index would.

--
greg