On Tue, 15 Jan 2019 at 12:24, James Coleman <jtc...@gmail.com> wrote: > While I add that though I wanted to get this updated version out to > get feedback on the approach.
I had a look at this and there's a couple of things I see: 1. In: + if (IsA(clause, ScalarArrayOpExpr)) + { + ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) clause; + Node *subexpr = (Node *) ((NullTest *) predicate)->arg; + if (op_strict(saop->opno) && + clause_is_strict_for((Node *) linitial(saop->args), subexpr)) + return true; + } + /* foo IS NOT NULL refutes foo IS NULL */ if (clause && IsA(clause, NullTest) && Your IsA(clause, ScalarArrayOpExpr) condition should also be checking that "clause" can't be NULL. The NullTest condition one below does this. 2. I was also staring predicate_implied_by_simple_clause() a bit at the use of clause_is_strict_for() to ensure that the IS NOT NULL's operand matches the ScalarArrayOpExpr left operand. Since clause_is_strict_for() = "Can we prove that "clause" returns NULL if "subexpr" does?", in this case, your clause is the ScalarArrayOpExpr's left operand and subexpr is the IS NOT NULL's operand. This means that a partial index with "WHERE a IS NOT NULL" should also be fine to use for WHERE strict_func(a) IN (1,2,..., 101); since strict_func(a) must be NULL if a is NULL. Also also works for WHERE a+a IN(1,2,...,101); I wonder if it's worth adding a test for that, or even just modify one of the existing tests to ensure you get the same result from it. Perhaps it's worth an additional test to ensure that x IN(1,2,...,101) does not imply x+x IS NOT NULL and maybe that x+x IS NULL does not refute x IN(1,2,...,101), as a strict function is free to return NULL even if it's input are not NULL. -- David Rowley http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services