Re: Accessing Database Data from C Function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Jeffrey Bigham" <jbigham(at)cs(dot)washington(dot)edu>
Cc: "Michael Fuhr" <mike(at)fuhr(dot)org>, pgsql-general(at)postgresql(dot)org
Subject: Re: Accessing Database Data from C Function
Date: 2006-08-10 04:01:41
Message-ID: 9970.1155182501@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Jeffrey Bigham" <jbigham(at)cs(dot)washington(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Harpreet Dhaliwal 2006-08-10 04:02:24 Re: Connection string
Previous Message Michael Fuhr 2006-08-10 03:42:54 Re: Connection string