Question on not-in and array-eq

From: Zhenghua Lyu <zlyu(at)vmware(dot)com>
To: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Question on not-in and array-eq
Date: 2021-12-08 15:15:22
Message-ID: CO6PR05MB7506DFE29434911C9290F2DCB56F9@CO6PR05MB7506.namprd05.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

I run the following SQL in Postgres (14_STABLE), and got the results:
zlyu=# create table t1(a int, b int);
CREATE TABLE
zlyu=# create table t2(a int, b int);
CREATE TABLE
zlyu=# insert into t1 values (null, 1);
INSERT 0 1
zlyu=# insert into t2 values (1, 1);
INSERT 0 1
zlyu=# select * from t1 where (a, b) not in (select * from t2);
a | b
---+---
(0 rows)

zlyu=# select * from t1 where (a, b) in (select * from t2);
a | b
---+---
(0 rows)

zlyu=# select * from t1 where array[a, b] in (select array[a,b] from t2);
a | b
---+---
(0 rows)

zlyu=# select * from t1 where array[a, b] not in (select array[a,b] from t2);
a | b
---+---
| 1
(1 row)

I run the SQL without array expr​ in other DBs(orcale, sqlite, ...), they all behave
the same as Postgres.

It seems a bit confusing for me that 'not in' and 'in' the same subquery both return 0
rows, but the table contains data.

Also, manually using array expression behaves differently from the first SQL. For not in case,
I step in the code, and find array_eq will consider null = null as true, however ExecSubPlan will
consider null as unprovable and exclude that row.

How to understand the result? It seems SQL standard does not mention array operation for null
value.

Thanks!

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2021-12-08 15:21:12 Re: Appetite for Frama-C annotations?
Previous Message Dagfinn Ilmari Mannsåker 2021-12-08 14:48:59 Re: Readd use of TAP subtests