Optimization rules:
1. In CBO mode, the table is queried from right to left, and the first on the right is the base table.
Select a small number of rows as the base table,
For three or more tables, You must select a crosstab chart (Table connected to the other two tables) as the base table,
2. When the data volume is large, use exists instead of in
3. Where
Bottom-up parsing where clauses,
The condition for filtering data records is written in the WHERE clause
The end of the table. name = 'zhangsan' is followed by the data in table A whose field name is 'zhangsan' is associated with table B)
Select * From table_name A, CCC B
Where a. Column = B. Column
And a. deptno in (20, 30)
4. Use decode
The statement block uses a short path. If (AA> 100) or (BB ='Cc '),
The first one is right, so we won't go into the second one,
If (1 = 2) and (A in (1, 2, 3, 4, 5 ))
If the first one is not satisfied, it will not enter the second one.
Therefore, lower overhead is placed before
5. Avoid implicit type conversion. When pls_integer is copied to number, implicit conversion occurs.
Comparison Method:
-- View the performance of the statement block corresponding to the number of rows
1. Press F5 to view the execution plan.
Glossary:
Cost: Operation Cost (calculated based on uses disk I/O, CPU usage, and memory usage)
Number of data rows accessed by the cardinality operation
The size of the data set accessed by the bytes operation.
2. One is the following method:
Declare
-- Local variables here
V_run_number integer;
P_contractid contract. contractid % type;
Begin
-- Start profiler
Dbms_profiler.start_profiler (run_number => v_run_number );
-- Display the running row number of the current trail
Dbms_output.put_line ('run _ number: '| v_run_number );
-- Run PLSQL to be tracked
For AA in (select * from contract where rownum <100) loop
P_contractid: = AA. contractid;
End loop;
-- Stop profiler
Dbms_profiler.stop_profiler;
End;
1. subquery and connection query comparison
When querying a large amount of data:
When querying a large amount of data connections:
-- Subquery
View code
1 -- subquery 2 select. contractno policy number, 3 (select chnname from syscode where recordid =. contractstatus) status, 4. acceptdate acceptance date, 5. effectivedate effective date, 6. approvedate underwriting date, 7. policyreturndate, 8. surrenderdate, 9 B. checkyearmonth reconciliation date, 10 max (B. yYear) year, 11 B. productname insurance name, 12 B. premiumperiod, 13 (select abbrname from branch where branchid = B. bizcbranchid) supervision area, 14 (select abbrname from branch where branchid = B. bizubranchid) Sales Department, 15 B. applicantname applicant, 16 B. insuredname, 17. agentname agent, 18 B. modalprem premium, 19 B. valueprem value premium 20 from contract A, premium B21 where. contractid = B. contractid22 and. providerid in ('promo-000000006 ', 'promo-0000000g6') 23 and. bizbranchid = 'bra0000000000006 '24 and. channeltype = 'channeltype _ a' 25 group by. contractno, 26. acceptdate, 27. required tivedate, 28. approvedate, 29. policyreturndate, 30 surrenderdate, 31 checkyearmonth, 32 productname, 33 B. premiumperiod, 34 B. applicantname, 35 B. insuredname, 36. agentname, 37 modalprem, 38. contractstatus, 39 B. bizcbranchid, 40 B. bizubranchid, 41 B. valueprem 42 43 -- select. providerid,. providername from provider a where providername like '% Xin Tai %' 44 -- select * From syscode where recordid like '% channel %'
The number of result sets is 14678, and the three time elapsed is 27.627 26.582 26.692 in sequence.
-- Connection Query
View code
1 -- all are join queries 2 select. contractno warranty number, 3 C. chnname status, 4. acceptdate acceptance date, 5. effectivedate effective date, 6. approvedate underwriting date, 7. policyreturndate, 8. surrenderdate, 9 B. checkyearmonth reconciliation date, 10 max (B. yYear) year, 11 B. productname insurance name, 12 B. premiumperiod, 13 E. branchname supervision area, 14 F. branchname sales department, 15 B. applicantname applicant, 16 B. insuredname, 17. agentname agent, 18 B. modalprem premium, 19 B. valueprem value premium 20 from contract A, premium B, syscode C, Branch E, branch F21 where. contractid = B. contractid22 and C. recordid =. contractstatus23 and B. bizcbranchid = E. branchid24 and B. cbranchid = f. branchid25 and. channeltype = 'channeltype _ a' 26 and. providerid in ('promo-000000006 ', 'promo-0000000g6') 27 and. bizbranchid = 'bra0000000000006 '28 group by. contractno, 29. acceptdate, 30. specified tivedate, 31. approvedate, 32. policyreturndate, 33 surrenderdate, 34 checkyearmonth, 35 productname, 36 B. premiumperiod, 37 B. applicantname, 38 B. insuredname, 39. agentname, 40 modalprem, 41 c. chnname, 42 E. branchname, 43 F. branchname, 44 B. valueprem 45 46 -- select. providerid,. providername from provider a where providername like '% Xin Tai %'
The result set contains 14678 results and takes three times.SequentialIs 25.178 23.806 25.037
2. Indexing
Before creating an index
After the index is created
Conclusion: The efficiency is nearly 100 times higher. Which fields should be indexed? When one of your SQL statements is not very complex, for example, it takes a long time to optimize them in many ways. When other methods cannot be optimized, it takes a long time to create an index, for example, the contract Table of the objectname. Check that three fields in your where statement use branchid, contractstatus, interval tivedate, and then, institution ID (Branchid(Contractstatus) Is not much, only dozens of values, but the effective time (Effectivedate) But there are tens of millions, 365 days a day, 24 hours, and so on, so the slow is slow here, add an index create index idx_cont_inclutivedate on contract (inclutivedate); the index is used well, the efficiency is improved, and vice versa, it will also affect the performance of the entire database.
Index Introduction: http://www.cnblogs.com/o-andy-o/archive/2012/08/16/2641974.html