Hi I have a query like this
SELECT (SELECT CSN FROM apps as b WHERE
a.key1=b.key1 AND a.key2 = b.key2 AND b.seq=MAX(b.seq) LIMIT 0,1) AS CSN,
a.key1
FROM apps as a GROUP BY key1, key2
Now when I use EXPLAIN I get that the type is range and extras is 'Using index for group-by'. This plan takes 10 seconds to complete on a 350 000 row table. Sometimes however it starts to take only 4 seconds, and the execution plan is type: index and extra: using where
So the question is why is this happening that once the plan is the first and once the second, and can I alter the plan somehow?
Okey I figured it out. The InnoDB statistics were probably off. I called Analyze table to update statistics and it now got back to the lower number.