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-28 12:31:10
Message-ID: m105qbG-000EBQC@orion.SAPserv.Hamburg.dsh.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Vadim wrote:
>
> Jan Wieck wrote:
> >
> > 1. I've just committed some changes to PL/pgSQL and the SPI
> > manager.
> >
> > It's a speedup of PL/pgSQL execution by calling
> > ExecEvalExpr() in the executor directly for simple
> > expressions that return one single Datum.
>
> BTW, Jan, did you consider ability to add new function
> for fast expression evaluation to SPI itself and than just
> use this func in PL/pgSQL?
> This function seems to be generally usefull.
> And we could avoid SPI_push/SPI_pop...

Clarification:

I'm doing many tests on the SPI generated plan to ensure
that it is so simple that ExecEvalExpr() cannot stumble
over it. In detail it must be something that has only one
targetentry, absolutely no qual, lefttree, righttree or
something else. And all the nodes in the TLE expression
must only be Expr (OP, FUNC, OR, AND, NOT only), Const or
Param ones.

This is required, because I have to fake an ExprContext
that contains the values for the parameters only. The
above ensures, that ExecEvalExpr() will never touch
anything else than the ecxt_param_list_info and thus will
not notice that it is a faked one.

Well, but you're right, I could add some smartness to SPI.
First, it could do the same checks on the generated plan that
ensure it really returns 1 (and only ever 1) Datum based only
on function calls, constants or parameters. If this is the
case, it could internally call ExecEvalExpr() and build a
faked heap tuple on SPI_execp(). Someone using SPI_exec()
isn't interested in speed, so I would leave it out there.

And two new functions

bool SPI_is_simple_expr(void *plan);
Datum SPI_eval_simple_expr(void *plan,
Datum *values,
char *Nulls,
bool *isNull,
Oid *rettype);

could gain more direct access to such expressions suppressing
the need to diddle with the SPI tuple table for getting just
one Datum.

Yes, I think it would be a good enhancement. I'll go for it.

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

Browse pgsql-hackers by date

  From Date Subject
Next Message The Hermit Hacker 1999-01-28 12:39:16 Re: [HACKERS] Death!
Previous Message Jan Wieck 1999-01-28 12:01:17 PL/pgSQL mixed case support