SQL结果缓存
来源:互联网 发布:mysql删除语句 编辑:程序博客网 时间:2024/05/16 12:53
最近遇到了一个比较头疼的数据库优化问题,业务需要对一个每天有50w条数据加载的维度表进行实时统计分析,并且统计分析的sql是根据界面选择动态生成的(组合情况太多)。最开始考虑写个过程每天晚上预先统计分析,但是情况太多根本没法预先统计。也考虑过改变表设计使用星型模型,发现转换后数据会翻7倍左右,一天的数据就变成近400w,经过测试根本行不通。然后从索引上想办法,使用了四个全文索引,四个bitmap索引,查询有了比较大的提高。接着sga调整、把表顶在内存(keep pool)、使用大页(hugepage)管理、索引开启并发等。最终一周的统计单条sql在1s以内,基本没有物理读,不过这种sql都是比较消耗cpu的,一致性读比较高,在多用户并发下,性能会降低,比较多,使用LoadRunner测试,发现在50用户并发查询时,平均响应时间在12s多。使用nmon发现,性能的瓶颈在cpu。最后没办法,想到oracle 11g有的sql结果缓存的特性,测试效果还算理想。下面大概总结下结果缓存特性的使用,其实很简单。
相关hint:
RESULT_CACHE、NO_RESULT_CACHE
当你设置RESULT_CACHE_MODE为MANUAL时,如果想缓存SQL结果则必须在SQL中添加RESULT_CACHE这个hint.并且如果你这个SQL的结果已经缓存,下次查询时也必须在sql中有RESULT_CACHE这个hint,数据库才会从缓存的结果集中去结果,否则会从基表中查询。
相关的初始化参数:
RESULT_CACHE_MODE
RESULT_CACHE_MODE = { MANUAL | FORCE }
Default valueMANUAL
ModifiableALTER SESSION
, ALTER SYSTEM
BasicNoRESULT_CACHE_MODE
specifies when a ResultCache
operator is spliced into a query's execution plan.
Values:
MANUAL
The
ResultCache
operator is added only when the query is annotated (that is, hints).FORCE
The
ResultCache
operator is added to the root of allSELECT
statements (provided that it is valid to do so).Note:
FORCE
mode is not recommended because the database and clients will attempt to cache all queries, which may create significant performance and latching overhead. Moreover, because queries that call non-deterministic PL/SQL functions are also cached, enabling the result cache in such a broad-based manner may cause material changes to the results.
For the FORCE
setting, if the statement contains a NO_RESULT_CACHE
hint, then the hint takes precedence over the parameter setting.
RESULT_CACHE_MAX_SIZE
RESULT_CACHE_MAX_SIZE =
integer
[K | M | G]
Default valueDerived from the values of SHARED_POOL_SIZE
, SGA_TARGET
, and MEMORY_TARGET
ModifiableALTER SYSTEM
Range of values0
to operating system-dependentBasicNoOracle RACYou must either set this parameter to 0
on all instances to disable the result cache, or use a nonzero value on all instances. Disabling the result cache on some instances may lead to incorrect results.RESULT_CACHE_MAX_SIZE
specifies the maximum amount of SGA memory (in bytes) that can be used by the Result Cache. Values of this parameter greater than 0
are rounded up to the next multiple of 32 KB. If the value of this parameter is 0
, then the feature is disabled.
相关初始化试图:
V$RESULT_CACHE_DEPENDENCY
V$RESULT_CACHE_MEMORY
V$RESULT_CACHE_OBJECTS
V$RESULT_CACHE_STATISTICS
有人说结果缓存有个缺陷,就是同样的sql,如果执行计划发生变化,可能会有错误的查询结果,这个我还没有验证,待验证。
我做实验发现,对一个表如果执行delete操作,别的用户的查询语句即使加hint(result_cache)结果也是不缓存的。
- SQL结果缓存
- Oracle11新特性——SQL缓存结果集
- Oracle 11g 的PL/SQL函数结果缓存
- Oracle 11g:SQL查询结果集缓存
- memcache实例:缓存一条sql语句的执行结果
- iBATIS SQL Maps之缓存Mapped Statement结果集。
- 结果缓存函数
- mysql结果缓存
- spray-caching缓存结果
- Dubbo结果缓存
- 关于Kylin结果缓存
- 如果在程序中重复调用一句SQL,Sqlserver 服务器会对其结果缓存
- sql缓存
- 支持并发的结果缓存
- 防止JavaScript加载缓存结果
- php 数据结果集缓存
- 支持并发的结果缓存
- 构建高效的结果缓存
- 3d工具收集
- 访问chm文件出现 已取消到该网页的导航的解决方法
- S5PV210(TQ210)学习笔记——USB HOST移植
- linux下vim命令详解
- 您需要TrustedInstaller提供的权限才能对此文件进行更改,解决方案
- SQL结果缓存
- Cygwin的使用
- ios开发环境搭建教程
- 【LeetCode】Search Insert Position
- 大美新疆 - 禾木之恋
- IOS开发 xcode5.1 App打包ipa与真机发布
- 手机定位——传统手机定位技术
- linux切换用户到root,并重置密码
- [3dmax教程] 人物+骨骼+蒙皮+动画教程