Re: [HACKERS] PREPARE

From: jwieck(at)debis(dot)com (Jan Wieck)
To: meskes(at)usa(dot)net (Michael Meskes)
Cc: pgsql-hackers(at)hub(dot)org
Subject: Re: [HACKERS] PREPARE
Date: 1998-11-18 20:02:06
Message-ID: m0zgDnj-000EBTC@orion.SAPserv.Hamburg.dsh.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers pgsql-interfaces

Michael Meskes wrote:

>
> On Wed, Nov 18, 1998 at 03:23:30AM +0000, Thomas G. Lockhart wrote:
> > > I didn't get this one completly. What input do you mean?
> >
> > Just the original string/query to be prepared...
>
> I see. But wouldn't it be more useful to preprocess the query and store the
> resulting nodes instead? We don't want to parse the statement everytime a
> variable binding comes in.

Right. A real improvement would only be to have the prepared
execution plan in the backend and just giving the parameter
values.

I can think of the following construct:

PREPARE optimizable-statement;

That one will run parser/rewrite/planner, create a new memory
context with a unique identifier and saves the querytree's
and plan's in it. Parameter values are identified by the
usual $n notation. The command returns the identifier.

EXECUTE QUERY identifier [value [, ...]];

then get's back the prepared plan and querytree by the id,
creates an executor context with the given values in the
parameter array and calls ExecutorRun() for them.

The PREPARE needs to analyze the resulting parsetrees to get
the datatypes (and maybe atttypmod's) of the parameters, so
EXECUTE QUERY can convert the values into Datum's using the
types input functions. And the EXECUTE has to be handled
special in tcop (it's something between a regular query and
an utility statement). But it's not too hard to implement.

Finally a

FORGET QUERY identifier;

(don't remember how the others named it) will remove the
prepared plan etc. simply by destroying the memory context
and dropping the identifier from the id->mcontext+prepareinfo
mapping.

This all restricts the usage of PREPARE to optimizable
statements. Is it required to be able to prepare utility
statements (like CREATE TABLE or so) too?

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 Thomas G. Lockhart 1998-11-19 03:17:08 Re: [HACKERS] More on 6.4 on DEC Alpha + Digital Unix 4.0d + DEC C compiler
Previous Message Bruce Momjian 1998-11-18 19:56:22 Re: [HACKERS] Bug in 6.4 release

Browse pgsql-interfaces by date

  From Date Subject
Next Message Taral 1998-11-18 20:59:49 IDL update + comments
Previous Message Mark Himsley 1998-11-18 17:22:29 Case problems in table and column names