From: Merlin Moncure <mmoncure@gmail.com>
To: Eliot Gable <egable+pgsql-performance@gmail.com>
Cc: Stephen Frost <sfrost@snowman.net>
Cc: pgsql-performance@postgresql.org
Subject: Re: PostgreSQL Function Language Performance: C vs PL/PGSQL
Date: Fri, 28 May 2010 08:22:22 -0400
Message-ID: <AANLkTimClqP0JhBtIOHOcZLBn0O7sK-dEPk7Az8QmLMx@mail.gmail.com> (raw)
In-Reply-To: <AANLkTinskJ9en0Mstxp96ZNYywRkucuM0Hn74IN1Lh_H@mail.gmail.com>
References: <AANLkTinPXHz0GMP6J6eWksip54AiCImJVNO4Yf4vzFm4@mail.gmail.com>
<20100526161839.GA21875@tamriel.snowman.net>
<AANLkTilqE1ODTmCtAqY6oUDnSYruapc6UdO0_ROf1-li@mail.gmail.com>
<20100526163251.GB21875@tamriel.snowman.net>
<AANLkTinskJ9en0Mstxp96ZNYywRkucuM0Hn74IN1Lh_H@mail.gmail.com>
On Wed, May 26, 2010 at 12:41 PM, Eliot Gable
<egable+pgsql-performance@gmail.com> wrote:
> Ah, that clears things up. Yes, the connections are more or less persistent.
> I have a connection manager which doles connections out to the worker
> threads and reclaims them when the workers are done with them. It
> dynamically adds new connections based on load. Each worker obtains a
> connection from the connection manager, performs a transaction which
> involves executing the function and pulling back the results from the
> cursors, then releases the connection back to the connection manager for
> other workers to use. So, this means that even when written in C, the SQL
> queries will be planned and cached on each connection after the first
> execution. So, I guess the question just becomes whether using SPI in C has
> any extra overhead verses using PL/PGSQL which might make it slower for
> performing queries. Since PostgreSQL is written in C, I assume there is no
> such additional overhead. I assume that the PL/PGSQL implementation at its
> heart also uses SPI to perform those executions. Is that a fair statement?
At best, if you are a ninja with the marginally documented backend
api, you will create code that goes about as fast as your pl/pgsql
function for 10 times the amount of input work, unless there are heavy
amounts of 'other than sql' code in your function. The reason to
write C in the backend is:
*) Interface w/3rd party libraries w/C linkage
*) Do things that are illegal in regular SQL (write files, etc)
*) Make custom types
Things like that. If your pl/pgsql function is running slow, it's
probably better to look at what's going on there.
merlin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-performance@postgresql.org
Cc: mmoncure@gmail.com, egable+pgsql-performance@gmail.com, sfrost@snowman.net
Subject: Re: PostgreSQL Function Language Performance: C vs PL/PGSQL
In-Reply-To: <AANLkTimClqP0JhBtIOHOcZLBn0O7sK-dEPk7Az8QmLMx@mail.gmail.com>
References: <AANLkTinPXHz0GMP6J6eWksip54AiCImJVNO4Yf4vzFm4@mail.gmail.com> <20100526161839.GA21875@tamriel.snowman.net> <AANLkTilqE1ODTmCtAqY6oUDnSYruapc6UdO0_ROf1-li@mail.gmail.com> <20100526163251.GB21875@tamriel.snowman.net> <AANLkTinskJ9en0Mstxp96ZNYywRkucuM0Hn74IN1Lh_H@mail.gmail.com> <AANLkTimClqP0JhBtIOHOcZLBn0O7sK-dEPk7Az8QmLMx@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox