Re: Array access performance - Mailing list pgsql-performance

From Tom Lane
Subject Re: Array access performance
Date
Msg-id 19283.1312296581@sss.pgh.pa.us
Whole thread Raw
In response to Array access performance  (Andreas Brandl <ml@3.141592654.de>)
Responses Re: Array access performance  (Andreas Brandl <ml@3.141592654.de>)
List pgsql-performance
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
accessof 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

pgsql-performance by date:

Previous
From: Gavin Flower
Date:
Subject: Re: Trigger or Function
Next
From: Andreas Brandl
Date:
Subject: Re: Array access performance