tags:

views:

297

answers:

3

When I run a large MySQL query that inserts 50k records (with 10 small columns) into the database, my query cache usage spikes from around 10MB to 400MB. Is MySQL caching my insert?

A: 

It's probably updating its caches that are in memory. If it's a table that's likely to be in cache, then MySQL might be trying to keep up to date.

Jeremy DeGroot
+1  A: 

The MySQL query cache documentation says:

The query cache stores the text of a SELECT statement together with the corresponding result that was sent to the client. If an identical statement is received later, the server retrieves the results from the query cache rather than parsing and executing the statement again.

It doesn't cache INSERT or other queries.

Greg
+1  A: 

As another user stated, there is a mechanism in MySQL which keeps the cache up to date. When you perform an INSERT which affects previously stored results in the cache, it must either be updated to reflect the new insert, or removed, to be created again later when that SELECT is processed again. I suspect this is what you are seeing.

Another possibility, although more obvious, and hopefully not your issue, is that if you are performing this INSERT with a tool which displays and automatically updates the table, it may be issuing SELECTS after you INSERT.

BigDave