Skip site navigation (1) Skip section navigation (2)

Re: Queries with conditions using bitand operator

From: Andy Colson <andy(at)squeakycode(dot)net>
To: Elias Ghanem <e(dot)ghanem(at)acteos(dot)com>, pgsql-performance(at)postgresql(dot)org
Subject: Re: Queries with conditions using bitand operator
Date: 2010-07-13 23:19:20
Message-ID: 4C3CF478.1060602@squeakycode.net (view raw or flat)
Thread:
Lists: pgsql-performance
On 07/13/2010 06:48 AM, Elias Ghanem wrote:
> Hi,
> I have table "ARTICLE" containing a String a field "STATUS" that represents a number in binary format (for ex: 10011101).
> My application issues queries with where conditions that uses BITAND operator on this field (for ex: select * from article where status & 4 = 4).
> Thus i'm facing performance problemes with these select queries: the queries are too slow.
> Since i'm using the BITAND operator in my conditions, creating an index on the status filed is useless
> and since the second operator variable (status & 4 = 4; status & 8 = 8; status & 16 = 16...) a functional index is also usless (because a functional index require the use of a function that accept only table column as input parameter: constants are not accepted).
> So is there a way to enhance the performance of these queries?
> Thanks,
> Elias
>

How many flags are there?  If its not too many you could make a separate column for each... but then that would be lots of indexes too...

One other thought I had was to make it a text column, turn the flags into words (space separated) and use full text indexes.

I played around with int's and string's but I couldnt find a way using the & operator.

-Andy

In response to

pgsql-performance by date

Next:From: Andy ColsonDate: 2010-07-13 23:26:09
Subject: Re: performance on new linux box
Previous:From: Magnus HaganderDate: 2010-07-13 14:44:13
Subject: Re: Pooling in Core WAS: Need help in performance tuning.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group