關於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的優化MySql優化
- mysql關於mysql.server的總結MySqlServer
- mysql關於variable的總結MySql
- Mysql 關於event的詳解MySql
- 關於MySQL使用的時長MySql
- 關於mysql的最佳化MySql
- mysql~關於mysql分割槽表的測試MySql
- MySQL:關於Bug #81119MySql
- MySQL:關於Bug #20939184MySql
- 關於SHELL+MYSQLMySql
- mysql關於ibdata檔案的理解MySql
- 關於 MySQL 的巢狀事務MySql巢狀
- 面試關於 MySQL 的編寫面試MySql
- Mysql關於procedure、function的詳解MySqlFunction
- mysql 關於exists 和in分析MySql
- mysql關於mysqld_safe的總結MySql
- mysql關於表空間的總結MySql
- 《關於MySQL的一些騷操作》MySql
- MySQL:關於ICP特性的說明(未完)MySql
- mysql關於臨時表的總結MySql
- 關於Mysql索引的資料結構MySql索引資料結構
- mysql關於memory引擎的表的總結MySql
- 關於MySQL中的自聯結的通俗理解MySql
- 關於MySQL核心,一定要知道的!MySql
- MySQL關於事務常見的問題MySql
- 關於Mysql使用的一些總結MySql
- MySQL 關於 INSERT INTO...ON DUPLICATE KEY UPDATE 的使用MySql
- 關於mysql基礎知識的介紹MySql
- MySql關於鎖的一些總結MySql
- 關於MySQL8的WITH查詢學習MySql
- 關於 mysql 中的 rand () 查詢問題MySql
- MySQL 關於Table cache設定MySql
- 關於mysql許可權管理MySql
- mysql關於聚集索引、非聚集索引的總結MySql索引
- 關於 phpMyAdmin 管理 Homestead MySQL 資料庫的配置PHPMySql資料庫
- mysql關於db.opt檔案的總結MySql
- mysql關於字符集character set的總結MySql
- 關於不同的MySQL複製解決方案概述MySql