Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 5D6D8632D2A for ; Tue, 13 Jul 2010 20:20:22 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 32157-04 for ; Tue, 13 Jul 2010 23:20:13 +0000 (UTC) Received: from mx1.hub.org (mx1.hub.org [200.46.208.106]) by mail.postgresql.org (Postfix) with ESMTP id 544BE632D3F for ; Tue, 13 Jul 2010 20:20:15 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from marajade.localdomain (vcs5.camavision.com [63.228.164.252]) by mx1.hub.org (Postfix) with ESMTP id 919E132682E7 for ; Tue, 13 Jul 2010 23:20:13 +0000 (UTC) Received: from [192.168.1.103] (173-20-246-8.client.mchsi.com [173.20.246.8]) (Authenticated sender: andy) by marajade.localdomain (Postfix) with ESMTPA id 018C240B77; Tue, 13 Jul 2010 18:19:21 -0500 (CDT) Message-ID: <4C3CF478.1060602@squeakycode.net> Date: Tue, 13 Jul 2010 18:19:20 -0500 From: Andy Colson User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.4) Gecko/20100608 Lightning/1.0b2 Thunderbird/3.1 MIME-Version: 1.0 To: Elias Ghanem , pgsql-performance@postgresql.org Subject: Re: Queries with conditions using bitand operator References: <4C3C5279.5090108@acteos.com> In-Reply-To: <4C3C5279.5090108@acteos.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.8 tagged_above=-10 required=5 tests=BAYES_50=0.8, RCVD_IN_DNSWL_NONE=-0.0001 X-Spam-Level: X-Archive-Number: 201007/209 X-Sequence-Number: 39598 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