Bug #100352 DELETE IGNORE deletes wrong rows

Submitted: 28 Jul 2020 9:05 Modified: 28 Jul 2020 9:10
Reporter: Kamil Holubicki (OCA) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:8.0.21 OS:Any
Assigned to: CPU Architecture:Any
Tags: regression

[28 Jul 2020 9:05] Kamil Holubicki
Description:
This is side effect of commit 44861c7d7134f6c71e0530417b14d5ac3274f52b 

How to repeat:
drop table if exists t3;
create table t3 (a int);
insert into t3 values (0), (5), (6), (7);
delete ignore t3.* from t3 where a != (SELECT 1 UNION SELECT 2);
select * from t3;
+------+
| a    |
+------+
|    0 |
+------+

but the intention was to delete every row where a is NOT 1 or 2.

Similarly:

drop table if exists t3;
create table t3 (a int);
insert into t3 values (0), (5), (6), (7);
delete ignore t3.* from t3 where a = (SELECT 1 UNION SELECT 2);
select * from t3;
+------+
| a    |
+------+
|    5 |
|    6 |
|    7 |
+------+

but the intention was to delete every row where a is 1 or 2.

In simple:
where a = (SELECT 1 UNION SELECT 2) => where a = 0
where a != (SELECT 1 UNION SELECT 2) => where a != 0

Suggested fix:
In my opinion the expected result should be failure of the query, as 'in' or 'not in' respectively should be used (not =, !=) and the table should not be affected at all.

or

= should evaluate to 'in'
!= should evaluate to 'not in'
and proper rows should be deleted
[28 Jul 2020 9:10] MySQL Verification Team
Hello Kamil Holubicki ,

Thank you for the report and test case.

regards,
Umesh

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.052 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.