mariadb cache

Since MariaDB Galera cluster versions 5.5.40 and 10.0.14 you can use the query cache. Earlier versions do NOT support the query cache.

See https://mariadb.com/kb/en/mariadb/documentation/optimization-and-tuning/buffers-caches-and-threads/query-cache/#limitations

 

http://www.fromdual.com/regularly-flushing-mysql-query-cache

 

 

Mariadb 5.5.31 and the new incredible query cache information plugin

 

Hi guys, i was reading the new query cache plugin from Roland Bouman, now default in mariadb-5.5.31
This is a very old feature request at mysql (27 Oct 2006 12:31):
http://bugs.mysql.com/bug.php?id=23714

And recent mariadb (thanks Sergei reading my MDEV =) ) (2012-05-04 01:22)
https://mariadb.atlassian.net/browse/MDEV-249

Well this is a very nice piece of code...
Every time i google about "mysql performace", "mysql cache" etc ... i get something like this:
http://www.cyberciti.biz/tips/how-does-query-caching-in-mysql-works-and-how-to-find-find-out-my-mysql-query-cache-is-working-or-not.html
or this:
http://stackoverflow.com/questions/4139936/query-cache-efficiency

But... What global statistics tell you about your specific query? How you know if your query is cached? You can do this via status variables, but you may not know if your cache have a good global cache hit for only one query, or only one database.

Well mariadb plugin tell you some infomations about what you need... but less information that might be usefull for a good query/table statistic
You can read the query and the size of query in cache memory. What this tell about "is my query qith a high hit rate?"? hum... this tell you have the query inside query cache, that's the only information...

Reading more and studying mariadb source code, i created a patch... at MDEV-4581 (https://mariadb.atlassian.net/browse/MDEV-4581), ok mariadb guys i don't know how to use lauchpad to help mariadb yet, but you can use the patch =)

well i will not explain statistics, let's show the results for 4 queries in cache:

SELECT
query_hits/(select max(query_hits) from query_cache_queries)*100 as p_query_hit,
select_expend_time_ms/(select max(select_expend_time_ms) from query_cache_queries)*100 as p_select_expend_time_ms,
select_rows_read/(select max(select_rows_read) from query_cache_queries)*100 AS p_select_rows_read,
result_found_rows/(select max(result_found_rows) from query_cache_queries)*100 AS p_result_found_rows,
select_rows_read/(select max(select_rows_read) from query_cache_queries)*100 AS p_select_rows_read,

`ENTRY_POSITION_IN_CACHE`,
`STATEMENT_SCHEMA`,
`STATEMENT_TEXT`,
`RESULT_FOUND_ROWS`, `QUERY_HITS`, `SELECT_EXPEND_TIME_MS`,
`SELECT_LOCK_TIME_MS`, `SELECT_ROWS_READ`, `TABLES`,
from_unixtime(`QUERY_INSERT_TIME`) as time, `RESULT_LENGTH`, `RESULT_BLOCKS_COUNT`, `RESULT_BLOCKS_SIZE`, `RESULT_BLOCKS_SIZE_USED`, `RESULT_TABLES_TYPE`, `FLAGS_CLIENT_LONG_FLAG`, `FLAGS_CLIENT_PROTOCOL_41`, `FLAGS_PROTOCOL_TYPE`, `FLAGS_MORE_RESULTS_EXISTS`, `FLAGS_IN_TRANS`, `FLAGS_AUTOCOMMIT`, `FLAGS_PKT_NR`, `FLAGS_CHARACTER_SET_CLIENT_NUM`, `FLAGS_CHARACTER_SET_RESULTS_NUM`, `FLAGS_COLLATION_CONNECTION_NUM`, `FLAGS_LIMIT`, `FLAGS_SQL_MODE`, `FLAGS_MAX_SORT_LENGTH`, `FLAGS_GROUP_CONCAT_MAX_LEN`, `FLAGS_DIV_PRECISION_INCREMENT`, `FLAGS_DEFAULT_WEEK_FORMAT`

FROM `information_schema`.`QUERY_CACHE_QUERIES`
ORDER BY statement_schema,`QUERY_HITS`

You can see the result if you have a very very big monitor =)

