Re: Performance between triggers/functions written in C and PL/PGSQL

From: Josh Berkus <josh(at)agliodbs(dot)com>
To: Ludwig Lim <lud_nowhere_man(at)yahoo(dot)com>, PostgreSQL Mailing List <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Performance between triggers/functions written in C and PL/PGSQL
Date: 2003-01-22 18:57:29
Message-ID: 200301221057.29207.josh@agliodbs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance


Ludwig,

> Has anyone done performance comparison between
> triggers/functions in C vs. PL/PGSQL?

On simple ON UPDATE triggers that update an archive table, but are called many
times per minute, about 20:1 in favor of C triggers. Partly that depends on
whether you load the C function as an external file or compile it into the
database. The latter is, of course, faster by far less flexible.

Partly this is because C is fast, being a lower-level language. Partly this
is because the PL/pgSQL parser is in *desperate* need of an overhaul, as it
was written in a hurry and has since suffered incremental development.

> What are the drawbacks of functions written using
> C?

Writing C is harder. Gotta manage your own memory. Plus a badly written C
function can easily crash Postgres, whereas that's much harder to do with
PL/pgSQL.

Usually I just write the original Trigger in PL/pgSQL, test & debug for data
errors, and then farm it out to a crack C programmer to convert to C.

--
-Josh Berkus
Aglio Database Solutions
San Francisco

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Rod Taylor 2003-01-22 20:02:05 Re: Slow query on OS X box
Previous Message Patrick Hatcher 2003-01-22 18:26:17 Slow query on OS X box