Re: pl/* overhead ...

From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: "Marc G(dot) Fournier" <scrappy(at)postgresql(dot)org>
Cc: Michael Fuhr <mike(at)fuhr(dot)org>, pgsql-sql(at)postgresql(dot)org
Subject: Re: pl/* overhead ...
Date: 2005-10-26 14:28:30
Message-ID: 435F928E.1080408@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

PL/pgSQL is as *internal* as for example PL/Tcl. The two are actually
pretty similar and I would expect them to perform similar, if one knows
what and how he does.

PL/pgSQL is an external shared object, loaded on call of the first func
per backend. Same for PL/Tcl.

PL/pgSQL takes pg_proc.prosrc and compiles all control structures (if,
else, loop) into a form of bytecode. Query strings are left alone until
the statements are actually executed. Tcl has a similar concept of
bytecode compilation.

PL/pgSQL turns all expressions and SQL statements into prepared SPI
plans. It short-circuits simple expressions by directly calling the node
execution, so it works with PostgreSQL's native types and operators.
Here is the big difference, PL/Tcl turns all datums into their external
string representations and then does the Tcl dual-ported-object munging
and math. However, if used right it also offers prepared SPI plans.

If the implementation of functionality results in widely similar code, I
would expect PL/pgSQL and PL/Tcl to perform similar. However, doing the
prepared SPI stuff in Tcl is a bit of work. OTOH doing extensive string
processing in PL/pgSQL is a nightmare. That difference should drive the
decision which language to use when.

Jan

On 10/26/2005 5:48 AM, Marc G. Fournier wrote:

> On Wed, 26 Oct 2005, Michael Fuhr wrote:
>
>> On Wed, Oct 26, 2005 at 12:58:13AM -0300, Marc G. Fournier wrote:
>>> Does anyone know of, or have, any comparisions of the overhead going with
>>> something like pl/perl or pl/php vs using pl/pgsql?
>>
>> Benchmark results will probably depend on the type of processing
>> you're doing. I'd expect PL/pgSQL to be faster at database operations
>> like looping through query results, and other languages to be faster
>> at non-database operations like text munging and number crunching,
>> depending on the particular language's strengths.
>>
>> [Does quick test.]
>>
>> Whale oil beef hooked. PL/pgSQL just outran PL/Perl when I expected
>> the latter to win. Hang on, let me play with it until it comes back
>> with the results I want....
>
> 'k, let's repharase the questions :)
>
> Overall, I'd expect pl/pgsql to have less overhead, since its "built into"
> the server ... in the case of something like pl/php or pl/perl, assuming
> that I don't use any external modules, is it just as 'built in', or am I
> effectively calling an external interpreter each time I run that function?
>
> For instance, if there wasn't something like to_char() (thanks for
> pointing that one out), then i could write a simple pl/perl function that
> 'simulated it', but itself did no db queries just a simple:
>
> RETURN sprintf("%04d", intval);
>
> Don't know if that made much more sense ... ?
>
>
> ----
> Marc G. Fournier Hub.Org Networking Services (http://www.hub.org)
> Email: scrappy(at)hub(dot)org Yahoo!: yscrappy ICQ: 7615664
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq

--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#================================================== JanWieck(at)Yahoo(dot)com #

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2005-10-26 14:40:22 Re: RETURNS SETOF primitive returns results in parentheses
Previous Message Mario Splivalo 2005-10-26 13:09:20 Re: RETURNS SETOF primitive returns results in parentheses