Re: Manipulating complex types as non-contiguous structures in-memory

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andres Freund <andres(at)anarazel(dot)de>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Manipulating complex types as non-contiguous structures in-memory
Date: 2015-05-01 19:16:52
Message-ID: CAFj8pRB-otCuSW4JMMAddwaEk9RnYuKjorjLdLtQM=QwzAs4mA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2015-05-01 20:53 GMT+02:00 Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>:

>
>
> 2015-05-01 20:11 GMT+02:00 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
>
>> Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> writes:
>> > I am looking on this patch, but it cannot be applied now.
>>
>> > lxml2 -lssl -lcrypto -lrt -lcrypt -ldl -lm -o postgres
>> > utils/fmgrtab.o:(.rodata+0x2678): undefined reference to `array_append'
>> > utils/fmgrtab.o:(.rodata+0x2698): undefined reference to `array_prepend'
>>
>> What are you trying to apply it to? I see array_append() in
>> src/backend/utils/adt/array_userfuncs.c in HEAD. Also, are
>> you checking the 1.1 version of the patch?
>>
>
> I tested old version. 1.1. looks well.
>

It is hard to believe how it is fast

I use buble sort for plpgsql benchmarking. Following variant is suboptimal
(but it is perfect for this test)

CREATE OR REPLACE FUNCTION public.buble(a anyarray, OUT r anyarray)
RETURNS anyarray
LANGUAGE plpgsql
AS $function$
DECLARE
aux r%type;
sorted bool := false;
BEGIN
r := a;
WHILE NOT sorted
LOOP
sorted := true;
FOR i IN array_lower(a,1) .. array_upper(a,1) - 1
LOOP
IF r[i] > r[i+1] THEN
sorted := false;
aux[1] := r[i];
r[i] := r[i+1]; r[i+1] := aux[1];
END IF;
END LOOP;
END LOOP;
END;
$function$

CREATE OR REPLACE FUNCTION public.array_generator(integer, anyelement, OUT
r anyarray)
RETURNS anyarray
LANGUAGE plpgsql
AS $function$
BEGIN
r := (SELECT ARRAY(SELECT random()*$2 FROM generate_series(1,$1)));
END;
$function$

Test for 3000 elements:

Original Patch
Integer 55sec 8sec
Numeric 341sec 8sec

Quicksort is about 3x faster -- so a benefit of this patch is clear.

Regards

Pavel

>
> Regards
>
> Pavel
>
>
>>
>> regards, tom lane
>>
>
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2015-05-01 19:59:21 Re: Manipulating complex types as non-contiguous structures in-memory
Previous Message Pavel Stehule 2015-05-01 18:53:05 Re: Manipulating complex types as non-contiguous structures in-memory