1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

Change expandRTE() and ResolveNew() back to taking just the single

RTE of interest, rather than the whole rangetable list.  This makes
the API more understandable and avoids duplicate RTE lookups.  This
patch reverts no-longer-needed portions of my patch of 2004-08-19.
This commit is contained in:
Tom Lane
2005-06-04 19:19:42 +00:00
parent fb91a83e0e
commit e18e8f8735
11 changed files with 92 additions and 94 deletions

View File

@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.153 2005/06/03 23:05:28 tgl Exp $
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.154 2005/06/04 19:19:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -106,6 +106,8 @@ AcquireRewriteLocks(Query *parsetree)
Relation rel;
LOCKMODE lockmode;
List *newaliasvars;
Index curinputvarno;
RangeTblEntry *curinputrte;
ListCell *ll;
++rt_index;
@@ -140,8 +142,14 @@ AcquireRewriteLocks(Query *parsetree)
* Scan the join's alias var list to see if any columns
* have been dropped, and if so replace those Vars with
* NULL Consts.
*
* Since a join has only two inputs, we can expect to
* see multiple references to the same input RTE; optimize
* away multiple fetches.
*/
newaliasvars = NIL;
curinputvarno = 0;
curinputrte = NULL;
foreach(ll, rte->joinaliasvars)
{
Var *aliasvar = (Var *) lfirst(ll);
@@ -165,12 +173,17 @@ AcquireRewriteLocks(Query *parsetree)
* but it's OK to assume here.)
*/
Assert(aliasvar->varlevelsup == 0);
if (aliasvar->varno >= rt_index)
elog(ERROR, "unexpected varno %d in JOIN RTE %d",
aliasvar->varno, rt_index);
if (get_rte_attribute_is_dropped(
rt_fetch(aliasvar->varno, parsetree->rtable),
aliasvar->varattno))
if (aliasvar->varno != curinputvarno)
{
curinputvarno = aliasvar->varno;
if (curinputvarno >= rt_index)
elog(ERROR, "unexpected varno %d in JOIN RTE %d",
curinputvarno, rt_index);
curinputrte = rt_fetch(curinputvarno,
parsetree->rtable);
}
if (get_rte_attribute_is_dropped(curinputrte,
aliasvar->varattno))
{
/*
* can't use vartype here, since that might be a
@@ -386,7 +399,8 @@ rewriteRuleAction(Query *parsetree,
sub_action = (Query *) ResolveNew((Node *) sub_action,
new_varno,
0,
sub_action->rtable,
rt_fetch(new_varno,
sub_action->rtable),
parsetree->targetList,
event,
current_varno);
@@ -1206,7 +1220,7 @@ CopyAndAddInvertedQual(Query *parsetree,
new_qual = ResolveNew(new_qual,
PRS2_NEW_VARNO,
0,
parsetree->rtable,
rt_fetch(rt_index, parsetree->rtable),
parsetree->targetList,
event,
rt_index);

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteManip.c,v 1.90 2005/03/10 23:21:24 tgl Exp $
* $PostgreSQL: pgsql/src/backend/rewrite/rewriteManip.c,v 1.91 2005/06/04 19:19:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -797,10 +797,9 @@ AddInvertedQual(Query *parsetree, Node *qual)
* If not, we either change the unmatched Var's varno to update_varno
* (when event == CMD_UPDATE) or replace it with a constant NULL.
*
* The caller must also provide target_rtable, the rangetable containing
* the target relation (which must be described by the target_varno'th
* RTE in that list). This is needed to handle whole-row Vars referencing
* the target. We expand such Vars into RowExpr constructs.
* The caller must also provide target_rte, the RTE describing the target
* relation. This is needed to handle whole-row Vars referencing the target.
* We expand such Vars into RowExpr constructs.
*
* Note: the business with inserted_sublink is needed to update hasSubLinks
* in subqueries when the replacement adds a subquery inside a subquery.
@@ -813,7 +812,7 @@ typedef struct
{
int target_varno;
int sublevels_up;
List *target_rtable;
RangeTblEntry *target_rte;
List *targetlist;
int event;
int update_varno;
@@ -885,7 +884,8 @@ ResolveNew_mutator(Node *node, ResolveNew_context *context)
* include dummy items for dropped columns. If the var is
* RECORD (ie, this is a JOIN), then omit dropped columns.
*/
expandRTE(context->target_rtable, this_varno, this_varlevelsup,
expandRTE(context->target_rte,
this_varno, this_varlevelsup,
(var->vartype != RECORDOID),
NULL, &fields);
/* Adjust the generated per-field Vars... */
@@ -929,14 +929,14 @@ ResolveNew_mutator(Node *node, ResolveNew_context *context)
Node *
ResolveNew(Node *node, int target_varno, int sublevels_up,
List *target_rtable,
RangeTblEntry *target_rte,
List *targetlist, int event, int update_varno)
{
ResolveNew_context context;
context.target_varno = target_varno;
context.sublevels_up = sublevels_up;
context.target_rtable = target_rtable;
context.target_rte = target_rte;
context.targetlist = targetlist;
context.event = event;
context.update_varno = update_varno;