C functions quicker than Plpgsql? - Mailing list pgsql-general

From Martin Hart
Subject C functions quicker than Plpgsql?
Date
Msg-id 200311032000.48121.martin@zsdfherg.com
Whole thread Raw
Responses Re: C functions quicker than Plpgsql?  (Peter Eisentraut <peter_e@gmx.net>)
List pgsql-general
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


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: question
Next
From: "scott.marlowe"
Date:
Subject: Re: Constraint Problem