1414 *
1515 *
1616 * 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 $
1818 *
1919 *-------------------------------------------------------------------------
2020 */
@@ -56,7 +56,7 @@ typedef struct
5656typedef struct
5757{
5858 List * varlist ;
59- bool includePlaceHolderVars ;
59+ PVCPlaceHolderBehavior behavior ;
6060} pull_var_clause_context ;
6161
6262typedef struct
@@ -614,11 +614,13 @@ find_minimum_var_level_walker(Node *node,
614614 * pull_var_clause
615615 * Recursively pulls all Var nodes from an expression clause.
616616 *
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.
620622 *
621- * CurrentOfExpr nodes are *not* included .
623+ * CurrentOfExpr nodes are ignored in all cases .
622624 *
623625 * Upper-level vars (with varlevelsup > 0) are not included.
624626 * (These probably represent errors too, but we don't complain.)
@@ -630,12 +632,12 @@ find_minimum_var_level_walker(Node *node,
630632 * of sublinks to subplans!
631633 */
632634List *
633- pull_var_clause (Node * node , bool includePlaceHolderVars )
635+ pull_var_clause (Node * node , PVCPlaceHolderBehavior behavior )
634636{
635637 pull_var_clause_context context ;
636638
637639 context .varlist = NIL ;
638- context .includePlaceHolderVars = includePlaceHolderVars ;
640+ context .behavior = behavior ;
639641
640642 pull_var_clause_walker (node , & context );
641643 return context .varlist ;
@@ -654,12 +656,20 @@ pull_var_clause_walker(Node *node, pull_var_clause_context *context)
654656 }
655657 if (IsA (node , PlaceHolderVar ))
656658 {
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+ }
663673 }
664674 return expression_tree_walker (node , pull_var_clause_walker ,
665675 (void * ) context );
0 commit comments