1. 程式人生 > >【轉】mysql的SQL_NO_CACHE(在查詢時不使用緩存)和sql_cache用法

【轉】mysql的SQL_NO_CACHE(在查詢時不使用緩存)和sql_cache用法

his let 作用 upd 做了 ble effect table mea

轉自:http://www.169it.com/article/5994930453423417575.html

為了測試sql語句的效率,有時候要不用緩存來查詢。 使用 SELECT SQL_NO_CACHE ... 語法即可 SQL_NO_CACHE的真正作用是禁止緩存查詢結果,但並不意味著cache不作為結果返回給query。 目前流傳的SQL_NO_CACHE不外乎兩種解釋: 1.對當前query不使用數據庫已有緩存來查詢,則當前query花費時間會多點 2.對當前query的產生的結果集不緩存至系統query cache裏,則下次相同query花費時間會多點 我做了下實驗,似乎兩種都對。 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的應用====================== MyBatis的flushCache和useCache的使用 轉自:http://blog.csdn.net/ssssny/article/details/52248960 (1)當為select語句時: flushCache默認為false,表示任何時候語句被調用,都不會去清空本地緩存和二級緩存。 useCache默認為true,表示會將本條語句的結果進行二級緩存。 (2)當為insert、update、delete語句時: flushCache默認為true,表示任何時候語句被調用,都會導致本地緩存和二級緩存被清空。 useCache屬性在該情況下沒有。 當為select語句的時候,如果沒有去配置flushCache、useCache,那麽默認是啟用緩存的,所以,如果有必要,那麽就需要人工修改配置,修改結果類似下面: <select id="save" parameterType="XX" flushCache="true" useCache="false"
> …… </select> update 的時候如果 flushCache="false",則當你更新後,查詢的數據數據還是老的數據。

【轉】mysql的SQL_NO_CACHE(在查詢時不使用緩存)和sql_cache用法