Bug #109192 Query produces incorrect resultset after unique index is created
Submitted: 24 Nov 2022 9:34 Modified: 25 Nov 2022 6:48
Reporter: Brian Yue (OCA) Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S2 (Serious)
Version:8.0.29 OS:Any (rhel-7.4)
Assigned to: CPU Architecture:Any (x86-64)
Tags: incorrect resultset, Optimizer

[24 Nov 2022 9:34] Brian Yue
Description:
Hello, 
  Recently we find a case that resultset of a query changes after a unique index is created.
  Please reference to `How to repeat` part for detail.

How to repeat:
create database if not exists bugtest;
use bugtest;
drop table if exists yyy;
create table yyy(id int primary key,c1 int);
insert into yyy values(1,NULL);
insert into yyy values(2,NULL);
insert into yyy values(3,3);
insert into yyy values(4,NULL);

mysql> select * from yyy where NULL<=>c1;
+----+------+
| id | c1   |
+----+------+
|  1 | NULL |
|  2 | NULL |
|  4 | NULL |
+----+------+
3 rows in set (0.00 sec)

mysql> select * from yyy where (INET_ATON('452683762'))<=>c1;
+----+------+
| id | c1   |
+----+------+
|  1 | NULL |
|  2 | NULL |
|  4 | NULL |
+----+------+
3 rows in set, 1 warning (0.00 sec)

alter table yyy add unique index c1(c1);

mysql> select * from yyy where NULL<=>c1;
+----+------+
| id | c1   |
+----+------+
|  1 | NULL |
|  2 | NULL |
|  4 | NULL |
+----+------+
3 rows in set (0.00 sec)

# Incorrect result
mysql> select * from yyy where (INET_ATON('452683762'))<=>c1;
+----+------+
| id | c1   |
+----+------+
|  1 | NULL |
+----+------+
1 row in set, 3 warnings (0.00 sec)
[25 Nov 2022 6:48] MySQL Verification Team
Hello Brian Yue,

Thank you for the report and test case.
Imho this is duplicate of Bug #109179, please see Bug #109179.

regards,
Umesh