Re: Accessing Database Data from C Function - Mailing list pgsql-general

From Tom Lane
Subject Re: Accessing Database Data from C Function
Date
Msg-id 9970.1155182501@sss.pgh.pa.us
Whole thread Raw
In response to Re: Accessing Database Data from C Function  ("Jeffrey Bigham" <jbigham@cs.washington.edu>)
List pgsql-general
"Jeffrey Bigham" <jbigham@cs.washington.edu> writes:
> I also have some vague understanding that C might be faster.  I hope I'm
> not opening a can-of-worms, but is C actually faster?

C should theoretically be faster than any of the alternatives you
mention, all else being equal (eg, you are implementing the identical
algorithm in each language).  Whether the difference is enough to notice
is another question --- for example, if effectively all the runtime is
spent inside SQL queries, shaving a few microseconds off the time it
takes you to issue the queries isn't going to improve your life.
You also have to consider the larger effort you'll need to put into
coding in C ... it's a pretty low-level language by any modern standard.
That effort might more profitably be spent elsewhere, eg improving the
SQL queries themselves.

My advice is don't code in C until it's clear you have to.  If you can
prototype in plpgsql or plperl or pl-your-favorite-language, do that
first and get it working; and then recode in C if the performance is
so bad you can't stand it (and you can prove that the cycles are
actually spent in your PL code and not somewhere else like the SQL
engine).  About the only time I'd not do it that way is if my problem
involves data structures too complex to express nicely in
my-favorite-pl or if I need access to low-level database details that
aren't exposed by my-favorite-pl.

            regards, tom lane

pgsql-general by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: Connection string
Next
From: "Harpreet Dhaliwal"
Date:
Subject: Re: Connection string