当前位置:网站首页>Some suggestions on Oracle SQL query return optimization
Some suggestions on Oracle SQL query return optimization
2022-06-22 07:59:00 【CodeStorys】
A friend asked : If a query returns data too slowly , Batch query is required , It should be checked !
Now let's talk about... Based on experience sql Some experience of query , There are no special reference books , Where do you want to write , If you don't , Please correct me !
stay Oracle Up operation SQL when , First of all, you should know how to analyze the execution plan . It's usually F5 You can enter the execution plan window . For simple queries , We can easily tell where COST more ,COST Larger steps , That is, the steps that affect query efficiency .
But for a beginner , I don't know what the implementation plan is , Then how to start learning to write better sql Well ? Theory we don't have , Is there any way to try bailing ?
In general , Optimize data storage , Improving execution efficiency is a common method , The general methods are as follows :
1、 Crop partition table
Partition large tables , The most common is to partition by time . When querying data , First confirm whether the queried table is a partitioned table , If it is , Just use the partition field as the partition clipping condition , That is to say where clause , Using partitioned fields , You can automatically crop the partition . such , Only query the data of one or more partitions , The amount of data returned is less , Improve query efficiency . About partition clipping , There are also assignments partition The way , If you are interested, just Baidu .
2、 Use index
Index a table , Is the key to improve query efficiency . For queries , The more indexes, the better , For write , The fewer indexes, the better . Building an index is like building a directory of dictionaries . With the index , Then you need to look at the table structure , See which fields are index fields . Without affecting the query results , Use index as where Condition of clause , Can improve index performance .
Be careful , Index and partition cropping , To ensure that the index where The conditional character type on the clause is consistent with it , And no conversion , Otherwise, neither index nor partition pruning will take effect .
Whether the execution process is indexed , You can know by viewing the execution plan .
3、 Limit the amount of data returned
In the case of low requirements for data return , The required data can be returned randomly , You can use the rownum Limit the number of data returned .rownum You can use Baidu .
4、 utilize hint Specify parallelism ( Or prompt to execute the plan )
hint It can be used as sql Execution plan prompter . It's written in :
select /*+ parallel(8)*/ * from table_name ;
among ,parallel It means parallelism , That is, how many CPU The kernel runs this sql
Use here 8 Is a common number , It can also be used. 2 ,4 ,16 , It is best to 2 Power of power , Don't use odd numbers .
thus , When you look up data , The return result will be much faster . So simple and rude , It's more suitable for beginners . And for optimization , In fact, the most important thing is business optimization , Reducing the repeated scanning of tables has a great gain for large tables .
As for what some people have said exists Instead of not in , use union all Instead of or ,where The order in which clauses are written , These are all CBO I have already made it for you . It should be said that it is a means of low income .
I believe the above 4 A way , Should be able to walk a flat Oracle The road to learning .
Poorly written , Not a professional document , If there is something wrong, please correct it , thank !
==============================================
A day later , The friend said , Still don't understand .
I don't understand , She said :
still select The process of , Then he will remind me that I have reached the maximum amount , Do you want to continue 
In fact, this is not because the data return is slow , But the memory burst .
Now , Should be able to use swap Swap partitions .
We need to know , What is shown to us , Are provided by memory , All data must be read into memory , And then through CPU Calculate , Reuse GPU Show us .
If the amount of data is too large , You want to stack it in memory at one time , How can memory stand .
The server memory may be a total of 128G, Sometimes a result set may contain hundreds of millions of data , Press 0.3KB One , The calculator calculates , One hundred million of them 28GB, Even if all the memory is for you , You can also export 5 A table of billion pieces of data stays in memory .
It's almost unthinkable .
therefore , Don't expect all the data to be presented in the tool , It doesn't make any sense .
If you need to look at specific data , Limit the corresponding conditions .
=================================================
however , I need to export to Excel Send it to someone else .
There are three suggestions :
1) If the amount of data is too large (5w More than ), It is not recommended to export to at one time Excel, Although I have seen 8 Ten thousand pieces sheet Of Excel surface , But it is already too laggy and too laggy to use . Now , Can be displayed rownum Return quantity , Export in batches .
2) Do you want all the columns ? Or just a few columns , You write down the columns you need , Do not use * Replace all columns , This reduces the number of data block returns .
3) Use ROWNUM Limit the amount of data returned . Are you sure you want all the data , Or do you only need some data for field analysis , Use rownum <= 100 The way , Allows you to export a specified number of rows of data .
Refer to the following code , Used row_number Perform windowing sorting , Then by sorting the results , Export the specified data row number range .
select * from (
SELECT Ffv.Flex_Value
,Ffv.Description
,row_number()over(partition by 1 order by 1 ) rn
FROM apps.table111 Fifs
,apps.table222 Ffv
,apps.table333 Fvs
WHERE Fifs.Application_Column_Name = 'SEGMENT1'
AND Fifs.Id_Flex_Code = 'GL#'
AND Fifs.Flex_Value_Set_Id = Ffv.Flex_Value_Set_Id
AND Ffv.Flex_Value_Set_Id = Fvs.Flex_Value_Set_Id(+)
AND Ffv.Enabled_Flag = 'Y'
AND Fvs.Flex_Value_Set_Name = Fifs.Segment_Name
AND Nvl(Trunc(Ffv.Start_Date_Active)
,SYSDATE - 1) <= SYSDATE
AND Nvl(Trunc(Ffv.End_Date_Active)
,SYSDATE + 1) >= SYSDATE )
where rn between 1 and 10000
Just limit where rn between 1 and 10000 The article number , You can export data at a time .
边栏推荐
- Download addresses of Xcode versions
- Windchill - how to start workflow through API
- A glimpse of easy rule
- How can MySQL query the records with the largest consumption amount of each user?
- [songhongkang MySQL database] [advanced chapter] [07] MySQL storage engine
- Layer drawing method
- Template code overview
- 【圖論常見模板題】4種最短路解法和2種最小生成樹解法
- LVS Technology Practice
- Mystery of power bank
猜你喜欢

The applet uses the step bar vant steps in vant

OSI and tcp/ip

Phpcms mobile portal configuration

Model electricity experiment -- Experiment 2 JFET common source amplifier circuit

What is distributed transaction

ES6 set data type de duplication of array, intersection, union and difference

丰田bZ4X取消上市发布会,就算低温充电问题不存在,产品力如何?

Orientdb batch execute SQL

对于mysql中数据为NULL引发的一些问题和思考

Microsoft Remote Desktop 10.7.6 official
随机推荐
Qualcomm platform msm8953 display subsystem learning
MySQL master-slave replication
模電實驗——實驗二 JFET共源極放大電路
Windchill API drops
Major enterprises are losing money one after another. Where will the environmental protection industry go?
4 solutions de court - circuit et 2 solutions d'arbre de génération minimum
XMIND 2022 mind map active resources?
AutoCAD 2020.3中文版 (旧版本)
Kubernetes practice
Daily maintenance of website
Stored procedures and functions of MySQL
Simplicity is the best method of network promotion
What is distributed transaction
Docker install redis
LR 2022 ultra detailed installation tutorial "latest"
(7) Bidirectional linked list
力扣(LeetCode)172. 阶乘后的零(2022.06.21)
8、 Slider assembly
Scrollrect rewrite recycle
JS to assign values to two objects with the same attributes