December 29, 2018 Oracle query performance optimization

When Oracle excessive use sub-queries, will lead to a decrease in query performance, thereby affecting queries appear efficiency

 

For example, now get from 1-19 in 11-14,

1) using a subquery as follows:

* from SELECT
(
            - a raw analog data line 20
             the SELECT LV the LEVEL the AS
               the FROM the DUAL
         the CONNECT BY the LEVEL <20
) TT
 the WHERE tt.lv> 10 tt.lv the AND <15

 

Of course, because the sql query is not very complex, you may not feel the efficiency problem, but when sql statement is complex, it will obviously feel Efficiency

2)使用 WITH  tempName AS  (select ....)

      select ...

    It will greatly improve query performance

   

with TT as(
      - a raw analog data line 20
     SELECT LEVEL AS lv
     FROM DUAL
     CONNECT BY LEVEL < 20
 ) 
select lv from TT
WHERE lv > 10 AND lv < 15

 With query to select not start, but in the beginning "WITH" keywords
 can be considered in advance before the actual query constructs a temporary table TT, then it can be used several times for further analysis and processing

 Adds SQL legibility, if constructed with multiple sub-queries, the structure will be clearer; more important is: "one analysis, use many times", which is why the performance will provide a place, to "read less" of aims.

  The first method uses a subquery table is scanned twice, and use the WITH Clause method, the table is scanned only once. This can greatly improve the efficiency of data analysis and query.

  In addition, the observation WITH Clause method implementation plan "SYS_TEMP_XXXX" is constructed in the middle of statistics during operation temporary table.

 

 

Use examples:

   with t1 as (

        select a,b,c from table1

    ),

    t2 as(

       select a,b,c,d from table2

   )

   select t1.a,

             t1.b,

             t1.c,

             t2.a,

             t2.b,

             t2.c

   from t1 left join t2 on t1.a=t2.a

 

Guess you like

Origin www.cnblogs.com/anzhao/p/10196041.html
Recommended