標籤:
當我們想用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)
MYSQL SQL_NO_CACHE的真正含義