I am no mysql
expert at all but I need to figure out the slowness of following query:
DELETE m,i from Table1 AS m
LEFT JOIN
Table2 AS i
ON m.id = i.id
WHERE m.state='in'
Table1
consist of 600 entries (SELECT COUNT(*) from Table1
took about 0.00 seconds) and Table2
of 202 entries (SELECT COUNT(*) from Table2
took about 0.00 seconds). However, the above JOIN DELETE
query takes about 0.77 seconds.
Is there any way to speed up this DELETE
query without changing the table definition?
I tried to 'index' the columns in question by applying the following three queries before the DELETE
query:
alter table Table1 add index(id);
alter table Table1 add index(state);
alter table Table2 add index(id);
but the above JOIN DELETE
query still takes about the same time! So indexing columns does not seem to have any effect on the effectiveness.
Is this query really so slow? Anything I can do to improve it?
Additional information:
The query
explain select * from Table1 AS m
LEFT JOIN
Table2 AS i
ON m.id = i.id
WHERE m.state='in'
yields the following output:
+----+-------------+-------+------+-----------------------------------------------+-----------+---------+-------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+-----------------------------------------------+-----------+---------+-------+------+-------------+
| 1 | SIMPLE | m | ref | state,state_2,state_3,state_4 | state | 1 | const | 1 | Using where |
| 1 | SIMPLE | i | ALL | id,id_2,id_3 | NULL | NULL | NULL | 2 | |
+----+-------------+-------+------+-----------------------------------------------+-----------+---------+-------+------+-------------+