9
9
*
10
10
*
11
11
* 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 $
13
13
*
14
14
*-------------------------------------------------------------------------
15
15
*/
@@ -2598,20 +2598,14 @@ get_variable(Var *var, int levelsup, bool showstar, deparse_context *context)
2598
2598
2599
2599
/*
2600
2600
* 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.
2604
2603
*/
2605
2604
if (var -> varno >= 1 && var -> varno <= list_length (dpns -> rtable ))
2606
2605
{
2607
2606
rte = rt_fetch (var -> varno , dpns -> rtable );
2608
2607
attnum = var -> varattno ;
2609
2608
}
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
- }
2615
2609
else if (var -> varno == OUTER && dpns -> outer_plan )
2616
2610
{
2617
2611
TargetEntry * tle ;
@@ -2631,9 +2625,11 @@ get_variable(Var *var, int levelsup, bool showstar, deparse_context *context)
2631
2625
* Force parentheses because our caller probably assumed a Var is a
2632
2626
* simple expression.
2633
2627
*/
2634
- appendStringInfoChar (buf , '(' );
2628
+ if (!IsA (tle -> expr , Var ))
2629
+ appendStringInfoChar (buf , '(' );
2635
2630
get_rule_expr ((Node * ) tle -> expr , context , true);
2636
- appendStringInfoChar (buf , ')' );
2631
+ if (!IsA (tle -> expr , Var ))
2632
+ appendStringInfoChar (buf , ')' );
2637
2633
2638
2634
dpns -> outer_plan = save_outer ;
2639
2635
dpns -> inner_plan = save_inner ;
@@ -2658,9 +2654,11 @@ get_variable(Var *var, int levelsup, bool showstar, deparse_context *context)
2658
2654
* Force parentheses because our caller probably assumed a Var is a
2659
2655
* simple expression.
2660
2656
*/
2661
- appendStringInfoChar (buf , '(' );
2657
+ if (!IsA (tle -> expr , Var ))
2658
+ appendStringInfoChar (buf , '(' );
2662
2659
get_rule_expr ((Node * ) tle -> expr , context , true);
2663
- appendStringInfoChar (buf , ')' );
2660
+ if (!IsA (tle -> expr , Var ))
2661
+ appendStringInfoChar (buf , ')' );
2664
2662
2665
2663
dpns -> outer_plan = save_outer ;
2666
2664
dpns -> inner_plan = save_inner ;
@@ -2700,7 +2698,13 @@ get_variable(Var *var, int levelsup, bool showstar, deparse_context *context)
2700
2698
* simple reference, we have to just print the unqualified
2701
2699
* variable name (this can only happen with columns that were
2702
2700
* 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.
2703
2705
*/
2706
+ if (rte -> joinaliasvars == NIL )
2707
+ elog (ERROR , "cannot decompile join alias var in plan tree" );
2704
2708
if (attnum > 0 )
2705
2709
{
2706
2710
Var * aliasvar ;
@@ -2798,9 +2802,7 @@ get_name_for_var_field(Var *var, int fieldno,
2798
2802
/*
2799
2803
* Try to find the relevant RTE in this rtable. In a plan tree, it's
2800
2804
* 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.
2804
2806
*/
2805
2807
if (var -> varno >= 1 && var -> varno <= list_length (dpns -> rtable ))
2806
2808
{
@@ -2963,6 +2965,8 @@ get_name_for_var_field(Var *var, int fieldno,
2963
2965
break ;
2964
2966
case RTE_JOIN :
2965
2967
/* Join RTE --- recursively inspect the alias variable */
2968
+ if (rte -> joinaliasvars == NIL )
2969
+ elog (ERROR , "cannot decompile join alias var in plan tree" );
2966
2970
Assert (attnum > 0 && attnum <= list_length (rte -> joinaliasvars ));
2967
2971
expr = (Node * ) list_nth (rte -> joinaliasvars , attnum - 1 );
2968
2972
if (IsA (expr , Var ))
0 commit comments