From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andreas Brandl <ml@3.141592654.de>
Cc: pgsql-performance@postgresql.org
Subject: Re: Array access performance
Date: Tue, 02 Aug 2011 10:49:41 -0400
Message-ID: <19283.1312296581@sss.pgh.pa.us> (raw)
In-Reply-To: <6332413.23.1312290008254.JavaMail.root@store1.zcs.ext.wpsrv.net>
References: <6332413.23.1312290008254.JavaMail.root@store1.zcs.ext.wpsrv.net>
Andreas Brandl <ml@3.141592654.de> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: tgl@sss.pgh.pa.us, ml@3.141592654.de
Subject: Re: Array access performance
In-Reply-To: <19283.1312296581@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox