8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.160 2004/01/05 18:04:39 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/backend/optimizer/util/clauses.c,v 1.161 2004/01/10 18:13:53 tgl Exp $
12
12
*
13
13
* HISTORY
14
14
* AUTHOR DATE MAJOR EVENT
@@ -697,10 +697,10 @@ contain_volatile_functions_walker(Node *node, void *context)
697
697
* Returns true if any nonstrict construct is found --- ie, anything that
698
698
* could produce non-NULL output with a NULL input.
699
699
*
700
- * XXX we do not examine sub-selects to see if they contain uses of
701
- * nonstrict functions. It's not real clear if that is correct or not...
702
- * for the current usage it does not matter, since inline_function()
703
- * rejects cases with sublinks .
700
+ * The idea here is that the caller has verified that the expression contains
701
+ * one or more Var or Param nodes (as appropriate for the caller's need), and
702
+ * now wishes to prove that the expression result will be NULL if any of these
703
+ * inputs is NULL. If we return false, then the proof succeeded .
704
704
*/
705
705
bool
706
706
contain_nonstrict_functions (Node * clause )
@@ -713,6 +713,11 @@ contain_nonstrict_functions_walker(Node *node, void *context)
713
713
{
714
714
if (node == NULL )
715
715
return false;
716
+ if (IsA (node , Aggref ))
717
+ {
718
+ /* an aggregate could return non-null with null input */
719
+ return true;
720
+ }
716
721
if (IsA (node , FuncExpr ))
717
722
{
718
723
FuncExpr * expr = (FuncExpr * ) node ;
@@ -745,16 +750,25 @@ contain_nonstrict_functions_walker(Node *node, void *context)
745
750
746
751
switch (expr -> boolop )
747
752
{
748
- case OR_EXPR :
749
753
case AND_EXPR :
750
- /* OR, AND are inherently non-strict */
754
+ case OR_EXPR :
755
+ /* AND, OR are inherently non-strict */
751
756
return true;
752
757
default :
753
758
break ;
754
759
}
755
760
}
761
+ if (IsA (node , SubLink ))
762
+ {
763
+ /* In some cases a sublink might be strict, but in general not */
764
+ return true;
765
+ }
766
+ if (IsA (node , SubPlan ))
767
+ return true;
756
768
if (IsA (node , CaseExpr ))
757
769
return true;
770
+ if (IsA (node , CaseWhen ))
771
+ return true;
758
772
/* NB: ArrayExpr might someday be nonstrict */
759
773
if (IsA (node , CoalesceExpr ))
760
774
return true;
@@ -764,18 +778,6 @@ contain_nonstrict_functions_walker(Node *node, void *context)
764
778
return true;
765
779
if (IsA (node , BooleanTest ))
766
780
return true;
767
- if (IsA (node , SubLink ))
768
- {
769
- SubLink * sublink = (SubLink * ) node ;
770
- List * opid ;
771
-
772
- foreach (opid , sublink -> operOids )
773
- {
774
- if (!op_strict (lfirsto (opid )))
775
- return true;
776
- }
777
- /* else fall through to check args */
778
- }
779
781
return expression_tree_walker (node , contain_nonstrict_functions_walker ,
780
782
context );
781
783
}
0 commit comments