From: | Matheus de Oliveira <matioli(dot)matheus(at)gmail(dot)com> |
---|---|
To: | Heikki Linnakangas <hlinnakangas(at)vmware(dot)com> |
Cc: | pgsql-performance <pgsql-performance(at)postgresql(dot)org>, Charles Gomes <charlesrg(at)outlook(dot)com> |
Subject: | Re: Partition insert trigger using C language |
Date: | 2013-01-11 11:55:07 |
Message-ID: | CAJghg4LWV5qp1nNtiaj_7jgXtEZ2vAdUgcnMwtPmSVaYg-d6hQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
On Fri, Jan 11, 2013 at 9:02 AM, Heikki Linnakangas <hlinnakangas(at)vmware(dot)com
> wrote:
> On 11.01.2013 12:36, Matheus de Oliveira wrote:
>
>> On Fri, Jan 11, 2013 at 8:19 AM, Heikki Linnakangas<hlinnakangas(at)**
>> vmware.com <hlinnakangas(at)vmware(dot)com>
>>
>>> wrote:
>>>
>>
>> One thing that caught my eye:
>>>
>>> CREATE OR REPLACE FUNCTION partition_insert_trigger_spi()
>>>
>>>> RETURNS trigger
>>>> LANGUAGE C
>>>> VOLATILE STRICT
>>>> AS 'partition_insert_trigger_spi'****,'partition_insert_trigger_***
>>>> *spi'
>>>> SET DateStyle TO 'ISO';
>>>>
>>>
>>> Calling a function with SET options has a fair amount of overhead, to
>>> set/restore the GUC on every invocation. That should be avoided in a
>>> performance critical function like this.
>>>
>>
>> I (stupidly) used SPI_getvalue [1] and expected it to always return as
>> YYYY-MM-DD, but them I remembered it would do that only with
>> DateStyle=ISO.
>>
>> But the truth is that I couldn't see any overhead, because the function
>> was
>> without that on my first tests, and after that I saw no difference on the
>> tests.
>>
>
> Oh, ok then. I would've expected it to make a measurable difference.
>
>
> I think I should use SPI_getbinvalue instead, but I don't know how
>> to parse the result to get year and month, any help on that?
>>
>
> The fastest way is probably to use j2date like date_out does:
>
> DateADT date = DatumGetDateADT(x)
> int year, month, mday;
>
> if (DATE_NOT_FINITE(date))
> elog(ERROR, "date must be finite");
> j2date(date + POSTGRES_EPOCH_JDATE, &year, &month, &mday);
>
> - Heikki
>
Nice. With the modifications you suggested I did saw a good improvement on
the function using SPI (and a little one with heap_insert). So I was wrong
to think that change the GUC would not make to much difference, the SPI
code now runs almost as fast as the heap_insert:
heap_insert: 31896.098 ms
SPI: 36558.564
Of course I still could make some improvements on it, like using a LRU to
keep the plans, or something like that.
The new code is at github.
Regards,
--
Matheus de Oliveira
Analista de Banco de Dados
Dextra Sistemas - MPS.Br nível F!
www.dextra.com.br/postgres
From | Date | Subject | |
---|---|---|---|
Next Message | Jeff Janes | 2013-01-11 17:12:16 | Re: Slow query after upgrade from 9.0 to 9.2 |
Previous Message | Heikki Linnakangas | 2013-01-11 11:02:29 | Re: Partition insert trigger using C language |