88 *
99 *
1010 * 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 $
1212 *
1313 * HISTORY
1414 * AUTHORDATEMAJOR EVENT
@@ -697,10 +697,10 @@ contain_volatile_functions_walker(Node *node, void *context)
697697 * Returns true if any nonstrict construct is found --- ie, anything that
698698 * could produce non-NULL output with a NULL input.
699699 *
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 thecurrent 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 theexpression result will be NULL if any of these
703+ *inputs is NULL. If we return false, then the proof succeeded .
704704 */
705705bool
706706contain_nonstrict_functions (Node * clause )
@@ -713,6 +713,11 @@ contain_nonstrict_functions_walker(Node *node, void *context)
713713{
714714if (node == NULL )
715715return false;
716+ if (IsA (node ,Aggref ))
717+ {
718+ /* an aggregate could return non-null with null input */
719+ return true;
720+ }
716721if (IsA (node ,FuncExpr ))
717722{
718723FuncExpr * expr = (FuncExpr * )node ;
@@ -745,16 +750,25 @@ contain_nonstrict_functions_walker(Node *node, void *context)
745750
746751switch (expr -> boolop )
747752{
748- case OR_EXPR :
749753case AND_EXPR :
750- /* OR, AND are inherently non-strict */
754+ case OR_EXPR :
755+ /* AND, OR are inherently non-strict */
751756return true;
752757default :
753758break ;
754759}
755760}
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;
756768if (IsA (node ,CaseExpr ))
757769return true;
770+ if (IsA (node ,CaseWhen ))
771+ return true;
758772/* NB: ArrayExpr might someday be nonstrict */
759773if (IsA (node ,CoalesceExpr ))
760774return true;
@@ -764,18 +778,6 @@ contain_nonstrict_functions_walker(Node *node, void *context)
764778return true;
765779if (IsA (node ,BooleanTest ))
766780return 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- }
779781return expression_tree_walker (node ,contain_nonstrict_functions_walker ,
780782context );
781783}