Bug #79246 "select null=ANY(non-empty subquery)" returns 0
Submitted: 12 Nov 2015 9:15 Modified: 27 Nov 2019 22:43
Reporter: Su Dylan Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:5.0/5.1/5.5/5.6/5.7 OS:Any
Assigned to: CPU Architecture:Any

[12 Nov 2015 9:15] Su Dylan
Description:
Output:
=======
mysql> drop table if exists t1,t2;
Query OK, 0 rows affected (0.01 sec)

mysql> create table t1(c1 int primary key);
create table t2(c1 int);
Query OK, 0 rows affected (0.00 sec)

mysql> create table t2(c1 int);
Query OK, 0 rows affected (0.01 sec)

mysql> insert into t1 values(1),(2);
rtQuery OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> insert into t2 values(1),(2);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> select null=any(select c1 from t1), null=any(select c1 from t2);
+-----------------------------+-----------------------------+
| null=any(select c1 from t1) | null=any(select c1 from t2) |
+-----------------------------+-----------------------------+
|                           0 |                        NULL |
+-----------------------------+-----------------------------+
1 row in set (0.00 sec)

mysql>
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.8-rc  |
+-----------+
1 row in set (0.00 sec)

Problems:
=========
"select null=ANY(non-empty subquery)" returns 0

How to repeat:

drop table if exists t1,t2;
create table t1(c1 int primary key);
create table t2(c1 int);
insert into t1 values(1),(2);
insert into t2 values(1),(2);
select null=any(select c1 from t1), null=any(select c1 from t2);

Suggested fix:
"select null=ANY(non-empty subquery)" returns NULL.
[12 Nov 2015 10:23] MySQL Verification Team
Thank you for the bug report. Version: 5.0/5.1/5.5/5.6/5.7 affected:

C:\dbs>c:\dbs\5.7\bin\mysql -uroot -p --port=3570 --prompt="mysql 5.7 > "
Enter password: ******
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.10 Source distribution PULL: 2015-NOV-07

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql 5.7 > use test
Database changed
mysql 5.7 >
mysql 5.7 > drop table if exists t1,t2;
Query OK, 0 rows affected (0.03 sec)

mysql 5.7 > create table t1(c1 int primary key);
Query OK, 0 rows affected (0.03 sec)

mysql 5.7 > create table t2(c1 int);
Query OK, 0 rows affected (0.03 sec)

mysql 5.7 > insert into t1 values(1),(2);
Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql 5.7 > insert into t2 values(1),(2);
Query OK, 2 rows affected (0.01 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql 5.7 > select null=any(select c1 from t1), null=any(select c1 from t2);
+-----------------------------+-----------------------------+
| null=any(select c1 from t1) | null=any(select c1 from t2) |
+-----------------------------+-----------------------------+
|                           0 |                        NULL |
+-----------------------------+-----------------------------+
1 row in set (0.00 sec)

mysql 5.7 > alter table t1 drop primary key;
Query OK, 2 rows affected (0.17 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql 5.7 > select null=any(select c1 from t1), null=any(select c1 from t2);
+-----------------------------+-----------------------------+
| null=any(select c1 from t1) | null=any(select c1 from t2) |
+-----------------------------+-----------------------------+
|                        NULL |                        NULL |
+-----------------------------+-----------------------------+
1 row in set (0.00 sec)
[27 Nov 2019 22:43] Roy Lyseng
Posted by developer:
 
Fixed in 5.7.29