But basically these few, for example will be described later
Use of a query or high-level functions to reduce the sub
2, the appropriate use of the index
3, note associated conditions associated multi-table
4, the number of planned to take a good way of writing table, see table to be used;
5, should be avoided term use is not a very resource-consuming, if they can not try to do (with the key query is not like taboo)
6, sub-queries do not write in conditions where write in select years;
Example 1 (try not to use a key not like the query)
select *
from IFSAPP.SHOP_ORD
where DATE_ENTERED>=DATE'2019-11-1'
AND DATE_ENTERED<= DATE '2019-11-30'
AND CONTRACT='PPCD'
AND PART_NO NOT IN (SELECT PART_NO FROM IFSAPP.SHOP_ORD WHERE PART_NO LIKE'45%'OR PART_NO LIKE '50%')
The following three minutes 52 seconds
select *
from IFSAPP.SHOP_ORD
where DATE_ENTERED>=DATE'2019-11-1'
AND DATE_ENTERED<= DATE '2019-11-30'
AND CONTRACT='PPCD'
AND SUBSTR(PART_NO,1,2) NOT IN ( '50','45')
The following took 57seconds
select *
from IFSAPP.SHOP_ORD so1
where DATE_ENTERED >= DATE '2019-11-1'
AND DATE_ENTERED <= DATE '2019-11-30'
AND CONTRACT = 'PPCD'
AND not exists
(SELECT 1
FROM IFSAPP.SHOP_ORD so2
WHERE so1.contract = so2.contract
and so1.order_no = so2.order_no
and so1.part_no = so2.part_no
and (PART_NO LIKE '45%' OR PART_NO LIKE '50%'))
Why is efficiency so high? I think the next.
The following took 55seconds
select *
from IFSAPP.SHOP_ORD
where DATE_ENTERED >= DATE '2019-11-1'
AND DATE_ENTERED <= DATE '2019-11-30'
AND CONTRACT = 'PPCD'
and instr(PART_NO, '45') != 1
and instr(PART_NO, '50') != 1
Multi 56 seconds
SQL optimization article: https: //blog.csdn.net/jianzhang11/article/details/102867120
ORACLE operation and maintenance
https://bbs.csdn.net/topics/395382796