Обсуждение: C functions quicker than Plpgsql?

Поиск
Список
Период
Сортировка

C functions quicker than Plpgsql?

От
Martin Hart
Дата:
Hi all,

Given a stored procedure that runs entirely within the database (e.g. loop
through a few rows of table A, apply "some function" and create a few rows in
table B) - I am wondering what the performance benefits are of implementing
such a
function in C using the SPI vs plpgsql.

Obviously if "some function" is fairly involved then there may be an
advantage by coding it in C - but if it isn't will the C function
still execute faster?

as an unrealistic simple example...

create function test() returns void as '
declare
 r record;
begin
 for r in select * from table_a where x > 500 loop
  insert into table_b (id) values (a.id);
 end loop;
 return;
end;
' language plpgsql;

now if i write it in C instead, what do i gain performance-wise?

thanks for any light you can shed on this...

Cheers,
Martin


Re: C functions quicker than Plpgsql?

От
Peter Eisentraut
Дата:
Martin Hart writes:

> I am wondering what the performance benefits are of implementing such a
> function in C using the SPI vs plpgsql.

plpgsql is itself implemented in C using SPI.  So you do the math.

--
Peter Eisentraut   peter_e@gmx.net