Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit dea1491

Browse files
committed
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.
1 parent a6492ff commit dea1491

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/backend/optimizer/util/predtest.c

+4
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,8 @@ arrayexpr_cleanup_fn(PredIterInfo info)
10281028
* "foo" is NULL, which we can take as equivalent to FALSE because we know
10291029
* we are within an AND/OR subtree of a WHERE clause. (Again, "foo" is
10301030
* already known immutable, so the clause will certainly always fail.)
1031+
* Also, if the clause is just "foo" (meaning it's a boolean variable),
1032+
* the predicate is implied since the clause can't be true if "foo" is NULL.
10311033
*
10321034
* Finally, if both clauses are binary operator expressions, we may be able
10331035
* to prove something using the system's knowledge about operators; those
@@ -1061,6 +1063,8 @@ predicate_implied_by_simple_clause(Expr *predicate, Node *clause)
10611063
list_member_strip(((FuncExpr *) clause)->args, nonnullarg) &&
10621064
func_strict(((FuncExpr *) clause)->funcid))
10631065
return true;
1066+
if (equal(clause, nonnullarg))
1067+
return true;
10641068
}
10651069
return false; /* we can't succeed below... */
10661070
}

0 commit comments

Comments
 (0)