| From: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
|---|---|
| To: | Josh Berkus <josh(at)agliodbs(dot)com> |
| Cc: | Karl Denninger <karl(at)denninger(dot)net>, pgsql-performance(at)postgresql(dot)org |
| Subject: | Re: Planner question - "bit" data types |
| Date: | 2009-09-05 20:09:07 |
| Message-ID: | b42b73150909051309h79a25985id2253a1f393a1dd7@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-performance |
On Fri, Sep 4, 2009 at 6:29 PM, Josh Berkus<josh(at)agliodbs(dot)com> wrote:
> Karl,
>
>> For reference, I was having SEVERE performance problems with the
>> following comparison in an SQL statement where "mask" was an integer:
>>
>> "select ... from .... where ...... and (permission & mask = permission)"
>
> AFAIK, the only way to use an index on these queries is through
> expression indexes. That's why a lot of folks use INTARRAY instead; it
> comes with a GIN index type.
>
> It would probably be possible to create a new index type using GiST or
> GIN which indexed bitstrings automatically, but I don't know that anyone
> has done it yet.
>
> Changing your integer to a bitstring will not, to my knowledge, improve
> this.
agreed. also, gist/gin is no free lunch, maintaining these type of
indexes is fairly expensive.
If you are only interested in one or a very small number of cases of
'permission', you can use an expression index to target constant
values:
"select ... from .... where ...... and (permission & mask = permission)"
create index foo_permission_xyz_idx on foo((64 & mask = 64));
select * from foo where 64 & mask = 64; --indexed!
this optimizes a _particular_ case of permission into a boolean based
index. this can be a big win if the # of matching cases is very small
or you want to use this in a multi-column index.
merlin
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2009-09-05 20:59:27 | Re: Planner question - "bit" data types |
| Previous Message | Josh Berkus | 2009-09-04 22:29:59 | Re: Planner question - "bit" data types |