Re: Simple query seems to be ignoring date index
Posted by:
Rick James
Date: October 30, 2013 07:47PM
Notice how one EXPLAIN says "Using index"? That means that the entire query could be performed by reading from the index; the data was not needed. The other one did not say that, meaning that it needed to jump back and forth between the index(mdate) and the data.
If it is bouncing back and forth 2488 times, and if the data is scattered around on disk, and if the disk blocks do not happen to be cached in ram, then I would estimate that it would take 2488/100 seconds to run the query. That's 25 seconds; you got
2488 rows in set (12.40 sec)
There are ways to improve the speed of this one query, but they are likely to have impact on other queries. So, let's see all the queries, including the INSERTs/DELETEs/UPDATEs/SELECTs. With that, we can craft a modified schema, and maybe change the queries some, in order to give you better performance overall.
The quick, but dumb, solution is to add
INDEX(date, sym, vol)