Bug #1079 Need a way to determine if a statement is in the query cache
Submitted: 18 Aug 2003 12:06 Modified: 21 Aug 2003 2:30
Reporter: [ name withheld ] Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S4 (Feature request)
Version:4.0 OS:Any (Any)
Assigned to: CPU Architecture:Any

[18 Aug 2003 12:06] [ name withheld ]
Description:
I'd like to request a method by which one can ask if a statement is presently in the query cache.  For example:

SELECT IN_QUERY_CACHE("STATEMENT")

The result would be 1 if the statement is in the cache, and 0 if it is not.

How to repeat:
N/A

Suggested fix:
N/A
[21 Aug 2003 2:30] Peter Zaitsev
Michael,

In MySQL 4.1 it will be possible to archive this a bit different way - 

We'll have per thread status variables, and so just by executing the query and comparing status variables values before and after it you'll be able to check if the query was in query cache, as well as if it was inserted to the query cache or not cached for some reason.

I hope this will match your needs.
[21 Aug 2003 10:01] [ name withheld ]
Actually, this is not good enough:

First, we will not know if the statement is cached the first time we query the statement.  We need to know *before* we execute the query.

Second, if the information is only available to the thread executing the statement, other threads executing the same statement will not know that the query was cached before they execute it (unless I provide a global data structure to provide such information, which is a lot of code).