views:

31

answers:

1

I am executing a mysql SELECT statement which takes 30 seconds to run the first time, but then just takes .2 all times after that.

I thought clearing the query cache would resolve the problem (RESET QUERY CACHE), but it still takes .2 seconds after that. Only restarting the server reverts the query back to taking 30 seconds, but then it takes .2 after that first run too. Adding SQL_NO_CACHE does not work either.

Query:

SELECT id FROM tblOne WHERE szAddress = '123 Main Street' AND szCity = 'LAS VEGAS' AND szStateCode = 'NV'

EXPLAIN:

"id","select_type","table","type","possible_keys","key","key_len","ref","rows","Extra"
1,"SIMPLE","tblOne","ref","szCity_2,idx_state_active","szCity_2","52","const",62620,"Using where"

Is there another way to get this to repeatedly run slowly (without restarting the server) so I can test adding new indexes and their performance?

I was planning on adding an address or an address+city+state index.

A: 

SQL_NO_CACHE should be the way to do it. I did stumble upon something in the configuration that lets you change if it honors that or not though, so you could check that.

Also, http://www.mysqlperformanceblog.com/2007/09/12/query-profiling-with-mysql-bypassing-caches/

E: http://stackoverflow.com/questions/181894/mysql-force-not-to-use-cache-for-testing-speed-of-query has a couple of other solutions to the same problem.

zebediah49
The first link gave me the info I needed, I am using innodb and it seems like the answer is that you need to restart.
Christopher