I have a column “name” in a table and there are at least 10 million records. I’ve added an index on this name column. Now, for the first initial few searches, it was taking more than 10 seconds to return a single answer (whether the name was present or not) but suddenly, it gives me the result in less than 0.1 seconds. Am I missing something? I know MySQL maintains a cache of the recent queries but the queries I am trying are pretty random… Any ideas as to why this is happening?
Share
Your query is simply warming the index caches. This has nothing to do with the query cache. InnoDB indexes particularly take some hits to warm up as their the index cardinality values are not stored in the table files. The initial queries will popluate the InnoDB buffer pool with the index data they encounter as defined by the value specified by innodb_buffer_pool_size in my.cnf. Though less important for MyISAM tables, the value key_buffer_size can be adjusted similarly.
MySQL’s InnoDB performance tunning chapter provides a good entry point into figure out what is going on:
http://dev.mysql.com/doc/refman/5.0/en/innodb-tuning.html