# how to measure query cache by queries ?

**URL:** <https://forums.percona.com/t/how-to-measure-query-cache-by-queries/1408>\
**Category:** Other MySQL® Questions\
**Created:** [May 14, 2010, 11:09am UTC](https://forums.percona.com/t/how-to-measure-query-cache-by-queries/1408 "2010-05-14T11:09:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pwlnw](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@pwlnw](https://forums.percona.com/u/pwlnw)\
**Post date:** [May 14, 2010, 11:09am UTC](https://forums.percona.com/t/how-to-measure-query-cache-by-queries/1408/1 "2010-05-14T11:09:33Z")

</div>

Recently I build and install special plugin from this source [http://rpbouman.blogspot.com/2008/07/inspect-query-cahce-usi](http://rpbouman.blogspot.com/2008/07/inspect-query-cahce-usi) ng-mysql.html#links

This seems to work fine (need some trivial code hacking for my 5.1.37 version, can share if anybody need it).

desc MYSQL\_CACHED\_QUERIES;±------------------------±------------±-----±----±--------±------+| Field | Type | Null | Key | Default | Extra |±------------------------±------------±-----±----±--------±------+| STATEMENT\_ID | int(21) | NO | | 0 | || SCHEMA\_NAME | varchar(64) | NO | | | || STATEMENT\_TEXT | longtext | NO | | NULL | || RESULT\_BLOCKS\_COUNT | int(21) | NO | | 0 | || RESULT\_BLOCKS\_SIZE | bigint(21) | NO | | 0 | || RESULT\_BLOCKS\_SIZE\_USED | bigint(21) | NO | | 0 | |±------------------------±------------±-----±----±--------±------+

but if mysql query cache really use LRU [http://en.wikipedia.org/wiki/Cache\_algorithms#Least\_Recently](http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently) \_Used algorithm (there are many sources in internet with this opinion), there must be hits counter or age value or linked list order must be moving frequently .  
But it doesn’t : you can select without order and see stable orded. you can produce query hit many times, but nothing changes.

I think mysql use “Least Recently Inserted” algorithm. Am I right?

So I have questions:

Does mysql really use LRU strategy for query cache ?  
Is existing realization good enough for general use ?  
Any other realization of query cache available in public ?

---

<div class="post-metadata">

**Author:** ![xaprb](https://avatars.discourse-cdn.com/v4/letter/x/49beb7/32.png) [@xaprb](https://forums.percona.com/u/xaprb)\
**Post date:** [May 14, 2010, 4:01pm UTC](https://forums.percona.com/t/how-to-measure-query-cache-by-queries/1408/2 "2010-05-14T16:01:39Z")

</div>

I think you’re right, but I don’t remember the code very well. However, the code has a novel’s worth of comments at the top of the file. It should be easy for you to inspect and see. Post back whatever you learn!

---

<div class="post-metadata">

**Author:** ![pwlnw](https://avatars.discourse-cdn.com/v4/letter/p/4af34b/32.png) [@pwlnw](https://forums.percona.com/u/pwlnw)\
**Post date:** [May 14, 2010, 4:55pm UTC](https://forums.percona.com/t/how-to-measure-query-cache-by-queries/1408/3 "2010-05-14T16:55:37Z")

</div>

ok, i move forward a bit :

1. yes, LRU really used by mysql query cache. every block move at top of linked list when cache hit. But this plugin cycle other data structure - query hash. So, for analyze hits I need wrote another plugin code. This is not good.

2. Many people think than query cache is a performance break. They even make joke site ( [URL][http://mituzas.lt/2009/07/08/query-cache-tuning/[/URL]](http://mituzas.lt/2009/07/08/query-cache-tuning/%5B/URL%5D)).  
Why ? My mysql installations are not concurrent enough and I couldn’t confirm this “joke”. if I turn of cache, this cause increasing small amount of cpu time.

3. still no other implementation of cache…
