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

From Emre Hasegeli
Subject Re: constraint exclusion and nulls in IN (..) clause
Date
Msg-id CAE2gYzxYx=R=1o=8NKfZx6hzO9C4-ZJK864iHYXYWMi-PiP04A@mail.gmail.com
Whole thread Raw
In response to Re: constraint exclusion and nulls in IN (..) clause  (Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>)
Responses Re: constraint exclusion and nulls in IN (..) clause  (Amit Langote <Langote_Amit_f8@lab.ntt.co.jp>)
List pgsql-hackers
> 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.

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?

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?


pgsql-hackers by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: [HACKERS] plpgsql - additional extra checks
Next
From: David Rowley
Date:
Subject: Re: [HACKERS] Removing useless DISTINCT clauses