Need to improve Performance of select...endselect query

Hi experts,
I have a query in my program like below with inner join of 3 tables.
In my program used select....endselect   again inside this select...endselect statements used..
While executing in production taking lot of time to fetch records. Can anyone suggest to improve performance of below query urgently...
Greatly appreciated ur help...
SELECT MVKEDWERK MVKEMATNR MVKEVKORG MVKEVTWEG MARA~MATNR
       MARAMTART ZM012MTART ZM012ZLIND ZM012ZPRICEREF
INTO (MVKE-DWERK , MVKE-MATNR , MVKE-VKORG , MVKE-VTWEG , MARA-MATNR
     , MARA-MTART , ZM012-MTART , ZM012-ZLIND , ZM012-ZPRICEREF )
FROM ( MVKE
       INNER JOIN MARA
       ON MARAMATNR = MVKEMATNR
       INNER JOIN ZM012
       ON ZM012MTART = MARAMTART )
       WHERE MVKE~DWERK IN SP$00004
         AND MVKE~MATNR IN SP$00001
         AND MVKE~VKORG IN SP$00002
         AND MVKE~VTWEG IN SP$00003
         AND MARA~MTART IN SP$00005
         AND ZM012~ZLIND IN SP$00006
         AND ZM012~ZPRICEREF IN SP$00007.
  %DBACC = %DBACC - 1.
  IF %DBACC = 0.
    STOP.
  ENDIF.
  CHECK SP$00005.
  CHECK SP$00004.
  CHECK SP$00001.
  CHECK SP$00002.
  CHECK SP$00003.
  CHECK SP$00006.
  CHECK SP$00007.
  clear Check_PR00.
  select * from A004
  where kappl = 'V'
  and kschl = 'PR00'
  and vkorg = mvke-vkorg
  and vtweg = mvke-vtweg
  and matnr = mvke-matnr
  and DATAB le sy-datum
  and DATBI ge sy-datum.
  if sy-subrc = 0.
  select * from konp
  where knumh = a004-knumh.
  if sy-subrc = 0.
  Check_PR00 = konp-kbetr.
  endif.
  endselect.
  endif.
  endselect.
  CHECK SP$00008.
  clear Check_ZPR0.
  select * from A004
  where kappl = 'V'
  and kschl = 'ZPR0'
  and vkorg = mvke-vkorg
  and vtweg = mvke-vtweg
  and matnr = mvke-matnr
  and DATAB le sy-datum
  and DATBI ge sy-datum.
  if sy-subrc = 0.
  select * from konp
  where knumh = a004-knumh.
  if sy-subrc = 0.
  Check_ZPR0 = konp-kbetr.
  endif.
  endselect.
  endif.
  endselect.
  CHECK SP$00009.
  clear ZFMP.
  select * from A004
  where kappl = 'V'
  and kschl = 'ZFMP'
  and vkorg = mvke-vkorg
  and vtweg = mvke-vtweg
  and matnr = mvke-matnr
  and DATAB le sy-datum
  and DATBI ge sy-datum.
  if sy-subrc = 0.
  select * from konp
  where knumh = a004-knumh.
  if sy-subrc = 0.
  ZFMP = konp-kbetr.
  endif.
  endselect.
  endif.
  endselect.
  CHECK SP$00010.
  clear mastercost.
  clear ZDCF.
  select * from A004
  where kappl = 'V'
  and kschl = 'ZDCF'
  and vkorg = mvke-vkorg
  and vtweg = mvke-vtweg
  and matnr = mvke-matnr
  and DATAB le sy-datum
  and DATBI ge sy-datum.
  if sy-subrc = 0.
  select * from konp
  where knumh = a004-knumh.
  if sy-subrc = 0.
  ZDCF = konp-kbetr.
  endif.
  endselect.
  endif.
  endselect.
  CHECK SP$00011.
  clear masterprice.
  clear Standardcost.
  select * from mbew
  where matnr = mvke-matnr
  and bwkey = mvke-dwerk.
  Standardcost = mbew-stprs.
  mastercost = MBEW-BWPRH.
  masterprice = mBEW-BWPH1.
  endselect.
  ADD 1 TO %COUNT-MVKE.
  %LINR-MVKE = '01'.
  EXTRACT %FG01.
  %EXT-MVKE01 = 'X'.
    EXTRACT %FGWRMVKE01.
ENDSELECT.
best rgds..
hari..

