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

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Merlin Moncure <mmoncure(at)gmail(dot)com>, Carlo Stonebanks <stonec(dot)register(at)sympatico(dot)ca>, kescobar(at)estudiantes(dot)uci(dot)cu, pgsql-general(at)postgresql(dot)org
Subject: Re: What language is faster, C or PL/PgSQL?
Date: 2013-02-05 06:56:05
Message-ID: CAFj8pRCcOi2bV8cjYrApB6+akevQ2YPbPi2UkDJZ6a8Cju+MKw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2013/2/5 Bruce Momjian <bruce(at)momjian(dot)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(dot)register(at)sympatico(dot)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?

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(at)momjian(dot)us> http://momjian.us
> EnterpriseDB http://enterprisedb.com
>
> + It's impossible for everything to be true. +
>
>
> --
> Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general

In response to

Browse pgsql-general by date

  From Date Subject
Next Message nvardar 2013-02-05 07:09:40 BUG #7850: left outer join is not working or I didn't contruct the query properly
Previous Message Carlo Stonebanks 2013-02-05 05:51:35 Re: What language is faster, C or PL/PgSQL?