mysql no cache_mysql的SQL_NO_CACHE(在查询时不使用缓存)和sql_cache用法
轉(zhuǎn)自:http://www.169it.com/article/5994930453423417575.html
為了測試sql語句的效率,有時候要不用緩存來查詢。
使用
SELECT SQL_NO_CACHE ...
語法即可
SQL_NO_CACHE的真正作用是禁止緩存查詢結(jié)果,但并不意味著cache不作為結(jié)果返回給query。
目前流傳的SQL_NO_CACHE不外乎兩種解釋:
1.對當(dāng)前query不使用數(shù)據(jù)庫已有緩存來查詢,則當(dāng)前query花費(fèi)時間會多點(diǎn)
2.對當(dāng)前query的產(chǎn)生的結(jié)果集不緩存至系統(tǒng)query cache里,則下次相同query花費(fèi)時間會多點(diǎn)
我做了下實(shí)驗(yàn),似乎兩種都對。
sql_cache意思是說,查詢的時候使用緩存。
對SQL_NO_CACHE的解釋及測試如下:
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)
================MyBatis的對CACHE的應(yīng)用======================
MyBatis的flushCache和useCache的使用
(1)當(dāng)為select語句時:
flushCache默認(rèn)為false,表示任何時候語句被調(diào)用,都不會去清空本地緩存和二級緩存。
useCache默認(rèn)為true,表示會將本條語句的結(jié)果進(jìn)行二級緩存。
(2)當(dāng)為insert、update、delete語句時:
flushCache默認(rèn)為true,表示任何時候語句被調(diào)用,都會導(dǎo)致本地緩存和二級緩存被清空。
useCache屬性在該情況下沒有。
當(dāng)為select語句的時候,如果沒有去配置flushCache、useCache,那么默認(rèn)是啟用緩存的,所以,如果有必要,那么就需要人工修改配置,修改結(jié)果類似下面:
……
update 的時候如果 flushCache="false",則當(dāng)你更新后,查詢的數(shù)據(jù)數(shù)據(jù)還是老的數(shù)據(jù)。
總結(jié)
以上是生活随笔為你收集整理的mysql no cache_mysql的SQL_NO_CACHE(在查询时不使用缓存)和sql_cache用法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 音频知识点(5)- VAD/CNG/DT
- 下一篇: 利用批处理一键卸载Win10Win11系