Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 3F4AC6321BA for ; Tue, 13 Jul 2010 09:17:10 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 82980-05 for ; Tue, 13 Jul 2010 12:17:01 +0000 (UTC) X-Greylist: delayed 00:29:01.777858 by SQLgrey-1.7.6 Received: from mailrelay7-out.ornis.com (mailrelay7-out.ornis.com [81.93.0.90]) by mail.postgresql.org (Postfix) with ESMTP id 6F77362DBF4 for ; Tue, 13 Jul 2010 09:17:02 -0300 (ADT) Received: from fsecure2.ornis.com ([192.168.162.2]) by mailrelay7-out.ornis.com (8.12.11/8.12.11) with ESMTP id o6DBlvto017893 for ; Tue, 13 Jul 2010 13:47:57 +0200 Received: from unknown (HELO relay-ext.ornis.com) ([192.168.160.6]) by mailgate401.ornis.com with ESMTP; 13 Jul 2010 13:47:57 +0200 Received: from [192.168.0.71] ([80.79.155.178]) by relay-ext.ornis.com (8.12.9/8.12.3) with ESMTP id o6DBlolu031384 for ; Tue, 13 Jul 2010 13:47:56 +0200 Message-ID: <4C3C5279.5090108@acteos.com> Date: Tue, 13 Jul 2010 14:48:09 +0300 From: Elias Ghanem User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.1.9) Gecko/20100317 Thunderbird/3.0.4 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: Queries with conditions using bitand operator 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.001 tagged_above=-10 required=5 tests=BAYES_40=-0.001 X-Spam-Level: X-Archive-Number: 201007/206 X-Sequence-Number: 39595 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