pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Brandl <ml@3.141592654.de>
To: pgsql-performance@postgresql.org
Subject: Array access performance
Date: Tue, 2 Aug 2011 15:00:08 +0200 (CEST)
Message-ID: <6332413.23.1312290008254.JavaMail.root@store1.zcs.ext.wpsrv.net> (raw)
In-Reply-To: <8377146.17.1312289231254.JavaMail.root@store1.zcs.ext.wpsrv.net>

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



view thread (4+ messages)  latest in thread

Message-ID: <6332413.23.1312290008254.JavaMail.root@store1.zcs.ext.wpsrv.net>
Permalink:  ../6332413.23.1312290008254.JavaMail.root@store1.zcs.ext.wpsrv.net/
Also on:    postgresql.org/message-id/6332413.23.1312290008254.JavaMail.root@store1.zcs.ext.wpsrv.net

 · 

reply

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: ml@3.141592654.de
  Subject: Re: Array access performance
  In-Reply-To: <6332413.23.1312290008254.JavaMail.root@store1.zcs.ext.wpsrv.net>

* 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