Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id D311CB5DC33 for ; Tue, 2 Aug 2011 10:06:30 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 56524-03 for ; Tue, 2 Aug 2011 13:06:24 +0000 (UTC) X-Greylist: delayed 00:06:13.178762 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 B8431B5DBBF for ; Tue, 2 Aug 2011 10:06:24 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by mta1.zcs.ext.wpsrv.net (Postfix) with ESMTP id 4A8A0A092 for ; Tue, 2 Aug 2011 15:00:10 +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 jheZHCe1Gawe for ; Tue, 2 Aug 2011 15:00:09 +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 350E0A091 for ; Tue, 2 Aug 2011 15:00:09 +0200 (CEST) Date: Tue, 2 Aug 2011 15:00:08 +0200 (CEST) From: Andreas Brandl To: pgsql-performance@postgresql.org Message-ID: <6332413.23.1312290008254.JavaMail.root@store1.zcs.ext.wpsrv.net> In-Reply-To: <8377146.17.1312289231254.JavaMail.root@store1.zcs.ext.wpsrv.net> Subject: 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/20 X-Sequence-Number: 44467 Hi, 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? May concrete example is a 1-dimensional array d of length <= 600 (which will grow at a rate of 1 entry/day) stored in a table's column. I need to access this array two times per tuple, i.e. d[a], d[b]. Therefore I hope access is not linear. Is this correct? Also I'm having some performance issues building this array. I'm doing this with a used-defined aggregate function, starting with an empty array and using array_append and some calculation for each new entry. I assume this involves some copying/memory allocation on each call, but I could not find the implementation of array_append in postgres-source/git. Is there an efficient way to append to an array? I could also start with a pre-initialized array of the required length, but this involves some complexity. Thank you Regards, Andreas