Re: Fold NOT IN / <> ALL expressions containing NULL to FALSE

From: Denis Smirnov <darthunix(at)gmail(dot)com>
To: Ilia Evdokimov <ilya(dot)evdokimov(at)tantorlabs(dot)com>
Cc: Rustam ALLAKOV <rustamallakov(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org, Yugo Nagata <nagata(at)sraoss(dot)co(dot)jp>
Subject: Re: Fold NOT IN / <> ALL expressions containing NULL to FALSE
Date: 2026-09-26 03:13:25
Message-ID: D28893E9-411D-4D89-B4A8-4F3E3FD48A21@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Ilia,

I checked v4. A few more cases could be simplified:

create table t(a int);
insert into t values (1), (42), (null);

explain (costs off)
select * from t where (a not in (42, null)) is true;

explain (costs off)
select * from t where (a not in (42, null)) is not true;

Both plans still contain the array comparison. The first condition
could be folded to false, and the second to true.

A null array is another case:

explain (costs off)
select * from t where a <> all (null::int[]);

explain (costs off)
select * from t where a = any (null::int[]);

Both plans still contain the array comparison. These comparisons
always return null, so in a where clause they could be folded
to false.

The comment in saop_never_true() says that ordinary constant folding
handles a null array, but this does not happen when the left argument
is a column.

Could you cover these cases and add regression tests?

Best regards,
Denis Smirnov

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Nico Williams 2026-09-26 03:25:00 Re: Proposal: Supporting URI SAN in Certificate Authentication
Previous Message Xuneng Zhou 2026-09-26 02:55:21 Re: Logical slot creation/synchronization on a standby may deadlock with recovery conflict resolution