当前位置:网站首页>A case of 94 SQL optimization (the writing method used is often rejected)
A case of 94 SQL optimization (the writing method used is often rejected)
2022-06-22 22:17:00 【Tiger Liu】
On the customer's production system SQL, The watch is getting bigger and bigger , The execution time is getting longer and longer , But as long as we can get results , As long as it's not too slow to accept , The user basically tolerated .
Many customers' systems are like this , Business SQL Consuming too many system resources , The execution efficiency is still very poor , Most of them have a lot of room for optimization , But many people first think of replacing advanced hardware , I don't know that optimization is the right way ( With a customer EBS Report after several hours of business execution ora-01555 error , The hardware is already very advanced , SQL Optimization is the only way out )
SQL Code ( Has been simplified desensitization treatment ):
select a.*, b.INPTBR as inst_no
from pa_agency a
left join
(
select tc.inptbr, tc.fragid
from book1 tc
union
select tcs.inptbr, tcs.fragid
from book2 tcs
) b
on a.agenid = b.fragid;
Implementation plan ( execution time 38 second ):
It is known that b Result set fragid There is no repetition value . 3 The record numbers of the tables are shown in the execution plan in the above figure . Please think about this SQL How to improve execution efficiency .
Thinking time ....................................................
I'll take this. SQL As an exercise, it was put in the wechat group of students to practice for everyone , Some students have given a better optimization method , The methods of the trainees and mine are listed below :
First of all, they should be created separately book1 and boo2 The two tables fragid Index on field .
The second is the need for sql To rewrite .
Students' rewriting methods :
select a.*,
nvl((select inptbr
from book1 tc
where a.agenid = tc.fragid
and rownum = 1
),
(select inptbr
from book2 tcs
where a.agenid = tcs.fragid
and rownum = 1
)) as inptbr
from pa_agency a;
My rewrite method :
select a.*,
(select inptbr from
(
select tc.inptbr,tc.fragid
from book1 tc
union all
select tcs.inptbr,tcs.fragid
from book2 tcs
) b where a.agenid=b.fragid
and rownum =1
) as inst_no
from pa_agency a ;
Both methods can greatly improve sql Execution efficiency ( It is expected that the execution will be completed in one second ), There are also some subtle differences in the efficiency of the two methods , I wonder if you can see ?
In my previous official account article , There are similar optimization ideas : <74- This kind of SQL Optimize ,oracle I lost it. mysql, How to remedy ?> , Some things are not necessarily bad , Sometimes we can use it for optimization .
( This is the end of this article. )
边栏推荐
- [GWCTF 2019]mypassword XSS
- [ROS introduction] cmakelist Txt and packages XML interpretation
- [icml2022] using virtual nodes to promote graph structure learning
- 【持续更新中...】2021年全国大学生电子设计大赛 (三)匿名四轴拓空者飞控系统设计解读
- Lesson 020: functions: embedded functions and closures | after class test questions and answers
- [recommended by Zhihu knowledge master] castle in UAV - focusing on the application of UAV in different technical fields
- Lesson 032: exception handling: you can't always be right | after class test questions and answers
- 5分钟快速上线Web应用和API(Vercel)
- Rendu stéréo
- PMP Exam admission ticket problems and precautions in June, which must be read by candidates
猜你喜欢

Lesson 019: function: my site listen to my after-school test questions and answers

Redis核心技术与实战:学习总结目录

Lesson 026: Dictionary: when the index is not easy to use 2 | after class test questions and answers

6-7 图的深度遍历-邻接表实现

勒索病毒横行下设备该如何进行加密防护

IDC發布中國數據治理報告 億信華辰第一

IDC publie le rapport sur la gouvernance des données en Chine

SPA项目开发之首页导航+左侧菜单

6-6 图的广度遍历-邻接矩阵实现

【论文解读】关于基于视觉无人机自主降落平台的论文梳理
随机推荐
The necessary materials for the soft test have been released. All the soft test materials for the whole subject have been prepared for you!
数据科学家是不是特有前途的职业?
5 minutes to quickly launch web applications and APIs (vercel)
Query es page subscript exceeds 10000
Shell (34): Time
微软 Edge 浏览器将支持网络测速,内置计算器和单位转换工具
如何在物联网低代码平台中使用数据字典功能?
[ongoing update...] 2021 National Electronic Design Competition for college students (III) interpretation of the anonymous four axis space developer flight control system design
Redis core technology and practice: learning summary directory
2022年6月25日PMP考试通关宝典-6
NIO复制文件调用getChannel方法 transferFrom()
Lesson 018: function: flexible is powerful after class test questions and answers
Redis-分布式锁
6-3 二叉树的非递归遍历
7-1 前序序列创建二叉树
6-7 图的深度遍历-邻接表实现
The machine that lies in the 52nd monthly race of Niuke (the complexity of interval assignment operation from O (n^2) to o (n))
TC397 Flash
CSV add a new column
IDC发布中国数据治理报告 亿信华辰第一