Skip to content

select ... not in ... returns wrong results for nulls #5954

@jycor

Description

@jycor

Setup:

create table t1 (i int);
create table t2 (j int);
insert into t1 values (1), (null);
insert into t2 values (2), (null);

Dolt:

tmp> select * from t1 where i not in (select j from t2);
+------+
| i    |
+------+
| 1    |
| NULL |
+------+
2 rows in set (0.00 sec)

MySQL:

mysql> select * from t1 where i not in (select j from t2);
Empty set (0.0006 sec)

Plan:

tmp> explain select * from t1 where i not in (select j from t2);
+-----------------------------+
| plan                        |
+-----------------------------+
| AntiJoin                    |
|  ├─ (t1.i = scalarSubq0.j)  |
|  ├─ Table                   |
|  │   └─ name: t1            |
|  └─ TableAlias(scalarSubq0) |
|      └─ Table               |
|          ├─ name: t2        |
|          └─ columns: [j]    |
+-----------------------------+
8 rows in set (0.00 sec)

It seems like we should either avoid using the optimization in this case or fix the join conditions.

Metadata

Metadata

Assignees

Labels

analyzerbugSomething isn't workingcorrectnessWe don't return the same result as MySQLsqlIssue with SQL

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions