CALCITE-3390 ITEM was marked with Policy.ANY strong policy, but according to its JavaDoc, the result may be null if and only if at least one of its arguments is null. This statement was used in RexSimplify.simplifyIsNotNull() method, so t1.c_nationkey is not null will be simplified to IS NOT NULL($0) which is wrong, since array may be empty, or index may be less than the size of the array.
Unit test which helps to reproduce this issue:
Returns plan with incorrectly simplified ITEM expression:
But the initial intention of
CALCITE-3390 was to allow pushing ITEM expression to the right input of left-outer-join.
I propose to add a new element to the Policy which will have a relaxed condition - expression is null if at least one of its arguments is null.