Mysql caches: Difference between revisions

From wikinotes
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
There are some general MySQL caches, but increasingly they are engine specific.
{{ TODO |
split up this page per database engine, it's hard to read }}
= Documentation =
= Documentation =
<blockquote>
<blockquote>
Line 6: Line 11:
|-
|-
| MyISAM: Key Cache || https://dev.mysql.com/doc/refman/5.7/en/myisam-key-cache.html
| MyISAM: Key Cache || https://dev.mysql.com/doc/refman/5.7/en/myisam-key-cache.html
|-
 
| InnoDB: Buffer Pool || https://dev.mysql.com/doc/refman/5.7/en/innodb-buffer-pool.html
|-
|}
|}
</blockquote><!-- Documentation -->
</blockquote><!-- Documentation -->
Line 14: Line 17:
= General =
= General =
<blockquote>
<blockquote>
== Query Cache (<8.0) ==
{| class="wikitable"
<blockquote>
|-
{{ NOTE |
| [[mysql query cache]]
It is disabled by default starting in MySQL-5.6<br>
|-
https://dev.mysql.com/blog-archive/mysql-8-0-retiring-support-for-the-query-cache/
| [[mysql os cache]]
}}
|-
 
|}
The query cache is a key-value store of cacheable-queries, and their result.<br>
This interferes with benchmarking, since repeat queries may be much faster to lookup.
 
To avoid the query cache:
<syntaxhighlight lang="mysql">
# 1. Add a calculated-function to your selected rows - since they are not cacheable
#    TODO: validate
SELECT ..., NOW() FROM ...
 
# 2. Use 'SQL_NO_CACHE' in your query
#    (This often has not worked for me)
SELECT SQL_NO_CACHE ... FROM ...
</syntaxhighlight>
 
It is implemented as an LRU key-value store for exact (byte-for-byte) query matches.<br>
Each cache entry knows which tables it references for permissions, and cache-invalidation.<br>
Whenever any row is changed in a table, all cache entries using that table are purged.
 
<syntaxhighlight lang="mysql">
SHOW VARIABLES LIKE 'query_cache_type';  # cache is 'ON/OFF/DEMAND'
SHOW VARIABLES LIKE 'query_cache_size';  # max capacity of cache
</syntaxhighlight>
</blockquote><!-- The Query Cache -->
 
== The OS Cache ==
<blockquote>
{{ TODO |
research. Apparently most prominent in MyISAM tables? }}
</blockquote><!-- The OS Cache -->
 
== Table Cache ==
<blockquote>
Used differently by different storage engines.


</blockquote><!-- Table Cache -->
</blockquote><!-- General -->
</blockquote><!-- General -->


= Engine Specific =
= Engine Specific =
<blockquote>
<blockquote>
== InnoDB: Buffer Pool ==
{| class="wikitable"
<blockquote>
|-
Stores calculated hashes, row data, write buffers, locks etc.
| [[mysql innodb caches]]
 
|-
Introspection
| [[mysql myisam caches]]
<syntaxhighlight lang="mysql">
|-
# pages in buffer pool (memory) (16KB/page ?)
|}
select count(*) from information_schema.innodb_buffer_page;
 
 
# ============
E configuration
# =============
 
# bytes per chunk
show variables like 'innodb_buffer_pool_chunk_size';
 
# bytes allowed for buffer pool
show variables like 'innodb_buffer_pool_size';
</syntaxhighlight>
 
Disabling
{{ NOTE |
untested, requires service restart possibly }}
<syntaxhighlight lang="mysql">
# my.cnf
[mysqld]
innodb_buffer_pool_size=1M
key_buffer_size=8
query_cache_type=0
</syntaxhighlight>
</blockquote><!-- InnoDB: Buffer Pool -->
 
== InnoDB: Data Dictionary ==
<blockquote>
 
 
</blockquote><!-- InnoDB: Data Dictionary -->
 
== MyISAM: Key Cache ==
<blockquote>
Key Caches/Buffers store index values, and depend on the OS cache for row data.


</blockquote><!-- MyISAM: Key Cache -->
</blockquote><!-- Engine Specific -->
</blockquote><!-- Engine Specific -->

Latest revision as of 04:25, 8 September 2022

There are some general MySQL caches, but increasingly they are engine specific.

TODO:

split up this page per database engine, it's hard to read

Documentation

MySQL: Query Cache https://dev.mysql.com/doc/refman/5.7/en/query-cache.html
MyISAM: Key Cache https://dev.mysql.com/doc/refman/5.7/en/myisam-key-cache.html

General

mysql query cache
mysql os cache

Engine Specific

mysql innodb caches
mysql myisam caches