mirror of
https://github.com/postgres/postgres.git
synced 2025-08-24 09:27:52 +03:00
Add support for invoking parser callback hooks via SPI and in cached plans.
As proof of concept, modify plpgsql to use the hooks. plpgsql is still inserting $n symbols textually, but the "back end" of the parsing process now goes through the ParamRef hook instead of using a fixed parameter-type array, and then execution only fetches actually-referenced parameters, using a hook added to ParamListInfo. Although there's a lot left to be done in plpgsql, this already cures the "if (TG_OP = 'INSERT' and NEW.foo ...)" problem, as illustrated by the changed regression test.
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994-5, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.192 2009/10/12 18:10:41 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/explain.c,v 1.193 2009/11/04 22:26:04 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -107,8 +107,6 @@ ExplainQuery(ExplainStmt *stmt, const char *queryString,
|
||||
ParamListInfo params, DestReceiver *dest)
|
||||
{
|
||||
ExplainState es;
|
||||
Oid *param_types;
|
||||
int num_params;
|
||||
TupOutputState *tstate;
|
||||
List *rewritten;
|
||||
ListCell *lc;
|
||||
@@ -150,9 +148,6 @@ ExplainQuery(ExplainStmt *stmt, const char *queryString,
|
||||
opt->defname)));
|
||||
}
|
||||
|
||||
/* Convert parameter type data to the form parser wants */
|
||||
getParamListTypes(params, ¶m_types, &num_params);
|
||||
|
||||
/*
|
||||
* Run parse analysis and rewrite. Note this also acquires sufficient
|
||||
* locks on the source table(s).
|
||||
@@ -163,8 +158,10 @@ ExplainQuery(ExplainStmt *stmt, const char *queryString,
|
||||
* executed repeatedly. (See also the same hack in DECLARE CURSOR and
|
||||
* PREPARE.) XXX FIXME someday.
|
||||
*/
|
||||
rewritten = pg_analyze_and_rewrite((Node *) copyObject(stmt->query),
|
||||
queryString, param_types, num_params);
|
||||
rewritten = pg_analyze_and_rewrite_params((Node *) copyObject(stmt->query),
|
||||
queryString,
|
||||
(ParserSetupHook) setupParserWithParamList,
|
||||
params);
|
||||
|
||||
/* emit opening boilerplate */
|
||||
ExplainBeginOutput(&es);
|
||||
|
@@ -10,7 +10,7 @@
|
||||
* Copyright (c) 2002-2009, PostgreSQL Global Development Group
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.99 2009/08/10 05:46:50 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.100 2009/11/04 22:26:05 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -379,6 +379,11 @@ EvaluateParams(PreparedStatement *pstmt, List *params,
|
||||
paramLI = (ParamListInfo)
|
||||
palloc(sizeof(ParamListInfoData) +
|
||||
(num_params - 1) *sizeof(ParamExternData));
|
||||
/* we have static list of params, so no hooks needed */
|
||||
paramLI->paramFetch = NULL;
|
||||
paramLI->paramFetchArg = NULL;
|
||||
paramLI->parserSetup = NULL;
|
||||
paramLI->parserSetupArg = NULL;
|
||||
paramLI->numParams = num_params;
|
||||
|
||||
i = 0;
|
||||
|
Reference in New Issue
Block a user