This query takes a split second
select * from tbl1 limit 0,1
This query takes a second
SELECT Distinct(col2) FROM tbl2 WHERE col3 = 2
This query eats 100% cpu and takes 190 seconds duration (0s fetch) to return the result
select * from tbl1 WHERE ID IN (SELECT Distinct(col2) FROM tbl2 WHERE col3 = 2) limit 0,1
I am trying to run this query on the full data set (not just limiting it to one record)
What could be causing the performance problem, my table structures?
Subqueries in MySQL are notoriously slow. You can speed this up with a join:
To update
tbl1: