Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 452C6B5DBC8 for ; Tue, 2 Aug 2011 12:16:27 -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 38425-10 for ; Tue, 2 Aug 2011 15:16:16 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mta1.zcs.ext.wpsrv.net (mta1.zcs.ext.wpsrv.net [78.47.55.244]) by mail.postgresql.org (Postfix) with ESMTP id 58869B5DBBF for ; Tue, 2 Aug 2011 12:16:16 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mta1.zcs.ext.wpsrv.net (Postfix) with ESMTP id 2529EA092; Tue, 2 Aug 2011 17:16:15 +0200 (CEST) X-Virus-Scanned: amavisd-new at mta1.zcs.ext.wpsrv.net Received: from mta1.zcs.ext.wpsrv.net ([127.0.0.1]) by localhost (mta1.zcs.ext.wpsrv.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id f2HGmtyONLEX; Tue, 2 Aug 2011 17:16:14 +0200 (CEST) Received: from store1.zcs.ext.wpsrv.net (store1.zcs.ext.wpsrv.net [78.47.55.243]) by mta1.zcs.ext.wpsrv.net (Postfix) with ESMTP id 59E5EA091; Tue, 2 Aug 2011 17:16:14 +0200 (CEST) Date: Tue, 2 Aug 2011 17:16:09 +0200 (CEST) From: Andreas Brandl To: Tom Lane Cc: pgsql-performance@postgresql.org Message-ID: <21733433.41.1312298168802.JavaMail.root@store1.zcs.ext.wpsrv.net> In-Reply-To: <19283.1312296581@sss.pgh.pa.us> Subject: Re: Array access performance MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Mailer: Zimbra 6.0.13_GA_2918 (ZimbraWebClient - FF3.0 (Linux)/6.0.13_GA_2918) 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: 201108/26 X-Sequence-Number: 44473 Hi Tom, > > I'm looking for a hint how array access performs in PostgreSQL in > > respect to performance. Normally I would expect access of a > > 1-dimensional Array at slot i (array[i]) to perform in constant time > > (random access). > > > Is this also true for postgres' arrays? > > Only if the element type is fixed-length (no strings for instance) and > the array does not contain, and never has contained, any nulls. > Otherwise a scan through all the previous elements is required to find > a particular element. We're using bigint elements here and don't have nulls, so this should be fine. > By and large, if you're thinking of using arrays large enough to make > this an interesting question, I would say stop right there and > redesign > your database schema. You're not thinking relationally, and it's gonna > cost ya. In general, I agree. We're having a nice relational database but are facing some perfomance issues. My approach is to build a materialized view which exploits the array feature and heavily relies on constant time access on arrays. Thank you! Regards, Andreas