Re: Strange plpgsql performance -- arithmetic, numeric() type, arrays - Mailing list pgsql-general

From Tom Lane
Subject Re: Strange plpgsql performance -- arithmetic, numeric() type, arrays
Date
Msg-id 13767.1112576667@sss.pgh.pa.us
Whole thread Raw
In response to Strange plpgsql performance -- arithmetic, numeric() type, arrays  ("Karl O. Pinc" <kop@meme.com>)
Responses Re: Strange plpgsql performance -- arithmetic, numeric()
List pgsql-general
"Karl O. Pinc" <kop@meme.com> writes:
> Incrementing the loop counter by a factor of 10, from 1000 to 10000
> makes the process take more than 100 times longer.  (I only saw
> this happen when I happened upon using a numeric() datatype
> and then dividing i/100 to avoid overflow.  It does not happen
> without the array and working with other, much larger, arrays
> of other data types you see no slowdown.)

It's the array access, not the arithmetic, that's getting you.
Since numeric is not a fixed-width datatype, accessing the N'th
element of the array requires O(N) time to find that element.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Strange plpgsql performance, diff plperl and plpgsql
Next
From: Tom Lane
Date:
Subject: Re: Question about format_type function