Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 43B08B5DC03 for ; Wed, 22 Jun 2011 18:34:54 -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 48609-04 for ; Wed, 22 Jun 2011 21:34:48 +0000 (UTC) X-Greylist: delayed 00:06:55.552617 by SQLgrey-1.7.6 Received: from mail-wy0-f174.google.com (mail-wy0-f174.google.com [74.125.82.174]) by mail.postgresql.org (Postfix) with ESMTP id F3CC0B5DC00 for ; Wed, 22 Jun 2011 18:34:47 -0300 (ADT) Received: by wyb38 with SMTP id 38so871630wyb.19 for ; Wed, 22 Jun 2011 14:34:47 -0700 (PDT) Received: by 10.216.145.210 with SMTP id p60mr954345wej.89.1308778071294; Wed, 22 Jun 2011 14:27:51 -0700 (PDT) Received: from mptpmbp.local (44-229.76-83.cust.bluewin.ch [83.76.229.44]) by mx.google.com with ESMTPS id b50sm532151wed.46.2011.06.22.14.27.49 (version=SSLv3 cipher=OTHER); Wed, 22 Jun 2011 14:27:50 -0700 (PDT) Message-ID: <4E025E54.6020402@engene.se> Date: Wed, 22 Jun 2011 23:27:48 +0200 From: Marcus Engene User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.16) Gecko/20101125 Thunderbird/3.0.11 MIME-Version: 1.0 To: pgsql-performance@postgresql.org Subject: bitmask index 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=-1.9 tagged_above=-10 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201106/214 X-Sequence-Number: 44147 Hi list, I use Postgres 9.0.4. I have some tables with bitmask integers. Set bits are the interesting ones. Usually they are sparse. -- Many rows & columns CREATE TABLE a_table ( objectid INTEGER PRIMARY KEY NOT NULL ,misc_bits INTEGER DEFAULT 0 NOT NULL ... ) WITHOUT OIDS; ...and when I use it I... select ... from a_table where 0 <> (misc_bits & (1 << 13)) Now the dear tables have swollen and these scans aren't as nice anymore. What indexing strategies would you use here? External table?: create table a_table_feature_x ( objectid INTEGER PRIMARY KEY NOT NULL -- fk to a_table.objectid ) WITHOUT OIDS; Internal in the big mama table?: CREATE TABLE a_table ( objectid INTEGER PRIMARY KEY NOT NULL ,misc_bits INTEGER DEFAULT 0 NOT NULL ,feature_x VARCHAR(1) -- 'y' or null ... ) WITHOUT OIDS; CREATE INDEX a_table_x1 ON a_table(feature_x); -- I assume nulls are not here Some other trick? Thanks, Marcus