mirror of
https://github.com/postgres/postgres.git
synced 2025-07-02 09:02:37 +03:00
First phase of plan-invalidation project: create a plan cache management
module and teach PREPARE and protocol-level prepared statements to use it. In service of this, rearrange utility-statement processing so that parse analysis does not assume table schemas can't change before execution for utility statements (necessary because we don't attempt to re-acquire locks for utility statements when reusing a stored plan). This requires some refactoring of the ProcessUtility API, but it ends up cleaner anyway, for instance we can get rid of the QueryContext global. Still to do: fix up SPI and related code to use the plan cache; I'm tempted to try to make SQL functions use it too. Also, there are at least some aspects of system state that we want to ensure remain the same during a replan as in the original processing; search_path certainly ought to behave that way for instance, and perhaps there are others.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteDefine.c,v 1.117 2007/02/01 19:10:27 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteDefine.c,v 1.118 2007/03/13 00:33:42 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -20,6 +20,7 @@
|
||||
#include "catalog/pg_rewrite.h"
|
||||
#include "miscadmin.h"
|
||||
#include "optimizer/clauses.h"
|
||||
#include "parser/analyze.h"
|
||||
#include "parser/parse_expr.h"
|
||||
#include "rewrite/rewriteDefine.h"
|
||||
#include "rewrite/rewriteManip.h"
|
||||
@ -177,15 +178,46 @@ InsertRule(char *rulname,
|
||||
return rewriteObjectId;
|
||||
}
|
||||
|
||||
/*
|
||||
* DefineRule
|
||||
* Execute a CREATE RULE command.
|
||||
*/
|
||||
void
|
||||
DefineQueryRewrite(RuleStmt *stmt)
|
||||
DefineRule(RuleStmt *stmt, const char *queryString)
|
||||
{
|
||||
List *actions;
|
||||
Node *whereClause;
|
||||
|
||||
/* Parse analysis ... */
|
||||
analyzeRuleStmt(stmt, queryString, &actions, &whereClause);
|
||||
|
||||
/* ... and execution */
|
||||
DefineQueryRewrite(stmt->rulename,
|
||||
stmt->relation,
|
||||
whereClause,
|
||||
stmt->event,
|
||||
stmt->instead,
|
||||
stmt->replace,
|
||||
actions);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* DefineQueryRewrite
|
||||
* Create a rule
|
||||
*
|
||||
* This is essentially the same as DefineRule() except that the rule's
|
||||
* action and qual have already been passed through parse analysis.
|
||||
*/
|
||||
void
|
||||
DefineQueryRewrite(char *rulename,
|
||||
RangeVar *event_obj,
|
||||
Node *event_qual,
|
||||
CmdType event_type,
|
||||
bool is_instead,
|
||||
bool replace,
|
||||
List *action)
|
||||
{
|
||||
RangeVar *event_obj = stmt->relation;
|
||||
Node *event_qual = stmt->whereClause;
|
||||
CmdType event_type = stmt->event;
|
||||
bool is_instead = stmt->instead;
|
||||
bool replace = stmt->replace;
|
||||
List *action = stmt->actions;
|
||||
Relation event_relation;
|
||||
Oid ev_relid;
|
||||
Oid ruleId;
|
||||
@ -304,7 +336,7 @@ DefineQueryRewrite(RuleStmt *stmt)
|
||||
/*
|
||||
* ... and finally the rule must be named _RETURN.
|
||||
*/
|
||||
if (strcmp(stmt->rulename, ViewSelectRuleName) != 0)
|
||||
if (strcmp(rulename, ViewSelectRuleName) != 0)
|
||||
{
|
||||
/*
|
||||
* In versions before 7.3, the expected name was _RETviewname. For
|
||||
@ -315,14 +347,14 @@ DefineQueryRewrite(RuleStmt *stmt)
|
||||
* worry about where a multibyte character might have gotten
|
||||
* truncated.
|
||||
*/
|
||||
if (strncmp(stmt->rulename, "_RET", 4) != 0 ||
|
||||
strncmp(stmt->rulename + 4, event_obj->relname,
|
||||
if (strncmp(rulename, "_RET", 4) != 0 ||
|
||||
strncmp(rulename + 4, event_obj->relname,
|
||||
NAMEDATALEN - 4 - 4) != 0)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
|
||||
errmsg("view rule for \"%s\" must be named \"%s\"",
|
||||
event_obj->relname, ViewSelectRuleName)));
|
||||
stmt->rulename = pstrdup(ViewSelectRuleName);
|
||||
rulename = pstrdup(ViewSelectRuleName);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -411,7 +443,7 @@ DefineQueryRewrite(RuleStmt *stmt)
|
||||
/* discard rule if it's null action and not INSTEAD; it's a no-op */
|
||||
if (action != NIL || is_instead)
|
||||
{
|
||||
ruleId = InsertRule(stmt->rulename,
|
||||
ruleId = InsertRule(rulename,
|
||||
event_type,
|
||||
ev_relid,
|
||||
event_attno,
|
||||
|
Reference in New Issue
Block a user