I would like to know why my DELETE on a MySQL 5.5 myisam table is sooo slow (i had to cancel it)
This SQL takes under a second:
SELECT id FROM backup
WHERE id > 0
AND userId NOT IN
(SELECT id FROM user WHERE state > 0)
ORDER BY id ASC LIMIT 100;
This identical DELETE did not finish afte 2 Minutes (i canceled it)
DELETE FROM backup
WHERE id > 0
AND userId NOT IN
(SELECT id FROM user WHERE state > 0)
ORDER BY id ASC LIMIT 100;
But the following DELETE - querying the SAME ROWS (just now selected by their primary key directly) - took under a second to complete!
DELETE FROM backup WHERE id IN (12, 33, 34, [... 100 ids...])
EDIT I also tried this modification using a sub-subquery - i canceld it after a minute...
DELETE FROM backup WHERE id IN (
SELECT ID FROM (
SELECT id FROM backup WHERE id > 0
AND userId NOT IN (SELECT id FROM user WHERE state > 0)
ORDER BY id ASC LIMIT 100
) a
);
Using INNER JOIN does not work with DELETE as i use ORDER BY.
Any idea?