Thread: What language is faster, C or PL/PgSQL?

What language is faster, C or PL/PgSQL?

From
Karel Riverón Escobar
Date:
<font face="Times New Roman">Hi people,<br /><br /> I need to write an algorithm for processing large amounts of data.
Iwant to write a function on PgAdmin 3 to solve my problem. I need to know what language should be used, C or PL/PgSQL?
<br/><br /> Needless to say, what I need is quickly. What language is faster, </font><font face="Times New Roman"><font
face="TimesNew Roman">C or PL/PgSQL</font>? <br /></font><div class="moz-signature"><br /><div style="font: 16px Times
NewRoman;color: black"> Greetings, Karel Riverón<br /> University of Informatics Science <br /><br /><br /></div></div> 

Re: What language is faster, C or PL/PgSQL?

From
Ovnicraft
Date:
On Sat, Feb 2, 2013 at 10:42 AM, Karel River=C3=B3n Escobar <
kescobar@estudiantes.uci.cu> wrote:

>  Hi people,
>
> I need to write an algorithm for processing large amounts of data. I want
> to write a function on PgAdmin 3 to solve my problem. I need to know what
> language should be used, C or PL/PgSQL?
>
> Needless to say, what I need is quickly. What language is faster, C or
> PL/PgSQL?
>

Hello, performance processing data is not 100% related to language, IMO is
more related with algorithm.
You need to check your algorithm and order.

Answering your question i suggest you C could be some ugly but will be
faster, in this point could be good read an opinion from any PG hacker.

Regards,

>
>  Greetings, Karel River=C3=B3n
> University of Informatics Science
>
>
>


--=20
Cristian Salamea
@ovnicraft

Re: What language is faster, C or PL/PgSQL?

From
"Carlo Stonebanks"
Date:
Here is an advantage Plpgsql has:
http://www.postgresql.org/docs/9.1/static/plpgsql-expressions.html

=20

I guess you can offset this by creating your own prepared statements in =
C.
Otherwise, I can=92t think of how C could be slower. I would choose C =
for
functions that don=92t have SQL statements in them =96 e.g. math and =
string
processing.=20

=20

From: pgsql-general-owner@postgresql.org
[mailto:pgsql-general-owner@postgresql.org] On Behalf Of Karel River=F3n
Escobar
Sent: February 2, 2013 10:42 AM
To: pgsql-general@postgresql.org
Subject: [GENERAL] What language is faster, C or PL/PgSQL?

=20

Hi people,

I need to write an algorithm for processing large amounts of data. I =
want to
write a function on PgAdmin 3 to solve my problem. I need to know what
language should be used, C or PL/PgSQL?=20

Needless to say, what I need is quickly. What language is faster, C or
PL/PgSQL?=20

=20

Greetings, Karel River=F3n
University of Informatics Science=20

Re: What language is faster, C or PL/PgSQL?

From
Merlin Moncure
Date:
On Sat, Feb 2, 2013 at 11:36 AM, Carlo Stonebanks
<stonec.register@sympatico.ca> wrote:
> Here is an advantage Plpgsql has:
> http://www.postgresql.org/docs/9.1/static/plpgsql-expressions.html
>
> I guess you can offset this by creating your own prepared statements in C=
.
> Otherwise, I can=92t think of how C could be slower. I would choose C for
> functions that don=92t have SQL statements in them =96 e.g. math and stri=
ng
> processing.

For cases involving data processing (SPI calls), C can be slower
because pl/pgsql has a lot of optimizations in it that can be very
easy to miss.  I don't suggest writing backend C functions at all
unless you are trying to interface with a C library to access
functionality currently not exposed in SQL.

merlin

Re: What language is faster, C or PL/PgSQL?

From
Bruce Momjian
Date:
On Mon, Feb  4, 2013 at 08:33:02AM -0600, Merlin Moncure wrote:
> On Sat, Feb 2, 2013 at 11:36 AM, Carlo Stonebanks
> <stonec.register@sympatico.ca> wrote:
> > Here is an advantage Plpgsql has:
> > http://www.postgresql.org/docs/9.1/static/plpgsql-expressions.html
> >
> > I guess you can offset this by creating your own prepared statements in C.
> > Otherwise, I can’t think of how C could be slower. I would choose C for
> > functions that don’t have SQL statements in them – e.g. math and string
> > processing.
>
> For cases involving data processing (SPI calls), C can be slower
> because pl/pgsql has a lot of optimizations in it that can be very
> easy to miss.  I don't suggest writing backend C functions at all
> unless you are trying to interface with a C library to access
> functionality currently not exposed in SQL.

