Bug #43334 indexes not used in DELETE-query with IN-condition on multiple keys
Submitted: 3 Mar 2009 16:34 Modified: 3 Mar 2009 18:16
Reporter: Maarten van Schaik Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: InnoDB storage engine Severity:S3 (Non-critical)
Version:5.0, 5.1 OS:Any (FreeBSD 6.4, Debian Linux 5)
Assigned to: CPU Architecture:Any

[3 Mar 2009 16:34] Maarten van Schaik
Description:
The query "DELETE FROM test WHERE (key1, key2) IN ((12345, 12345))" takes unusually long and does not seem to use an index, while "SELECT * FROM test WHERE (key1, key2) IN ((12345, 12345))" is very fast. The second query seems to optimize to (key1=12345 AND key2=12345), but the DELETE-query doesn't.

As far as I can see the conditions for this problem occurring are:
- InnoDB storage engine 
- key with more than one value 
- DELETE-query 
- WHERE-clause using ... IN (...) syntax

See http://forums.mysql.com/read.php?22,249112,249112 for details.

How to repeat:
CREATE TABLE test ( 
key1 INT, 
key2 INT, 
PRIMARY KEY (key1, key2) 
) ENGINE=InnoDB;

-- Fill table with 1,000,000 random records

SELECT * FROM test WHERE key1=12345 AND key2=12345; 
Empty set (0.00 sec) 
SELECT * FROM test WHERE (key1, key2) IN ((12345, 12345)); 
Empty set (0.00 sec) 
DELETE FROM test WHERE key1=12345 AND key2=12345; 
Query OK, 0 rows affected (0.00 sec) 
DELETE FROM test WHERE (key1, key2) IN ((12345, 12345)); 
Query OK, 0 rows affected (2.16 sec) -- Takes ridiculous long, doesn't matter if record exists or not.
[3 Mar 2009 18:16] Valeriy Kravchuk
This is a duplicate of bug #43187.