p_query_hitp_select_expend_time_msp_select_rows_readp_result_found_rowsp_select_rows_readENTRY_POSITION_IN_CACHESTATEMENT_SCHEMASTATEMENT_TEXTRESULT_FOUND_ROWSQUERY_HITSSELECT_EXPEND_TIME_MSSELECT_LOCK_TIME_MSSELECT_ROWS_READTABLEStimeRESULT_LENGTHRESULT_BLOCKS_COUNTRESULT_BLOCKS_SIZERESULT_BLOCKS_SIZE_USEDRESULT_TABLES_TYPEFLAGS_CLIENT_LONG_FLAGFLAGS_CLIENT_PROTOCOL_41FLAGS_PROTOCOL_TYPEFLAGS_MORE_RESULTS_EXISTSFLAGS_IN_TRANSFLAGS_AUTOCOMMITFLAGS_PKT_NRFLAGS_CHARACTER_SET_CLIENT_NUMFLAGS_CHARACTER_SET_RESULTS_NUMFLAGS_COLLATION_CONNECTION_NUMFLAGS_LIMITFLAGS_SQL_MODEFLAGS_MAX_SORT_LENGTHFLAGS_GROUP_CONCAT_MAX_LENFLAGS_DIV_PRECISION_INCREMENTFLAGS_DEFAULT_WEEK_FORMAT
null1001,78573,57141,78570dev_cadastrosSELECT SQL_CACHE SQL_SMALL_RESULT moeda FROM moedas10101`dev_cadastros`.`moedas`2013-05-25 22:35:52.00091151215501100011888-1335544341024102440
null1001001001001dev_cadastrosSELECT indice,nome,grupo FROM analise_credito_indices ORDER BY grupo,ordem2801156`dev_cadastros`.`analise_credito_indices`2013-05-25 22:35:52.000123411304129801100011888-1335544341024102440
null01,78573,57141,78572sharedSELECT SQL_CACHE SQL_SMALL_RESULT inteiro,inteiros,centavo,centavos,decimais,precisao_fatores,cod_bcb,ultima_alteracao,nome FROM moedas_atual WHERE moeda="R$"10001`shared`.`moedas_atual`2013-05-25 22:35:52.000759182482301100011888-1335544341024102440
null01,78573,57141,78573sharedSELECT SQL_CACHE SQL_SMALL_RESULT fator_venda,fator_compra,ultima_alteracao,nome FROM moedas_atual WHERE moeda="R$"10001`shared`.`moedas_atual`2013-05-25 22:35:52.000393151245701100011888-1335544341024102440



------------
ok you don't have a 180" monitor? here the columns:

p_query_hit
p_select_expend_time_ms
p_select_rows_read
p_result_found_rows
p_select_rows_read
ENTRY_POSITION_IN_CACHE
STATEMENT_SCHEMA
STATEMENT_TEXT
RESULT_FOUND_ROWS
QUERY_HITS
SELECT_EXPEND_TIME_MS
SELECT_LOCK_TIME_MS
SELECT_ROWS_READ
TABLES
 time (it return as unixtime stamp) => QUERY_INSERT_TIME
RESULT_LENGTH
RESULT_BLOCKS_COUNT
RESULT_BLOCKS_SIZE
RESULT_BLOCKS_SIZE_USED
RESULT_TABLES_TYPE
FLAGS_CLIENT_LONG_FLAG
FLAGS_CLIENT_PROTOCOL_41
FLAGS_PROTOCOL_TYPE
FLAGS_MORE_RESULTS_EXISTS
FLAGS_IN_TRANS
FLAGS_AUTOCOMMIT
FLAGS_PKT_NR
FLAGS_CHARACTER_SET_CLIENT_NUM
FLAGS_CHARACTER_SET_RESULTS_NUM
FLAGS_COLLATION_CONNECTION_NUM
FLAGS_LIMIT
FLAGS_SQL_MODE
FLAGS_MAX_SORT_LENGTH
FLAGS_GROUP_CONCAT_MAX_LEN
FLAGS_DIV_PRECISION_INCREMENT
FLAGS_DEFAULT_WEEK_FORMAT


------------
What more you need now?

You can see: how many hits you have in each query
How many time it take to execute if your query cache entry is "lost"
How many rows it read to result and many, many, many others informations
What's the oldest query entry

Humm do you want know what query in table X?
select * from information_schema.query_cache_queries where tables like "%´my_database´.´my_table´%"
And you got all queries from that table
You can do many things now =)

Now, we have a nice (very nice) tool to improve query cache statistics =)

Thanks Sergei from Mariadb with mariadb source code help, and many many thanks to Roland Bouman with this nice peace of code

New life to query cache!

转载于:https://www.cnblogs.com/jvava/p/4239353.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值