Re: constraint exclusion and nulls in IN (..) clause - Mailing list pgsql-hackers

From Amit Langote
Subject Re: constraint exclusion and nulls in IN (..) clause
Date
Msg-id 837bd350-6aeb-d0ec-d51c-6a0dd740798f@lab.ntt.co.jp
Whole thread Raw
In response to Re: constraint exclusion and nulls in IN (..) clause  (Emre Hasegeli <emre@hasegeli.com>)
Responses Re: constraint exclusion and nulls in IN (..) clause  (Emre Hasegeli <emre@hasegeli.com>)
List pgsql-hackers
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 this patch without any familiarity to the code.

Thanks for the review.

> arrayconst_next_fn():
> 
>> +   /* skip nulls if ok to do so */
>> +   if (state->opisstrict)
>> +   {
>> +       while (state->elem_nulls[state->next_elem])
>> +           state->next_elem++;
>> +   }
> 
> Shouldn't we check if we consumed all elements (state->next_elem >=
> state->num_elems) inside the while loop?

You're right.  Fixed.

> arrayexpr_next_fn():
> 
>> +   /* skip nulls if ok to do so */
>> +   if (state->opisstrict)
>> +   {
>> +       Node *node = (Node *) lfirst(state->next);
>> +
>> +       while (IsA(node, Const) && ((Const *) node)->constisnull)
>> +           state->next = lnext(state->next);
>> +   }
> 
> I cannot find a way to test this change.  Can you imagine a query to
> exercise it on the regression tests?

So far, I hadn't either.  I figured one out and added it to inherit.sql.
Basically, I needed to write the query such that an IN () expression
doesn't get const-simplified to a Const containing array, but rather
remains an ArrayExpr.  So, arrayexpr_*() functions in predtest.c are now
exercised.

Attached updated patch.

Thanks,
Amit

Attachment

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: Server won't start with fallback setting by initdb.
Next
From: Amit Langote
Date:
Subject: Re: non-bulk inserts and tuple routing