Bug #113462 Incorrect result
Submitted: 19 Dec 2023 16:05 Modified: 20 Dec 2023 11:50
Reporter: haizhen xue Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version:8.0 OS:Any
Assigned to: CPU Architecture:Any

[19 Dec 2023 16:05] haizhen xue
Description:
1. when insert table t1 (1,1),(NULL,NULL), the select query result is NULL.
mysql> create table t0(smallint_col smallint, mediumint_col  mediumint);
Query OK, 0 rows affected (0.08 sec)

mysql> insert into t0 values(NULL,NULL);
Query OK, 1 row affected (0.01 sec)

mysql> create table t1(smallint_col smallint, mediumint_col  mediumint);
Query OK, 0 rows affected (0.09 sec)

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

mysql> SELECT smallint_col FROM t0  where (mediumint_col, smallint_col) <=> (SELECT mediumint_col,smallint_col FROM t1  WHERE(mediumint_col, smallint_col) < (3,3) XOR 2  LIMIT 1);
+--------------+
| smallint_col |
+--------------+
|         NULL |
+--------------+
1 row in set (0.00 sec)

2. when insert t1 values (NULL,NULL),(1,1), the select result is empty, expect result is same:
mysql> create table t0(smallint_col smallint, mediumint_col  mediumint);
Query OK, 0 rows affected (0.07 sec)

mysql> insert into t0 values(NULL,NULL);
Query OK, 1 row affected (0.01 sec)

mysql> create table t1(smallint_col smallint, mediumint_col  mediumint);
Query OK, 0 rows affected (0.07 sec)

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

mysql> SELECT smallint_col FROM t0  where (mediumint_col, smallint_col) <=> (SELECT mediumint_col,smallint_col FROM t1  WHERE(mediumint_col, smallint_col) < (3,3) XOR 2  LIMIT 1);
Empty set (0.00 sec)

How to repeat:
expect select result is same:

create table t0(smallint_col smallint, mediumint_col  mediumint);
insert into t0 values(NULL,NULL);
create table t1(smallint_col smallint, mediumint_col  mediumint);
insert into t1 values(1,1),(NULL,NULL);
SELECT smallint_col FROM t0  where (mediumint_col, smallint_col) <=> (SELECT mediumint_col,smallint_col FROM t1  WHERE(mediumint_col, smallint_col) < (3,3) XOR 2  LIMIT 1);
delete from t1;
insert into t1 values(NULL,NULL),(1,1); 
SELECT smallint_col FROM t0  where (mediumint_col, smallint_col) <=> (SELECT mediumint_col,smallint_col FROM t1  WHERE(mediumint_col, smallint_col) < (3,3) XOR 2  LIMIT 1);
[20 Dec 2023 11:50] MySQL Verification Team
Hi Mr. xue,

Thank you for your bug report.

We have managed to repeat it. The problem is in XOR 2 , which has no place in the row compariaons.

Hence , this is now a very low severity verified bug in 8.0 and higher versions.