MYSQL SQL_NO_CACHE的真正含義

當我們想用SQL_NO_CACHE來禁止結果緩存時發現結果和我們的預期不一樣,查詢執行的結果仍然是緩存後的結果。其實,SQL_NO_CACHE的真正作用是禁止緩存查詢結果,但並不意味着cache不作爲結果返回給query。

SQL_NO_CACHE means that the query result is not cached. It does not mean
that the cache is not used to answer the query.

You may use RESET QUERY CACHE to remove all queries from the cache and
then your next query should be slow again. Same effect if you change
the table, because this makes all cached queries invalid.

mysql> select count(*) from users where email = 'hello';
+----------+
| count(*) |
+----------+
| 0 |
+----------+
1 row in set (7.22 sec) 
 
mysql> select count(*) from users where email = 'hello';
+----------+
| count(*) |
+----------+
| 0 |
+----------+
1 row in set (0.45 sec)

mysql> select count(*) from users where email = 'hello';
+----------+
| count(*) |
+----------+
| 0 |
+----------+
1 row in set (0.45 sec)

mysql> select SQL_NO_CACHE count(*) from users where email = 'hello';
+----------+
| count(*) |
+----------+
| 0 |
+----------+
1 row in set (0.43 sec)
發佈了6 篇原創文章 · 獲贊 18 · 訪問量 19萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章