Re: constraint exclusion and nulls in IN (..) clause

2018-03-22 Thread Tom Lane
Amit Langote writes: > I too wasn't sure if the patch's modifications to > operator_predicate_proof() led to correct handling for the case where both > clause_const and pred_const are both NULL consts. ISTM that the result in > that case becomes what operator_same_subexprs_proof() would return fo

Re: constraint exclusion and nulls in IN (..) clause

2018-03-22 Thread Amit Langote
On 2018/03/21 23:00, Tom Lane wrote: > Emre Hasegeli writes: >> I am not sure if we are covering the case when clause_const and >> pred_const are both NULL. In this case, we should be able to return >> true only by checking op_strict(pred_op) or maybe even without >> checking that. Am I mistaken

Re: constraint exclusion and nulls in IN (..) clause

2018-03-21 Thread Emre Hasegeli
> Yeah, that's there. We need both operators to be strict, I think; > otherwise we can't really assume anything about what they'd return > for NULL inputs. But if they are, we have NULL => NULL which is > valid for all proof cases. I understand. I don’t see any problems in this case.

Re: constraint exclusion and nulls in IN (..) clause

2018-03-21 Thread Tom Lane
Emre Hasegeli writes: > I am not sure if we are covering the case when clause_const and > pred_const are both NULL. In this case, we should be able to return > true only by checking op_strict(pred_op) or maybe even without > checking that. Am I mistaken? Yeah, that's there. We need both operat

Re: constraint exclusion and nulls in IN (..) clause

2018-03-21 Thread Emre Hasegeli
> After further thought, it seems like the place to deal with this is > really operator_predicate_proof(), as in the attached draft patch > against HEAD. This passes the smell test for me, in the sense that > it's an arguably correct and general extension of the proof rules, > but it could use mor

Re: constraint exclusion and nulls in IN (..) clause

2018-03-20 Thread Tom Lane
I wrote: > After further thought, it seems like the place to deal with this is > really operator_predicate_proof(), as in the attached draft patch > against HEAD. This passes the smell test for me, in the sense that > it's an arguably correct and general extension of the proof rules, > but it coul

Re: constraint exclusion and nulls in IN (..) clause

2018-03-14 Thread Amit Langote
On 2018/03/14 17:16, Amit Langote wrote: > On 2018/03/10 13:40, Tom Lane wrote: >> I wrote: >>> I think it'd make more sense to see about incorporating that idea in >>> predicate_implied_by_simple_clause/predicate_refuted_by_simple_clause. >> >> After further thought, it seems like the place to dea

Re: constraint exclusion and nulls in IN (..) clause

2018-03-14 Thread Amit Langote
On 2018/03/10 13:40, Tom Lane wrote: > I wrote: >> I think it'd make more sense to see about incorporating that idea in >> predicate_implied_by_simple_clause/predicate_refuted_by_simple_clause. > > After further thought, it seems like the place to deal with this is > really operator_predicate_proo

Re: constraint exclusion and nulls in IN (..) clause

2018-03-09 Thread Tom Lane
I wrote: > I think it'd make more sense to see about incorporating that idea in > predicate_implied_by_simple_clause/predicate_refuted_by_simple_clause. After further thought, it seems like the place to deal with this is really operator_predicate_proof(), as in the attached draft patch against HEA

Re: constraint exclusion and nulls in IN (..) clause

2018-03-06 Thread Tom Lane
Amit Langote writes: > [ v4-0001-Disregard-nulls-in-SAOP-rightarg-array-list-durin.patch ] This patch seems pretty wrong to me. The proposed proof rule is wrong for !useOr expressions (that is, "scalar op ALL (array)"); you can't just ignore null items in that case. It's also wrong when we need

Re: constraint exclusion and nulls in IN (..) clause

2018-03-06 Thread Amit Langote
On 2018/03/06 19:16, Emre Hasegeli wrote: >> Hmm, state->next refers to two different pointer values on line 1 and line >> 2. It may end up being set to NULL on line 1. Am I missing something? > > True, lnext(state->next) can set it to NULL. I confused by the below > code on the same function d

Re: constraint exclusion and nulls in IN (..) clause

2018-03-06 Thread Emre Hasegeli
> Hmm, state->next refers to two different pointer values on line 1 and line > 2. It may end up being set to NULL on line 1. Am I missing something? True, lnext(state->next) can set it to NULL. I confused by the below code on the same function doing the steps in reverse order. With this cleare

