当前位置:网站首页>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. )
边栏推荐
- The third training of Hongmeng
- Shell (34): time
- Es total number of data queried by criteria
- 数据科学家是不是特有前途的职业?
- [recommended by Zhihu knowledge master] castle in UAV - focusing on the application of UAV in different technical fields
- CSV add a new column
- SPA项目开发之CRUD+表单验证
- sitl_ gazebo/include/gazebo_ opticalflow_ plugin. h:43:18: error: ‘TRUE’ was not declared in this scope
- IDC publie le rapport sur la gouvernance des données en Chine
- Analysis of fegin
猜你喜欢

注意|24日截止 2022年广东二级造价工程师准考证打印入口开通

Implementation of breadth traversal adjacency matrix of 6-6 graph
![[interpretation of the paper] sort out the papers on the vision based autonomous landing platform of UAV](/img/a5/bfa011c961b8f05348f9905fe3d996.png)
[interpretation of the paper] sort out the papers on the vision based autonomous landing platform of UAV

LeetCode 每日一题——513. 找树左下角的值

CVPR2022 | 用于重采图像的特征解耦学习与动态融合

Lesson 030: file system: introduce a big thing | after class test questions and answers

Cvpr2022 𞓜 Heidelberg University's course "deep visual similarity and measurement learning"

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

Share deadlock problems encountered in insert into select (project practice)

自助图书馆系统-Tkinter界面和openpyxl表格综合设计案例
随机推荐
Lesson 031: permanent storage: pickle a jar of delicious pickles | after class test questions and answers
What is a data asset? How should data asset management be implemented?
[GWCTF 2019]mypassword XSS
Liunx installing MySQL
二级造价工程师考前必备15个知识点来了!祝你旗开得胜!
Rendu stéréo
Lesson 025: Dictionary: after class test questions and answers when the index is not easy to use
Campus errand management app Shaanxi Gechuang
redis 报错解决与常用配置
KDD'22 | 阿里: 基于EE探索的精排CTR预估
【李沐】 如何读论文【论文精读】
How to use the data dictionary function in the low code platform of the Internet of things?
Share deadlock problems encountered in insert into select (project practice)
RealNetworks vs. Microsoft: the battle in the early streaming media industry
Note: by the end of 2022, the printing entrance of Guangdong second-class cost engineer's admission card has been opened
Registration of spa project development
322.零钱兑换
(duc/ddc) digital up mixing / quadrature down mixing principle and MATLAB simulation
Lesson 014-15: string (see lesson 27-32 of the new version of little turtle) | after class test questions and answers
LinkedList 源码解析