X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 144B032A446 for ; Fri, 8 Oct 2004 13:29:05 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 00267-03 for ; Fri, 8 Oct 2004 12:28:56 +0000 (GMT) Received: from main.gmane.org (main.gmane.org [80.91.229.2]) by svr1.postgresql.org (Postfix) with ESMTP id AB5CF32A46B for ; Fri, 8 Oct 2004 13:28:58 +0100 (BST) Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 1CFtrk-0002Yw-00 for ; Fri, 08 Oct 2004 14:28:56 +0200 Received: from srv.protecting.net ([212.126.218.242]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 08 Oct 2004 14:28:56 +0200 Received: from hf0722x by srv.protecting.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 08 Oct 2004 14:28:56 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-performance@postgresql.org From: Harald Fuchs Subject: Re: integer[] indexing. Date: 08 Oct 2004 14:28:52 +0200 Organization: Linux Private Site Lines: 24 Message-ID: References: <758d5e7f041008021163fb40eb@mail.gmail.com> Reply-To: hf0722x@protecting.net Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: srv.protecting.net User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/99 X-Sequence-Number: 8575 In article , =?iso-8859-15?Q?Pierre-Fr=E9d=E9ric_Caillaud?= writes: > disclaimer : brainless proposition > (SELECT * FROM table WHERE (icount(ids) <= 1 AND ids[1] = 33) > UNION ALL > (SELECT * FROM table WHERE (icount(ids) > 1 AND ids && '{33}')); I guess my proposition is even more brainless :-) If 95% of all records have only one value, how about putting the first (and most often only) value into a separate column with a btree index on it? Something like that: CREATE TABLE tbl ( -- other columns id1 INT NOT NULL, idN INT[] NULL ); CREATE INDEX tbl_id1_ix ON tbl (id1); If id1 is selective enough, you probably don't need another index on idn.