Hi there.
Some advices:
- why going to MVKE first and MARA then? You will find n rows in MVKE for 1 matnr, and then go n times to the same record in MARA. Do the oposite, i.e, go first to MARA (1 time per matnr) and then to MVKE.
- avoid select *, you will save time.
- use trace or measure performance in tcodes ST05 and SM30.
-  replace:
select * from konp
where knumh = a004-knumh.
if sy-subrc = 0.
Check_ZPR0 = konp-kbetr.
endif.
endselect.
by
select * from konp
where knumh = a004-knumh.
Check_ZPR0 = konp-kbetr.
exit.
endselect.    
Here, if I understood, you only need to atribute kbetr value to Check_ZPR0 if selecting anything (don't need the IF because if enters in select, subrc always equal to 0, and also don't need to do it several times from same a004-knumh - reason for the EXIT.
Hope this helps.
Regards.
Valter Oliveira.
Edited by: Valter Oliveira on Jun 5, 2008 3:16 PM

Similar Messages

  • How to improve performance of the attached query

    Hi,
    How to improve performance of the below query, Please help. also attached explain plan -
    SELECT Camp.Id,
    rCam.AccountKey,
    Camp.Id,
    CamBilling.Cpm,
    CamBilling.Cpc,
    CamBilling.FlatRate,
    Camp.CampaignKey,
    Camp.AccountKey,
    CamBilling.billoncontractedamount,
    (SUM(rCam.Impressions) * 0.001 + SUM(rCam.Clickthrus)) AS GR,
    rCam.AccountKey as AccountKey
    FROM Campaign Camp, rCamSit rCam, CamBilling, Site xSite
    WHERE Camp.AccountKey = rCam.AccountKey
    AND Camp.AvCampaignKey = rCam.AvCampaignKey
    AND Camp.AccountKey = CamBilling.AccountKey
    AND Camp.CampaignKey = CamBilling.CampaignKey
    AND rCam.AccountKey = xSite.AccountKey
    AND rCam.AvSiteKey = xSite.AvSiteKey
    AND rCam.RmWhen BETWEEN to_date('01-01-2009', 'DD-MM-YYYY') and
    to_date('01-01-2011', 'DD-MM-YYYY')
    GROUP By rCam.AccountKey,
    Camp.Id,
    CamBilling.Cpm,
    CamBilling.Cpc,
    CamBilling.FlatRate,
    Camp.CampaignKey,
    Camp.AccountKey,
    CamBilling.billoncontractedamount
    Explain Plan :-
    Description Object_owner Object_name Cost Cardinality Bytes
    SELECT STATEMENT, GOAL = ALL_ROWS 14 1 13
    SORT AGGREGATE 1 13
    VIEW GEMINI_REPORTING 14 1 13
    HASH GROUP BY 14 1 103
    NESTED LOOPS 13 1 103
    HASH JOIN 12 1 85
    TABLE ACCESS BY INDEX ROWID GEMINI_REPORTING RCAMSIT 2 4 100
    NESTED LOOPS 9 5 325
    HASH JOIN 7 1 40
    SORT UNIQUE 2 1 18
    TABLE ACCESS BY INDEX ROWID GEMINI_PRIMARY SITE 2 1 18
    INDEX RANGE SCAN GEMINI_PRIMARY SITE_I0 1 1
    TABLE ACCESS FULL GEMINI_PRIMARY SITE 3 27 594
    INDEX RANGE SCAN GEMINI_REPORTING RCAMSIT_I 1 1 5
    TABLE ACCESS FULL GEMINI_PRIMARY CAMPAIGN 3 127 2540
    TABLE ACCESS BY INDEX ROWID GEMINI_PRIMARY CAMBILLING 1 1 18
    INDEX UNIQUE SCAN GEMINI_PRIMARY CAMBILLING_U1 0 1

    duplicate thread..
    How to improve performance of attached query

  • Improve performance of the below query

    Hi Gurus,
    I have following query with the plan described. I need to improve the the performance of this query as it is using full table scans.
    How could achieve this.
    SELECT csf.*,
           NULL subject_flag,
           NULL next_exp_rewards_date,
           0 next_exp_rewards,
           (csf.rewards_cf - csf.rewards_bf - csf.total_rewards) * -1 reward_spent
      FROM crm_statement_fulfilled csf, crm_accounts ca
    WHERE csf.account_id = ca.account_id
       AND csf.procg_date = '01-jul-2012'
       AND ca.cycle_id = '01'
       AND ca.date_closed IS NULL
       AND ca.account_type IN ('LTT', 'LTY', 'LYI')
    ORDER BY csf.account_id
    Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.2.0
    Connected as crm
    SQL> desc crm_statement_fulfilled
    Name                  Type         Nullable Default Comments
    ACCOUNT_ID            NUMBER(19)                            
    CAMPAIGN_ID           NUMBER(10)                            
    CYCLE_ID              VARCHAR2(2)                           
    CUSTOMER_ID           NUMBER(14)   Y                        
    PROCG_DATE            DATE                                  
    GE_FULFILLED          VARCHAR2(1)  Y                        
    POINTS_DISPLAYED      VARCHAR2(1)  Y                        
    REASON_ID             VARCHAR2(10) Y                        
    POINTS_BF             NUMBER(10,2) Y                        
    PROMO_POINTS          NUMBER(10,2) Y                        
    GW_ADJ_POINTS         NUMBER(10,2) Y                        
    TOTAL_REWARDS         NUMBER(10,2) Y                        
    GW_FUL_POINTS         NUMBER(10,2) Y                        
    REC_POINTS            NUMBER(10,2) Y                        
    REC_FC_POINTS         NUMBER(10,2) Y                        
    POINTS_CONVERTED      NUMBER(10,2) Y                        
    POINTS_CF             NUMBER(10,2) Y                        
    TOTAL_POINTS          NUMBER(10,2) Y                        
    TOTAL_AIR_MILES_VALUE NUMBER(10)   Y                        
    POINTS_EXPIRED        NUMBER(10,2) Y                        
    CDT_IN_STR_POINTS     NUMBER(10,2) Y                        
    CDT_OUT_STR_POINTS    NUMBER(10,2) Y                        
    ANNIVERSARY_POINTS    NUMBER(10,2) Y                        
    LOYALTY_POINTS        NUMBER(10,2) Y                        
    NEXT_EXP_POINTS       NUMBER(10,2) Y                        
    NEXT_EXP_POINTS_DATE  DATE         Y                        
    REWARDS_BF            NUMBER(10,2) Y                        
    REWARDS_CF            NUMBER(10,2) Y                        
    SQL> desc crm_accounts
    Name               Type         Nullable Default Comments
    ACCOUNT_ID         NUMBER(19)                            
    CYCLE_ID           VARCHAR2(2)                           
    ACCOUNT_TYPE       VARCHAR2(3)                           
    SECURITY_PASSWORD  VARCHAR2(80) Y                        
    ACCESS_PASSWORD    VARCHAR2(80) Y                        
    AIRMILES_ID        VARCHAR2(16) Y                        
    DATE_OPENED        DATE                                  
    SEED               VARCHAR2(1)  Y                        
    AUTO_AIRMILES      VARCHAR2(1)  Y                        
    CURRENCY           VARCHAR2(3)  Y                        
    DATE_CLOSED        DATE         Y                        
    STORE_OPENED       VARCHAR2(4)  Y                        
    DATE_ACTIVATED     DATE         Y                        
    OLD_ACCOUNT_ID     NUMBER(19)   Y                        
    CARDPAC_ACCOUNT_ID NUMBER(19)   Y                        
    ORG_ID             VARCHAR2(10) Y                        
    LOGO_ID            VARCHAR2(10) Y                        
    PTS_TO_ACCOUNT_ID  NUMBER(19)   Y                        
    DMW_ACCOUNT_ID     VARCHAR2(19) Y                        
    SQL>

    Hi,
    Sid_ Z. wrote:
    Hi Gurus,
    I have following query with the plan described. I need to improve the the performance of this query as it is using full table scans...For all tuning requests, see the forum FAQ {message:id=9360003}
    AND csf.procg_date = '01-jul-2012'Don't try to compare a DATE (such as procg_date) with as VARCHAR2 (such as '01-jul-2012'.
    Use TO_DATE or a DATE literal instead.

  • How to improve Performance for Select statement

    Hi Friends,
    Can  you please help me in improving the performance of the following query:
    SELECT SINGLE MAX( policyterm ) startterm INTO (lv_term, lv_cal_date) FROM zu1cd_policyterm WHERE gpart = gv_part GROUP BY startterm.
    Thanks and Regards,
    Johny

    long lists can not be produced with  a SELECT SINGLE, there is also nothing to group.
    But I guess the SINGLE is a bug
    SELECT MAX( policyterm ) startterm
                  INTO (lv_term, lv_cal_date)
                  FROM zu1cd_policyterm
                  WHERE gpart = gv_part
                  GROUP BY startterm.
    How many records are in zu1cd_policyterm ?
    Is there an index starting with gpart?
    If first answer is 'large' and second 'no'   =>   slow
    What is the meaning of gpart?  How many different values can it assume?
    If many different values then an index makes sense, if you are allowed to create
    an index.
    Otherwise you must be patient.
    Siegfried

  • Need to improve performance for bex queries

    Dear Experts,
    Here we have bex queries buit on BW infoset, further infoset is buit on 2 dsos and 4 infoobjects.
    we have built secondary indices to the two dso assuming will improve performance, but still query execution time is very long.
    Could you suggest me on this.
    Thanks in advance,
    Mannu

    HI,
    Thanks for the repsonse.
    But as I have mentioned the infoset is based on DSOs and Infoobjects. So we could not perform on aggregates.
    in RSRT
    I have tried look in read mode of the query i.e. in 'x', which is also valid as qurey needs to fetch huge data.
    Could you pls look into other possible areas, in order to improve this.
    Thanks in advance,
    Mannu

  • Need to Improve  pefromance for select statement using MSEG table

    Hi all,
    We are using a select statement using MSEG table
    which takes a very long time to run the program which is scheduled in back ground.
    Please see the history below.;
    1) Previously this program was using SELECT-ENDSELECT statement inside the loop i.e.
    LOOP AT I_MCHB.
    To get Material Doc. Details
          SELECT MBLNR
                 MJAHR
                 ZEILE INTO (MSEG-MBLNR,MSEG-MJAHR,MSEG-ZEILE)
                 UP TO 1 ROWS
                 FROM MSEG
                WHERE CHARG EQ I_MCHB-CHARG
                 AND  MATNR EQ I_MCHB-MATNR
                 AND  WERKS EQ I_MCHB-WERKS
                 AND  LGORT EQ I_MCHB-LGORT.
          ENDSELECT.
    Endloop.
    The program was taking 1 hr  for  20 k data
    2)The above statement was replaced by ALL ENTRIES to remove the SELECT-ENDSELECT from the loop.
    ***GET MATERIAL DOC NUMBER AND FINANCIAL YEAR DETAILS FROM MSEG TABLE
        SELECT MBLNR
               MJAHR
               ZEILE
               MATNR
               CHARG
               WERKS
               LGORT
                   INTO TABLE I_MSEG
                   FROM   MSEG
                   FOR ALL ENTRIES IN I_MCHB
                   WHERE CHARG EQ I_MCHB-CHARG
                   AND   MATNR EQ I_MCHB-MATNR
                   AND   WERKS EQ I_MCHB-WERKS
                   AND   LGORT EQ I_MCHB-LGORT.
    3)After getting the further technical analysis from BASIS team , And with the suggestion to optimize the program by changing the INDEX RANGE SCAN to
           MSEG~M.
    SELECT MBLNR
               MJAHR
               ZEILE
               MATNR
               CHARG
               WERKS
               LGORT
                   INTO TABLE  I_MSEG
                   FROM   MSEG
                   FOR ALL ENTRIES IN I_MCHB
                   WHERE MATNR EQ I_MCHB-MATNR
                   AND   WERKS EQ I_MCHB-WERKS
                   AND   LGORT EQ I_MCHB-LGORT.
    At present the program is taking 3 to 4 hrs in back ground .
    The table is complete table scan using index
    MSEG~M.
    Please suggest to improve the performance of this
    many many thanks
    deepak

    The benchmark should be the join, and I can not see how any of your solutions can be faster than the join
    SELECT   .....
                  INTO TABLE  ....
                  UP TO 1 ROWS
                  FROM mchb as a
                  INNER JOIN mseg as b
                  ON    amatnr EQ bmatnr
                  AND  awerks  EQ bwerks
                  AND  algort    EQ blgort
                  And   acharg  EQ bcharg
                  WHERE a~ ....
    The WHERE condition must come from the select on MCHB, the field list from the total results
    you want.
    If you want to compare, must compare your solutions plus the select to fill I_MCHB.
    Siegfried
    Edited by: Siegfried Boes  on Dec 20, 2007 2:28 PM

  • How to improve performance of select query when primary key is not referred

    Hi,
    There is a select query where we are unable to refrence primary key of the tables:
    Since, the the below code is refrensing to vgbel and vgpos fields instead of vbeln and posnr..... the performance is very  slow.
    select vbeln posnr into (wa-vbeln1, wa-posnr1)             
           from lips                                            
           where ( pstyv ne 'ZBAT'    
               and pstyv ne 'ZNLN' )  
               and vgbel = i_vbap-vbeln                         
               and vgpos = i_vbap-posnr.                        
    endselect.                                                 
    Please le t me know if you have some tips..

    hi,
    I hope you are using the select statement inside a loop ...endloop get that outside to improve the performance ..
    if not i_vbap[] is initial.
    select vbeln posnr into table it_lips
    from lips
    for all entries in  i_vbap
    where ( pstyv ne 'ZBAT'
    and pstyv ne 'ZNLN' )
    and vgbel = i_vbap-vbeln
    and vgpos = i_vbap-posnr.
    endif.

  • SLOW Query ... Need help improving performance

    Database: Oracle 8i
    Note: I don't have a whole lot of experience with writing queries, so please forgive me for any dumb mistakes I most likely made.
    I have a query in which I have a SUM in two levels. I think this is probably the root cause of the very slow performance of the query. However, I just don't see any way around it, and can't come up with any other ways to speed up the query. The query itself only returns one line, the summary line. And, by slow, I mean it can take up to an hour or two. This is a query I need to run multiple times, based on some parameters that I cannot query from a database.
    The query basically calculates the current unit cost of a part. It has to sum up the issue cost of the part (cost of material issued to the part's order), the actual dollars put into a part (labor, etc.), and the burden dollars associated with the part. This sum has to be divided by the total quantity of parts completed on the part's order to get the unit cost. I have to account for the possibility that the quantity complete is 0, so that I don't end up dividing by 0.
    Below is my query, and sample data for it:
    SELECT     a.part_nbr
    ,     a.mo_nbr
    ,     a.unit_iss_cost
    ,     CASE
              WHEN     a.qty_complete_ind     ='Nonzero'
              THEN     SUM(a.act_dlrs/a.qty_complete)
              ELSE     0
         END                                             AS unit_dlrs
    ,     CASE
              WHEN     a.qty_complete_ind     ='Zero'
              THEN     SUM(a.act_dlrs)
              ELSE     0
         END                                             AS qty_0_dlrs
    FROM     (     SELECT     act.part_nbr                              AS part_nbr
              ,     act.order_nbr || '-' || act.sub_order_nbr          AS mo_nbr
              ,     ic.unit_iss_cost                         AS unit_iss_cost
              ,     SUM     (
                             act.act_dlrs_earned          +
                             act.act_brdn_dls_earned          +
                             act.tool_dlrs_earned          +
                             act.act_fix_brdn_dls_ea     
                        )                              AS act_dlrs
              ,     ord.qty_complete                         AS qty_complete
              ,     CASE
                        WHEN     ord.qty_complete     <>0
                        THEN     'Nonzero'
                        ELSE     'Zero'
                   END                                   AS qty_complete_ind
              FROM     ACT          act
              ,     ISSUE_COST     ic
              ,     ORD          ord
              WHERE     ord.ord_nbr          =act.order_nbr          AND
                   ord.sub_ord_nbr          =act.sub_order_nbr     AND
                   ord.major_seq_nbr     =act.maj_seq_nbr     AND
                   ic.ord_nbr          =act.order_nbr          AND
                   ic.sub_ord_nbr          =act.sub_order_nbr     AND
                        (act.order_nbr          =LPAD(?,10,'0'))     AND
                        (act.sub_order_nbr     =LPAD(?,3,'0'))          AND
                        (act.activity_date     <=?)               
              GROUP BY     act.part_nbr
              ,          act.order_nbr || '-' || act.sub_order_nbr
              ,          act.maj_seq_nbr
              ,          ord.qty_complete
              ,          ic.unit_iss_cost
         ) a
    GROUP BY     a.part_nbr
    ,          a.mo_nbr
    ,          a.unit_iss_cost
    ,          a.qty_complete_ind
    CREATE TABLE ACT
              creation_date          date
         ,     c_id               number (5,0)
         ,     part_nbr          varchar(25)
         ,     order_nbr          varchar(10)
         ,     sub_order_nbr          varchar(3)
         ,     maj_seq_nbr          varchar(4)
         ,     act_dlrs_earned          number (15,2)
         ,     act_brdn_dls_earned     number (15,2)
         ,     tool_dlrs_earned     number (15,2)
         ,     act_fix_brdn_dls_ea     number (15,2)
         ,     activity_date          date
         CONSTRAINT     ACT_PK
         PRIMARY KEY     (creation_date, c_id)
    );--Please note, issue_cost is actually a view, not a table, but by itself it runs very quickly
    CREATE TABLE ISSUE_COST
              unit_iss_cost     number(15,2)
         ,     ord_nbr          varchar(10)
         ,     sub_ord_nbr     varchar(3)
    );--Please note, ord table has a couple of foreign keys that I did not mention
    CREATE TABLE ORD
              ord_nbr          varchar(10)
         ,     sub_ord_nbr     varchar(3)
         ,     major_seq_nbr     varchar(4)
         ,     qty_complete     number (13,4)
    );Sample tables:
    ACT
    creation_date     c_id     part_nbr     order_nbr     sub_order_nbr     maj_seq_nbr     act_dlrs_earned     act_brdn_dls_earned     tool_dlrs_earned     act_fix_brdn_dls_ea     activity_date
    01/02/2000      12345     ABC-123          0000012345     001          0010          10.00          20.00               0.00               0.00               01/01/2000
    01/02/2000     12345     XYZ-987          0000054321     001          0030          100.00          175.00               10.00               10.00               01/01/2000
    01/03/2000     12347     ABC-123          0000012345     001          0020          25.00          75.00               5.00               1.00               01/02/2000
    01/03/2000     12348     ABC-123          0000012345     001          0020          75.00          120.00               25.00               5.00               01/02/2000
    01/03/2000     12349     XYZ-987          0000054321     001          0050          50.00          110.00               0.00               0.00               01/02/2000
    01/04/2000     12350     ABC-123          0000012345     001          0030          25.00          40.00               0.00               0.00               01/03/2000
    ISSUE_COST
    unit_iss_cost     ord_nbr          sub_ord_nbr
    125.00          0000012345     001
    650.00          0000054321     001
    ORD
    ord_nbr          sub_ord_nbr     major_seq_nbr     qty_complete
    0000012345     001          0010          10
    0000012345     001          0020          10
    0000012345     001          0030          0
    0000054321     001          0030          20
    0000054321     001          0050          19If insert statements are needed for the sample tables, let me know and I'll go re-figure out how to write them. (I only have read-only access to the database I'm querying, so creating tables and inserting values aren't things I ever do).
    Thanks in advance!

    For diagnosing where the time of your query is being spent, we don't need create table and insert statements. If we execute your query with only a handful of rows, the query will be very fast. What we do need to know, is the plan the optimizer takes to compute your result set, and the cardinalities of each step.
    Please read When your query takes too long ... carefully and post the full explain plan and tkprof output.
    Regards,
    Rob.

  • Need to improve performance of oracle query

    Hi ,
    Currently i have written query to get maximun salary from XYZ company like this
    select salary from (
    select salary from employee
    where company='XYZ'
    order by salary desc )
    where rownum<2;
    i thought of replacing the same with following query
    select max(salary)
    from employee
    where company='XYZ';
    Which one will be faster ? can you provide some statistical data.It will be good if you share some oracle documentation for this.
    Thanks,
    Kannan

    Most likely the second one. And in any case: the second one is much more straightforward and readable (i.e. the syntax describes exactly what you want: get the max salary). In that way, your application is better maintainable (i.e. cheaper and better in the long run), and likely more easy to optimize for the database. And yes, in this case it's a simple query, but if you're thinking of writing even simple queries in the style of your first example, I'd hate to think of what more complex queries would get to look like...

  • What Indexes should be created for improve performance of the sql query

    Hello Admins
    One of my user is facing slow performance issue while running the below query. Can someone, please guide me for the same. I want to know, what indexes should be created to improve the performance of this query. Also what else can be done to achieve the same.
    SQL Query:-
    SELECT UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PO_NUMBER))),
    CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_NUMBER,
    CGSBI_SHIP_DIST_S_EXTRACT.PO_SHIPMENT_NUMBER,
    CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_SHIP_DIST_NUMBER,
    CGSBI_SHIP_DIST_S_EXTRACT.DISTRIBUTION_DATE,
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_SHIP_DIST_LINE_ID))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PROJECT_ID))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.ACCOUNT_DISTRIBUTION_CODE))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.ORACLE_ACCOUNT_NUMBER))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.COMPONENT_CODE))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.TRANSACTION_CURRENCY_CODE))),
    CGSBI_SHIP_DIST_S_EXTRACT.ORDER_QUANTITY, UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.ORDER_UOM))),
    CGSBI_SHIP_DIST_S_EXTRACT.UNIT_PRICE_TRX_CURRENCY,
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.EXPENSE_TYPE_INDICATOR))),
    CGSBI_SHIP_DIST_S_EXTRACT.SOR_ID,
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_ITEM_CODE))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_ITEM_DESC))),
    CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_ITEM_LEAD_TIME,
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.UNSPSC_CODE))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.BUYER_ID))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.REQUESTOR_ID))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.APPROVER_ID))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.SUPPLIER_SITE_ID))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.SUPPLIER_GSL_NUMBER))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.SHIP_TO_LOCATION_CODE))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.TASK_ID))),
    (LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PO_RELEASE_ID)))
    FROM
    CGSBI_SHIP_DIST_S_EXTRACT
    WHERE PO_NUMBER IS NOT NULL;
    I generated the explain plan for this query and found the following:-
    Explain Plan:-
    SQL> explain plan for SELECT UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PO_NUMBER))),
    2 CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_NUMBER,
    3 CGSBI_SHIP_DIST_S_EXTRACT.PO_SHIPMENT_NUMBER,
    4 CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_SHIP_DIST_NUMBER,
    5 CGSBI_SHIP_DIST_S_EXTRACT.DISTRIBUTION_DATE,
    6 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_SHIP_DIST_LINE_ID))),
    7 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PROJECT_ID))),
    8 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.ACCOUNT_DISTRIBUTION_CODE))),
    9 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.ORACLE_ACCOUNT_NUMBER))),
    10 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.COMPONENT_CODE))),
    11 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.TRANSACTION_CURRENCY_CODE))),
    12 CGSBI_SHIP_DIST_S_EXTRACT.ORDER_QUANTITY, UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.ORDER_UOM))),
    13 CGSBI_SHIP_DIST_S_EXTRACT.UNIT_PRICE_TRX_CURRENCY,
    14 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.EXPENSE_TYPE_INDICATOR))),
    15 CGSBI_SHIP_DIST_S_EXTRACT.SOR_ID,
    16 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_ITEM_CODE))),
    17 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_ITEM_DESC))),
    18 CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_ITEM_LEAD_TIME,
    19 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.UNSPSC_CODE))),
    20 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.BUYER_ID))),
    21 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.REQUESTOR_ID))),
    22 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.APPROVER_ID))),
    23 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.SUPPLIER_SITE_ID))),
    24 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.SUPPLIER_GSL_NUMBER))),
    25 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.SHIP_TO_LOCATION_CODE))),
    26 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.TASK_ID))),
    27 (LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PO_RELEASE_ID)))
    28 FROM
    29 CGSBI_SHIP_DIST_S_EXTRACT
    30 WHERE PO_NUMBER IS NOT NULL;
    Explained.
    SQL>
    SQL>
    SQL> SELECT * FROM TABLE(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 3891180274
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 77647 | 39M| 2006 (1)| 00:00:25 |
    |* 1 | TABLE ACCESS FULL| CGSBI_SHIP_DIST_S_EXTRACT | 77647 | 39M| 2006 (1)| 00:00:25 |
    Predicate Information (identified by operation id):
    1 - filter("PO_NUMBER" IS NOT NULL)
    13 rows selected.
    SQL>
    SQL>
    Kindly suggest on this...
    Thanks & Regards
    -Naveen Gangil
    Oracle DBA

    Rafi is correct. Since po_number is the filter column, the only chance you have for using an index to access the table is on that column. However, if there are few (or none) rows with null po_number, you will always have FTS. Does the table have a PK ( which probably consists of at least po_number, line_number )? If that is the case po_number could never be null and in which case you are dumping the whole table and no indexing scheme is going to improve the queri's performance. You might, repeat might, see performance improvement if you cleanse the data in the table ( to eliminate the need for UPPER(LTRIM)RTRIM())) ) before querying it so the the data does not have to be massaged before returning it.

  • Need to Improve Performance on a Spatial Boundary Crossing Calculator

    I am attempting to compare a series of geometries to calculate a number of statistics where they overlap. Essentially I have a table of 50,000 lines and another table of 1000 circles. I need to determine which lines overlap each circle, and for each intersection, I need to determine how much time and distance each line spends in each circle.
    I have a PL/SQL program that performs this operation now and it works. The problem is that it takes far too long.
    Here is a summary of how the job runs:
    1) For each LINE, determine which CIRCLES it overlaps with
    2) Each each LINE/CIRCLE pair, determine the intersection points
    3) Insert the intersection points in a temporary table
    4) Once you have all the points, pair them up as Entry/Exit points for each circle
    5) Calculate duration (time) and distance between entry and exit points
    6) Return to step 1 for next LINE
    There are multiple loops here:
    1-6 is the outer loop performed once for each of the 50,000 lines.
    2-3 is performed once for each line/circle pair (probable avg of 5 circles per line)
    4-5 is performed once again for each line/circle pair
    Even if the process only takes a couple of seconds per LINE, we are still taking more than 24 hours to process, which is not acceptable.
    This original process was written with 9i, and I am now running 10gR2, so I know there are new features that should help. For starters, I think I can use SDO_JOIN in place of the original outer loop to generate a complete list of geometry interactions in one query. Of course, I am still concerned about how long that might take.
    Even more troubling is, if that works, I still don't see how to improve the rest of the calculations. Any suggestions would be appreciated.

    No, I don't mind providing it.
    Here it is:
    -- cre_&stab._bndxing.sql
    --Procedure definition of bndxings
    def stab=&1
    CREATE OR REPLACE PROCEDURE Find_&stab._bndxings
    (theDate IN DATE, theStr IN VARCHAR2) IS
    --Select flights from table
    CURSOR FCursor IS
    SELECT new_Flight_Index,
    Acid,
    New_Act_Date,
    Dept_Aprt,
    Dep_Time,
    Arr_Aprt,
    Arr_Time,
    Acft_Type,
    Physical_Class,
    User_Class,
    Nrp,
         d_lat,
    d_lon,
    a_lat,
    a_lon,
         flight_track
    FROM jady.Flight
    WHERE new_act_date = theDate
    AND flight_track IS NOT NULL
    AND substr(acid,1,1) = theStr
    --AND acid in (select acid from name_temp)
    --AND acid = 'AAL1242'
    ORDER BY acid,new_flight_index;
    --Temp vars for storing flight info
    fi_var NUMBER;
    acid_var VARCHAR2(7);
    dep_time_var DATE;
    arr_time_var DATE;
    F_Rec FCursor%ROWTYPE;
    --Temp vars for flight
    tcnt INTEGER;
    cur_lat NUMBER;
    cur_lon NUMBER;
    last_lat NUMBER;
    last_lon NUMBER;
    --Temp vars for airspace and xing geometries
    aname VARCHAR2(20);
    bxings MDSYS.SDO_GEOMETRY;
    bxcnt INTEGER;
    --Select xings made from temp bndxing table
    CURSOR XCursor IS
    SELECT Act_Date,
    Name,
    Lon,
    Lat,
    Alt,
    Time,
    OPS
    FROM bndxing_tmp
    WHERE Flight_Index = fi_var
    AND Acid = acid_var
    ORDER BY Name,Time;
    --Temp vars for paired in/out xings
    ad date;
    ilon NUMBER;
    ilat NUMBER;
    ialt NUMBER;
    isec NUMBER;
    iops NUMBER;
    olon NUMBER;
    olat NUMBER;
    oalt NUMBER;
    osec NUMBER;
    oops NUMBER;
    gcr NUMBER;
    dist NUMBER;
    dura NUMBER;
    ops VARCHAR2(1);
    i INTEGER;
    i_aname VARCHAR2(20);
    o_aname VARCHAR2(20);
    names_match BOOLEAN;
    theSeq NUMBER;
    same_airport_no_tzdata BOOLEAN;
    -- Cursor and variables for bndxing sequencing
    CURSOR BCursor IS
    SELECT * FROM bndxing
    WHERE act_date = theDate
         AND Acid = acid_var
         AND Flight_Index = fi_var
    ORDER BY in_time
    FOR UPDATE;
    BRec BCursor%ROWTYPE;
    --Error logging variable
    strErrorMessage VARCHAR2(255);
    BEGIN --Start of Main Loop
    --Loop for each flight in table
    OPEN FCursor;
    FETCH FCursor INTO F_Rec;
    -- FOR f IN FCursor LOOP
    WHILE FCursor%FOUND LOOP
    fi_var:= F_Rec.new_Flight_Index;
    acid_var := F_Rec.acid;
    arr_time_var := F_Rec.arr_time;
    dep_time_var := F_Rec.dep_time;
    last_lat := -10000; --initializtion
    last_lon := -10000; --initializtion
    -- DEBUG STATEMENT
    /* Insert into bnd_error values (err_seq.NEXTVAL,
    sysdate,
    F_Rec.Acid,
    F_Rec.new_Flight_Index,
    'Checkpoint 1');
    --Add departing xing to temp table if in US airspace
    DECLARE
    CURSOR DepCur IS
    SELECT Name
    FROM &stab.
    WHERE SDO_RELATE(Airspace,
         MDSYS.SDO_GEOMETRY(2001,8307,
    MDSYS.SDO_POINT_TYPE(F_Rec.d_lon,F_Rec.d_lat,null),
         null, null),
    'mask=CONTAINS querytype=WINDOW') = 'TRUE';
    BEGIN -- Start of Departing Airspace Loop
    FOR c in DepCur LOOP
    INSERT INTO Bndxing_Tmp VALUES (F_Rec.new_Flight_Index,
    F_Rec.acid,
    F_Rec.New_Act_Date,
    c.name,
    2,
    F_Rec.d_lon,
    F_Rec.d_lat,
    0,
    (F_Rec.Dep_Time-F_Rec.New_Act_Date)*86400);
    END LOOP;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN NULL;
    WHEN OTHERS THEN
    strErrorMessage := SQLERRM;
    INSERT INTO bnd_error VALUES (err_seq.NEXTVAL,
    sysdate,
                             F_Rec.Acid,
                             F_Rec.new_Flight_Index,
                             'Exception from Departing Airspace loop: ' || strErrorMessage);
    COMMIT;
    END; -- End of Departing Airspace Loop
    --Add arrival xing to temp table if in US airspace
    DECLARE
    CURSOR ArrCur IS
    SELECT name
    FROM &stab.
    WHERE SDO_RELATE(Airspace,
         MDSYS.SDO_GEOMETRY(2001,8307,
    MDSYS.SDO_POINT_TYPE(F_Rec.a_lon, F_Rec.a_lat, null),
    null, null),
    'mask=CONTAINS querytype=WINDOW') = 'TRUE';
    BEGIN -- Start of Arrival Airspace Loop
    FOR c IN ArrCur LOOP
    INSERT INTO Bndxing_Tmp VALUES (F_Rec.new_Flight_Index,
    F_Rec.acid,
    F_Rec.New_Act_Date,
    c.name,
    1,
    F_Rec.a_lon,
    F_Rec.a_lat,
    0,
    (F_Rec.Arr_Time - F_Rec.New_Act_Date)*86400);
    END LOOP;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN NULL;
    WHEN OTHERS THEN
    strErrorMessage := SQLERRM;
    INSERT INTO bnd_error VALUES (err_seq.NEXTVAL,
    sysdate,
                             F_Rec.Acid,
                             F_Rec.new_Flight_Index,
                             'Exception from Arrival Airspace loop: ' || strErrorMessage);
    COMMIT;
    END; -- End of Arrival Airspace Loop
    --DEBUG STATEMENT
    /* Insert into bnd_error values (err_seq.NEXTVAL,
    sysdate,
    F_Rec.Acid,
    F_Rec.new_Flight_Index,
    'Checkpoint 4');
    --Find all intersections between the flight track and airspace boundaries and insert into temp table
    DECLARE
    --Find airspace boundaries that interact with the flight track
    CURSOR CCursor IS
    SELECT Name, Boundary
    FROM &stab.
    WHERE SDO_RELATE(boundary,F_Rec.flight_track,'mask=OVERLAPBDYDISJOINT querytype=WINDOW')='TRUE';
    BEGIN
    FOR c IN CCursor LOOP
    bxings := SDO_GEOM.SDO_INTERSECTION(c.boundary,F_Rec.flight_track,10);
    bxcnt:=bxings.sdo_ordinates.count;
    LOOP
    INSERT INTO bndxing_tmp VALUES (F_Rec.new_Flight_Index,
    F_Rec.acid,
    F_Rec.New_Act_Date,
    c.name,
    0,
    bxings.sdo_ordinates(bxcnt-3),
    bxings.sdo_ordinates(bxcnt-2),
    bxings.sdo_ordinates(bxcnt-1),
    SDO_LRS.FIND_MEASURE(F_Rec.flight_track,
    MDSYS.SDO_GEOMETRY(2001,8307,NULL,
    MDSYS.SDO_ELEM_INFO_ARRAY(1,1,1),
    MDSYS.SDO_ORDINATE_ARRAY(bxings.sdo_ordinates(bxcnt-3),
    bxings.sdo_ordinates(bxcnt-2)))));
    bxcnt := bxcnt - 4;
    EXIT WHEN (bxcnt < 1);
    END LOOP;
    END LOOP; -- end CCursor LOOP
    EXCEPTION
    WHEN OTHERS THEN
    strErrorMessage := SQLERRM;
    INSERT INTO bnd_error VALUES (err_seq.NEXTVAL,
    sysdate,
                             F_Rec.Acid,
                             F_Rec.new_Flight_Index,
                             'Exception from bndxing loop: ' || strErrorMessage);
    COMMIT;
    END;
    --DEBUG STATEMENT
    /* Insert into bnd_error values (err_seq.NEXTVAL,
    sysdate,
    F_Rec.Acid,
    F_Rec.new_Flight_Index,
    'Checkpoint 6');
    --After all xings for a flight have been collected sort Xings by name and time and grab pairwise
    theSeq :=0;
    OPEN XCursor;
    BEGIN -- Start of Stats Loop
    LOOP
         FETCH XCursor INTO ad, i_aname, ilon, ilat, ialt, isec, iops; --CHANGED CODE
    EXIT WHEN XCursor%NOTFOUND ;
    FETCH XCursor INTO ad, o_aname, olon, olat, oalt, osec, oops; --CHANGED CODE
    EXIT WHEN XCursor%NOTFOUND ;
    names_match := (i_aname = o_aname); --NEW CODE
    WHILE not names_match LOOP --NEW CODE
    i_aname := o_aname; --NEW CODE
         ilon := olon; --NEW CODE
         ilat := olat; --NEW CODE
         ialt := oalt; --NEW CODE
         isec := osec; --NEW CODE
         iops := oops; --NEW CODE
    FETCH XCursor INTO ad, o_aname, olon, olat, oalt, osec, oops; --NEW CODE
    EXIT WHEN XCursor%NOTFOUND; --NEW CODE
    names_match := (i_aname = o_aname); --NEW CODE
    END LOOP; --NEW CODE
         --Calculate stats
         BEGIN -- Start of In Values Loop
         i:=4;
         IF (iops<>2) THEN
         -- Did not depart from this airspace, calculate entry altitude into airspace.
         LOOP
         i:=i+4;
         EXIT WHEN F_Rec.flight_track.sdo_ordinates(i)>isec;
         END LOOP;
    IF ( F_Rec.flight_track.sdo_ordinates(i-1) = F_Rec.flight_track.sdo_ordinates(i-5) ) THEN
    ialt := F_Rec.flight_track.sdo_ordinates(i-1);
    ELSE
    ialt:=SDO_LRS.FIND_MEASURE(
         MDSYS.SDO_GEOMETRY(3302,8307,NULL,
         MDSYS.SDO_ELEM_INFO_ARRAY(1,2,1),
    MDSYS.SDO_ORDINATE_ARRAY(F_Rec.flight_track.sdo_ordinates(i-7),
    F_Rec.flight_track.sdo_ordinates(i-6),
    F_Rec.flight_tracK.sdo_ordinates(i-5),
    F_Rec.flight_track.sdo_ordinates(i-3),
    F_Rec.flight_track.sdo_ordinates(i-2),
    F_Rec.flight_track.sdo_ordinates(i-1))),
         MDSYS.SDO_GEOMETRY(2001,8307,NULL,
    MDSYS.SDO_ELEM_INFO_ARRAY(1,1,1),
    MDSYS.SDO_ORDINATE_ARRAY(ilon,ilat)));
    END IF;
         END IF;
         EXCEPTION
         WHEN OTHERS THEN
         strErrorMessage := SQLERRM;
         INSERT INTO bnd_error VALUES (err_seq.NEXTVAL,
         sysdate,
                                  F_Rec.Acid,
                                  F_Rec.new_Flight_Index,
                                  'Exception from In Values section: ' || strErrorMessage);
         COMMIT;
         END; -- End of In Values Loop
    BEGIN -- Start of Out Values Loop
         i:=4;
         IF (oops<>1) THEN
    -- Did not arrive in this airspace, calculate departure altitude from airspace.
    LOOP
    i:=i+4;
    EXIT WHEN F_Rec.flight_track.sdo_ordinates(i)>osec;
    END LOOP;
         --Find alt at this time
    IF ( F_Rec.flight_track.sdo_ordinates(i-1) = F_Rec.flight_track.sdo_ordinates(i-5) ) THEN
    oalt := F_Rec.flight_track.sdo_ordinates(i-1);
    ELSE
         oalt:=SDO_LRS.FIND_MEASURE(
         MDSYS.SDO_GEOMETRY(3302, 8307, NULL,
         MDSYS.SDO_ELEM_INFO_ARRAY(1,2,1),
    MDSYS.SDO_ORDINATE_ARRAY(F_Rec.flight_track.sdo_ordinates(i-7),
    F_Rec.flight_track.sdo_ordinates(i-6),
    F_Rec.flight_track.sdo_ordinates(i-5),
    F_Rec.flight_track.sdo_ordinates(i-3),
    F_Rec.flight_track.sdo_ordinates(i-2),
    F_Rec.flight_track.sdo_ordinates(i-1))),
         MDSYS.SDO_GEOMETRY(2001,8307,NULL,
    MDSYS.SDO_ELEM_INFO_ARRAY(1,1,1),
    MDSYS.SDO_ORDINATE_ARRAY(olon,olat)));
    END IF;
    END IF;
         EXCEPTION
    WHEN OTHERS THEN
    strErrorMessage := SQLERRM;
    INSERT INTO bnd_error VALUES (err_seq.NEXTVAL,
         sysdate,
                                  F_Rec.Acid,
                                  F_Rec.new_Flight_Index,
                                  'Exception from Out Values loop: ' || strErrorMessage);
    COMMIT;
    END; -- End of Out Values Loop
    BEGIN -- Start of Finish Loop
    --Find GCR, actual distance and duration in airspace
    gcr := SDO_GEOM.SDO_DISTANCE(MDSYS.SDO_GEOMETRY(2001,8307,
    MDSYS.SDO_POINT_TYPE(ilon,ilat,NULL),NULL,NULL),
    MDSYS.SDO_GEOMETRY(2001,8307,
    MDSYS.SDO_POINT_TYPE(olon,olat,NULL),NULL,NULL),
    10,'unit=naut_mile');
    --DEBUG STATEMENT
    /* Insert into bnd_error values (err_seq.NEXTVAL,
    sysdate,
    F_Rec.Acid,
    F_Rec.new_Flight_Index,
    'In Finish Loop: isec: ' ||isec||' osec: '||osec
                        ||' airspace: '||i_aname);
    dist := SDO_GEOM.SDO_LENGTH(SDO_LRS.CLIP_GEOM_SEGMENT(F_Rec.flight_track,isec,osec),10,'unit=naut_mile');
         dura := (osec - isec);
    --Set OPS Flag
    iops := iops + oops;
    IF (iops=3) THEN
    ops := 'B';
    ELSIF (iops=2) THEN
    ops := 'D';
    ELSIF (iops=1) THEN
    ops := 'A';
    ELSE
    ops := 'O';
    END IF;
         theSeq := theSeq + 1;
    --Insert into Bndxing table
    INSERT INTO Bndxing VALUES (F_Rec.Acid,
    F_Rec.new_Flight_Index,
    F_Rec.New_Act_Date,
         theSeq,
         F_Rec.Dept_Aprt,
         F_Rec.Arr_Aprt,
    i_aname,
    round(ilon,3),
    round(ilat,3),
    ialt,
    isec/86400 + ad,
    NULL, -- IN_SPEED (TBD)
    round(olon,3),
    round(olat,3),
    oalt,
    osec/86400 + ad,
    NULL, -- OUT_SPEED (TBD)
    gcr,
    dist,
    dura,
    ops, -- CHANGED CODE
    nvl(F_Rec.Acft_Type,'----'),
    NULL, -- IF_FLAG (NULL)
    nvl(F_Rec.Physical_Class,'-'),
    nvl(F_Rec.User_Class,'-'),
    F_Rec.Nrp,
    NULL, -- FFS_FLAG (NULL)
    NULL, -- ER_SG (NULL)
    NULL, -- ER_TI (NULL)
    NULL, -- ER_ZT (NULL)
    NULL, -- ER_DU (NULL)
    NULL, -- ER_SP (NULL)
    NULL -- ER_BD (NULL)
    DELETE FROM bndxing_tmp
         WHERE acid=F_Rec.Acid and flight_index=F_Rec.new_Flight_Index;
         COMMIT;
    EXCEPTION
    WHEN OTHERS THEN
    strErrorMessage := SQLERRM;
    INSERT INTO bnd_error VALUES (err_seq.NEXTVAL,
         sysdate,
         F_Rec.Acid,
         F_Rec.new_Flight_Index,
         'Exception from Finish loop: ' || strErrorMessage);
    COMMIT;
    END; -- End of Finish Loop
    END LOOP;
    EXCEPTION
    WHEN OTHERS THEN
    strErrorMessage := SQLERRM;
    INSERT INTO bnd_error VALUES (err_seq.NEXTVAL,
    sysdate,
    F_Rec.Acid,
    F_Rec.new_Flight_Index,
    'Exception from Stats loop: ' || strErrorMessage);
    COMMIT;
    END; -- End of Stats Loop
    --Reset cursor and track geometry
    CLOSE XCursor;
    F_Rec.flight_track.sdo_ordinates.delete;
    -- delete from hist_bndxing_tmp
    -- where acid=acid_var and new_flight_index=fi_var;
    FETCH FCursor INTO F_Rec;
    END LOOP;
    --DEBUG STATEMENT
    /* INSERT INTO bnd_error VALUES (err_seq.NEXTVAL,
    sysdate,
    acid_var,
    fi_var,
    'Checkpoint 7');
    CLOSE FCursor;
    theSeq := 1;
    OPEN BCursor;
    LOOP
    FETCH BCursor INTO BRec;
    IF BCursor%NOTFOUND THEN
    EXIT;
    END IF;
    UPDATE bndxing
    SET segment = theSeq
    WHERE CURRENT OF BCursor;
    theSeq := theSeq + 1;
    END LOOP;
    CLOSE BCursor;
    EXCEPTION
    WHEN OTHERS THEN
    strErrorMessage := SQLERRM;
    Insert into bnd_error values (err_seq.NEXTVAL,
    sysdate,
                             acid_var,
                             fi_var,
                             'Exception from main: ' || strErrorMessage);
    COMMIT;
    CLOSE FCursor;
    END; -- End of Main Loop
    SHOW ERRORS;
    --exit;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

  • To improve performance of select

    Hi all,
    I premise that I'm not a Dba Administrator, but I must resolve a performance problem.
    I read the Rob Van Wijk thread "When your query takes too long ..." and I'll post you my tkprof result
    Trace file: c:\oracle\product\10.2.0\admin\orcl\udump\orcl_ora_4220.trc
    Sort options: prsela  exeela  fchela 
    count    = number of times OCI procedure was executed
    cpu      = cpu time in seconds executing
    elapsed  = elapsed time in seconds executing
    disk     = number of physical reads of buffers from disk
    query    = number of buffers gotten for consistent read
    current  = number of buffers gotten in current mode (usually for update)
    rows     = number of rows processed by the fetch or execute call
    select a.CODI_AVVI, a.DESC_DENO_ENTE, a.DESC_DENO_ENTE_VISU, a.DESC_UFFI_ENTE, a.CODI_SIGL_PROV, a.NUME_AVVI,
    a.DESC_OGGE_LAVO_VISU, a.DESC_LAVO DESC_LAVO_VISU, a.IMPO_AVVI_VISU, NVL(a.IMPO_RIBA_visu,0) IMPO_RIBA_visu,
    ROUND(DECODE(a.PERC_RIBA,NULL, (((a.IMPO_AVVI-a.IMPO_RIBA)/(DECODE(a.IMPO_aVvi,0,1,a.IMPO_aVvi)))*100),a.PERC_RIBA),3) PERC_RIBA_VISU,
    a.DESC_NOTE_IMPO, a.CODI_LEGG_VINC, a.CODI_TIPO_AVVI, a.CODI_AZIE, a.DESC_FINA_0001, a.DESC_FINA_0002, a.DATA_PUBL DATA_PUBL_VISU,
    a.DATA_SCAD_VISU, a.DESC_SCAD_ORAA, a.DESC_SCAD_MINU, a.DATA_LICI_ESTE_RISU, a.CODI_IMPR_APPA, a.DESC_IMPR_AGGI, a.DESC_TIPO_AVVI_VISU,
    a.DESC_NOTE_ENTE, a.FLAG_CATE_STIM , a.CODI_TIPO_AGGI, a.FLAG_CIRC, a.DESC_caap, a.DESC_prov, a.DESC_NUME_TELE01 , a.DESC_NUME_FAXX01 ,
    a.DESC_INDI, a.DESC_ARTI_LEGG_BOLL DESC_ARTI_LEGG
    FROM V_ASP_REPOANAGAVVISTAM a
    WHERE (a.flag_risu in ('R','S') or (a.flag_risu='N' and a.NUME_DITT_INVI is not null))
    AND (to_Date('01/01/2002','dd/mm/yyyy') <= A.DATA_SCAD OR A.DATA_SCAD is null)
    and exists (select 1 from relaavvidettcate d where a.codi_avvi=d.codi_avvi and D.CODI_DETT_CATE IN ('114','115') )
    and ( a.impo_avvi >= 1000 and a.impo_avvi <= 3000000 )
    and decode(LENGTH(A.DATA_LICI), 10,to_date(A.DATA_LICI,'dd/mm/yyyy'), to_date(A.DATA_LICI,'mm/yyyy')) BETWEEN to_Date('04/2007','mm/yyyy') AND to_Date('05/2008','mm/yyyy')
    and ( UPPER(a.desc_deno_ente) like '%COMUNE DI ROMA%' )
    ORDER BY decode(LENGTH(A.DATA_LICI), 10,to_date(A.DATA_LICI,'dd/mm/yyyy'), to_date(A.DATA_LICI,'mm/yyyy')) DESC
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.37       0.38          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch       11      2.39       3.64        346     109663          0         139
    total       13      2.76       4.02        346     109663          0         139
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 385 
    Rows     Row Source Operation
        139  SORT ORDER BY (cr=109663 pr=346 pw=0 time=3640309 us)
        139   NESTED LOOPS OUTER (cr=109663 pr=346 pw=0 time=3665123 us)
        139    NESTED LOOPS OUTER (cr=109659 pr=346 pw=0 time=3638446 us)
        139     NESTED LOOPS OUTER (cr=109659 pr=346 pw=0 time=3634127 us)
        139      NESTED LOOPS OUTER (cr=109379 pr=346 pw=0 time=3626615 us)
        139       NESTED LOOPS OUTER (cr=109256 pr=346 pw=0 time=3621185 us)
        139        NESTED LOOPS OUTER (cr=109115 pr=346 pw=0 time=3616587 us)
        139         HASH JOIN OUTER (cr=109005 pr=346 pw=0 time=3608065 us)
        139          NESTED LOOPS OUTER (cr=108989 pr=346 pw=0 time=36498189 us)
        139           NESTED LOOPS  (cr=108848 pr=346 pw=0 time=36491383 us)
       1285            NESTED LOOPS OUTER (cr=106276 pr=346 pw=0 time=17103682 us)
       1285             NESTED LOOPS OUTER (cr=105171 pr=346 pw=0 time=17045852 us)
       1285              NESTED LOOPS  (cr=103907 pr=346 pw=0 time=16979031 us)
      50565               SORT UNIQUE (cr=2775 pr=0 pw=0 time=360760 us)
      51193                TABLE ACCESS FULL RELAAVVIDETTCATE (cr=2775 pr=0 pw=0 time=271031 us)
       1285               TABLE ACCESS BY INDEX ROWID ANAGAVVI (cr=101132 pr=346 pw=0 time=3041988 us)
      50565                INDEX UNIQUE SCAN PK_ANAGAVVI_CODIAVVI (cr=50567 pr=0 pw=0 time=762424 us)(object id 300074)
       1262              TABLE ACCESS BY INDEX ROWID PARATIPOAVVI (cr=1264 pr=0 pw=0 time=37709 us)
       1262               INDEX UNIQUE SCAN PK_PARATIPOAVVI_CODITIPO (cr=2 pr=0 pw=0 time=18013 us)(object id 300304)
       1103             TABLE ACCESS BY INDEX ROWID PARALEGG (cr=1105 pr=0 pw=0 time=35235 us)
       1103              INDEX UNIQUE SCAN PK_PARALEGG_CODILEGG (cr=2 pr=0 pw=0 time=16840 us)(object id 300245)
        139            TABLE ACCESS BY INDEX ROWID ANAGENTI (cr=2572 pr=0 pw=0 time=44695 us)
       1285             INDEX UNIQUE SCAN PK_ANAGENTI_CODIENTE (cr=1287 pr=0 pw=0 time=19447 us)(object id 300099)
        139           TABLE ACCESS BY INDEX ROWID PARAPROV (cr=141 pr=0 pw=0 time=4931 us)
        139            INDEX UNIQUE SCAN PK_CODIPROV (cr=2 pr=0 pw=0 time=1899 us)(object id 300286)
        781          TABLE ACCESS FULL ANAGIMPRPROG (cr=16 pr=0 pw=0 time=3167 us)
         54         TABLE ACCESS BY INDEX ROWID ANAGUFFIENTI (cr=110 pr=0 pw=0 time=5719 us)
         54          INDEX RANGE SCAN PK_ANAG_UFFI_ENTI_CODIUFFI (cr=56 pr=0 pw=0 time=1685 us)(object id 300135)
        139        INDEX UNIQUE SCAN PK_CODIPROVCOMU (cr=141 pr=0 pw=0 time=2599 us)(object id 300214)
         53       TABLE ACCESS BY INDEX ROWID ANAGIMPRAPPA (cr=123 pr=0 pw=0 time=3428 us)
         53        INDEX UNIQUE SCAN PK_ANAGIMPRAPPA_CODIIMPRAPPA (cr=70 pr=0 pw=0 time=1568 us)(object id 300103)
        139      TABLE ACCESS BY INDEX ROWID ANAGAZIERISU (cr=280 pr=0 pw=0 time=4380 us)
        139       INDEX UNIQUE SCAN PK_CODIAZIERISU (cr=141 pr=0 pw=0 time=2106 us)(object id 300080)
          0     TABLE ACCESS BY INDEX ROWID PARAFINA (cr=0 pr=0 pw=0 time=2975 us)
          0      INDEX UNIQUE SCAN PK_PARAFINA_CODIFINA (cr=0 pr=0 pw=0 time=1158 us)(object id 300234)
          3    TABLE ACCESS BY INDEX ROWID PARAFINA (cr=4 pr=0 pw=0 time=3210 us)
          3     INDEX UNIQUE SCAN PK_PARAFINA_CODIFINA (cr=1 pr=0 pw=0 time=1483 us)(object id 300234)
    alter session set sql_trace true
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total        1      0.00       0.00          0          0          0           0
    Misses in library cache during parse: 0
    Misses in library cache during execute: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 385 
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.37       0.38          0          0          0           0
    Execute      2      0.00       0.00          0          0          0           0
    Fetch       11      2.39       3.64        346     109663          0         139
    total       14      2.76       4.02        346     109663          0         139
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse       34      0.03       0.03          0          0          0           0
    Execute    200      0.01       0.01          0          0          0           0
    Fetch      820      0.04       0.03          0       1009          0         645
    total     1054      0.09       0.08          0       1009          0         645
    Misses in library cache during parse: 3
    Misses in library cache during execute: 3
        2  user  SQL statements in session.
      200  internal SQL statements in session.
      202  SQL statements in session.
    Trace file: c:\oracle\product\10.2.0\admin\orcl\udump\orcl_ora_4220.trc
    Trace file compatibility: 10.01.00
    Sort options: prsela  exeela  fchela 
           1  session in tracefile.
           2  user  SQL statements in trace file.
         200  internal SQL statements in trace file.
         202  SQL statements in trace file.
          25  unique SQL statements in trace file.
        2082  lines in trace file.
         355  elapsed seconds in trace file.I hope that I have problems on the full access of those table
    ANAGAVVI (228650 records)
    RELAAVVIDETTCATE (that have a PK of CODI_AVVI of ANAGAVVI and 394587records)
    Well... I have yet those indexes on those table
    AnagAvvi
    1^ index
    CREATE INDEX INDX_ANAGAVVI_NUMEAVVI
        ON ANAGAVVI("NUME_AVVI")
        TABLESPACE "TS_DATI" PCTFREE 10 INITRANS 2 MAXTRANS 255
        STORAGE ( INITIAL 5120K NEXT 0K MINEXTENTS 1 MAXEXTENTS
        2147483645 PCTINCREASE 0)
        LOGGING2^ index
    CREATE INDEX INDX_ANAGAVVI_NUMEAVVI02
        ON ANAGAVVI (SUBSTR("NUME_AVVI",2))
        TABLESPACE "TS_DATI" PCTFREE 10 INITRANS 2 MAXTRANS 255
        STORAGE ( INITIAL 7168K NEXT 0K MINEXTENTS 1 MAXEXTENTS
        2147483645 PCTINCREASE 0)
        LOGGING3^ index PK_
    CREATE UNIQUE INDEX PK_ANAGAVVI_CODIAVVI
        ON ANAGAVVI ("CODI_AVVI")
        TABLESPACE "TS_DATI" PCTFREE 10 INITRANS 2 MAXTRANS 255
        STORAGE ( INITIAL 4096K NEXT 0K MINEXTENTS 1 MAXEXTENTS
        2147483645 PCTINCREASE 0)
        LOGGINGOn table RELAAVVIDETTCATE, I have only this index
    CREATE UNIQUE INDEX PK_RELAAVVIDETTCATE_CODI
        ON RELAAVVIDETTCATE ("CODI_AVVI_DETT_CATE")
        TABLESPACE "TS_DATI" PCTFREE 10 INITRANS 2 MAXTRANS 255
        STORAGE ( INITIAL 7168K NEXT 0K MINEXTENTS 1 MAXEXTENTS
        2147483645 PCTINCREASE 0)
        LOGGINGI have just found this configuration, so I didn't because it has done in this way.
    If you need more information, I'll give all :)
    Thank's for read this post
    Paolo from Madrid

    Hi Rob and Hi all,
    sorry for the answer too late.
    I'll post again my problems for the select that you'll find on the tkprof file of this post.
    You can see the View V_ASP_REPOANAGAVVISTAM, in one of my messagge above.
    When I produced tkprof, I have got this indexes
    CREATE INDEX INDX_RELAAVVIDETTCATE_DETTCATE
        ON RELAAVVIDETTCATE("CODI_DETT_CATE")
        TABLESPACE "TS_SIAG_DATI" PCTFREE 10 INITRANS 2 MAXTRANS 255
        STORAGE ( INITIAL 5120K NEXT 0K MINEXTENTS 1 MAXEXTENTS
        2147483645 PCTINCREASE 0)
        LOGGING
    CREATE INDEX INDX_RELAAVVIPROV_CODIPROV
        ON RELAAVVIPROV("CODI_PROV")
        TABLESPACE "TS_SIAG_DATI" PCTFREE 10 INITRANS 2 MAXTRANS 255
        STORAGE ( INITIAL 5120K NEXT 0K MINEXTENTS 1 MAXEXTENTS
        2147483645 PCTINCREASE 0)
        LOGGINGThere aren't on table AnagAvvi.
    The Tkprof is this
    TKPROF: Release 10.2.0.1.0 - Production on Lun Apr 28 13:50:42 2008
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Trace file: c:\oracle\product\10.2.0\admin\orcl\udump\orcl_ora_4160.trc
    Sort options: prsela  exeela  fchela 
    count    = number of times OCI procedure was executed
    cpu      = cpu time in seconds executing
    elapsed  = elapsed time in seconds executing
    disk     = number of physical reads of buffers from disk
    query    = number of buffers gotten for consistent read
    current  = number of buffers gotten in current mode (usually for update)
    rows     = number of rows processed by the fetch or execute call
    select CODI_AVVI, NVL(IMPO_RIBA_visu,0) IMPO_RIBA_visu,
    ROUND(DECODE(PERC_RIBA,NULL, (((IMPO_AVVI-IMPO_RIBA)/(DECODE(IMPO_aVvi,0,1,IMPO_aVvi)))*100),PERC_RIBA),3) PERC_RIBA_VISU
    FROM V_ASP_REPOANAGAVVISTAM
    WHERE (flag_risu in ('R','S') or (flag_risu='N' and NUME_DITT_INVI is not null))
    AND (to_Date('01/01/2002','dd/mm/yyyy') <= DATA_SCAD OR DATA_SCAD is null)
    and exists ( select  1  from relaavvidettcate d  where  codi_avvi=d.codi_avvi  and  D.CODI_DETT_CATE IN ('114','115')  )
    and ( impo_avvi >= 1000 and impo_avvi <= 3000000 )
    and decode(LENGTH(DATA_LICI), 10,to_date(DATA_LICI,'dd/mm/yyyy'), to_date(DATA_LICI,'mm/yyyy')) BETWEEN to_Date('04/2007','mm/yyyy')
    AND to_Date('05/2008','mm/yyyy') and ( UPPER(desc_deno_ente) like '%COMUNE DI ROMA%' )
    ORDER BY decode(LENGTH(DATA_LICI), 10,to_date(DATA_LICI,'dd/mm/yyyy'), to_date(DATA_LICI,'mm/yyyy')) DESC
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.45       0.46          0          0          0           0
    Execute      1      0.00       0.00          0          3          0           0
    Fetch       18      0.62       0.61          0      19101          0         251
    total       20      1.07       1.08          0      19104          0         251
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 385 
    Rows     Row Source Operation
        251  SORT ORDER BY (cr=19104 pr=0 pw=0 time=620275 us)
        251   FILTER  (cr=19104 pr=0 pw=0 time=628996 us)
        251    NESTED LOOPS OUTER (cr=19101 pr=0 pw=0 time=627135 us)
        251     NESTED LOOPS OUTER (cr=19100 pr=0 pw=0 time=622610 us)
        251      NESTED LOOPS OUTER (cr=19100 pr=0 pw=0 time=617834 us)
        251       NESTED LOOPS OUTER (cr=18847 pr=0 pw=0 time=610298 us)
        251        NESTED LOOPS OUTER (cr=18716 pr=0 pw=0 time=605522 us)
        251         NESTED LOOPS OUTER (cr=18463 pr=0 pw=0 time=597736 us)
        251          HASH JOIN OUTER (cr=18370 pr=0 pw=0 time=591443 us)
        251           NESTED LOOPS OUTER (cr=18354 pr=0 pw=0 time=159246 us)
        251            NESTED LOOPS  (cr=18352 pr=0 pw=0 time=127968 us)
       3732             NESTED LOOPS OUTER (cr=10886 pr=0 pw=0 time=536807 us)
       3732              NESTED LOOPS OUTER (cr=10884 pr=0 pw=0 time=443498 us)
       3732               TABLE ACCESS FULL ANAGAVVI (cr=10882 pr=0 pw=0 time=331524 us)
       3687               INDEX UNIQUE SCAN PK_PARATIPOAVVI_CODITIPO (cr=2 pr=0 pw=0 time=52258 us)(object id 300304)
       3158              INDEX UNIQUE SCAN PK_PARALEGG_CODILEGG (cr=2 pr=0 pw=0 time=47517 us)(object id 300245)
        251             TABLE ACCESS BY INDEX ROWID ANAGENTI (cr=7466 pr=0 pw=0 time=124877 us)
       3732              INDEX UNIQUE SCAN PK_ANAGENTI_CODIENTE (cr=3734 pr=0 pw=0 time=56423 us)(object id 300099)
        251            INDEX UNIQUE SCAN PK_CODIPROV (cr=2 pr=0 pw=0 time=3502 us)(object id 300286)
        781           TABLE ACCESS FULL ANAGIMPRPROG (cr=16 pr=0 pw=0 time=3159 us)
         91          INDEX RANGE SCAN PK_ANAG_UFFI_ENTI_CODIUFFI (cr=93 pr=0 pw=0 time=2887 us)(object id 300135)
        251         INDEX UNIQUE SCAN PK_CODIPROVCOMU (cr=253 pr=0 pw=0 time=3616 us)(object id 300214)
        102        INDEX UNIQUE SCAN PK_ANAGIMPRAPPA_CODIIMPRAPPA (cr=131 pr=0 pw=0 time=2804 us)(object id 300103)
        251       INDEX UNIQUE SCAN PK_CODIAZIERISU (cr=253 pr=0 pw=0 time=3684 us)(object id 300080)
          0      INDEX UNIQUE SCAN PK_PARAFINA_CODIFINA (cr=0 pr=0 pw=0 time=2205 us)(object id 300234)
          6     INDEX UNIQUE SCAN PK_PARAFINA_CODIFINA (cr=1 pr=0 pw=0 time=2330 us)(object id 300234)
          1    INLIST ITERATOR  (cr=3 pr=0 pw=0 time=87 us)
          1     INDEX RANGE SCAN INDX_RELAAVVIDETTCATE_DETTCATE (cr=3 pr=0 pw=0 time=40 us)(object id 303246)
    alter session set sql_trace true
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.02          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total        1      0.00       0.02          0          0          0           0
    Misses in library cache during parse: 0
    Misses in library cache during execute: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 385 
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.45       0.46          0          0          0           0
    Execute      2      0.00       0.02          0          3          0           0
    Fetch       18      0.62       0.61          0      19101          0         251
    total       21      1.07       1.10          0      19104          0         251
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse       19      0.01       0.19          0          0          0           0
    Execute     41      0.07       0.16          0          0          0           0
    Fetch       51      0.00       0.03          0        118          0         162
    total      111      0.09       0.39          0        118          0         162
    Misses in library cache during parse: 5
    Misses in library cache during execute: 5
        2  user  SQL statements in session.
       41  internal SQL statements in session.
       43  SQL statements in session.
    Trace file: c:\oracle\product\10.2.0\admin\orcl\udump\orcl_ora_4160.trc
    Trace file compatibility: 10.01.00
    Sort options: prsela  exeela  fchela 
           1  session in tracefile.
           2  user  SQL statements in trace file.
          41  internal SQL statements in trace file.
          43  SQL statements in trace file.
          10  unique SQL statements in trace file.
         455  lines in trace file.
          10  elapsed seconds in trace file.While the explain plain is this
    PLAN_TABLE_OUTPUT
    | Id  | Operation                              | Name
    | Rows  | Bytes | Cost (%CPU)|
    |   0 | SELECT STATEMENT                       |
    PLAN_TABLE_OUTPUT
    |     1 |   136 |  2452   (3)|
    |   1 |  SORT ORDER BY                         |
    |     1 |   136 |  2452   (3)|
    |   2 |   FILTER                               |
    |       |       |            |
    |   3 |    NESTED LOOPS OUTER                  |
    |     1 |   136 |  2447   (3)|
    PLAN_TABLE_OUTPUT
    |   4 |     NESTED LOOPS OUTER                 |
    |     1 |   133 |  2447   (3)|
    |   5 |      NESTED LOOPS OUTER                |
    |     1 |   130 |  2447   (3)|
    |   6 |       NESTED LOOPS OUTER               |
    |     1 |   125 |  2447   (3)|
    |   7 |        NESTED LOOPS OUTER              |
    |     1 |   120 |  2447   (3)|
    PLAN_TABLE_OUTPUT
    |   8 |         NESTED LOOPS OUTER             |
    |     1 |   114 |  2447   (3)|
    |   9 |          HASH JOIN OUTER               |
    |     1 |   110 |  2446   (3)|
    |  10 |           NESTED LOOPS OUTER           |
    |     1 |   106 |  2440   (3)|
    |  11 |            NESTED LOOPS                |
    PLAN_TABLE_OUTPUT
    |     1 |   102 |  2440   (3)|
    |  12 |             NESTED LOOPS OUTER         |
    |     1 |    52 |  2439   (3)|
    |  13 |              NESTED LOOPS OUTER        |
    |     1 |    49 |  2439   (3)|
    |  14 |               TABLE ACCESS FULL        | ANAGAVVI
    |     1 |    46 |  2439   (3)|
    PLAN_TABLE_OUTPUT
    |  15 |               INDEX UNIQUE SCAN        | PK_PARATIPOAVVI_CODITIPO
    |     1 |     3 |     0   (0)|
    |  16 |              INDEX UNIQUE SCAN         | PK_PARALEGG_CODILEGG
    |     1 |     3 |     0   (0)|
    |  17 |             TABLE ACCESS BY INDEX ROWID| ANAGENTI
    |     1 |    50 |     1   (0)|
    |  18 |              INDEX UNIQUE SCAN         | PK_ANAGENTI_CODIENTE
    |     1 |       |     0   (0)|
    PLAN_TABLE_OUTPUT
    |  19 |            INDEX UNIQUE SCAN           | PK_CODIPROV
    |     1 |     4 |     0   (0)|
    |  20 |           TABLE ACCESS FULL            | ANAGIMPRPROG
    |   781 |  3124 |     5   (0)|
    |  21 |          INDEX RANGE SCAN              | PK_ANAG_UFFI_ENTI_CODIUFFI
    |     1 |     4 |     1   (0)|
    |  22 |         INDEX UNIQUE SCAN              | PK_CODIPROVCOMU
    PLAN_TABLE_OUTPUT
    |     1 |     6 |     0   (0)|
    |  23 |        INDEX UNIQUE SCAN               | PK_ANAGIMPRAPPA_CODIIMPRAPPA
    |     1 |     5 |     0   (0)|
    |  24 |       INDEX UNIQUE SCAN                | PK_CODIAZIERISU
    |     1 |     5 |     0   (0)|
    |  25 |      INDEX UNIQUE SCAN                 | PK_PARAFINA_CODIFINA
    |     1 |     3 |     0   (0)|
    PLAN_TABLE_OUTPUT
    |  26 |     INDEX UNIQUE SCAN                  | PK_PARAFINA_CODIFINA
    |     1 |     3 |     0   (0)|
    |  27 |    INLIST ITERATOR                     |
    |       |       |            |
    |  28 |     INDEX RANGE SCAN                   | INDX_RELAAVVIDETTCATE_DETTCATE
    |       |       |     3   (0)|
    PLAN_TABLE_OUTPUT
    Note
       - 'PLAN_TABLE' is old version
    [PRE]
    Thank's for any suggestion                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          

  • How to improve performance of this SQL query?

    Hi,
    I have a query that tries to build a string (RPATH) for use as a url parameter. The query is:
    SELECT DISTINCT USERNAME, PASSWORD, ROLE, RIGHTS,
    DECODE(GEO, ROLE, 'g='||NVL(GEO,'none'), NULL)||
         DECODE(AREA, ROLE, 'g='||NVL(GEO,'none')||'&a='||NVL(AREA,'none'), NULL)||
         DECODE(REGION, ROLE, 'g='||NVL(GEO,'none')||'&a='||NVL(AREA,'none')||'&r='||NVL(REGION,'none'), NULL)||
         DECODE(DISTRICT, ROLE, 'g='||NVL(GEO,'none')||'&a='||NVL(AREA,'none')||'&r='||NVL(REGION,'none')||'&d='||NVL(DISTRICT,'none'), NULL)||
         DECODE(OFFICE, ROLE, 'g='||NVL(GEO,'none')||'&a='||NVL(AREA,'none')||'&r='||NVL(REGION,'none')||'&d='||NVL(DISTRICT,'none')||'&o='||NVL(OFFICE,'none')
    , NULL) RPATH
    FROM (SELECT U.*, L.*
         FROM (SELECT * FROM T_USERS WHERE USERNAME='xxx' AND PASSWORD='yyy') U, T_LOC_SUB L
         WHERE U.ROLE IN ('WW', L.GEO, L.AREA, L.REGION, L.DISTRICT, L.OFFICE))
    GROUP BY USERNAME, PASSWORD, ROLE, RIGHTS, GEO, AREA, REGION, DISTRICT, OFFICE;
    T_USERS is defined as
    CREATE TABLE T_USERS (
    username          VARCHAR2(10)     CONSTRAINT T_USERS_username_pk PRIMARY KEY,
    password          VARCHAR2(10),
    role                    CONSTRAINT T_USERS_role_FK REFERENCES T_LOC_MAIN(loc),
    rights          VARCHAR2(3)
    T_LOC_SUB is defined as
    CREATE TABLE T_LOC_SUB (
    geo          CONSTRAINT T_LOC_SUB_geo_FK REFERENCES T_LOC_MAIN(loc),
    area          CONSTRAINT T_LOC_SUB_area_FK REFERENCES T_LOC_MAIN(loc),
    region          CONSTRAINT T_LOC_SUB_region_FK REFERENCES T_LOC_MAIN(loc),
    district     CONSTRAINT T_LOC_SUB_district_FK REFERENCES T_LOC_MAIN(loc),
    office          CONSTRAINT T_LOC_SUB_office_FK REFERENCES T_LOC_MAIN(loc)
    T_LOC_MAIN is defined as
    CREATE TABLE T_LOC_MAIN (
    loc          VARCHAR2(4)     CONSTRAINT T_LOC_MAIN_loc_PK PRIMARY KEY,
    label          VARCHAR2(60),
    rank          NUMBER
    REGION and DISTRICT columns in T_LOC_SUB may be NULL at times. How can I rewrite the SQL to make it run faster or more efficiently?
    Please help.. Thank you..

    Hi,
    I just realised I can simplify the query to:
    SELECT DISTINCT USERNAME, PASSWORD, ROLE, RIGHTS,
    DECODE(ROLE,
         GEO, 'g='||NVL(GEO,'none'),
         AREA, 'g='||NVL(GEO,'none')||'&a='||NVL(AREA,'none'),
         REGION, 'g='||NVL(GEO,'none')||'&a='||NVL(AREA,'none')||'&r='||NVL(REGION,'none'),
         DISTRICT, 'g='||NVL(GEO,'none')||'&a='||NVL(AREA,'none')||'&r='||NVL(REGION,'none')||'&d='||NVL(DISTRICT,'none'),
         OFFICE, 'g='||NVL(GEO,'none')||'&a='||NVL(AREA,'none')||'&r='||NVL(REGION,'none')||'&d='||NVL(DISTRICT,'none')||'&o='||NVL(OFFICE,'none'),
         NULL) RPATH
    FROM (SELECT U.*, L.*
    FROM (SELECT * FROM T_USERS WHERE USERNAME='xxx' AND PASSWORD='yyy') U, T_LOC_SUB L
    WHERE U.ROLE IN ('WW', L.GEO, L.AREA, L.REGION, L.DISTRICT, L.OFFICE))
    GROUP BY USERNAME, PASSWORD, ROLE, RIGHTS, GEO, AREA, REGION, DISTRICT, OFFICE;
    Anyone can offer a better and more efficient improvement?
    Thanx!

  • How can we improve performance while selection production orders from resb

    Dear all,
    there is a performance issue in a report which compares sales order and production order.
    Below is the code, in this while reading production order data from resb with the below select statement.
    can any body tell me how can we improve the performance? should we use indexing, if yes how to use indexing.
    *read sales order data
      SELECT vbeln posnr arktx zz_cl zz_qty
      INTO (itab-vbeln, itab-sposnr, itab-arktx, itab-zz_cl, itab-zz_qty)
      FROM vbap
      WHERE vbeln  = p_vbeln
      AND   uepos  = p_posnr.
        itab-so_qty = itab-zz_cl * itab-zz_qty / 1000.
        CONCATENATE itab-vbeln itab-sposnr
           INTO itab-document SEPARATED BY '/'.
        CLEAR total_pro.
    **read production order data*
        SELECT aufnr posnr roms1 roanz
        INTO (itab-aufnr, itab-pposnr, itab-roms1, itab-roanz)
        FROM resb
        WHERE kdauf  = p_vbeln
        AND   ablad  = itab-sposnr+2.

    Himanshu,
    Put a break point before these two select statements and execute in the production.This way you will come to know which select statement is taking much time to get executed.
    In both the select statements the where clause is not having the primary keys.
    Coming to the point of selecting the data from vbap do check the SAP note no:-185530 accordigly modify the select statement.
    As far as the table RESB is concerened here also the where clause doesn't have the primary keys.Do check the SAP Note No:-187906.
    I guess not using primary keys is maring the performance.
    K.Kiran.

  • Improve Performance on Inline view Query

    All,
    I have a unique situation where I have to limit the number of rows based on group. so I created an Inline view and applied a limit on it.
    ex:
    SELECT col_A, col_B FROM ( SELECT col_a, count(*) FROM tab_a WHERE col_a = 'XXX' GROUP BY col_a) ROWNUM <-10.
    but this design was rejected, because it seems to have a great impact on performance due to inline view.
    Also I cant set a rowlimit directly on the query because GROUP BY clause is used in the select.
    When the rownum is directly applied in the WHERE, first it limits the rows and then it makes a GROUP, so when user asks to retrieve 10 records, it may show less than 10 rows because of the grouping.
    please help to find a alternative solution which helps to get the expected result set and same time without loosing performance

    but this design was rejected, because it seems to have a great impact on performance due to inline view.What proof was offered that this query performed badly. There is nothing inherently non-performant about in-line views. I would demand to see some evidence that this query uses an unreasonable amount of system resource.
    However, you could try this:
    SELECT t.col1, avg(t.col2)
    FROM   t1 t
    WHERE  t.col1 IN ( SELECT DISTINCT x.col1
                       FROM   t1 x
                       WHERE  col3 = 'XXX'
                       AND    rownum <=10 )
    GROUP  BY t.col1
    /I assume your example is not derived from your real code (otherwise the WHERE clause would restrict the inline query to one returned row - problem solved!)
    Cheers, APC

Maybe you are looking for

  • Error while starting Integrated Weblogic Server - Jdeveloper 11.1.1.4

    I installed Jdevloper 11.1.1.4, and getting the below error while starting Integrated Weblogic Server: [Waiting for the domain to finish building...] [05:13:34 PM] Creating Integrated Weblogic domain... The Server Instance cannot be started because t

  • My ipod doesn't get recognized by my pc

    hi, for a longer time now, i've got several problems with my ipod nano, the first is, the ipod doesnt really start, it shows the apple logo and after that it turns off and restarts... and thats what it does all the time, until the battery is empty...

  • HELP! : Missing harddrive

    Hello, I'm hoping someone, anyone can possibly help me here. I'm not exactly a techy, so if i haven't described the full picture enough, please let me know. I have a powerbook G4 (OS X 10.3.9. 1.25 GHz Processor, 512 MB Memory and 60Gb Harddrive). It

  • Apple mail set up

    I'm a new Max user, I couldn't add my university email (based on gmail) to Apple mail, however I have another regular gmail and it worked just fine. My university email works fine on my iPhone and iPad. Could someone please give some suggestions?

  • UNABLE TO SET parallel_automatic_tuning=TRUE IN Oracle9i Enterprise Edition

    Hi, i am trying to set parallel_automatic_tuning=TRUE . but i am unable to set it. My oracle version is as below. SQL> SELECT * FROM V$VERSION; BANNER Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production PL/SQL Release 9.2.0.1.0 - Production CO