MySQL Query cache mechanism (2) bitsCN.com
+ --------------- + ------- +
8 rows in set (0.00 sec)
Mysql> select count (*) from animals;
+ ---------- +
| Count (*) |
+ ---------- +
| 6 |
+ ---------- +
1 row in set (0.00 sec)
Mysql> show status like 'qcache % ';
+ --------------- + ------- +
| Variable_name | Value |
+ --------------- + ------- +
| Qcache_hits | 1 | -- indicates that the SQL statement is directly obtained in the cache and does not need to be parsed.
+ --------------- + ------- +
8 rows in set (0.00 sec)
Mysql> select count (*) from animals;
+ ---------- +
| Count (*) |
+ ---------- +
| 6 |
+ ---------- +
1 row in set (0.00 sec)
Mysql> select count (*) from animals;
+ ---------- +
| Count (*) |
+ ---------- +
| 6 |
+ ---------- +
1 row in set (0.00 sec)
Mysql> show status like 'qcache _ hits ';
+ --------------- + ------- +
| Variable_name | Value |
+ --------------- + ------- +
| Qcache_hits | 3 | -- the preceding SQL statement is obtained directly from the cache.
+ --------------- + ------- +
1 row in set (0.00 sec)
Mysql> insert into animals select 9, 'testsds '; -- after data is inserted, all SQL caches related to the table will be cleared.
Query OK, 1 row affected (0.00 sec)
Records: 1 Duplicates: 0 Warnings: 0
Mysql> select count (*) from animals;
+ ---------- +
| Count (*) |
+ ---------- +
| 7 |
+ ---------- +
1 row in set (0.00 sec)
Mysql> show status like 'qcache _ hits ';
+ --------------- + ------- +
| Variable_name | Value |
+ --------------- + ------- +
| Qcache_hits | 3 | -- or equal to 3, indicating that the previous SQL statement was not directly obtained from the cache.
+ --------------- + ------- +
1 row in set (0.00 sec)
Mysql> select count (*) from animals;
+ ---------- +
| Count (*) |
+ ---------- +
| 7 |
+ ---------- +
1 row in set (0.00 sec)
Mysql> show status like 'qcache _ hits ';
+ --------------- + ------- +
| Variable_name | Value |
+ --------------- + ------- +
| Qcache_hits | 4 |
+ --------------- + ------- +
1 row in set (0.00 sec)
BitsCN.com