X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 4B7C09DCCC9 for ; Fri, 24 Mar 2006 08:52:45 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 00621-06 for ; Fri, 24 Mar 2006 08:52:47 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from noel.decibel.org (noel.decibel.org [67.100.216.10]) by postgresql.org (Postfix) with ESMTP id B85219DCB82 for ; Fri, 24 Mar 2006 08:52:42 -0400 (AST) Received: by noel.decibel.org (Postfix, from userid 1001) id 8016A56427; Fri, 24 Mar 2006 06:52:46 -0600 (CST) Received: (hashcash-sendmail, from uid 1001); Fri, 24 Mar 2006 06:52:45 -0600 Date: Fri, 24 Mar 2006 06:52:45 -0600 From: "Jim C. Nasby" To: Ruben Rubio Rey Cc: pgsql-performance@postgresql.org Subject: Re: Array performance Message-ID: <20060324125245.GB90527@pervasive.com> References: <200603170625.k2H6PJ926955@pillette.com> <1143112188.2810.27.camel@theo-laptop.int.coza.net.za> <20060323132448.GB4881@surnet.cl> <4423E90E.2090607@rentalia.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4423E90E.2090607@rentalia.com> X-Operating-System: FreeBSD 6.0-RELEASE-p4 amd64 X-Distributed: Join the Effort! http://www.distributed.net User-Agent: Mutt/1.5.11 X-Hashcash: 1:20:060324:ruben@rentalia.com::YUed2gMHqV0eW7ec:0000000000000000000 0000000000000000000000009kxM X-Hashcash: 1:20:060324:pgsql-performance@postgresql.org::Ch4uy4Pv56TqgoLX:00000 0000000000000000000000002EDa X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.108 required=5 tests=[AWL=0.108] X-Spam-Score: 0.108 X-Spam-Level: X-Archive-Number: 200603/489 X-Sequence-Number: 17926 On Fri, Mar 24, 2006 at 01:41:50PM +0100, Ruben Rubio Rey wrote: > Hi, > > I have a select like > > SELECT (array[20]+array[21]+ ... +array[50]+array[51]) as total > FROM table > WHERE > (array[20]+array[21]+ ... +array[50]+array[51])<5000 http://www.varlena.com/GeneralBits/109.php might provide some useful insights. I also recall seeing something about sum operators for arrays, but I can't recall where. > AND array[20]<>0 > AND array[21]<>0 > ... > AND array[50]<>0 > AND array[51])<>0 Uhm... please don't tell me that you're using 0 in place of NULL... You might be able to greatly simplify that by use of ANY; you'd need to ditch elements 1-19 though: ... WHERE NOT ANY(array) = 0 See http://www.postgresql.org/docs/8.1/interactive/arrays.html -- Jim C. Nasby, Sr. Engineering Consultant jnasby@pervasive.com Pervasive Software http://pervasive.com work: 512-231-6117 vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461