Re: [HACKERS] PL/pgSQL and SPI

From: jwieck(at)debis(dot)com (Jan Wieck)
To: vadim(at)krs(dot)ru (Vadim Mikheev)
Cc: jwieck(at)debis(dot)com, pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [HACKERS] PL/pgSQL and SPI
Date: 1999-01-27 18:04:18
Message-ID: m105ZK6-000EBQC@orion.SAPserv.Hamburg.dsh.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Vadim wrote:

>
> Jan Wieck wrote:
> > 2. While doing the above I've encountered some bad details
> > of the SPI manager and the executor. The Func and Oper
> > nodes point to a function cache, which is initially NULL
> > and is not copied by copyNode().
> >
> > For every call of SPI_execp() to execute a prepared plan,
> > the whole plan is copied into the current memory context.
> > Since this clears out the fcache, the executor has to do
> > several syscache lookups for every function or operator
> > hit during execution of the plan.
> >
> > Unfortunately I haven't found a way yet to avoid it.
> > Anything I tried so far ended in coredumps or other
> > misbehaviour. Maybe someone else has an idea.
>
> Could we fill most of FunctionCache while parsing query ?!
> We can do this for
>
> int typlen; /* length of the return type */
> int typbyval; /* true if return type is pass by value */
> ...
> Oid foid; /* oid of the function in pg_proc */
> Oid language; /* oid of the language in pg_language */
> int nargs; /* number of arguments */
>
> Oid *argOidVect; /* oids of all the arguments */
> ...
> bool istrusted; /* trusted fn? */
>
> and may be others too.

And then letting copyNode() copy the fcache too so it's
allocated in the same memory context.

Will require a flag in the fcache that is used to tell that
setFcache() must be called to fill in the remaining fields
(there are some things taken from the actual executor state).
This flag is then cleared by copyNode() and the fields in
question left uncopied.

This might also let us get rid of the tree copy in
SPI_execp(), if we form another tree-traversal function that
resets the flag in all Func and Oper nodes of the whole tree,
so the prepared/saved plan can be used directly.

I'll give it a try some time.

Thanks for the kick, Vadim.

Jan

--

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 1999-01-27 18:34:18 Re: [HACKERS] regression test HAVING fixed
Previous Message Bruce Momjian 1999-01-27 17:50:35 Re: [HACKERS] TEMP tables