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 计划自动创建数据库分区 固定增量的数据,自动创建 ...
随机推荐
- PostgreSQL创建扩展出错
问题: loraserver_as=# create extension pg_trgm; ERROR: could not open extension control file "/us ...
- 强烈推荐 GitHub 上值得前端学习的开源实战项目
强烈推荐 GitHub 上值得前端学习的开源实战项目. Vue.js vue-element-admin 是一个后台前端解决方案,它基于和 element-ui 实现 基于 iView 的 Vue 2 ...
- GSS4&&花仔游历各国
首先呢,我们想到一种数据结构可以区间开方,一看就不行,但是一看就算是10^18开六次方也只剩一,就不用开根了,所以可以想到用线段树或者分块水过,由于本人 不会用分块,只能用常数巨大的线段树 Code ...
- [程序人生]那些IT界“活久见”的奇葩现象
常言道,人活久了什么稀奇古怪的事都会见到.本文盘点几件刚毕业工作时想当然,工作若干年后啪啪打脸的“奇葩”事. (1)去年推荐一朋友来我们公司面试时,朋友说起当年她去某游戏公司时,那公司HR说这家公司是 ...
- sed命令及替换文件内容
一.sed (三剑客老二) 1.sed 替换文件内容 sed s###g file 前面两个#中的是原内容,后两个#中的是替换的内容 例:将a.txt文件中的linux替换成java 但是,此时 ...
- 【阿里云IoT+YF3300】4.Alink物模型之事件触发
名词解释:设备的功能模型之一,设备运行时的事件,事件一般包含需要被外部感知和处理的通知信息,可包含多个输出参数.如,某项任务完成的信息,或者设备发生故障或告警时的温度等,事件可以被订阅和推送. 在工控 ...
- Java多线程之线程的启动
Java多线程之线程的启动 一.前言 启动线程的方法有如下两种. 利用Thread 类的子类的实例启动线程 利用Runnable 接口的实现类的实例启动线程 最后再介绍下java.util.concu ...
- javascript之操作数组方法
掌握如何操作数组,会让你的开发变得更加高效 1.栈和队列方法(以下四个方法都改变原数组) arr.push() //接受任意类型的参数,逐个添加到数组的末尾,并返回数组的长度 改变原数组 arr.po ...
- spring boot application 配置详情
# =================================================================== # COMMON SPRING BOOT PROPERTIE ...
- Hadoop3.1.2 + Hbase2.2.0 设置lzo压缩算法
Hadoop3.1.2 + Hbase2.2.0 设置lzo压缩算法: 写在前面,在配置hbase使用lzo算法时,在网上搜了很多文章,一般都是比较老的文章,一是版本低,二是一般都是使用hadoop- ...