GS-PON数据库分区列范围查询优化案例
查询慢的SQL:
with p as(select np.nodecode , np.nodename, d.deviceid, d.devicename, d.loopaddress, p.respara, p.rxcrcerror, p.txcrcerrorfrom perf_t_ponport p,device d, node c,node npwhere p.resid = d.deviceidand d.nodecode = c.nodecodeand c.citynodecode = np.nodecodeand c.nodecode in (SELECT S.NODECODE FROM SINGLEUSERNODEAUTH S WHERE S.NETUSERID = 'admin' AND S.AUTHTYPE = 'VIEW')and d.changetype = 0and p.coltime between trunc(sysdate-1,'dd') and trunc(sysdate,'dd')and p.rxcrcerror is not nulland p.rxcrcerror >0order by p.rxcrcerror desc)select *from pwhere rownum <=10
SQL> explain plan for with p as(2 select np.nodecode , np.nodename, d.deviceid, d.devicename, d.loopaddress, p.respara, p.rxcrcerror, p.txcrcerror3 from perf_t_ponport p,device d, node c,node np4 where p.resid = d.deviceid5 and d.nodecode = c.nodecode6 and c.citynodecode = np.nodecode7 and c.nodecode in (SELECT S.NODECODE FROM SINGLEUSERNODEAUTH S WHERE S.NETUSERID = 'admin' AND S.AUTHTYPE = 'VIEW')8 and d.changetype = 09 and p.coltime between trunc(sysdate-1,'dd') and trunc(sysdate,'dd')10 and p.rxcrcerror is not null11 and p.rxcrcerror >012 order by p.rxcrcerror desc13 )14 select *15 from p16 where rownum <=1017 ;已解释。SQL> select * from table(dbms_xplan.display);PLAN_TABLE_OUTPUT----------------------------------------------------------------------------------------------------Plan hash value: 733587010----------------------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |----------------------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 10 | 3430 | 1125K (19)| 03:45:09 | | ||* 1 | COUNT STOPKEY | | | | | | | || 2 | VIEW | | 133 | 45619 | 1125K (19)| 03:45:09 | | ||* 3 | SORT ORDER BY STOPKEY | | 133 | 22743 | 1125K (19)| 03:45:09 | | ||* 4 | FILTER | | | | | | | ||* 5 | HASH JOIN | | 133 | 22743 | 1125K (19)| 03:45:09 | | ||* 6 | HASH JOIN SEMI | | 133 | 19950 | 1125K (19)| 03:45:08 | | ||* 7 | HASH JOIN | | 219 | 28251 | 1125K (19)| 03:45:08 | | || 8 | NESTED LOOPS | | 219 | 25185 | 1125K (19)| 03:45:08 | | || 9 | PARTITION RANGE ITERATOR | | 219 | 10074 | 1125K (19)| 03:45:03 | KEY | KEY ||* 10 | TABLE ACCESS FULL | PERF_T_PONPORT | 219 | 10074 | 1125K (19)| 03:45:03 | KEY | KE| 11 | TABLE ACCESS BY INDEX ROWID| DEVICE | 1 | 69 | 2 (0)| 00:00:01 | ||* 12 | INDEX UNIQUE SCAN | PK_DEVICE | 1 | | 1 (0)| 00:00:01 | || 13 | TABLE ACCESS FULL | NODE | 1214 | 16996 | 8 (0)| 00:00:01 | | ||* 14 | INDEX RANGE SCAN | SYS_C00543203 | 1167 | 24507 | 10 (0)| 00:00:01 | || 15 | TABLE ACCESS FULL | NODE | 1214 | 25494 | 8 (0)| 00:00:01 | |----------------------------------------------------------------------------------------------------Predicate Information (identified by operation id):---------------------------------------------------1 - filter(ROWNUM<=10)3 - filter(ROWNUM<=10)4 - filter(TRUNC(SYSDATE@!-1,'fmdd')<=TRUNC(SYSDATE@!,'fmdd'))5 - access("C"."CITYNODECODE"="NP"."NODECODE")6 - access("C"."NODECODE"="S"."NODECODE")7 - access("D"."NODECODE"="C"."NODECODE")10 - filter("P"."RXCRCERROR" IS NOT NULL AND "P"."RXCRCERROR">0 AND"P"."COLTIME">=TRUNC(SYSDATE@!-1,'fmdd') AND "P"."COLTIME"<=TRUNC(SYSDATE@!,'fmdd'))12 - access("P"."RESID"="D"."DEVICEID" AND "D"."CHANGETYPE"=0)14 - access("S"."NETUSERID"='admin' AND "S"."AUTHTYPE"='VIEW')已选择36行。
with p as(select np.nodecode , np.nodename, d.deviceid, d.devicename, d.loopaddress, p.respara, p.rxcrcerror, p.txcrcerrorfrom perf_t_ponport p,device d, node c,node npwhere p.resid = d.deviceidand d.nodecode = c.nodecodeand c.citynodecode = np.nodecodeand d.changetype = 0and c.nodecode in (SELECT S.NODECODE FROM SINGLEUSERNODEAUTH S WHERE S.NETUSERID = 'admin' AND S.AUTHTYPE = 'VIEW')and (p.coltime =trunc(sysdate-1,'dd') or p.coltime =trunc(sysdate,'dd') )and p.rxcrcerror is not nulland p.rxcrcerror >0order by p.rxcrcerror desc)select *from pwhere rownum <=10;
SQL> explain plan for with p as(2 select np.nodecode , np.nodename, d.deviceid, d.devicename, d.loopaddress, p.respara, p.rxcrcerror, p.txcrcerror3 from perf_t_ponport p,device d, node c,node np4 where p.resid = d.deviceid5 and d.nodecode = c.nodecode6 and c.citynodecode = np.nodecode7 and d.changetype = 08 and c.nodecode in (SELECT S.NODECODE FROM SINGLEUSERNODEAUTH S WHERE S.NETUSERID = 'admin' AND S.AUTHTYPE = 'VIEW')9 and (p.coltime =trunc(sysdate-1,'dd') or p.coltime =trunc(sysdate,'dd') )10 and p.rxcrcerror is not null11 and p.rxcrcerror >012 order by p.rxcrcerror desc13 )14 select *15 from p16 where rownum <=10;已解释。SQL>SQL> select * from table(dbms_xplan.display);PLAN_TABLE_OUTPUT----------------------------------------------------------------------------------------------------Plan hash value: 2287749996----------------------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |----------------------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 10 | 3430 | 915 (2)| 00:00:11 | | ||* 1 | COUNT STOPKEY | | | | | | | || 2 | VIEW | | 266 | 91238 | 915 (2)| 00:00:11 | | ||* 3 | SORT ORDER BY STOPKEY | | 266 | 45486 | 915 (2)| 00:00:11 | | ||* 4 | HASH JOIN | | 266 | 45486 | 915 (2)| 00:00:11 | | || 5 | TABLE ACCESS FULL | NODE | 1214 | 25494 | 8 (0)| 00:00:01 | | ||* 6 | HASH JOIN RIGHT SEMI | | 267 | 40050 | 905 (2)| 00:00:11 | | ||* 7 | INDEX RANGE SCAN | SYS_C00543203 | 1167 | 24507 | 10 (0)| 00:00:01 | ||* 8 | HASH JOIN | | 437 | 56373 | 895 (2)| 00:00:11 | | || 9 | TABLE ACCESS FULL | NODE | 1214 | 16996 | 8 (0)| 00:00:01 | | || 10 | NESTED LOOPS | | 437 | 50255 | 885 (2)| 00:00:11 | | || 11 | PARTITION RANGE INLIST | | 437 | 20102 | 2 (0)| 00:00:01 |KEY(I) |KEY(I) ||* 12 | TABLE ACCESS FULL | PERF_T_PONPORT | 437 | 20102 | 2 (0)| 00:00:01 |KEY(I) |KEY(I)| 13 | TABLE ACCESS BY INDEX ROWID| DEVICE | 1 | 69 | 2 (0)| 00:00:01 | | ||* 14 | INDEX UNIQUE SCAN | PK_DEVICE | 1 | | 1 (0)| 00:00:01 | | |----------------------------------------------------------------------------------------------------Predicate Information (identified by operation id):---------------------------------------------------1 - filter(ROWNUM<=10)3 - filter(ROWNUM<=10)4 - access("C"."CITYNODECODE"="NP"."NODECODE")6 - access("C"."NODECODE"="S"."NODECODE")7 - access("S"."NETUSERID"='admin' AND "S"."AUTHTYPE"='VIEW')8 - access("D"."NODECODE"="C"."NODECODE")12 - filter("P"."RXCRCERROR" IS NOT NULL AND "P"."RXCRCERROR">0 AND("P"."COLTIME"=TRUNC(SYSDATE@!-1,'fmdd') OR "P"."COLTIME"=TRUNC(SYSDATE@!,'fmdd')))14 - access("P"."RESID"="D"."DEVICEID" AND "D"."CHANGETYPE"=0)已选择34行。
SQL> explain plan for select * from perf_t_ponport p where p.coltime <trunc(sysdate,'dd');已解释。SQL> select * from table(dbms_xplan.display);PLAN_TABLE_OUTPUT----------------------------------------------------------------------------------------------------Plan hash value: 4015217925----------------------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |----------------------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 100 | 4600 | 2 (0)| 00:00:01 | | || 1 | PARTITION RANGE ITERATOR| | 100 | 4600 | 2 (0)| 00:00:01 | 1 | KEY ||* 2 | TABLE ACCESS FULL | PERF_T_PONPORT | 100 | 4600 | 2 (0)| 00:00:01 | 1 | KEY |----------------------------------------------------------------------------------------------------Predicate Information (identified by operation id):---------------------------------------------------2 - filter("P"."COLTIME"<TRUNC(SYSDATE@!,'fmdd'))已选择14行。
SQL> explain plan for select * from perf_t_ponport p where p.coltime > trunc(sysdate-1,'dd') and p.coltime <trunc(sysdate,'dd');已解释。SQL> select * from table(dbms_xplan.display);PLAN_TABLE_OUTPUT----------------------------------------------------------------------------------------------------Plan hash value: 1162550374----------------------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |----------------------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 100 | 4600 | 1637 (37)| 00:00:20 | | ||* 1 | FILTER | | | | | | | || 2 | PARTITION RANGE ITERATOR| | 100 | 4600 | 1637 (37)| 00:00:20 | KEY | KEY ||* 3 | TABLE ACCESS FULL | PERF_T_PONPORT | 100 | 4600 | 1637 (37)| 00:00:20 | KEY |----------------------------------------------------------------------------------------------------Predicate Information (identified by operation id):---------------------------------------------------1 - filter(TRUNC(SYSDATE@!-1,'fmdd')<TRUNC(SYSDATE@!,'fmdd'))3 - filter("P"."COLTIME">TRUNC(SYSDATE@!-1,'fmdd') AND "P"."COLTIME"<TRUNC(SYSDATE@!,'fmdd'))已选择16行。
SQL> explain plan for select * from perf_t_ponport partition(P_20170307) p;已解释。SQL> select * from table(dbms_xplan.display);PLAN_TABLE_OUTPUT----------------------------------------------------------------------------------------------------Plan hash value: 1021280532----------------------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |----------------------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 100 | 4600 | 2 (0)| 00:00:01 | | || 1 | PARTITION RANGE SINGLE| | 100 | 4600 | 2 (0)| 00:00:01 | 85 | 85 || 2 | TABLE ACCESS FULL | PERF_T_PONPORT | 100 | 4600 | 2 (0)| 00:00:01 | 85 |----------------------------------------------------------------------------------------------------已选择9行。
SQL> explain plan for select * from perf_t_ponport p where p.coltime = trunc(sysdate-1,'dd') and p.coltime <trunc(sysdate,'dd');已解释。SQL> select * from table(dbms_xplan.display);PLAN_TABLE_OUTPUT----------------------------------------------------------------------------------------------------Plan hash value: 506920385----------------------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |----------------------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 100 | 4600 | 8 (25)| 00:00:01 | | ||* 1 | FILTER | | | | | | | || 2 | PARTITION RANGE SINGLE| | 100 | 4600 | 8 (25)| 00:00:01 | KEY | KEY ||* 3 | TABLE ACCESS FULL | PERF_T_PONPORT | 100 | 4600 | 8 (25)| 00:00:01 | KEY | KE----------------------------------------------------------------------------------------------------Predicate Information (identified by operation id):---------------------------------------------------1 - filter(TRUNC(SYSDATE@!-1,'fmdd')<TRUNC(SYSDATE@!,'fmdd'))3 - filter("P"."COLTIME"=TRUNC(SYSDATE@!-1,'fmdd') AND "P"."COLTIME"<TRUNC(SYSDATE@!,'fmdd'))已选择16行。
SQL> explain plan for select * from perf_t_ponport p where p.coltime = trunc(sysdate-1,'dd') or p.coltime = trunc(sysdate,'dd');已解释。SQL> select * from table(dbms_xplan.display);PLAN_TABLE_OUTPUT----------------------------------------------------------------------------------------------------Plan hash value: 2473962793----------------------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |----------------------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 100 | 4600 | 2 (0)| 00:00:01 | | || 1 | PARTITION RANGE INLIST| | 100 | 4600 | 2 (0)| 00:00:01 |KEY(I) |KEY(I) ||* 2 | TABLE ACCESS FULL | PERF_T_PONPORT | 100 | 4600 | 2 (0)| 00:00:01 |KEY(I) |KEY(I)----------------------------------------------------------------------------------------------------Predicate Information (identified by operation id):---------------------------------------------------2 - filter("P"."COLTIME"=TRUNC(SYSDATE@!-1,'fmdd') OR "P"."COLTIME"=TRUNC(SYSDATE@!,'fmdd'))已选择14行。
SQL> explain plan for select * from perf_t_ponport p where p.coltime >trunc(sysdate-1,'dd') or p.coltime < trunc(sysdate-5,'dd');已解释。SQL> select * from table(dbms_xplan.display);PLAN_TABLE_OUTPUT----------------------------------------------------------------------------------------------------Plan hash value: 3647984539----------------------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |----------------------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 100 | 4600 | 2 (0)| 00:00:01 | | || 1 | PARTITION RANGE ALL| | 100 | 4600 | 2 (0)| 00:00:01 | 1 | 101 ||* 2 | TABLE ACCESS FULL | PERF_T_PONPORT | 100 | 4600 | 2 (0)| 00:00:01 | 1 | 101 |----------------------------------------------------------------------------------------------------Predicate Information (identified by operation id):---------------------------------------------------2 - filter("P"."COLTIME"<TRUNC(SYSDATE@!-5,'fmdd') OR"P"."COLTIME">TRUNC(SYSDATE@!-1,'fmdd'))已选择15行。
SQL> explain plan for select * from perf_t_ponport p where p.coltime >trunc(sysdate-1,'dd') or p.coltime < trunc(sysdate-5,'dd');已解释。SQL> select * from table(dbms_xplan.display);PLAN_TABLE_OUTPUT----------------------------------------------------------------------------------------------------Plan hash value: 470656424----------------------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | Pstart| Pstop |----------------------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 1512M| 67G| 3783K (3)| 12:36:37 | | || 1 | PARTITION RANGE OR| | 1512M| 67G| 3783K (3)| 12:36:37 |KEY(OR)|KEY(OR)||* 2 | TABLE ACCESS FULL| PERF_T_PONPORT | 1512M| 67G| 3783K (3)| 12:36:37 |KEY(OR)|KEY(OR)|----------------------------------------------------------------------------------------------------Predicate Information (identified by operation id):---------------------------------------------------2 - filter("P"."COLTIME"<TRUNC(SYSDATE@!-5,'fmdd') OR"P"."COLTIME">TRUNC(SYSDATE@!-1,'fmdd'))Note------ 'PLAN_TABLE' is old version已选择19行。
GS-PON数据库分区列范围查询优化案例的更多相关文章
- MySql学习(六) —— 数据库优化理论(二) —— 查询优化技术
逻辑查询优化包括的技术 1)子查询优化 2)视图重写 3)等价谓词重写 4)条件简化 5)外连接消除 6)嵌套连接消除 7)连接消除 8)语义优化 9)非SPJ优化 一.子查询优化 1. ...
- (转)mysql水平分表和垂直分表和数据库分区
坚信数据库的物理设计在对高级数据库的性能影响上远比其他因素重要.给大家说一下经过专家对Oracle的研究,他们解释了为什么拙劣的物理设计是数据库停机(无论是有计划的还是没计划的)背后的主要原因.但在这 ...
- MySQL数据库分区的概念与2大好处(1)
我们大家都知道通过MySQL数据库分区(Partition)可以提升MySQL数据库的性能,那么到底什么是MySQL数据库分区呢?以及其实际应用的好处的表现有哪些呢?以下的文章就是对这些内容的描述. ...
- mysql数据库分区功能及实例详解
分区听起来怎么感觉是硬盘呀,对没错除了硬盘可以分区数据库现在也支持分区了,分区可以解决大数据量的处理问题,下面一起来看一个mysql数据库分区功能及实例详解 一,什么是数据库分区 前段时间写过一篇 ...
- DB2 9.5 数据库分区管理及应用实践
DB2 数据库分区是 DB2 企业版 DPF(Data Partitioning Feature)选件提供的,它主要用来为大规模数据处理.高并发数据访问提供支持.DB2 数据库分区采用 Share-n ...
- Atitit.数据库分区的设计 attilax 总结
Atitit.数据库分区的设计 attilax 总结 1. 分区就是分门别类的文件夹 (what)1 2. 分区的好处(y)1 3. 分区原则(要不要分区,何时分区)how2 4. 主要的分表类型有 ...
- SqlServer数据库分区
在最近的项目中,在尽可能优化了sql语句后,上层仍要求对数据库进行优化,因为考虑到系统上线后数据量会非常庞大,而且这些个表的数据都有明显的时间划分,于是就引入了数据库分区的概念.摘用百度百科的定义,数 ...
- MSSQL 2005 列转行应用案例
/*MSSQL 2005 列转行应用案例 By claro(陈亮) 2008-12-2 转载请包含此信息*/ --test table KuCunMX If object_id ('KuCunMX') ...
- sql2008 计划自动创建数据库分区【转】
本文转自:http://jingyan.baidu.com/article/6b97984d9a26ec1ca3b0bf77.html sql2008 计划自动创建数据库分区 固定增量的数据,自动创建 ...
随机推荐
- css3弹性盒子 flex布局
CSS3 弹性盒 1.display:flex 说明: 设置为弹性盒(父元素添加) 2.flex-direction(主轴排列方式) 说明: 顺序指定了弹性子元素在父容器中的位置 row 默认在一行内 ...
- MongoDB 数据库的学习与使用
MongoDB 数据库 一.MongoDB 简介(了解) MongoDB 数据库是一种 NOSQL 数据库,NOSQL 数据库不是这几年才有的,从数据库的初期发展就以及存在了 NOSQL 数据库. ...
- 服务注册发现、配置中心集一体的 Spring Cloud Consul
前面讲了 Eureka 和 Spring Cloud Config,今天介绍一个全能选手 「Consul」.它是 HashiCorp 公司推出,用于提供服务发现和服务配置的工具.用 go 语言开发,具 ...
- Okhttp3源码解析(5)-拦截器RetryAndFollowUpInterceptor
### 前言 回顾: [Okhttp的基本用法](https://www.jianshu.com/p/8e404d9c160f) [Okhttp3源码解析(1)-OkHttpClient分析](htt ...
- 随笔编号-08 MYSQL 存储过程,5分钟执行调用过程;
delimiter //DROP PROCEDUREIF EXISTS jdt.day_instan_data_task// CREATE PROCEDURE jdt.day_instan_data_ ...
- HDU 6044
题意略. 思路: I.对于整个区间a1,....,an,必然有一个区间[1,n]与之对应,因为a1,...,an是1,...,n的一个排列,所以在[1,n]中定然有一个最小的数字1, 如果最大的区间[ ...
- Java多线程之Runnable与Thread
Java多线程之Thread与Runnable 一.Thread VS Runnable 在java中可有两种方式实现多线程,一种是继承Thread类,一种是实现Runnable接口:Thread类和 ...
- python爬取豆瓣首页热门栏目详细流程
记录一下爬取豆瓣热门专栏的经过,通过这篇文章,你能学会requests,HTMLParser,json的基本使用,以及爬取网页内容的基本思路. 使用模块 1,获取豆瓣首页代码:首先我们需要访问豆瓣页面 ...
- 【Linux命令】nohup命令
nohup命令 不挂断的运行,它会使您的脚本被忽略SIGHUP,并重定向stdout/stderr到一个文件nohup.out,以便在您注销后该命令可以在后台继续运行. 1)语法 nohup Comm ...
- HDU - 2255 奔小康赚大钱 KM算法 模板题
HDU - 2255 题意: 分配n所房子给n个家庭,不同家庭对一所房子所需缴纳的钱是不一样的,问你应当怎么分配房子,使得最后收到的钱最多. 思路: KM算法裸题.上模板 #include <i ...