Re: C trigger significantly slower than PL/pgSQL? - Mailing list pgsql-interfaces

From Ernst-Georg Schmid
Subject Re: C trigger significantly slower than PL/pgSQL?
Date
Msg-id 8306edcc-8458-44b3-485b-0725de3c7743@tuschehund.de
Whole thread Raw
In response to Re: C trigger significantly slower than PL/pgSQL?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: C trigger significantly slower than PL/pgSQL?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-interfaces
 > Yeah, there's your problem.  Each time through the trigger, that query
 > is being parsed, planned, and executed from scratch.  plpgsql knows
 > how to cache the planned statement, so it's doing less work per-call.

Hello again,

thank you for your help.

I have now used SPI_prepare() and SPI_keepplan() to cache the plan in a 
static variable - and now it performs exactly like the PL/pgSQL version. 
Which also probably means that either the Trigger is so trivial that C 
makes no difference, or the observed TPS limit comes from somewhere else.

I have still a follow-up question, though. Since I'm not calling 
SPI_freeplan(), the cached plan lives forever, right? Which is no 
problem, since the trigger does the same statement over and over. But 
does this generate a memory leak? Or is the saved plan tied to the 
session and is deallocated when the session ends?

best regards

Ernst-Georg



pgsql-interfaces by date:

Previous
From: Tom Lane
Date:
Subject: Re: C trigger significantly slower than PL/pgSQL?
Next
From: Tom Lane
Date:
Subject: Re: C trigger significantly slower than PL/pgSQL?