Oracle查询脚本优化
发现生产环境的Oracle数据库cpu使用率上升超过70%,其中一条查询语句达到每秒调用40多次。现在我们来观摩下该语句:
select t.id,t.level,t.policy, t.type,t1.point,t2.channel,t3.user from t_wlf_charge t, t_wlf_point t1, t_wlf_channel t2, (select t4.id,t4.phone user from t_wlf_user t4 where t4.phone=? union select t5.id,t5.city user from t_wlf_city t5 where t5.city=? or t5.city=0) t3 where t.id=t1.id and t.id=t2.id and t.id=t3.id and t.code=? and (t1.point=NVL(?,t1.point) or t1.point=0) and (t2.channel=? or t2.channel=0) order by t.type asc
开始考虑缓存,但发现关联查询缓存命中率是个问题,而且本身重复查询率就低。最后决定通过视图优化以上1主表+5从表的关联查询,先创建视图:
create or replace view v_wlf_charge as select t.id,t.level,t.policy, t.type,t.code,nvl(t1.point,0) point,nvl(t2.channel,0) channel, nvl(t3.phone,0) phone,nvl(t4.city,0) city from t_wlf_charge t left join t_wlf_point t1 on t.id=t1.id left join t_wlf_channel t2 on t.id=t2.id left join t_wlf_phone t3 on t.id=t3.id left join t_wlf_city t4 on t.id=t4.id where t.id is not null
再用这条脚本查:
select id,level,policy, type,point,channel,phone as user from v_wlf_charge where code=? and point in(0,?) and channel in (0,?) and phone in (0,?) and city in (0,?) order by type asc
Oracle查询脚本优化的更多相关文章
- MYSQL 查询脚本优化
业务需要,优化一段多表查询脚本. 总结下来,采取以下步骤. 分析语句 分析语句,了解逻辑,是否可以先优化逻辑. 查询语句的查询范围,是否是全表查询,如果是,尽量优化为按索引查询. 查看语句数量,是否有 ...
- Oracle 查询性能优化(转)
原则一:注意WHERE子句中的连接顺序: ORACLE采用自下而上的顺序解析WHERE子句,根据这个原理,表之间的连接必须写在其他WHERE条件之前, 那些可以过滤掉最大数量记录的条件必须写在WHER ...
- oracle查询性能优化
原文http://www.cnblogs.com/cnjava/archive/2013/02/28/2937699.html 讲解的oracle数据库面对大数据如何优化查询.
- oracle查询SQL优化相当重要
如果表中的时间字段是索引,那么时间字段不要使用函数,函数会使索引失效. 例如: select * from mytable where trunc(createtime)=trunc(sysdate) ...
- Oracle 查询性能优化实践
1.索引使用原则 不要对索引使用全模糊,但是 LIKE 'asdf%'是可以的,即不要Contains,可用StartWith 不要对索引进行函数,表达式操作,或者使用is null判断,否则 ...
- Oracle的分页查询语句优化
Oracle的分页查询语句基本上可以按照本文给出的格式来进行套用. (一) 分页查询格式: SELECT * FROM ( SELECT A.*, ROWNUM RN FROM (SELECT ...
- Oracle DBA 必须掌握的 查询脚本:
Oracle DBA 必须掌握的 查询脚本: 0:启动与关闭 orcle 数据库的启动与关闭 1:连接数据库 2:数据库开启状态的实现步骤: 2-1:启动数据库 2- ...
- 基于Oracle的SQL优化(社区万众期待 数据库优化扛鼎巨著)
基于Oracle的SQL优化(社区万众期待数据库优化扛鼎巨著) 崔华 编 ISBN 978-7-121-21758-6 2014年1月出版 定价:128.00元 856页 16开 编辑推荐 本土O ...
- 转://从一条巨慢SQL看基于Oracle的SQL优化
http://mp.weixin.qq.com/s/DkIPwbDKIjH2FMN13GkT4w 本次分享的内容是基于Oracle的SQL优化,以一条巨慢的SQL为例,从快速解读SQL执行计划.如何从 ...
随机推荐
- Linux.Siggen.180
from: https://vms.drweb.com/virus/?i=15455134&lng=en Linux.Siggen.180 Added to Dr.Web virus data ...
- Gnostice PDFtoolkit VCL的安装
Installation and Uninstallation For New Users Close all open applications including the IDE. Run the ...
- oracle 10g和11g将表到缓存到内存中
alter table 表名 cache;alter table 表名 storage(buffer_pool keep);
- FZU 1759 Super A^B mod C 指数循环节
Problem 1759 Super A^B mod C Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description G ...
- LeetCode第[48]题(Java):Rotate Image
题目:矩阵旋转 难度:Medium 题目内容: You are given an n x n 2D matrix representing an image. Rotate the image by ...
- .Net Core使用jexus配置https
今天搞了一下怎么从http换成https,写一篇博客记录该过程.关于jexus的安装和使用请看我之前的一篇博客<Jexus部署Asp.Net Core项目>,唯一的不同是,将jexus升级 ...
- Oracle的导出和导入
(摘自:http://www.cnblogs.com/mchina/archive/2012/09/12/2678093.html) 数据库的备份操作是在整个项目运行中最重要的工作之一. 一.数据的导 ...
- IIS(IISReset.exe)命令行
(转自:http://www.cnblogs.com/itech/archive/2009/05/18/1459231.html) 一 IIS命令行 Iisreset.exe 的概述 Iisreset ...
- flask_sqlalchemy + sqlite 的一系列使用方法
如何使用在官网上有详细记录 :http://flask-sqlalchemy.pocoo.org/2.3/ 作为项目笔记,简单阐述使用方法: 1.创建flask_sqlalchemy基于sqlite的 ...
- [eShopOnContainers 学习系列] - Index - 开篇索引
[资料] 学习资料来源于 eShopOnContainers wiki 以及 微软官方微服务架构指南 [eShopOnContainers 学习系列] - 00 - 开发环境需求 [eShopOnCo ...