Skip site navigation (1) Skip section navigation (2)

Re: PostgreSQL Function Language Performance: C vsPL/PGSQL

From: Stephen Frost <sfrost(at)snowman(dot)net>
To: Eliot Gable <egable+pgsql-performance(at)gmail(dot)com>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: PostgreSQL Function Language Performance: C vsPL/PGSQL
Date: 2010-05-26 16:32:51
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-performance
* Eliot Gable (egable+pgsql-performance(at)gmail(dot)com) wrote:
> Thanks for the quick follow-up. So, you are saying that if I can do SPI in
> _PG_init, then I could prepare all my queries there and they would be
> prepared once for the entire function when it is loaded? That would
> certainly achieve what I want. Does anybody know whether I can do SPI in
> _PG_init?

Unless you're using EXECUTE in your pl/pgsql, the queries in your
pl/pgsql function are already getting prepared on the first call of the
function for a given backend connection..  If you're using EXECUTE in
pl/gpsql then your problem might be planning time.  Moving that to C
isn't going to change things as much as you might hope if you still have
to plan the query every time you call it..

> The function gets called a lot, but not in the same transaction. It is only
> called once per transaction.

That's not really relevant..  Is it called alot from the same
backend/database connection?  If so, and if you're using regular SELECT
statements and the like (not EXECUTE), then they're getting prepared the
first time they're used and that is kept across transactions.



In response to


pgsql-performance by date

Next:From: Eliot GableDate: 2010-05-26 16:41:23
Subject: Re: PostgreSQL Function Language Performance: C vs PL/PGSQL
Previous:From: David JarvisDate: 2010-05-26 16:30:19
Subject: Re: Random Page Cost and Planner

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group