pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #8495: PLSQL PG Terrible performance by using two-dimensional arrays.
2+ messages / 2 participants
[nested] [flat]
* BUG #8495: PLSQL PG Terrible performance by using two-dimensional arrays.
@ 2013-10-01 08:01 m.manso@upm.es
2013-10-01 15:59 ` Re: BUG #8495: PLSQL PG Terrible performance by using two-dimensional arrays. Pavel Stehule <pavel.stehule@gmail.com>
0 siblings, 1 reply; 2+ messages in thread
From: m.manso@upm.es @ 2013-10-01 08:01 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 8495
Logged by: Miguel A. Manso Callejo
Email address: m.manso@upm.es
PostgreSQL version: 9.1.9
Operating system: Ubuntu 12.04LTS
Description:
I'm trying to random access to a 2-dimensional array of double precision
numbers. When range of the array increase, the performance decrease
quickly.
A simple function as:
CREATE OR REPLACE FUNCTION fill_2d_array( rows integer, cols integer)
RETURNS integer AS
$BODY$
DECLARE
img double precision[][];
i integer; j integer;
cont integer;
BEGIN
img := ARRAY( SELECT 0 FROM generate_series(1, rows * cols) ) ;
cont:= 0;
For i IN 1..rows LOOP
For j IN 1..cols LOOP
img[i * cols + j] := (i * cols + j)::double precision;
cont := cont + 1;
END LOOP;
END LOOP;
return cont;
END;
$BODY$
LANGUAGE plpgsql;
ALTER FUNCTION fill_2d_array( integer, integer)
OWNER TO postgres;
when call the function with 700 rows & 1200 cols (explain (analyze,buffers)
select fill_2d_array(700,1200); ) the time consumed is about 50minutes.
What is bad? what i'm doing bad?
Thank you very much.
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: BUG #8495: PLSQL PG Terrible performance by using two-dimensional arrays.
2013-10-01 08:01 BUG #8495: PLSQL PG Terrible performance by using two-dimensional arrays. m.manso@upm.es
@ 2013-10-01 15:59 ` Pavel Stehule <pavel.stehule@gmail.com>
0 siblings, 0 replies; 2+ messages in thread
From: Pavel Stehule @ 2013-10-01 15:59 UTC (permalink / raw)
To: m.manso@upm.es; +Cc: pgsql-bugs
Hello
2013/10/1 <m.manso@upm.es>
> The following bug has been logged on the website:
>
> Bug reference: 8495
> Logged by: Miguel A. Manso Callejo
> Email address: m.manso@upm.es
> PostgreSQL version: 9.1.9
> Operating system: Ubuntu 12.04LTS
> Description:
>
> I'm trying to random access to a 2-dimensional array of double precision
> numbers. When range of the array increase, the performance decrease
> quickly.
> A simple function as:
> CREATE OR REPLACE FUNCTION fill_2d_array( rows integer, cols integer)
> RETURNS integer AS
> $BODY$
> DECLARE
> img double precision[][];
> i integer; j integer;
> cont integer;
> BEGIN
> img := ARRAY( SELECT 0 FROM generate_series(1, rows * cols) ) ;
> cont:= 0;
> For i IN 1..rows LOOP
> For j IN 1..cols LOOP
> img[i * cols + j] := (i * cols + j)::double precision;
> cont := cont + 1;
> END LOOP;
> END LOOP;
> return cont;
> END;
> $BODY$
> LANGUAGE plpgsql;
> ALTER FUNCTION fill_2d_array( integer, integer)
> OWNER TO postgres;
>
>
> when call the function with 700 rows & 1200 cols (explain (analyze,buffers)
> select fill_2d_array(700,1200); ) the time consumed is about 50minutes.
>
>
> What is bad? what i'm doing bad?
>
update a large array is terrible slow due fact, so PostgreSQL arrays are
immutable - so any update is same as copy of array.
sometimes is better to generate table and build a array from table, but it
is not possible for two dimensional array without custom C extension :(
if you can, try to use PLPerl instead PL/pgSQL
You cannot do much more - for 1D arrays exists some tricks, but it doesn't
work for 2D arrays. You can write relative simply C extension, and solve
problem there.
Regards
Pavel Stehule
>
>
> Thank you very much.
>
>
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs
>
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2013-10-01 15:59 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-10-01 08:01 BUG #8495: PLSQL PG Terrible performance by using two-dimensional arrays. m.manso@upm.es
2013-10-01 15:59 ` Pavel Stehule <pavel.stehule@gmail.com>
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