mysql sql no cache
来源:互联网 发布:h3c路由器查看端口 编辑:程序博客网 时间:2024/04/26 13:31
缓存2(SQL_NO_CACHE和SQL_CACHE的区别)
可以在 SELECT语句中指定查询缓存的选项,对于那些肯定要实时的从表中获取数据的查询,或者对于那些一天只执行一次的查询,我们都可以指定不进行查询缓存,使用SQL_NO_CACHE 选项。
对于那些变化不频繁的表,查询操作很固定,我们可以将该查询操作缓存起来,这样每次执行的时候不实际访问表和执行查询,只是从缓存获得结果,可以有效地改善查询的性能,使用SQL_CACHE 选项。
下面是使用 SQL_NO_CACHE 和 SQL_CACHE 的例子:
mysql> select sql_no_cache id,name from test3 whereid < 2;
mysql> select sql_cache id,name from test3 where id< 2;
注意:查询缓存的使用还需要配合相应得服务器参数的设置。
本文是整理 chapter 5. Advance
1. 何时cache
a)
b) prepared statement永远不会cache到结果,即使参数完全一样。据说在 5.1之后会得到改善。
c) where条件中如包含了某些函数永远不会被cache, 比如current_date,now等。
d) date 之类的函数如果返回是以小时或天级别的,最好先算出来再传进去。
select * from foo where date1=current_date --不会被
select * from foo where date1='2008-12-30' -- 被cache, 正确的做法
e) 太大的result set不会被cache
2. 何时invalidate
a) 一旦表数据进行任何一行的修改,基于该表相关cache立即全部失效。
b) 为什么不做聪明一点判断修改的是否cache的内容?因为分析cache内容太复杂,服务器需要追求最大的性能。
3. 性能
a)
当有大量的查询和大量的修改时,cache机制可能会造成性能下降。因为每次修改会导致系统去做cache失效操作,造成不小开销。
另外系统cache的访问由一个单一的全局锁来控制,这时候大量>的查询将被阻塞,直至锁释放。所以不要简单认为设置cache必定会带来性能提升。
b) 大result set不会被cache的开销
太大的result set不会被cache,但mysql预先不知道resultset的长度,所以只能等到reset set在cache添加到临界值 query_cache_limit之后才会简单的把这个cache
query_cache_min_res_unit = (query_cache_size –Qcache_free_memory) /Qcache_queries_in_cache
4. 内存池使用
mysql
(引用:High Performance
定长:空间浪费
变长:需清理碎片
block 小: 链表超长,访问大块数据效率低。
另外发现 surfchen 的
MYSQL SQL_NO_CACHE的真正含义
that the cache is not used to answer the query.
You may use RESET QUERY CACHE to remove all queries from the cacheand
then your next query should be slow again. Same effect if youchange
the table, because this makes all cached queries invalid.
+----------+
| 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 whereemail = 'hello';
+----------+
| count(*) |
+----------+
| 0 |
+----------+
1 row in set (0.43 sec)
- mysql sql no cache
- mysql SQL cache
- No Cache
- no cache
- Cache-Control no-cache no-store
- Cache-Control: no-cache和no-store
- Request Header (no cache)
- SWF No Cache Solution
- JSP expire/no cache
- nginx no-cache
- mysql主从复制错误sql-running no
- MySQL SQL 分析 - 参数化查询 vs query cache 功能
- Cache-Control: no-cache,Cache-Control: no-store,Pragma: no-cache区别
- Cache-Control: no-cache,Cache-Control: no-store,Pragma: no-cache区别
- response.setHeader("Cache-Control","no-cache"); 作用
- Cache-control”:private、no-cache、max-age
- Cache-Control: no-cache,Cac…
- nginx 配置缓存 no-cache no-store
- Mac开启root用户
- leetcode:Search in Rotated Sorted Array
- WINDOWS编程基础-最简单的windows程序
- 电商行业深度窥探
- Utils.toDip()的用法
- mysql sql no cache
- java中数据类型转换
- 如何在mac下备份mac os x系统
- 27_C# 实现VMS客户端——编码_线程池概念
- 1.写个HelloWorld关于TextView的两种创建方式
- 分享按钮源码
- 黑马程序员-学习笔记-第一天-C语言(正式)-基础知识
- windows的常用路径和环境变量
- ranges建立内表