Re: constraint exclusion and nulls in IN (..) clause

2018-03-06 Thread Amit Langote
On 2018/03/06 18:46, Emre Hasegeli wrote: >> Patch teaches it to ignore nulls when it's known that the operator being >> used is strict. It is harmless and has the benefit that constraint >> exclusion gives an answer that is consistent with what actually running >> such a qual against a table's ro

Re: constraint exclusion and nulls in IN (..) clause

2018-03-06 Thread Emre Hasegeli
> Patch teaches it to ignore nulls when it's known that the operator being > used is strict. It is harmless and has the benefit that constraint > exclusion gives an answer that is consistent with what actually running > such a qual against a table's rows would do. Yes, I understood that. I just

Re: constraint exclusion and nulls in IN (..) clause

2018-03-05 Thread Amit Langote
Hi. Thanks for reviewing again. On 2018/03/05 23:04, Emre Hasegeli wrote: >>> Shouldn't we check if we consumed all elements (state->next_elem >= >>> state->num_elems) inside the while loop? >> >> You're right. Fixed. > > I don't think the fix is correct. arrayconst_next_fn() can still > execu

Re: constraint exclusion and nulls in IN (..) clause

2018-03-05 Thread Emre Hasegeli
>> Shouldn't we check if we consumed all elements (state->next_elem >= >> state->num_elems) inside the while loop? > > You're right. Fixed. I don't think the fix is correct. arrayconst_next_fn() can still execute state->next_elem++ without checking if we consumed all elements. I couldn't manage

Re: constraint exclusion and nulls in IN (..) clause

2018-03-04 Thread Amit Langote
Hi. On 2018/03/04 22:12, Emre Hasegeli wrote: >> Yeah, the patch in its current form is wrong, because it will give wrong >> answers if the operator being used in a SAOP is non-strict. I modified >> the patch to consider operator strictness before doing anything with nulls. > > I tried to review

Re: constraint exclusion and nulls in IN (..) clause

2018-03-04 Thread Emre Hasegeli
> Yeah, the patch in its current form is wrong, because it will give wrong > answers if the operator being used in a SAOP is non-strict. I modified > the patch to consider operator strictness before doing anything with nulls. I tried to review this patch without any familiarity to the code. arra

Re: constraint exclusion and nulls in IN (..) clause

2018-02-06 Thread Robert Haas
On Sun, Feb 4, 2018 at 11:20 PM, Ashutosh Bapat wrote: > On Thu, Feb 1, 2018 at 2:23 PM, Amit Langote > wrote: >> Yeah, the patch in its current form is wrong, because it will give wrong >> answers if the operator being used in a SAOP is non-strict. I modified >> the patch to consider operator s

Re: constraint exclusion and nulls in IN (..) clause

2018-02-04 Thread Amit Langote
On 2018/02/05 13:20, Ashutosh Bapat wrote: > On Thu, Feb 1, 2018 at 2:23 PM, Amit Langote > wrote: >> >> Yeah, the patch in its current form is wrong, because it will give wrong >> answers if the operator being used in a SAOP is non-strict. I modified >> the patch to consider operator strictness

Re: constraint exclusion and nulls in IN (..) clause

2018-02-04 Thread Ashutosh Bapat
On Thu, Feb 1, 2018 at 2:23 PM, Amit Langote wrote: > > Yeah, the patch in its current form is wrong, because it will give wrong > answers if the operator being used in a SAOP is non-strict. I modified > the patch to consider operator strictness before doing anything with nulls. That's fine, but

Re: constraint exclusion and nulls in IN (..) clause

2018-02-01 Thread Amit Langote
Thanks for the comments. On 2018/02/01 16:40, Ashutosh Bapat wrote: > On Thu, Feb 1, 2018 at 12:26 PM, Amit Langote > wrote: >> Hi. >> >> When addressing a review comment on the fast partition pruning thread [1], >> I noticed that specifying null in the IN-list will cause constraint >> exclusion

Re: constraint exclusion and nulls in IN (..) clause

2018-01-31 Thread Ashutosh Bapat
On Thu, Feb 1, 2018 at 12:26 PM, Amit Langote wrote: > Hi. > > When addressing a review comment on the fast partition pruning thread [1], > I noticed that specifying null in the IN-list will cause constraint > exclusion to wrongly fail to refute a table's check predicate. > > create table foo (a i