How is PL/pgSQL faster than C?  I thought we had optimized PL/pgSQL to
save parsed functions, but I don't see how that would help with queries,
which use SPI.  Am I missing something?

--
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + It's impossible for everything to be true. +

Re: What language is faster, C or PL/PgSQL?

From
"Carlo Stonebanks"
Date:
If a C function was a call to multiple (unprepared) SQL statements, =
could PL/PGSQL's prepare-once plan caching have an advantage?


-----Original Message-----
From: pgsql-general-owner@postgresql.org =
[mailto:pgsql-general-owner@postgresql.org] On Behalf Of Bruce Momjian
Sent: February 5, 2013 12:06 AM
To: Merlin Moncure
Cc: Carlo Stonebanks; kescobar@estudiantes.uci.cu; =
pgsql-general@postgresql.org
Subject: Re: [GENERAL] What language is faster, C or PL/PgSQL?

On Mon, Feb  4, 2013 at 08:33:02AM -0600, Merlin Moncure wrote:
> On Sat, Feb 2, 2013 at 11:36 AM, Carlo Stonebanks=20
> <stonec.register@sympatico.ca> wrote:
> > Here is an advantage Plpgsql has:
> > http://www.postgresql.org/docs/9.1/static/plpgsql-expressions.html
> >
> > I guess you can offset this by creating your own prepared statements =
in C.
> > Otherwise, I can t think of how C could be slower. I would choose C=20
> > for functions that don t have SQL statements in them   e.g. math and =

> > string processing.
>=20
> For cases involving data processing (SPI calls), C can be slower=20
> because pl/pgsql has a lot of optimizations in it that can be very=20
> easy to miss.  I don't suggest writing backend C functions at all=20
> unless you are trying to interface with a C library to access=20
> functionality currently not exposed in SQL.

How is PL/pgSQL faster than C?  I thought we had optimized PL/pgSQL to =
save parsed functions, but I don't see how that would help with queries, =
which use SPI.  Am I missing something?

--=20
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

  + It's impossible for everything to be true. +


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To =
make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Re: What language is faster, C or PL/PgSQL?

From
Pavel Stehule
Date:
2013/2/5 Bruce Momjian <bruce@momjian.us>:
> On Mon, Feb  4, 2013 at 08:33:02AM -0600, Merlin Moncure wrote:
>> On Sat, Feb 2, 2013 at 11:36 AM, Carlo Stonebanks
>> <stonec.register@sympatico.ca> wrote:
>> > Here is an advantage Plpgsql has:
>> > http://www.postgresql.org/docs/9.1/static/plpgsql-expressions.html
>> >
>> > I guess you can offset this by creating your own prepared statements i=
n C.
>> > Otherwise, I can=E2=80=99t think of how C could be slower. I would cho=
ose C for
>> > functions that don=E2=80=99t have SQL statements in them =E2=80=93 e.g=
. math and string
>> > processing.
>>
>> For cases involving data processing (SPI calls), C can be slower
>> because pl/pgsql has a lot of optimizations in it that can be very
>> easy to miss.  I don't suggest writing backend C functions at all
>> unless you are trying to interface with a C library to access
>> functionality currently not exposed in SQL.
>
> How is PL/pgSQL faster than C?  I thought we had optimized PL/pgSQL to
> save parsed functions, but I don't see how that would help with queries,
> which use SPI.  Am I missing something?

PL/pgSQL can be faster than badly written C functions if there are
bottle neck is in server side routines. Any well written C code will
be faster then well written PL/pgSQL - how much depends on specific
use case. If bottle neck is in IO op, then not too much - PL/pgSQL has
not any specific optimization, that cannot be used in C.

Regards

Pavel

>
> --
>   Bruce Momjian  <bruce@momjian.us>        http://momjian.us
>   EnterpriseDB                             http://enterprisedb.com
>
>   + It's impossible for everything to be true. +
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general