Re: [HACKERS] PL/pgSQL and SPI

Поиск
Список
Период
Сортировка
От jwieck@debis.com (Jan Wieck)
Тема Re: [HACKERS] PL/pgSQL and SPI
Дата
Msg-id m105ZK6-000EBQC@orion.SAPserv.Hamburg.dsh.de
обсуждение исходный текст
Ответ на Re: [HACKERS] PL/pgSQL and SPI  (Vadim Mikheev <vadim@krs.ru>)
Список 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@debis.com (Jan Wieck) #

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Vadim Mikheev
Дата:
Сообщение: Re: [HACKERS] PL/pgSQL and SPI
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: [HACKERS] TEMP tables