Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id 52112B5DC00 for ; Tue, 2 Aug 2011 11:49:50 -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 81533-07 for ; Tue, 2 Aug 2011 14:49:44 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id 21791B5DBD1 for ; Tue, 2 Aug 2011 11:49:44 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id p72EnfO3019284; Tue, 2 Aug 2011 10:49:41 -0400 (EDT) To: Andreas Brandl cc: pgsql-performance@postgresql.org Subject: Re: Array access performance In-reply-to: <6332413.23.1312290008254.JavaMail.root@store1.zcs.ext.wpsrv.net> References: <6332413.23.1312290008254.JavaMail.root@store1.zcs.ext.wpsrv.net> Comments: In-reply-to Andreas Brandl message dated "Tue, 02 Aug 2011 15:00:08 +0200" Date: Tue, 02 Aug 2011 10:49:41 -0400 Message-ID: <19283.1312296581@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.706 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.806 X-Spam-Level: X-Archive-Number: 201108/25 X-Sequence-Number: 44472 Andreas Brandl writes: > 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. 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. regards, tom lane