Commit dea1491f authored by Tom Lane's avatar Tom Lane

Teach predtest.c that "foo" implies "foo IS NOT NULL".

Per complaint from Peter Holzer.  It's useful to cover this special case,
since for a boolean variable "foo", earlier parts of the planner will have
reduced variants like "foo = true" to just "foo", and thus we may fail
to recognize the applicability of a partial index with predicate
"foo IS NOT NULL".

Back-patch to 9.5, but not further; given the lack of previous complaints
this doesn't seem like behavior to change in stable branches.
parent a6492ff8
...@@ -1028,6 +1028,8 @@ arrayexpr_cleanup_fn(PredIterInfo info) ...@@ -1028,6 +1028,8 @@ arrayexpr_cleanup_fn(PredIterInfo info)
* "foo" is NULL, which we can take as equivalent to FALSE because we know * "foo" is NULL, which we can take as equivalent to FALSE because we know
* we are within an AND/OR subtree of a WHERE clause. (Again, "foo" is * we are within an AND/OR subtree of a WHERE clause. (Again, "foo" is
* already known immutable, so the clause will certainly always fail.) * already known immutable, so the clause will certainly always fail.)
* Also, if the clause is just "foo" (meaning it's a boolean variable),
* the predicate is implied since the clause can't be true if "foo" is NULL.
* *
* Finally, if both clauses are binary operator expressions, we may be able * Finally, if both clauses are binary operator expressions, we may be able
* to prove something using the system's knowledge about operators; those * to prove something using the system's knowledge about operators; those
...@@ -1061,6 +1063,8 @@ predicate_implied_by_simple_clause(Expr *predicate, Node *clause) ...@@ -1061,6 +1063,8 @@ predicate_implied_by_simple_clause(Expr *predicate, Node *clause)
list_member_strip(((FuncExpr *) clause)->args, nonnullarg) && list_member_strip(((FuncExpr *) clause)->args, nonnullarg) &&
func_strict(((FuncExpr *) clause)->funcid)) func_strict(((FuncExpr *) clause)->funcid))
return true; return true;
if (equal(clause, nonnullarg))
return true;
} }
return false; /* we can't succeed below... */ return false; /* we can't succeed below... */
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment