14
14
*
15
15
*
16
16
* IDENTIFICATION
17
- * $PostgreSQL: pgsql/src/backend/optimizer/util/var.c,v 1.84 2009/02/25 03:30:37 tgl Exp $
17
+ * $PostgreSQL: pgsql/src/backend/optimizer/util/var.c,v 1.85 2009/04/19 19:46:33 tgl Exp $
18
18
*
19
19
*-------------------------------------------------------------------------
20
20
*/
@@ -56,7 +56,7 @@ typedef struct
56
56
typedef struct
57
57
{
58
58
List * varlist ;
59
- bool includePlaceHolderVars ;
59
+ PVCPlaceHolderBehavior behavior ;
60
60
} pull_var_clause_context ;
61
61
62
62
typedef struct
@@ -614,11 +614,13 @@ find_minimum_var_level_walker(Node *node,
614
614
* pull_var_clause
615
615
* Recursively pulls all Var nodes from an expression clause.
616
616
*
617
- * PlaceHolderVars are included too, if includePlaceHolderVars is true.
618
- * If it isn't true, an error is thrown if any are found.
619
- * Note that Vars within a PHV's expression are *not* included.
617
+ * PlaceHolderVars are handled according to 'behavior':
618
+ * PVC_REJECT_PLACEHOLDERS throw error if PlaceHolderVar found
619
+ * PVC_INCLUDE_PLACEHOLDERS include PlaceHolderVars in output list
620
+ * PVC_RECURSE_PLACEHOLDERS recurse into PlaceHolderVar argument
621
+ * Vars within a PHV's expression are included only in the last case.
620
622
*
621
- * CurrentOfExpr nodes are *not* included .
623
+ * CurrentOfExpr nodes are ignored in all cases .
622
624
*
623
625
* Upper-level vars (with varlevelsup > 0) are not included.
624
626
* (These probably represent errors too, but we don't complain.)
@@ -630,12 +632,12 @@ find_minimum_var_level_walker(Node *node,
630
632
* of sublinks to subplans!
631
633
*/
632
634
List *
633
- pull_var_clause (Node * node , bool includePlaceHolderVars )
635
+ pull_var_clause (Node * node , PVCPlaceHolderBehavior behavior )
634
636
{
635
637
pull_var_clause_context context ;
636
638
637
639
context .varlist = NIL ;
638
- context .includePlaceHolderVars = includePlaceHolderVars ;
640
+ context .behavior = behavior ;
639
641
640
642
pull_var_clause_walker (node , & context );
641
643
return context .varlist ;
@@ -654,12 +656,20 @@ pull_var_clause_walker(Node *node, pull_var_clause_context *context)
654
656
}
655
657
if (IsA (node , PlaceHolderVar ))
656
658
{
657
- if (!context -> includePlaceHolderVars )
658
- elog (ERROR , "PlaceHolderVar found where not expected" );
659
- if (((PlaceHolderVar * ) node )-> phlevelsup == 0 )
660
- context -> varlist = lappend (context -> varlist , node );
661
- /* we do NOT descend into the contained expression */
662
- return false;
659
+ switch (context -> behavior )
660
+ {
661
+ case PVC_REJECT_PLACEHOLDERS :
662
+ elog (ERROR , "PlaceHolderVar found where not expected" );
663
+ break ;
664
+ case PVC_INCLUDE_PLACEHOLDERS :
665
+ if (((PlaceHolderVar * ) node )-> phlevelsup == 0 )
666
+ context -> varlist = lappend (context -> varlist , node );
667
+ /* we do NOT descend into the contained expression */
668
+ return false;
669
+ case PVC_RECURSE_PLACEHOLDERS :
670
+ /* ignore the placeholder, look at its argument instead */
671
+ break ;
672
+ }
663
673
}
664
674
return expression_tree_walker (node , pull_var_clause_walker ,
665
675
(void * ) context );
0 commit comments