MySQL: Do killed query results get cached

MySQLquery-cache

If a query is executed from the MySQL command line, then KILLed it while it is running will the query and its partial results* be in the query cache and usable to subsequent runs of the identical query?

For simplicity's sake, let's say this is a plain old SELECT with no subqueries.

The list of exclusions on this page covers cases in which queries will not be cached such as the queried table changing between executions, and certain operations that are by nature not identical, but I do not see interrupted or killed queries listed anywhere. It must not be that a killed query is treated the same as one that ran to completion, but if it met all of the other criteria for caching it would already be cached* before it got killed, so I'm wondering what happens next.

MySQL 5.6


*I'm making several assumptions here.

Best Answer

Yes and no.

The Query cache will not see, much less keep, the partial result. The page you referenced is talking only about the Query cache. The QC is populated only after the complete result is built. This gives a significant boost for a repeat of the identical query. (Similar queries are not helped any by the QC.)

InnoDB's buffer_pool (and the equivalent in MyISAM) caches whatever blocks are read from disk. Blocks that were read from disk before the killed was process will probably still be in RAM. This will provide some performance boost for repeated executions of the same or similar queries, whether killed or not.