On a mysql database (running on Linux) I do the following query:
delete m,i from Table1 AS m
LEFT JOIN
Table2 AS i
ON m.GUID = i.OutId
WHERE m.Direction='in'
AND m.Id<4294967296
which takes a time of almost 2 minutes! There were 458 entries in Table1
and 5659 entries in Table2
.
Why does this query consume so much time? The COUNT
query to count the elements in Table2
just used 0.24 seconds for comparison.
How can I speed up this query? Which parts are the time consuming?
Additional information:
- I am no
sql
expert - I tried to add indexes to the table by running
alter table Table add index (GUID);
(and similar commands for the other columns), but it seems it has no effect on the time consumption. Am I doing something wrong here? - The 'optimization' or whatever must be done without altering the table structure.