Re: pl/pgsql functions outperforming sql ones?

Поиск
Список
Период
Сортировка
От Robert Haas
Тема Re: pl/pgsql functions outperforming sql ones?
Дата
Msg-id CA+TgmobFfyivRvFDrRFR7dfK=8hwgic_+BWrv4idiMBGDQpyXA@mail.gmail.com
обсуждение исходный текст
Ответ на Re: pl/pgsql functions outperforming sql ones?  ("Carlo Stonebanks" <stonec.register@sympatico.ca>)
Список pgsql-performance
On Sat, Jan 28, 2012 at 11:20 PM, Carlo Stonebanks
<stonec.register@sympatico.ca> wrote:
> Update: The main stored function in question and all of its sub
> sub-functions were recoded to new pure sql functions.
>
> I then stub tested the sub functions sql vs. plpgsql.
>
> Here were the results for new sql vs old plpgsql:
>
> Individual sub functions tested 20-30% faster
>
> But the main function calling new sql sub functions ran 100% slower
>
> So I tried this:
>
> I modified the old plpgsql function to call the new sql sub functions.
>
> THAT ran 20-30% faster then the unmodified version.
>
> That modified function is listed below. All the functions ending in 2 are
> the new SQL versions.

One advantage of PL/pgsql for code like this is that you can compute
values once and save them in variables.  SQL doesn't have variables,
so you can end up repeating the same SQL in multiple places (causing
multiple evaluation), or even if you manage to avoid that, the system
can inline things in multiple places and produce the same effect.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

В списке pgsql-performance по дате отправления:

Предыдущее
От: Ofer Israeli
Дата:
Сообщение: Re: Vacuuming problems on TOAST table
Следующее
От: Merlin Moncure
Дата:
Сообщение: Re: index scan forward vs backward = speed difference of 357X slower!