Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ce5b24a

Browse files
committed
Remove ruleutils.c's use of varnoold/varoattno as a shortcut for determining
what a Var node refers to. This is no longer necessary because the new flat-range-table representation of plan trees makes it relatively easy to dig down through child plan levels to find the original reference; and to keep doing it that way, we'd have to store joinaliasvars lists in flattened RTEs, as demonstrated by bug report from Leszek Trenkner. This change makes varnoold/varoattno truly just debug aids, which wasn't quite the case before. Perhaps we should drop them, or only have them in assert-enabled builds?
1 parent a868e24 commit ce5b24a

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/backend/utils/adt/ruleutils.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.257 2007/03/27 23:21:10 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.258 2007/05/24 18:58:42 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -2598,20 +2598,14 @@ get_variable(Var *var, int levelsup, bool showstar, deparse_context *context)
25982598

25992599
/*
26002600
* Try to find the relevant RTE in this rtable. In a plan tree, it's
2601-
* likely that varno is OUTER or INNER, in which case we try to use
2602-
* varnoold instead. If the Var references an expression computed by a
2603-
* subplan, varnoold will be 0, and we must dig down into the subplans.
2601+
* likely that varno is OUTER or INNER, in which case we must dig down
2602+
* into the subplans.
26042603
*/
26052604
if (var->varno >= 1 && var->varno <= list_length(dpns->rtable))
26062605
{
26072606
rte = rt_fetch(var->varno, dpns->rtable);
26082607
attnum = var->varattno;
26092608
}
2610-
else if (var->varnoold >= 1 && var->varnoold <= list_length(dpns->rtable))
2611-
{
2612-
rte = rt_fetch(var->varnoold, dpns->rtable);
2613-
attnum = var->varoattno;
2614-
}
26152609
else if (var->varno == OUTER && dpns->outer_plan)
26162610
{
26172611
TargetEntry *tle;
@@ -2631,9 +2625,11 @@ get_variable(Var *var, int levelsup, bool showstar, deparse_context *context)
26312625
* Force parentheses because our caller probably assumed a Var is a
26322626
* simple expression.
26332627
*/
2634-
appendStringInfoChar(buf, '(');
2628+
if (!IsA(tle->expr, Var))
2629+
appendStringInfoChar(buf, '(');
26352630
get_rule_expr((Node *) tle->expr, context, true);
2636-
appendStringInfoChar(buf, ')');
2631+
if (!IsA(tle->expr, Var))
2632+
appendStringInfoChar(buf, ')');
26372633

26382634
dpns->outer_plan = save_outer;
26392635
dpns->inner_plan = save_inner;
@@ -2658,9 +2654,11 @@ get_variable(Var *var, int levelsup, bool showstar, deparse_context *context)
26582654
* Force parentheses because our caller probably assumed a Var is a
26592655
* simple expression.
26602656
*/
2661-
appendStringInfoChar(buf, '(');
2657+
if (!IsA(tle->expr, Var))
2658+
appendStringInfoChar(buf, '(');
26622659
get_rule_expr((Node *) tle->expr, context, true);
2663-
appendStringInfoChar(buf, ')');
2660+
if (!IsA(tle->expr, Var))
2661+
appendStringInfoChar(buf, ')');
26642662

26652663
dpns->outer_plan = save_outer;
26662664
dpns->inner_plan = save_inner;
@@ -2700,7 +2698,13 @@ get_variable(Var *var, int levelsup, bool showstar, deparse_context *context)
27002698
* simple reference, we have to just print the unqualified
27012699
* variable name (this can only happen with columns that were
27022700
* merged by USING or NATURAL clauses).
2701+
*
2702+
* This wouldn't work in decompiling plan trees, because we don't
2703+
* store joinaliasvars lists after planning; but a plan tree
2704+
* should never contain a join alias variable.
27032705
*/
2706+
if (rte->joinaliasvars == NIL)
2707+
elog(ERROR, "cannot decompile join alias var in plan tree");
27042708
if (attnum > 0)
27052709
{
27062710
Var *aliasvar;
@@ -2798,9 +2802,7 @@ get_name_for_var_field(Var *var, int fieldno,
27982802
/*
27992803
* Try to find the relevant RTE in this rtable. In a plan tree, it's
28002804
* likely that varno is OUTER or INNER, in which case we must dig down
2801-
* into the subplans. (We can't shortcut with varnoold here, because
2802-
* it might reference a SUBQUERY RTE; we have to dig down to the
2803-
* SubqueryScan plan level to cope with that. See below.)
2805+
* into the subplans.
28042806
*/
28052807
if (var->varno >= 1 && var->varno <= list_length(dpns->rtable))
28062808
{
@@ -2963,6 +2965,8 @@ get_name_for_var_field(Var *var, int fieldno,
29632965
break;
29642966
case RTE_JOIN:
29652967
/* Join RTE --- recursively inspect the alias variable */
2968+
if (rte->joinaliasvars == NIL)
2969+
elog(ERROR, "cannot decompile join alias var in plan tree");
29662970
Assert(attnum > 0 && attnum <= list_length(rte->joinaliasvars));
29672971
expr = (Node *) list_nth(rte->joinaliasvars, attnum - 1);
29682972
if (IsA(expr, Var))

0 commit comments

Comments
 (0)