aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2015-08-01 14:31:46 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2015-08-01 14:31:59 -0400
commit8dccf030e884ea8c723275a070acf8a8ed1eebe1 (patch)
tree80ec64b4a380655ddcac88629966d0ab0190a94f /src
parentedf26ed033f18bddc9bfe5c239388330150766a1 (diff)
downloadpostgresql-8dccf030e884ea8c723275a070acf8a8ed1eebe1.tar.gz
postgresql-8dccf030e884ea8c723275a070acf8a8ed1eebe1.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/backend/optimizer/util/predtest.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/backend/optimizer/util/predtest.c b/src/backend/optimizer/util/predtest.c
index d9e49d127e1..7e86ca974be 100644
--- a/src/backend/optimizer/util/predtest.c
+++ b/src/backend/optimizer/util/predtest.c
@@ -1028,6 +1028,8 @@ arrayexpr_cleanup_fn(PredIterInfo info)
* "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
* 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
* to prove something using the system's knowledge about operators; those
@@ -1061,6 +1063,8 @@ predicate_implied_by_simple_clause(Expr *predicate, Node *clause)
list_member_strip(((FuncExpr *) clause)->args, nonnullarg) &&
func_strict(((FuncExpr *) clause)->funcid))
return true;
+ if (equal(clause, nonnullarg))
+ return true;
}
return false; /* we can't succeed below... */
}