By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,372 Members | 1,950 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,372 IT Pros & Developers. It's quick & easy.

C functions quicker than Plpgsql?

P: n/a

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
---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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 pe*****@gmx.net
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.