GS-PON数据库分区列范围查询优化案例
查询慢的SQL:
with p as(
select np.nodecode , np.nodename, d.deviceid, d.devicename, d.loopaddress, p.respara, p.rxcrcerror, p.txcrcerror
from perf_t_ponport p,device d, node c,node np
where p.resid = d.deviceid
and d.nodecode = c.nodecode
and c.citynodecode = np.nodecode
and c.nodecode in (SELECT S.NODECODE FROM SINGLEUSERNODEAUTH S WHERE S.NETUSERID = 'admin' AND S.AUTHTYPE = 'VIEW')
and d.changetype = 0
and p.coltime between trunc(sysdate-1,'dd') and trunc(sysdate,'dd')
and p.rxcrcerror is not null
and p.rxcrcerror >0
order by p.rxcrcerror desc
)
select *
from p
where rownum <=10
SQL> explain plan for with p as(
2 select np.nodecode , np.nodename, d.deviceid, d.devicename, d.loopaddress, p.respara, p.rx
crcerror, p.txcrcerror
3 from perf_t_ponport p,device d, node c,node np
4 where p.resid = d.deviceid
5 and d.nodecode = c.nodecode
6 and c.citynodecode = np.nodecode
7 and c.nodecode in (SELECT S.NODECODE FROM SINGLEUSERNODEAUTH S WHERE S.NETUSERID = 'adm
in' AND S.AUTHTYPE = 'VIEW')
8 and d.changetype = 0
9 and p.coltime between trunc(sysdate-1,'dd') and trunc(sysdate,'dd')
10 and p.rxcrcerror is not null
11 and p.rxcrcerror >0
12 order by p.rxcrcerror desc
13 )
14 select *
15 from p
16 where rownum <=10
17 ;
已解释。
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.txcrcerror
from perf_t_ponport p,device d, node c,node np
where p.resid = d.deviceid
and d.nodecode = c.nodecode
and c.citynodecode = np.nodecode
and d.changetype = 0
and 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 null
and p.rxcrcerror >0
order by p.rxcrcerror desc
)
select *
from p
where rownum <=10;
SQL> explain plan for with p as(
2 select np.nodecode , np.nodename, d.deviceid, d.devicename, d.loopaddress, p.respara, p.r
xcrcerror, p.txcrcerror
3 from perf_t_ponport p,device d, node c,node np
4 where p.resid = d.deviceid
5 and d.nodecode = c.nodecode
6 and c.citynodecode = np.nodecode
7 and d.changetype = 0
8 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 null
11 and p.rxcrcerror >0
12 order by p.rxcrcerror desc
13 )
14 select *
15 from p
16 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.c
oltime = 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.c
oltime < 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.c
oltime < 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 计划自动创建数据库分区 固定增量的数据,自动创建 ...
随机推荐
- 谈谈JVM垃圾回收
概述 Java运行时区域中,程序计数器,虚拟机栈,本地方法栈三个区域随着线程的而生,随线程而死,这几个区域的内存分配和回收都具备确定性,不需要过多考虑回收问题.而Java堆和方法区则不一样,一个接口的 ...
- Java 学习笔记---Java double类型相加问题
多个double类型的数直接相加的时候,可能存在精度误差.( 由于计算机算法以及硬件环境决定只能识别 0 1.计算机默认的计算结果在都在一个指定精度范围之内,想往深的了解,可以学习数值分析等) 在金融 ...
- Java中synchronized关键字你知道多少
1.什么是synchronized 我们将其理解为同步锁,可以实现共享资源的同步访问,解决线程并发的安全问题.synchronize翻译成中文:同步,使同步.synchronized:已同步. 1.1 ...
- Java中时间格式处理,指定N天/小时等之后的时间
1)根据当前时间,获取具体的时刻的时间 N天前 M小时之前 可用 new Date().getTime() - 24 * 60 * 60 * 1000*N[N天之前]的方法来获取处理时间之后的具体的值 ...
- C#开发BIMFACE系列6 服务端API之获取文件信息
在<C#开发BIMFACE系列4 服务端API之源上传文件>.<C#开发BIMFACE系列5 服务端API之文件直传>两篇文章中详细介绍了如何将本地文件上传到BIMFACE服务 ...
- Java利用Apache poi导出图表
jar compile('org.apache.poi:poi:4.0.1') compile('org.apache.poi:poi-scratchpad:4.0.1') compile('org. ...
- Codeforces 940D
题意略. 这道题目在比赛的时候怎么想也没想明白,后来看了别人的题解才顿悟,可以说很辣鸡了. 只有b[i - 1],b[i - 2],b[i - 3],b[i - 4]相等的时候才能对答案产生限制,否则 ...
- [转]Android ImageView的scaleType属性与adjustViewBounds属性
Android ImageView的scaleType属性与adjustViewBounds属性 ImageView的scaleType的属性有好几种,分别是matrix(默认).center.c ...
- 在SpringMVC中,jsp和后台互相传值
如题,这个是以前做的笔记,现在搬到博客上...... package com.ruide.action; import java.util.HashMap; import java.util.Ma ...
- Keras(五)LSTM 长短期记忆模型 原理及实例
LSTM 是 long-short term memory 的简称, 中文叫做 长短期记忆. 是当下最流行的 RNN 形式之一 RNN 的弊端 RNN没有长久的记忆,比如一个句子太长时开头部分可能会忘 ...