mySQL index and preparing state
I get a complicate query:
SELECT * FROM ( SELECT Transaction FROM table1 WHERE Transaction IN
(SELECT Transaction FROM table2 WHERE Plugin='XXX' AND Server='XXX') AND
Transaction NOT IN (SELECT Transaction FROM table1 WHERE Detail IN
('Monitor','Version','monitor','version')) ORDER BY Date DESC, Millisecond
DESC LIMIT 10) AS res
I get indexes on table1:Detail and the "Transaction" is the primary key of
table2.
It will take a while(5-10 secs) for the database to return result. So I
create another index on table2:Plugin, the query is fasted now, but a
preparing state shows up and also takes 5-10 secs. So after I create a new
index, the time does not change at all.
Can someone tell me what`s going on and how can I optimize this query?
Thank you!
No comments:
Post a Comment