1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-10 17:42:29 +03:00
Hi,

    as  proposed here comes the first patch for the query rewrite
    system.

  <for details, see archive dated Mon, 17 Aug 1998>
This commit is contained in:
Marc G. Fournier
1998-08-18 00:49:04 +00:00
parent fde6526753
commit 338c54cbc1
8 changed files with 942 additions and 40 deletions

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.79 1998/07/20 20:48:51 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.80 1998/08/18 00:48:54 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -742,11 +742,33 @@ static Query *
transformRuleStmt(ParseState *pstate, RuleStmt *stmt)
{
Query *qry;
Query *action;
List *actions;
qry = makeNode(Query);
qry->commandType = CMD_UTILITY;
/*
* 'instead nothing' rules with a qualification need a
* query a rangetable so the rewrite handler can add the
* negated rule qualification to the original query. We
* create a query with the new command type CMD_NOTHING
* here that is treated special by the rewrite system.
*/
if (stmt->actions == NIL) {
Query *nothing_qry = makeNode(Query);
nothing_qry->commandType = CMD_NOTHING;
addRangeTableEntry(pstate, stmt->object->relname, "*CURRENT*",
FALSE, FALSE);
addRangeTableEntry(pstate, stmt->object->relname, "*NEW*",
FALSE, FALSE);
nothing_qry->rtable = pstate->p_rtable;
stmt->actions = lappend(NIL, nothing_qry);
}
actions = stmt->actions;
/*
@@ -768,7 +790,9 @@ transformRuleStmt(ParseState *pstate, RuleStmt *stmt)
pstate->p_is_rule = true; /* for expand all */
pstate->p_hasAggs = false;
lfirst(actions) = transformStmt(pstate, lfirst(actions));
action = (Query *)lfirst(actions);
if (action->commandType != CMD_NOTHING)
lfirst(actions) = transformStmt(pstate, lfirst(actions));
actions = lnext(actions);
}

View File

@@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.22 1998/08/17 16:08:34 thomas Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.23 1998/08/18 00:48:55 scrappy Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
@@ -1955,6 +1955,7 @@ RuleStmt: CREATE RULE name AS
OptStmtList: NOTHING { $$ = NIL; }
| OptimizableStmt { $$ = lcons($1, NIL); }
| '[' OptStmtBlock ']' { $$ = $2; }
| '(' OptStmtBlock ')' { $$ = $2; }
;
OptStmtBlock: OptStmtMulti

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.12 1998/07/08 14:04:11 thomas Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/parse_relation.c,v 1.13 1998/08/18 00:48:57 scrappy Exp $
*
*-------------------------------------------------------------------------
*/
@@ -191,8 +191,13 @@ addRangeTableEntry(ParseState *pstate,
if (pstate != NULL)
{
if (refnameRangeTablePosn(pstate, refname, &sublevels_up) != 0 &&
(!inFromCl || sublevels_up == 0))
(!inFromCl || sublevels_up == 0)) {
if (!strcmp(refname, "*CURRENT*") || !strcmp(refname, "*NEW*")) {
int rt_index = refnameRangeTablePosn(pstate, refname, &sublevels_up);
return (RangeTblEntry *)nth(rt_index - 1, pstate->p_rtable);
}
elog(ERROR, "Table name %s specified more than once", refname);
}
}
rte->relname = pstrdup(relname);