mysql flush cache_mysql的SQL_NO_CACHE(在查询时不使用缓存)和sql_cache用法
轉(zhuǎn)自:http://www.169it.com/article/5994930453423417575.html
為了測(cè)試sql語(yǔ)句的效率,有時(shí)候要不用緩存來(lái)查詢(xún)。
使用
SELECT SQL_NO_CACHE ...
語(yǔ)法即可
SQL_NO_CACHE的真正作用是禁止緩存查詢(xún)結(jié)果,但并不意味著cache不作為結(jié)果返回給query。
目前流傳的SQL_NO_CACHE不外乎兩種解釋:
1.對(duì)當(dāng)前query不使用數(shù)據(jù)庫(kù)已有緩存來(lái)查詢(xún),則當(dāng)前query花費(fèi)時(shí)間會(huì)多點(diǎn)
2.對(duì)當(dāng)前query的產(chǎn)生的結(jié)果集不緩存至系統(tǒng)query cache里,則下次相同query花費(fèi)時(shí)間會(huì)多點(diǎn)
我做了下實(shí)驗(yàn),似乎兩種都對(duì)。
sql_cache意思是說(shuō),查詢(xún)的時(shí)候使用緩存。
對(duì)SQL_NO_CACHE的解釋及測(cè)試如下:
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的對(duì)CACHE的應(yīng)用======================
MyBatis的flushCache和useCache的使用
(1)當(dāng)為select語(yǔ)句時(shí):
flushCache默認(rèn)為false,表示任何時(shí)候語(yǔ)句被調(diào)用,都不會(huì)去清空本地緩存和二級(jí)緩存。
useCache默認(rèn)為true,表示會(huì)將本條語(yǔ)句的結(jié)果進(jìn)行二級(jí)緩存。
(2)當(dāng)為insert、update、delete語(yǔ)句時(shí):
flushCache默認(rèn)為true,表示任何時(shí)候語(yǔ)句被調(diào)用,都會(huì)導(dǎo)致本地緩存和二級(jí)緩存被清空。
useCache屬性在該情況下沒(méi)有。
當(dāng)為select語(yǔ)句的時(shí)候,如果沒(méi)有去配置flushCache、useCache,那么默認(rèn)是啟用緩存的,所以,如果有必要,那么就需要人工修改配置,修改結(jié)果類(lèi)似下面:
……
update 的時(shí)候如果 flushCache="false",則當(dāng)你更新后,查詢(xún)的數(shù)據(jù)數(shù)據(jù)還是老的數(shù)據(jù)。
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的mysql flush cache_mysql的SQL_NO_CACHE(在查询时不使用缓存)和sql_cache用法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 药品价格备案及公示制度(药品价格备案)
- 下一篇: -%3erow mysql_MySQL查