關於mysql的query_cache
以前看別人的文章也沒有太理解,這兩天測試有個update速度問題,以為是query_cache導致,然後仔細測試了一下才明白其中的道理。
mysql的query_cache是緩衝的是select語句執行計劃及其執行結果的(開頭我還以為僅僅是緩衝執行計劃,受對oracle的理解影響)
而update語句會將query_cache裡邊相關被update表的東西(計劃與資料)清空。
下邊兩個老大算是研究比較清楚,不過只有自己仔細實驗了似乎才理解了
另外Qcache_not_cached是可以記錄DML語句的數量的
順便還看了一下怎麼去檢視select,update,insert語句的計數器,
mysql> show status like '%hits%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Qcache_hits | 7 |
+---------------+-------+
1 row in set (0.01 sec)
mysql> show status like '%Qca%';
+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_free_blocks | 1 |
| Qcache_free_memory | 33543040 |
| Qcache_hits | 7 |
| Qcache_inserts | 5 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 72 |
| Qcache_queries_in_cache | 2 |
| Qcache_total_blocks | 6 |
+-------------------------+----------+
8 rows in set (0.01 sec)
mysql> update a set a = a+1;
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> show status like '%Qca%';
+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_free_blocks | 1 |
| Qcache_free_memory | 33545600 |
| Qcache_hits | 7 |
| Qcache_inserts | 5 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 73 |
| Qcache_queries_in_cache | 0 |
| Qcache_total_blocks | 1 |
+-------------------------+----------+
8 rows in set (0.00 sec)
mysql> show status like '%hits%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Qcache_hits | 7 |
+---------------+-------+
1 row in set (0.00 sec)
mysql> show status like '%hits%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Qcache_hits | 7 |
+---------------+-------+
1 row in set (0.00 sec)
mysql> show status like '%Qca%';
+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_free_blocks | 1 |
| Qcache_free_memory | 33545600 |
| Qcache_hits | 7 |
| Qcache_inserts | 5 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 76 |
| Qcache_queries_in_cache | 0 |
| Qcache_total_blocks | 1 |
+-------------------------+----------+
8 rows in set (0.00 sec)
mysql> select a from a;
+------+
| a |
+------+
| 4 |
| 5 |
+------+
2 rows in set (0.00 sec)
mysql> show status like '%Qca%';
+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_free_blocks | 1 |
| Qcache_free_memory | 33544064 |
| Qcache_hits | 7 |
| Qcache_inserts | 6 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 77 |
| Qcache_queries_in_cache | 1 |
| Qcache_total_blocks | 4 |
+-------------------------+----------+
8 rows in set (0.01 sec)
mysql> select a from a;
+------+
| a |
+------+
| 4 |
| 5 |
+------+
2 rows in set (0.00 sec)
mysql> show status like '%hits%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Qcache_hits | 8 |
+---------------+-------+
1 row in set (0.00 sec)
mysql> show status like '%Qca%';
+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_free_blocks | 1 |
| Qcache_free_memory | 33544064 |
| Qcache_hits | 8 |
| Qcache_inserts | 6 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 79 |
| Qcache_queries_in_cache | 1 |
| Qcache_total_blocks | 4 |
+-------------------------+----------+
8 rows in set (0.01 sec)
mysql> select a,b from a;
+------+------+
| a | b |
+------+------+
| 4 | 2 |
| 5 | 3 |
+------+------+
2 rows in set (0.00 sec)
mysql> show status like '%Qca%';
+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_free_blocks | 1 |
| Qcache_free_memory | 33543040 |
| Qcache_hits | 8 |
| Qcache_inserts | 7 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 80 |
| Qcache_queries_in_cache | 2 |
| Qcache_total_blocks | 6 |
+-------------------------+----------+
8 rows in set (0.00 sec)
mysql> create table b (a int,b int);
Query OK, 0 rows affected (0.00 sec)
mysql> create table b (a int,b int);
ERROR 1050 (42S01): Table 'b' already exists
mysql> show status like '%Qca%';
+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_free_blocks | 1 |
| Qcache_free_memory | 33543040 |
| Qcache_hits | 8 |
| Qcache_inserts | 7 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 81 |
| Qcache_queries_in_cache | 2 |
| Qcache_total_blocks | 6 |
+-------------------------+----------+
8 rows in set (0.01 sec)
mysql> insert into b values (1,2);
Query OK, 1 row affected (0.00 sec)
mysql> show status like '%Qca%';
+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_free_blocks | 1 |
| Qcache_free_memory | 33543040 |
| Qcache_hits | 8 |
| Qcache_inserts | 7 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 82 |
| Qcache_queries_in_cache | 2 |
| Qcache_total_blocks | 6 |
+-------------------------+----------+
8 rows in set (0.00 sec)
mysql> insert into b values (2,3);
Query OK, 1 row affected (0.00 sec)
mysql> show status like '%Qca%';
+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_free_blocks | 1 |
| Qcache_free_memory | 33543040 |
| Qcache_hits | 8 |
| Qcache_inserts | 7 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 83 |
| Qcache_queries_in_cache | 2 |
| Qcache_total_blocks | 6 |
+-------------------------+----------+
8 rows in set (0.00 sec)
mysql> select a from b;
+------+
| a |
+------+
| 1 |
| 2 |
+------+
2 rows in set (0.00 sec)
mysql> show status like '%Qca%';
+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_free_blocks | 1 |
| Qcache_free_memory | 33541504 |
| Qcache_hits | 8 |
| Qcache_inserts | 8 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 84 |
| Qcache_queries_in_cache | 3 |
| Qcache_total_blocks | 9 |
+-------------------------+----------+
8 rows in set (0.01 sec)
mysql> show status like '%hits%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Qcache_hits | 8 |
+---------------+-------+
1 row in set (0.00 sec)
mysql> select a from b;
+------+
| a |
+------+
| 1 |
| 2 |
+------+
2 rows in set (0.00 sec)
mysql> show status like '%hits%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Qcache_hits | 9 |
+---------------+-------+
1 row in set (0.00 sec)
mysql> update a set a = a+1;
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> show status like '%hits%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| Qcache_hits | 9 |
+---------------+-------+
1 row in set (0.01 sec)
mysql> show status like '%Qca%';
+-------------------------+----------+
| Variable_name | Value |
+-------------------------+----------+
| Qcache_free_blocks | 2 |
| Qcache_free_memory | 33544064 |
| Qcache_hits | 9 |
| Qcache_inserts | 8 |
| Qcache_lowmem_prunes | 0 |
| Qcache_not_cached | 88 |
| Qcache_queries_in_cache | 1 |
| Qcache_total_blocks | 5 |
+-------------------------+----------+
8 rows in set (0.01 sec)
select,update,insert語句的計數器
mysql> show status like '%select%';
+------------------------+-------+
| Variable_name | Value |
+------------------------+-------+
| Com_insert_select | 0 |
| Com_replace_select | 0 |
| Com_select | 10 |
| Select_full_join | 0 |
| Select_full_range_join | 0 |
| Select_range | 0 |
| Select_range_check | 0 |
| Select_scan | 99 |
+------------------------+-------+
8 rows in set (0.01 sec)
mysql> show status like '%update%';
+---------------------+---------+
| Variable_name | Value |
+---------------------+---------+
| Com_update | 4 |
| Com_update_multi | 0 |
| Handler_update | 0 |
| Innodb_rows_updated | 6930012 |
+---------------------+---------+
4 rows in set (0.00 sec)
mysql> update a set a = a+2;
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> show status like '%update%';
+---------------------+---------+
| Variable_name | Value |
+---------------------+---------+
| Com_update | 5 |
| Com_update_multi | 0 |
| Handler_update | 0 |
| Innodb_rows_updated | 6930014 |
+---------------------+---------+
4 rows in set (0.01 sec)
mysql> show status like '%insert%';
+------------------------+---------+
| Variable_name | Value |
+------------------------+---------+
| Com_insert | 4 |
| Com_insert_select | 0 |
| Delayed_insert_threads | 0 |
| Innodb_rows_inserted | 3191778 |
| Qcache_inserts | 9 |
+------------------------+---------+
5 rows in set (0.01 sec)
mysql> insert into a (100,101);
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '100,101)' at line 1
mysql> show status like '%insert%';
+------------------------+---------+
| Variable_name | Value |
+------------------------+---------+
| Com_insert | 4 |
| Com_insert_select | 0 |
| Delayed_insert_threads | 0 |
| Innodb_rows_inserted | 3191778 |
| Qcache_inserts | 9 |
+------------------------+---------+
5 rows in set (0.00 sec)
mysql> insert into a values(100,101);
Query OK, 1 row affected (0.00 sec)
mysql> show status like '%insert%';
+------------------------+---------+
| Variable_name | Value |
+------------------------+---------+
| Com_insert | 5 |
| Com_insert_select | 0 |
| Delayed_insert_threads | 0 |
| Innodb_rows_inserted | 3191779 |
| Qcache_inserts | 9 |
+------------------------+---------+
5 rows in set (0.00 sec)
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/82392/viewspace-144699/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Mysql 查詢快取 query_cacheMySql快取
- 關於MySQLMySql
- 關於mysql的優化MySql優化
- mysql關於mysql.server的總結MySqlServer
- 面試關於 MySQL 的編寫面試MySql
- Mysql 關於event的詳解MySql
- 關於mysql的最佳化MySql
- mysql關於variable的總結MySql
- 關於MySQL使用的時長MySql
- 關於MYSQL flush table的作用MySql
- 【Mysql】關於mysql存入emoji表情的問題MySql
- mysql~關於mysql分割槽表的測試MySql
- 查詢快取(query_cache)的影響快取
- 關於SHELL+MYSQLMySql
- 關於SUNONE+MYSQLNoneMySql
- 關於 MySQL 的巢狀事務MySql巢狀
- Mysql關於procedure、function的詳解MySqlFunction
- 關於mysql連線慢的分析.MySql
- 關於mysql連線的問題MySql
- 關於MySQL的compound-statementSQLMySql
- MySQL 關於毫秒的處理薦MySql
- mysql 關於exists 和in分析MySql
- 【mysql】關於binlog格式MySql
- MySQL:關於ICP特性的說明(未完)MySql
- 《關於MySQL的一些騷操作》MySql
- mysql關於臨時表的總結MySql
- 關於Mysql索引的資料結構MySql索引資料結構
- mysql關於mysqld_safe的總結MySql
- mysql關於表空間的總結MySql
- mysql關於ibdata檔案的理解MySql
- 關於mysql5.6 的排序問題.MySql排序
- 關於MySQL的一些小見解MySql
- 關於mysql 1067的錯誤MySql
- 關於MySQL event的一些整理MySql
- 【MySQL】關於 unauthenticated user的哲學思考MySql
- mysql關於memory引擎的表的總結MySql
- 【Mysql】關於一個mysql的坑比時區問題MySql
- MySQL 關於Table cache設定MySql