Help me query tunning

Hi Guru's
Can you please help me query tunning.
Database Version : Oracle 11g - 11.2.0.3
select  distinct  corporation_name custer_name,
        glog_util.remove_domain(SHIP_BUY.SERVPROV_GID ) SCAC,
        glog_util.remove_domain(ship_buy.shipment_gid) buy_shipment_gid,
        F_Get_SELL_ID_STRING(SHIP_BUY.SHIPMENT_GID) sell_shipment_gid,
        ship_buy.domain_name,    
        F_GET_ORDER_RELEASE_GID('B',SHIP_BUY.SHIPMENT_GID,0) ORDER_RELEASE_GID,
        f_get_refnum_string('SHIPMENT', ship_buy.shipment_gid, 'MBOL_NUMBER_CLEANSED')MBOL_NUMBER,
        F_GET_POD_RECEIVED_DATE (ship_BUY.SHIPMENT_GID) POD_RECEIVED_DATE,
        f_get_exp_accrue_amt(ship_buy.shipment_gid,'SHIPMENT') Total_accrual_amount    
from shipment ship_buy,
        invoice inv,
        invoice_shipment si,
        --voucher v,
        corporation corp
where corp.domain_name=ship_buy.domain_name
        and corp.is_domain_master='Y'
      and 1=1
      AND ship_buy.domain_name like 'UPS/CP/DFP/%'
      and F_GET_POD_RECEIVED_DATE (ship_BUY.SHIPMENT_GID)  <= to_char(to_date('31-JUL-2013', 'DD-MON-YYYY'), 'dd-mon-yyyy')
        --and V.INVOICE_GID(+) = inv.invoice_gid
        --and ship_buy.domain_name = 'UPS/CP/VZNB'
        and si.shipment_gid(+) = SHIP_BUY.SHIPMENT_GID
        AND SI.INVOICE_GID = INV.INVOICE_GID(+)
        and SHIP_BUY.INSERT_DATE > '1-JAN-2007'
        and SHIP_BUY.USER_DEFINED1_ICON_GID = 'ACCEPTED'
UNION        
select  distinct  corporation_name custer_name,
        glog_util.remove_domain(SHIP_BUY.SERVPROV_GID ) SCAC,
        glog_util.remove_domain(ship_buy.shipment_gid) buy_shipment_gid,
        F_GET_SELL_ID_STRING( SHIP_BUY.SHIPMENT_GID) sell_shipment_gid,
        ship_buy.domain_name,    
        F_GET_ORDER_RELEASE_GID('B',SHIP_BUY.SHIPMENT_GID,0) ORDER_RELEASE_GID,
        f_get_refnum_string('SHIPMENT', ship_buy.shipment_gid, 'MBOL_NUMBER_CLEANSED')MBOL_NUMBER,
        F_GET_POD_RECEIVED_DATE (ship_BUY.SHIPMENT_GID) POD_RECEIVED_DATE,
        f_get_exp_accrue_amt(inv.invoice_gid,'INVOICE') Total_accrual_amount  
from shipment ship_buy,
        invoice inv,
        invoice_shipment si,
      -- voucher v,
        corporation corp
where corp.domain_name=ship_buy.domain_name
        and corp.is_domain_master='Y'
        and 1=1
        AND ship_buy.domain_name like 'UPS/CP/DFP/%'
        and F_GET_POD_RECEIVED_DATE (ship_BUY.SHIPMENT_GID)  <= to_char(to_date('31-JUL-2013', 'DD-MON-YYYY'), 'dd-mon-yyyy')
      --AND INV.DOMAIN_NAME = 'UPS/CP/VZNB'
      --and V.INVOICE_GID(+) = inv.invoice_gid
        and si.shipment_gid(+) = SHIP_BUY.SHIPMENT_GID
        AND SI.INVOICE_GID = INV.INVOICE_GID(+)
        and SHIP_BUY.INSERT_DATE > '1-JAN-2007'
        and INV.USER_DEFINED1_ICON_GID = 'ACCEPTED'
GROUP BY corporation_name,SHIP_BUY.SHIPMENT_GID,SHIP_BUY.SERVPROV_GID,ship_buy.domain_name,inv.invoice_gid
ORDER BY CUSTER_NAME, BUY_SHIPMENT_GID;
And I generated the execution plan :
| Id  | Operation                          | Name                    | Rows  | Bytes | Cost (%CPU)| Time    |
|  0 | SELECT STATEMENT                  |                        |    3 |  448 |  415  (2)| 00:00:05 |
|  1 |  SORT UNIQUE                      |                        |    3 |  448 |  414  (87)| 00:00:05 |
|  2 |  UNION-ALL                        |                        |      |      |            |          |
|  3 |    NESTED LOOPS OUTER              |                        |    3 |  384 |    57  (0)| 00:00:01 |
|*  4 |    HASH JOIN                      |                        |    3 |  294 |    54  (0)| 00:00:01 |
|*  5 |      TABLE ACCESS BY INDEX ROWID  | SHIPMENT                |    3 |  195 |    40  (0)| 00:00:01 |
|*  6 |      INDEX SKIP SCAN              | IND_SHIP_DOM_ICON      |    54 |      |    25  (0)| 00:00:01 |
|*  7 |      TABLE ACCESS FULL            | CORPORATION            |    4 |  132 |    14  (0)| 00:00:01 |
|*  8 |    INDEX RANGE SCAN              | IND_INVOICESHIP_SHP_GID |    1 |    30 |    1  (0)| 00:00:01 |
|  9 |    HASH GROUP BY                  |                        |    1 |  192 |  356  (1)| 00:00:05 |
|* 10 |    HASH JOIN                      |                        |    1 |  192 |  354  (1)| 00:00:05 |
|  11 |      NESTED LOOPS                  |                        |      |      |            |          |
|  12 |      NESTED LOOPS                |                        |    1 |  159 |  339  (0)| 00:00:05 |
|  13 |        NESTED LOOPS                |                        |  145 | 13920 |  194  (0)| 00:00:03 |
|  14 |        TABLE ACCESS BY INDEX ROWID| INVOICE                |  145 |  5220 |    49  (0)| 00:00:01 |
|* 15 |          INDEX SKIP SCAN          | IDX_INV_TYP_ICON_NAM    |  145 |      |    17  (0)| 00:00:01 |
|* 16 |        INDEX RANGE SCAN          | UK_INVOICE_SHIPMENT    |    1 |    60 |    1  (0)| 00:00:01 |
|* 17 |        INDEX UNIQUE SCAN          | PK_SHIPMENT            |    1 |      |    1  (0)| 00:00:01 |
|* 18 |      TABLE ACCESS BY INDEX ROWID  | SHIPMENT                |    1 |    63 |    1  (0)| 00:00:01 |
|* 19 |      TABLE ACCESS FULL            | CORPORATION            |    4 |  132 |    14  (0)| 00:00:01 |
Predicate Information (identified by operation id):
  4 - access("CORP"."DOMAIN_NAME"="SHIP_BUY"."DOMAIN_NAME")
  5 - filter("F_GET_POD_RECEIVED_DATE"("SHIP_BUY"."SHIPMENT_GID")<=TO_DATE(' 2013-07-31 00:00:00',
              'syyyy-mm-dd hh24:mi:ss') AND "SHIP_BUY"."INSERT_DATE">TO_DATE(' 2007-01-01 00:00:00', 'syyyy-mm-dd
              hh24:mi:ss'))
  6 - access("SHIP_BUY"."USER_DEFINED1_ICON_GID"='ACCEPTED' AND "SHIP_BUY"."DOMAIN_NAME" LIKE
              'UPS/CP/DFP/%')
      filter("SHIP_BUY"."DOMAIN_NAME" LIKE 'UPS/CP/DFP/%' AND
              "SHIP_BUY"."USER_DEFINED1_ICON_GID"='ACCEPTED')
  7 - filter("CORP"."IS_DOMAIN_MASTER"='Y' AND "CORP"."DOMAIN_NAME" LIKE 'UPS/CP/DFP/%')
  8 - access("SI"."SHIPMENT_GID"(+)="SHIP_BUY"."SHIPMENT_GID")
  10 - access("CORP"."DOMAIN_NAME"="SHIP_BUY"."DOMAIN_NAME")
  15 - access("INV"."USER_DEFINED1_ICON_GID"='ACCEPTED')
      filter("INV"."USER_DEFINED1_ICON_GID"='ACCEPTED')
  16 - access("SI"."INVOICE_GID"="INV"."INVOICE_GID")
  17 - access("SI"."SHIPMENT_GID"="SHIP_BUY"."SHIPMENT_GID")
      filter("F_GET_POD_RECEIVED_DATE"("SHIP_BUY"."SHIPMENT_GID")<=TO_DATE(' 2013-07-31 00:00:00',
              'syyyy-mm-dd hh24:mi:ss'))
  18 - filter("SHIP_BUY"."DOMAIN_NAME" LIKE 'UPS/CP/DFP/%' AND "SHIP_BUY"."INSERT_DATE">TO_DATE('
              2007-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
  19 - filter("CORP"."IS_DOMAIN_MASTER"='Y' AND "CORP"."DOMAIN_NAME" LIKE 'UPS/CP/DFP/%')
Statistics
    246247  recursive calls
          2  db block gets
    1660067  consistent gets
      13839  physical reads
          0  redo size
    592054  bytes sent via SQL*Net to client
      6024  bytes received via SQL*Net from client
        502  SQL*Net roundtrips to/from client
      15296  sorts (memory)
          0  sorts (disk)
      7513  rows processed

Hmmm...why does this look familiar?
F_GET_POD_RECEIVED_DATE (ship_BUY.SHIPMENT_GID)  <= to_char(to_date('31-JUL-2013', 'DD-MON-YYYY'), 'dd-mon-yyyy')
SHIP_BUY.INSERT_DATE > '1-JAN-2007'
Like I said in your other thread about this, these two lines need to be fixed and your function needs to be fixed so the return statement doesn't do an implicit date conversion.
Can't you see what that first line is doing?  You're taking a character string, turning it into a date, then back to a character string.
If nothing else, these lines should be...
F_GET_POD_RECEIVED_DATE (ship_BUY.SHIPMENT_GID)  <= to_date('31-JUL-2013', 'DD-MON-YYYY')
SHIP_BUY.INSERT_DATE > to_date('01-JAN-2007','DD-MON-YYYY')
(assuming insert_date is a proper date format, fingers crossed)

Similar Messages

  • Help needed to tune the Query:Statistics added

    Can someone DBA please help me to tune this query:
    SELECT DISTINCT K.ATTRIBUTE_VALUE AGENCY_ID,B.PROFILE_NM ,NVL(G.OFFICE_DESC,'--') OFFICE_DESC,f.OFFICE_ID,B.PROFILE_ID,'%' ROLE,'%' LAYOUT,
    CASE
    WHEN 'flagB' = '%' THEN
    NVL(J.ISS_GRP_DESC,'BILLING')
    WHEN 'flagO' = '%' THEN
    NVL(J.ISS_GRP_DESC,'ORDERING')
    WHEN 'flag' = '%' THEN
    NVL(J.ISS_GRP_DESC,'BILLING/ORDERING')
    ELSE
    NVL(J.ISS_GRP_DESC,' ')
    END ISS_GRP_DESC,
    DECODE(NVL(H.USERID,' ') ,' ','--','<a sbcuid_in=' || H.USERID || ' target=NEW >'||H.FIRSTNAME || ' ' || H.LASTNAME || '( ' || H.USERID || ' )</a>' ) USER_NAME
    FROM
    PROFILE_PORTAL B ,
    TBL_BDA_AGENCY_RESP_REP C ,
    TBL_BDA_AGENCY_OFFICE F,
    TBL_BDA_OFFICE G,
    USERS_PORTAL H,
    TBL_BDA_USR_ISS_GRP I ,
    TBL_BDA_ISS_GROUP J,
    ATTRIBUTE_VALUES_PORTAL K,
    PROFILE_TYPE_PORTAL L
    WHERE
    B.PROFILE_ID = F.AGENCY_ID (+)
    AND B.PROFILE_ID = C.AGENCY_ID (+)
    AND G.OFFICE_ID (+)= F.OFFICE_ID
    AND H.USERID (+)= C.RESP_USR_ID
    AND C.ISS_GRP_ID = I.ISS_GRP_ID (+)
    AND I.ISS_GRP_ID = J.ISS_GRP_ID(+)
    AND 'PROFILE.'||B.PROFILE_ID = K.ENTITY_ID(+)
    AND K.ATTRIBUTE_VALUE IS NOT NULL
    AND L.PROFILE_TYPE_ID = B.PROFILE_TYPE_ID
    AND L.APPLICATION_CD='BDA'
    AND NOT EXISTS (SELECT agency_id
    FROM TBL_BDA_AGENCY_RESP_REP t
    WHERE t.ISS_GRP_ID IN ('%')
    AND t.AGENCY_ID = C.AGENCY_ID)
    AND K.ATTRIBUTE_VALUE LIKE '%'
    AND UPPER(B.PROFILE_NM) LIKE UPPER('%')
    AND (to_char(NVL(B.PROFILE_ID,0)) LIKE '%' OR NVL(B.PROFILE_ID,0) IN ('a'))
    AND NVL(G.OFFICE_ID,0) IN ('%')
    AND (to_char(NVL(C.RESP_USR_ID,'0')) LIKE '%' OR NVL(C.RESP_USR_ID,'0') IN ('k'))
    ORDER BY PROFILE_NM
    The number of rows in these tables are as follows:
    PROFILE_PORTAL -- 2392
    TBL_BDA_AGENCY_RESP_REP 3508
    TBL_BDA_AGENCY_OFFICE 2151
    TBL_BDA_OFFICE 3
    USERS_PORTAL 270500
    TBL_BDA_USR_ISS_GRP 234
    TBL_BDA_ISS_GROUP 2
    ATTRIBUTE_VALUES_PORTAL 2790
    PROFILE_TYPE_PORTAL 3
    The Explain pal nhas given this o/p to me:
    SQL> select * from table(dbms_xplan.display) dual;
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost |
    | 0 | SELECT STATEMENT | | 807 | 102K| | 2533 |
    | 1 | SORT UNIQUE | | 807 | 102K| 232K| 82 |
    |* 2 | FILTER | | | | | |
    |* 3 | HASH JOIN OUTER | | 807 | 102K| | 52 |
    |* 4 | HASH JOIN OUTER | | 807 | 95226 | | 40 |
    |* 5 | TABLE ACCESS BY INDEX ROWID | ATTRIBUTE_VALUES | 1 | 23 | | 2 |
    | 6 | NESTED LOOPS | | 7 | 805 | | 37 |
    | 7 | NESTED LOOPS OUTER | | 6 | 552 | | 25 |
    |* 8 | FILTER | | | | | |
    | 9 | NESTED LOOPS OUTER | | | | | |
    |* 10 | FILTER | | | | | |
    | 11 | NESTED LOOPS OUTER | | | | | |
    | 12 | NESTED LOOPS OUTER | | 3 | 141 | | 10 |
    |* 13 | HASH JOIN | | 3 | 120 | | 7 |
    |* 14 | TABLE ACCESS FULL | PROFILE | 6 | 198 | | 4 |
    |* 15 | TABLE ACCESS FULL | PROFILE_TYPE | 1 | 7 | | 2 |
    |* 16 | INDEX RANGE SCAN | SYS_C0019777 | 1 | 7 | | 1 |
    | 17 | TABLE ACCESS BY INDEX ROWID| TBL_BDA_OFFICE | 1 | 10 | | 1 |
    |* 18 | INDEX UNIQUE SCAN | SYS_C0019800 | 1 | | | |
    | 19 | TABLE ACCESS BY INDEX ROWID | TBL_BDA_AGENCY_RESP_REP | 2 | 26 | | 2 |
    |* 20 | INDEX RANGE SCAN | IDX_AGECYRESP_AGNCYID | 2 | | | 1 |
    | 21 | TABLE ACCESS BY INDEX ROWID | USER_ | 1 | 22 | | 1 |
    |* 22 | INDEX UNIQUE SCAN | USER_PK | 1 | | | |
    |* 23 | INDEX RANGE SCAN | IDX_ATTVAL_ENTATTID | 1 | | | 1 |
    | 24 | TABLE ACCESS FULL | TBL_BDA_USR_ISS_GRP | 234 | 702 | | 2 |
    | 25 | TABLE ACCESS FULL | TBL_BDA_ISS_GROUP | 2 | 24 | | 2 |
    |* 26 | TABLE ACCESS BY INDEX ROWID | TBL_BDA_AGENCY_RESP_REP | 1 | 7 | | 3 |
    |* 27 | INDEX RANGE SCAN | IDX_AGECYRESP_AGNCYID | 2 | | | 1 |
    Predicate Information (identified by operation id):
    2 - filter( NOT EXISTS (SELECT /*+ */ 0 FROM "TBL_BDA_AGENCY_RESP_REP" "T" WHERE "T"."AGENCY_ID"=:B1
    AND "T"."ISS_GRP_ID"=TO_NUMBER('%')))
    3 - access("I"."ISS_GRP_ID"="J"."ISS_GRP_ID"(+))
    4 - access("SYS_ALIAS_1"."ISS_GRP_ID"="I"."ISS_GRP_ID"(+))
    5 - filter("K"."ATTRIBUTE_VALUE" IS NOT NULL AND "K"."ATTRIBUTE_VALUE" LIKE '%')
    8 - filter(NVL("SYS_ALIAS_1"."RESP_USR_ID",'0') LIKE '%' OR NVL("SYS_ALIAS_1"."RESP_USR_ID",'0')='k')
    10 - filter(NVL("G"."OFFICE_ID",0)=TO_NUMBER('%'))
    13 - access("L"."PROFILE_TYPE_ID"="B"."PROFILE_TYPE_ID")
    14 - filter(UPPER("B"."PROFILE_NM") LIKE '%' AND (TO_CHAR(NVL("B"."PROFILE_ID",0)) LIKE '%' OR
    NVL("B"."PROFILE_ID",0)=TO_NUMBER('a')))
    15 - filter("L"."APPLICATION_CD"='BDA')
    16 - access("B"."PROFILE_ID"="F"."AGENCY_ID"(+))
    18 - access("G"."OFFICE_ID"(+)="F"."OFFICE_ID")
    20 - access("B"."PROFILE_ID"="SYS_ALIAS_1"."AGENCY_ID"(+))
    22 - access("H"."USERID"(+)="SYS_ALIAS_1"."RESP_USR_ID")
    23 - access("K"."ENTITY_ID"='PROFILE.'||TO_CHAR("B"."PROFILE_ID"))
    26 - filter("T"."ISS_GRP_ID"=TO_NUMBER('%'))
    27 - access("T"."AGENCY_ID"=:B1)
    Note: cpu costing is off
    57 rows selected.
    Elapsed: 00:00:01.08
    Please help me.
    Aashish S.

    Hello Eric,
    Here is the code:
    SELECT DISTINCT
    K.ATTRIBUTE_VALUE AGENCY_ID,
    B.PROFILE_NM ,
    NVL(G.OFFICE_DESC,'--') OFFICE_DESC,
    f.OFFICE_ID,
    B.PROFILE_ID,
    '%' ROLE,
    '%' LAYOUT,
    case
    WHEN 'flagB' = '%' THEN
    NVL(J.ISS_GRP_DESC,'BILLING')
    WHEN 'flagO' = '%' THEN
    NVL(J.ISS_GRP_DESC,'ORDERING')
    WHEN 'flag' = '%' THEN
    NVL(J.ISS_GRP_DESC,'BILLING/ORDERING')
    else
    NVL(J.ISS_GRP_DESC,' ')
    END ISS_GRP_DESC,
    DECODE(NVL(H.USERID,' ') ,' ','--','&lt;a sbcuid_in=' || H.USERID || ' target=NEW &gt;'||H.FIRSTNAME || ' ' || H.LASTNAME ||
    '( ' || H.USERID || ' )&lt;/a&gt;' ) USER_NAME
    from
    PROFILE_PORTAL B ,
    TBL_BDA_AGENCY_RESP_REP C ,
    TBL_BDA_AGENCY_OFFICE F,
    TBL_BDA_OFFICE G,
    USERS_PORTAL H,
    TBL_BDA_USR_ISS_GRP I ,
    TBL_BDA_ISS_GROUP J,
    ATTRIBUTE_VALUES_PORTAL K,
    PROFILE_TYPE_PORTAL L
    WHERE
    B.PROFILE_ID = F.AGENCY_ID (+)
    AND B.PROFILE_ID = C.AGENCY_ID (+)
    AND G.OFFICE_ID (+)= F.OFFICE_ID
    AND H.USERID (+)= C.RESP_USR_ID
    AND C.ISS_GRP_ID = I.ISS_GRP_ID (+)
    AND I.ISS_GRP_ID = J.ISS_GRP_ID(+)
    AND 'PROFILE.'||B.PROFILE_ID = K.ENTITY_ID(+)
    AND K.ATTRIBUTE_VALUE IS NOT NULL
    AND L.PROFILE_TYPE_ID = B.PROFILE_TYPE_ID
    AND L.APPLICATION_CD='BDA'
    AND NOT EXISTS
    (SELECT agency_id
    FROM TBL_BDA_AGENCY_RESP_REP t
    WHERE t.ISS_GRP_ID IN (1)
    AND t.AGENCY_ID = C.AGENCY_ID)
    AND K.ATTRIBUTE_VALUE LIKE '%'
    AND UPPER(B.PROFILE_NM) LIKE UPPER('%')
    AND (to_char(NVL(B.PROFILE_ID,0))
    LIKE '%'
    OR NVL(B.PROFILE_ID,0) IN (1))
    AND NVL(G.OFFICE_ID,0) IN (1)
    AND (to_char(NVL(C.RESP_USR_ID,'0'))
    LIKE '%'
    OR NVL(C.RESP_USR_ID,'0') IN ('%'))
    ORDER BY PROFILE_NM
    This is the Query and the query takes some mins. to run in prod environment.
    From the Query plan ,I am not able to get any idea for optimization.
    Now,Can you tell me which steps I need to follow to run it faster and which all modifications should be made?
    Thanks.
    Aashish S.

  • Need help for performance tunning

    Hello,
    I have 16K records return by query, it takes long time to proceed for 7K it takes 7.5 sec.
    Note: I used all seeded tables only.
    If possible please help me to tune it.
    SELECT       msi.inventory_item_id,msi.segment1,msi.rimary_uom_code , msi.primary_unit_of_measure
    FROM  mtl_system_items_b msi, qp_list_lines qpll,qp_pricing_attributes qppr,
              mtl_category_sets_tl mcs,mtl_category_sets_b mcsb,
              mtl_categories_b mc, mtl_item_categories mcb
    WHERE     msi.enabled_flag = 'Y'
         AND qpll.list_line_id = qppr.list_line_id
         AND qppr.product_attr_value = TO_CHAR (msi.inventory_item_id(+))
         AND qppr.product_uom_code = msi.primary_uom_code
         AND mc.category_id = mcb.category_id
         AND msi.inventory_item_id = mcb.inventory_item_id
         AND msi.organization_id = mcb.organization_id
         AND TRUNC (SYSDATE) BETWEEN NVL (qpll.start_date_active,TRUNC (SYSDATE)) AND NVL (qpll.end_date_active,TRUNC (SYSDATE))
         AND mcs.category_set_name = 'LSS SALES CATEGORY'
         AND mcs.language = 'US'
         AND mcs.category_set_id = mcsb.category_set_id
         AND mcsb.structure_id = mc.structure_id
         AND msi.organization_id = :p_organization_id
         AND qpll.list_header_id = :p_price_list_id
         AND mcb.category_id = :p_category_id;
    Thanks and regards
    Akil.

    Thanks Helios ,
    here is answers
    Databse version
    Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit  
    PL/SQL Release 11.1.0.7.0
    explain plan
    | Id  | Operation                       | Name                     | Rows  | Bytes | Cost (%CPU)|

    0 | SELECT STATEMENT              
    |                          |   
    1 |   149 |  9439 
    (1)|

    1 |  NESTED LOOPS                   |                          |     1 | 
    149 |  9439   (1)|
    |*
    2 |   HASH JOIN OUTER               |                          |     1 | 
    135 |  9437   (1)|
    |*
    3 |    HASH JOIN                    |                          |     1 |  
    71 |  9432   (1)|

    4 |     NESTED LOOPS                |                          |     2 |  
    76 |    53   (0)|
    |*
    5 |      TABLE ACCESS BY INDEX
    ROWID| QP_LIST_LINES            |     2 |  
    44 |    49   (0)|
    |*
    6 |       INDEX SKIP SCAN           | QP_LIST_LINES_N2         | 
    702 |       |    20 
    (0)|
    |*
    7 |      INDEX RANGE SCAN           | QP_PRICING_ATTRIBUTES_N3 |     1 |  
    16 |     2   (0)|
    |*
    8 |     TABLE ACCESS BY INDEX
    ROWID | MTL_SYSTEM_ITEMS_B       | 46254
    |  1490K|
    9378   (1)|
    |*
    9 |      INDEX RANGE SCAN           | MTL_SYSTEM_ITEMS_B_N9    | 46254 |       | 
    174   (1)|
    |
    10 |    TABLE ACCESS FULL            | XX_WEB_ITEM_IMAGE_TBL    | 
    277 | 17728 |     5   (0)|
    |* 11 |   INDEX RANGE SCAN              | MTL_ITEM_CATEGORIES_U1   |   
    1 |    14 |     2 
    (0)|
    Predicate Information (identified
    by operation id):
    2 -
    access("XWIIT"."IMAGE_CODE"(+)="MSI"."SEGMENT1")
    3 -
    access("QPPR"."PRODUCT_ATTR_VALUE"=TO_CHAR("MSI"."INVENTORY_ITEM_ID")
    AND
    "QPPR"."PRODUCT_UOM_CODE"="MSI"."PRIMARY_UOM_CODE")
    5 - filter(NVL("QPLL"."START_DATE_ACTIVE",TRUNC(SYSDATE@!))<=TRUNC(SYSDATE@!)
    AND
    NVL("QPLL"."END_DATE_ACTIVE",TRUNC(SYSDATE@!))>=TRUNC(SYSDATE@!))
    6 -
    access("QPLL"."LIST_HEADER_ID"=TO_NUMBER(:P_PRICE_LIST_ID))
    filter("QPLL"."LIST_HEADER_ID"=TO_NUMBER(:P_PRICE_LIST_ID))
    7 -
    access("QPLL"."LIST_LINE_ID"="QPPR"."LIST_LINE_ID")
    filter("QPPR"."PRODUCT_UOM_CODE" IS NOT NULL)
    8 - filter("MSI"."ENABLED_FLAG"='Y')
    9 - access("MSI"."ORGANIZATION_ID"=TO_NUMBER(:P_ORGANIZATION_ID))
    11 -
    access("MCB"."ORGANIZATION_ID"=TO_NUMBER(:P_ORGANIZATION_ID)
    AND
    "MSI"."INVENTORY_ITEM_ID"="MCB"."INVENTORY_ITEM_ID"
    AND
    "MCB"."CATEGORY_ID"=TO_NUMBER(:P_CATEGORY_ID))
           filter("MCB"."CATEGORY_ID"=TO_NUMBER(:P_CATEGORY_ID))
    Note
    - 'PLAN_TABLE' is old version
    TKprof Plan
    TKPROF: Release 11.1.0.7.0 - Production on Fri Nov 15 06:12:26 2013
    Copyright (c) 1982, 2007, Oracle.  All rights reserved.
    Trace file: LSSD_ora_19760.trc
    Sort options: default
    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 msi.inventory_item_id,
           msi.segment1,
           primary_uom_code,
           primary_unit_of_measure,
           xwiit.image_url
      FROM mtl_system_items_b msi,
           qp_list_lines qpll,
           qp_pricing_attributes qppr,
           mtl_item_categories mcb,
           xx_web_item_image_tbl xwiit
    WHERE     msi.enabled_flag = 'Y'
           AND qpll.list_line_id = qppr.list_line_id
           AND qppr.product_attr_value = TO_CHAR (msi.inventory_item_id)
           AND qppr.product_uom_code = msi.primary_uom_code
           AND msi.inventory_item_id = mcb.inventory_item_id
           AND msi.organization_id = mcb.organization_id
           AND TRUNC (SYSDATE) BETWEEN NVL (qpll.start_date_active,
                                            TRUNC (SYSDATE))
                                   AND NVL (qpll.end_date_active,
                                            TRUNC (SYSDATE))
           AND xwiit.image_code(+) = msi.segment1
           AND msi.organization_id = :p_organization_id
           AND qpll.list_header_id = :p_price_list_id
           AND mcb.category_id = :p_category_id
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        2      0.00       0.00          0          0          0           0
    Execute      2      0.00       0.00          0          0          0           0
    Fetch        2      3.84       3.85          0     432560          0        1002
    total        6      3.84       3.85          0     432560          0        1002
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 173 
    Rows     Row Source Operation
        501  NESTED LOOPS  (cr=216280 pr=0 pw=0 time=115 us cost=9439 size=149 card=1)
       2616   HASH JOIN OUTER (cr=211012 pr=0 pw=0 time=39 us cost=9437 size=135 card=1)
      78568    HASH JOIN  (cr=210997 pr=0 pw=0 time=3786 us cost=9432 size=71 card=1)
      78571     NESTED LOOPS  (cr=29229 pr=0 pw=0 time=35533 us cost=53 size=76 card=2)
      78571      TABLE ACCESS BY INDEX ROWID QP_LIST_LINES (cr=9943 pr=0 pw=0 time=27533 us cost=49 size=44 card=2)
    226733       INDEX SKIP SCAN QP_LIST_LINES_N2 (cr=865 pr=0 pw=0 time=4122 us cost=20 size=0 card=702)(object id 99730)
      78571      INDEX RANGE SCAN QP_PRICING_ATTRIBUTES_N3 (cr=19286 pr=0 pw=0 time=0 us cost=2 size=16 card=1)(object id 99733)
    128857     TABLE ACCESS BY INDEX ROWID MTL_SYSTEM_ITEMS_B (cr=181768 pr=0 pw=0 time=9580 us cost=9378 size=1526382 card=46254)
    128857      INDEX RANGE SCAN MTL_SYSTEM_ITEMS_B_N9 (cr=450 pr=0 pw=0 time=1657 us cost=174 size=0 card=46254)(object id 199728)
        277    TABLE ACCESS FULL XX_WEB_ITEM_IMAGE_TBL (cr=15 pr=0 pw=0 time=22 us cost=5 size=17728 card=277)
        501   INDEX RANGE SCAN MTL_ITEM_CATEGORIES_U1 (cr=5268 pr=0 pw=0 time=0 us cost=2 size=14 card=1)(object id 99557)
    Note: I modified query and it gives good result, now it takes 3 to 4 sec for 16000 records.
    If possible can you plz explain what we have to take care while doing performance tunning
    I am a fresher so don't have that much idea.
    and also Thanks Hussein for your replay

  • Query Tunning Problem

    I am using oracle Db 9.2.4 ,
    Beloq query is taking lot of time ie.5mins, can anybody help me to tune the query....
    SELECT    LTRIM
                 (RTRIM (   DECODE (tit_name,
                                    'MR.', 'CA.',
                                    'MS.', 'CA.',
                                    'MRS.', 'CA.'
                         || ' '
                         || mrh_first_name
                         || ' '
                         || mrh_middle_name
                         || ' '
                         || mrh_sur_name
                         || ' '
                         || DECODE (mrh_appr_uid,
                                    NULL, NULL,
                                    DECODE (mrh_mem_status,
                                            2, NULL,
                                            DECODE (mrh_fellow_status_yn,
                                                    'Y', 'FCA',
                                                    'ACA'
                         || DECODE (mrh_resi_status,
                                    'A', '                         AIR - MAIL'
                         || CHR (10)
           || DECODE (mrh_cop_status,
                      1, DECODE (mrh_cop_type,
                                 13, 'CHARTERED ACCOUNTANT' || CHR (10),
                                 NULL
                      NULL
           || LTRIM (RTRIM (mrh_prof_addr_line_1))
           || DECODE (mrh_prof_addr_line_1, NULL, NULL, CHR (10))
           || LTRIM (RTRIM (mrh_prof_addr_line_2))
           || DECODE (mrh_prof_addr_line_2, NULL, NULL, CHR (10))
           || LTRIM (RTRIM (mrh_prof_addr_line_3))
           || DECODE (mrh_prof_addr_line_3, NULL, NULL, CHR (10))
           || LTRIM (RTRIM (mrh_prof_addr_line_4))
           || DECODE (mrh_prof_addr_line_4, NULL, NULL, CHR (10))
           || LTRIM (RTRIM (   city_name
                            || '-'
                            || mrh_prof_zip_postal_code
                            || DECODE (mrh_resi_status,
                                       'A', CHR (10) || cou_name,
                                       NULL
                    ) l_common,
           DECODE (mrh_appr_uid, NULL, 'T', 'P') p_t_flag
      FROM cadata3.om_mem_reg_head, cadata3.om_city, cadata3.om_country, cadata3.om_title
    WHERE cou_code = mrh_prof_cou_code
       AND city_code = mrh_prof_city_code(+)
       AND mrh_title = tit_code(+)
       AND NVL (mrh_clo_status, 0) != 1
    164245 rows selected.
    Elapsed: 00:04:26.09
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id  | Operation                |  Name                  | Rows  | Bytes |TempS
    pc| Cost  | Pstart| Pstop |
    |   0 | SELECT STATEMENT         |                        |   164K|    25M|
    PLAN_TABLE_OUTPUT
      |  2332 |       |       |
    |   1 |  HASH JOIN               |                        |   164K|    25M|
      |  2332 |       |       |
    |   2 |   TABLE ACCESS FULL      | OM_COUNTRY             |   676 | 12168 |
      |     3 |       |       |
    |   3 |   HASH JOIN OUTER        |                        |   164K|    22M|    2
    3M|  2296 |       |       |
    PLAN_TABLE_OUTPUT
    |   4 |    FILTER                |                        |       |       |
      |       |       |       |
    |   5 |     HASH JOIN OUTER      |                        |       |       |
      |       |       |       |
    |   6 |      INDEX FAST FULL SCAN| IDM_OM_CITY_CITY_NAME  | 24226 |   449K|
      |    11 |       |       |
    |   7 |      PARTITION LIST ALL  |                        |       |       |
      |       |     1 |     7 |
    PLAN_TABLE_OUTPUT
    |   8 |       TABLE ACCESS FULL  | OM_MEM_REG_HEAD        |   164K|    18M|
      |  1155 |     1 |     7 |
    |   9 |    TABLE ACCESS FULL     | OM_TITLE               |     8 |    88 |
      |     2 |       |       |
    PLAN_TABLE_OUTPUT
    Note: cpu costing is off, 'PLAN_TABLE' is old version
    17 rows selected.
    SQL>
    SQL> select index_name, COLUMN_NAMe,column_position from  dba_ind_columns where
    table_name='OM_MEM_REG_HEAD' and column_name like 'MRH_PROF%';
    INDEX_NAME
    COLUMN_NAME
    COLUMN_POSITION
    IDM_MRH_PROF_CITY2
    MRH_PROF_CITY_CODE
                  1
    ABC
    MRH_PROF_REGION_CODE
                  1
    INDEX_NAME
    COLUMN_NAME
    COLUMN_POSITION
    ---------------After using an index hint in the query of the table OM_MEM_REG_HEAD, timing of the query goes down to 3.5 mins,pls suggest me to tune the query so that the timing of the query goes down.....

    Pls find a tkprof report
    TKPROF: Release 9.2.0.4.0 - Production on Mon Aug 18 11:53:08 2008
    Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    Trace file: G:\oracle\admin\hotest\udump\hotest_ora_3216.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    LTRIM
                 (RTRIM (   DECODE (tit_name,
                                    'MR.', 'CA.',
                                    'MS.', 'CA.',
                                    'MRS.', 'CA.'
                         || ' '
                         || mrh_first_name
                         || ' '
                         || mrh_middle_name
                         || ' '
                         || mrh_sur_name
                         || ' '
                         || DECODE (mrh_appr_uid,
                                    NULL, NULL,
                                    DECODE (mrh_mem_status,
                                            2, NULL,
                                            DECODE (mrh_fellow_status_yn,
                                                    'Y', 'FCA',
                                                    'ACA'
                         || DECODE (mrh_resi_status,
                                    'A', '                         AIR - MAIL'
                         || CHR (10)
           || DECODE (mrh_cop_status,
                      1, DECODE (mrh_cop_type,
                                 13, 'CHARTERED ACCOUNTANT' || CHR (10),
                                 NULL
                      NULL
           || LTRIM (RTRIM (mrh_prof_addr_line_1))
           || DECODE (mrh_prof_addr_line_1, NULL, NULL, CHR (10))
           || LTRIM (RTRIM (mrh_prof_addr_line_2))
           || DECODE (mrh_prof_addr_line_2, NULL, NULL, CHR (10))
           || LTRIM (RTRIM (mrh_prof_addr_line_3))
           || DECODE (mrh_prof_addr_line_3, NULL, NULL, CHR (10))
           || LTRIM (RTRIM (mrh_prof_addr_line_4))
           || DECODE (mrh_prof_addr_line_4, NULL, NULL, CHR (10))
           || LTRIM (RTRIM (   city_name
                            || '-'
                            || mrh_prof_zip_postal_code
                            || DECODE (mrh_resi_status,
                                       'A', CHR (10) || cou_name,
                                       NULL
                    ) l_common,
           DECODE (mrh_appr_uid, NULL, 'T', 'P') p_t_flag
      FROM om_mem_reg_head, om_city, om_country, om_title
    WHERE cou_code = mrh_prof_cou_code
       AND city_code = mrh_prof_city_code(+)
       AND mrh_title = tit_code(+)
       AND NVL (mrh_clo_status, 0) != 1
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        4      0.01       0.05          2         16          0           0
    Execute      5      0.00       0.03          0          0          0           0
    Fetch    10258      4.78      23.62      12420      12157          0      153818
    total    10267      4.79      23.72      12422      12173          0      153818
    Misses in library cache during parse: 3
    Misses in library cache during execute: 1
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        9      0.00       0.00          0          0          0           0
    Execute     10      0.00       0.00          0          0          0           0
    Fetch       10      0.00       0.06          5         21          0           8
    total       29      0.00       0.06          5         21          0           8
    Misses in library cache during parse: 2
        5  user  SQL statements in session.
        9  internal SQL statements in session.
       14  SQL statements in session.
    Trace file: G:\oracle\admin\hotest\udump\hotest_ora_3216.trc
    Trace file compatibility: 9.00.01
    Sort options: prsela  exeela  fchela 
           1  session in tracefile.
           5  user  SQL statements in trace file.
           9  internal SQL statements in trace file.
          14  SQL statements in trace file.
           6  unique SQL statements in trace file.
       10522  lines in trace file.here we can easily seen rows/call is much greater than elapsed/call......
    pls suggest...

  • Need Help to query Lync Database for User Information

    Need Help to Query the lync database to retrieve below user information.
    1. SIP Address of the registered user
            2. Phone Number configured to the particular account.
            3. IP Address
           4. Last Logged in time.
    I am trying to pull the above information from rtc database for all the registered users. Please let me know if this is possible and it would be great if you can throw some light on what tables to look for the data. Thank You.

    Hi,
    For SIP address and Phone number you can check RTC database.
    IP Address:
    You can refer to the link below to query IP address: 
    http://h30499.www3.hp.com/t5/Business-Service-Management-BAC/Monitoring-Lync-with-the-User-Registrations-Viewer-Free-NMC-tool/ba-p/5961497#.UtOU43mIrwo
    Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.
    Please make sure that you completely understand the risk before retrieving any suggestions from the above link.
    Last Logged in time:
    You can refer to the link below:
    http://blogs.technet.com/b/dodeitte/archive/2011/05/11/how-to-get-the-last-time-a-user-registered-with-a-front-end.aspx
    Best Regards,
    Eason Huang
    Eason Huang
    TechNet Community Support

  • Sql Query Tuning. Please help me to tune this query

    Hi All ,
    I have this problematic Sql . It is taking huge time to execute. It contains a view CIDV, which i think is the bottleneck.
    I have pasted the query below. I will be pasting TKPROF and explain plan for the same. Please advice me to tune this query.
    SELECT GCC.SEGMENT1 || '.' || GCC.SEGMENT2 || '.' || GCC.SEGMENT3 || '.' ||
           GCC.SEGMENT4 || '.' || GCC.SEGMENT5 || '.' || GCC.SEGMENT6 || '.' ||
           GCC.SEGMENT7 || '.' || GCC.SEGMENT8 || '.' || GCC.SEGMENT9 OFFSET_ACCOUNT,
           OOD.ORGANIZATION_CODE,
           CIDV.SUBINVENTORY_CODE OFFSET_SUBINV,
           MIL.SEGMENT1 || '.' || MIL.SEGMENT2 || '.' || MIL.SEGMENT3 || '.' ||
           MIL.SEGMENT4 || '.' || MIL.SEGMENT5 OFFSET_LOCATOR,
           CIDV.LAST_UPDATE_LOGIN
      FROM APPS.CST_INV_DISTRIBUTION_V       CIDV,
           APPS.GL_CODE_COMBINATIONS         GCC,
           APPS.MTL_ITEM_LOCATIONS           MIL,
           APPS.ORG_ORGANIZATION_DEFINITIONS OOD
    WHERE CIDV.TRANSACTION_ID = :B2
       AND CIDV.PRIMARY_QUANTITY = (-1) * :B1
       AND CIDV.REFERENCE_ACCOUNT = GCC.CODE_COMBINATION_ID
       AND OOD.ORGANIZATION_ID = CIDV.ORGANIZATION_ID
       AND MIL.INVENTORY_LOCATION_ID = CIDV.LOCATOR_ID
       AND GCC.ACCOUNT_TYPE = 'A'****************
    TKPROF
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute  68337     10.32      10.32          0          0          0           0
    Fetch    68337    229.75     936.36      58819    6743323       1121       68232
    total   136675    240.07     946.69      58819    6743323       1121       68232
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 203     (recursive depth: 1)
    Number of plan statistics captured: 1
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
             1          1          1  MERGE JOIN CARTESIAN (cr=102 pr=15 pw=0 time=193608 us cost=56 size=219 card=1)
             1          1          1   NESTED LOOPS  (cr=100 pr=15 pw=0 time=193483 us cost=53 size=219 card=1)
             1          1          1    NESTED LOOPS  (cr=99 pr=15 pw=0 time=193407 us cost=52 size=215 card=1)
             1          1          1     NESTED LOOPS  (cr=96 pr=15 pw=0 time=193378 us cost=51 size=190 card=1)
             1          1          1      NESTED LOOPS  (cr=93 pr=15 pw=0 time=193284 us cost=49 size=162 card=1)
             1          1          1       NESTED LOOPS  (cr=89 pr=14 pw=0 time=185515 us cost=46 size=138 card=1)
             1          1          1        NESTED LOOPS  (cr=85 pr=12 pw=0 time=157975 us cost=44 size=81 card=1)
             1          1          1         NESTED LOOPS  (cr=83 pr=12 pw=0 time=157925 us cost=43 size=73 card=1)
             1          1          1          NESTED LOOPS  (cr=81 pr=12 pw=0 time=157641 us cost=43 size=132 card=2)
             1          1          1           VIEW  CST_INV_DISTRIBUTION_V (cr=78 pr=12 pw=0 time=156386 us cost=41 size=118 card=2)
             1          1          1            UNION-ALL  (cr=78 pr=12 pw=0 time=156378 us)
             0          0          0             NESTED LOOPS OUTER (cr=44 pr=9 pw=0 time=124997 us cost=20 size=291 card=1)
             0          0          0              NESTED LOOPS  (cr=44 pr=9 pw=0 time=124993 us cost=18 size=255 card=1)
             0          0          0               NESTED LOOPS  (cr=44 pr=9 pw=0 time=124990 us cost=18 size=251 card=1)
            33         33         33                MERGE JOIN CARTESIAN (cr=25 pr=6 pw=0 time=98544 us cost=14 size=192 card=1)
             1          1          1                 NESTED LOOPS OUTER (cr=22 pr=5 pw=0 time=85754 us cost=12 size=156 card=1)
             1          1          1                  NESTED LOOPS  (cr=19 pr=4 pw=0 time=79830 us cost=10 size=120 card=1)
             1          1          1                   NESTED LOOPS OUTER (cr=17 pr=4 pw=0 time=79813 us cost=9 size=113 card=1)
             1          1          1                    NESTED LOOPS  (cr=15 pr=4 pw=0 time=79752 us cost=8 size=106 card=1)
             1          1          1                     NESTED LOOPS  (cr=11 pr=2 pw=0 time=43120 us cost=6 size=93 card=1)
             1          1          1                      NESTED LOOPS  (cr=7 pr=2 pw=0 time=43087 us cost=4 size=83 card=1)
             1          1          1                       NESTED LOOPS  (cr=6 pr=2 pw=0 time=43072 us cost=4 size=80 card=1)
             1          1          1                        TABLE ACCESS BY INDEX ROWID MTL_MATERIAL_TRANSACTIONS (cr=5 pr=2 pw=0 time=43042 us cost=4 size=76 card=1)
             1          1          1                         INDEX UNIQUE SCAN MTL_MATERIAL_TRANSACTIONS_U1 (cr=4 pr=2 pw=0 time=43011 us cost=3 size=0 card=1)(object id 12484094)
             1          1          1                        INDEX UNIQUE SCAN MTL_TRANSACTION_TYPES_U1 (cr=1 pr=0 pw=0 time=20 us cost=0 size=764 card=191)(object id 9983)
             1          1          1                       INDEX UNIQUE SCAN MTL_TXN_SOURCE_TYPES_U1 (cr=1 pr=0 pw=0 time=7 us cost=0 size=54 card=18)(object id 9987)
             1          1          1                      INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=4 pr=0 pw=0 time=27 us cost=2 size=736324450 card=73632445)(object id 12484155)
             1          1          1                     INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_TL_U1 (cr=4 pr=2 pw=0 time=36626 us cost=2 size=957481070 card=73652390)(object id 12484137)
             1          1          1                    TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 pr=0 pw=0 time=42 us cost=1 size=3290 card=470)
             1          1          1                     INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=28 us cost=0 size=0 card=1)(object id 9847)
             1          1          1                   TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 pr=0 pw=0 time=12 us cost=1 size=3290 card=470)
             1          1          1                    INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=7 us cost=0 size=0 card=1)(object id 9847)
             0          0          0                  INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=3 pr=1 pw=0 time=5915 us cost=2 size=36 card=1)(object id 705891)
            33         33         33                 BUFFER SORT (cr=3 pr=1 pw=0 time=12713 us cost=12 size=36 card=1)
            33         33         33                  INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=3 pr=1 pw=0 time=12582 us cost=2 size=36 card=1)(object id 705891)
             0          0          0                TABLE ACCESS BY INDEX ROWID MTL_TRANSACTION_ACCOUNTS (cr=19 pr=3 pw=0 time=26591 us cost=4 size=59 card=1)
            66         66         66                 INDEX RANGE SCAN MTL_TRANSACTION_ACCOUNTS_N1 (cr=18 pr=2 pw=0 time=13607 us cost=3 size=0 card=3)(object id 12484127)
             0          0          0               INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=0 pr=0 pw=0 time=0 us cost=0 size=4 card=1)(object id 9847)
             0          0          0              INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=0 pr=0 pw=0 time=0 us cost=2 size=36 card=1)(object id 705891)
             1          1          1             NESTED LOOPS  (cr=34 pr=3 pw=0 time=31269 us cost=21 size=288 card=1)
             1          1          1              NESTED LOOPS  (cr=30 pr=3 pw=0 time=31161 us cost=19 size=275 card=1)
             1          1          1               NESTED LOOPS  (cr=26 pr=3 pw=0 time=31105 us cost=17 size=265 card=1)
             1          1          1                NESTED LOOPS  (cr=25 pr=3 pw=0 time=31082 us cost=17 size=261 card=1)
             1          1          1                 NESTED LOOPS OUTER (cr=23 pr=3 pw=0 time=31027 us cost=16 size=254 card=1)
             1          1          1                  NESTED LOOPS  (cr=21 pr=3 pw=0 time=30980 us cost=15 size=247 card=1)
             1          1          1                   NESTED LOOPS  (cr=20 pr=3 pw=0 time=30957 us cost=15 size=243 card=1)
             1          1          1                    NESTED LOOPS OUTER (cr=19 pr=3 pw=0 time=30926 us cost=15 size=240 card=1)
             1          1          1                     NESTED LOOPS  (cr=16 pr=3 pw=0 time=30389 us cost=13 size=204 card=1)
             1          1          1                      NESTED LOOPS  (cr=11 pr=0 pw=0 time=665 us cost=9 size=131 card=1)
             1          1          1                       NESTED LOOPS OUTER (cr=8 pr=0 pw=0 time=306 us cost=7 size=95 card=1)
             1          1          1                        TABLE ACCESS BY INDEX ROWID MTL_TRANSACTION_ACCOUNTS (cr=5 pr=0 pw=0 time=37 us cost=5 size=59 card=1)
             2          2          2                         INDEX RANGE SCAN MTL_TRANSACTION_ACCOUNTS_N1 (cr=4 pr=0 pw=0 time=17 us cost=4 size=0 card=3)(object id 12484127)
             1          1          1                        INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=3 pr=0 pw=0 time=216 us cost=2 size=36 card=1)(object id 705891)
             1          1          1                       INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=3 pr=0 pw=0 time=352 us cost=2 size=36 card=1)(object id 705891)
             1          1          1                      TABLE ACCESS BY INDEX ROWID MTL_MATERIAL_TRANSACTIONS (cr=5 pr=3 pw=0 time=29716 us cost=4 size=73 card=1)
             1          1          1                       INDEX RANGE SCAN MTL_MATERIAL_TRANSACTIONS_N23 (cr=4 pr=3 pw=0 time=29588 us cost=3 size=0 card=1)(object id 12484133)
             0          0          0                     INDEX RANGE SCAN FND_LOOKUP_VALUES_U1 (cr=3 pr=0 pw=0 time=520 us cost=2 size=36 card=1)(object id 705891)
             1          1          1                    INDEX UNIQUE SCAN MTL_TXN_SOURCE_TYPES_U1 (cr=1 pr=0 pw=0 time=22 us cost=0 size=3 card=1)(object id 9987)
             1          1          1                   INDEX UNIQUE SCAN MTL_TRANSACTION_TYPES_U1 (cr=1 pr=0 pw=0 time=16 us cost=0 size=4 card=1)(object id 9983)
             1          1          1                  TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 pr=0 pw=0 time=34 us cost=1 size=7 card=1)
             1          1          1                   INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=19 us cost=0 size=0 card=1)(object id 9847)
             1          1          1                 TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 pr=0 pw=0 time=44 us cost=1 size=7 card=1)
             1          1          1                  INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=14 us cost=0 size=0 card=1)(object id 9847)
             1          1          1                INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=13 us cost=0 size=4 card=1)(object id 9847)
             1          1          1               INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_B_U1 (cr=4 pr=0 pw=0 time=49 us cost=2 size=10 card=1)(object id 12484155)
             1          1          1              INDEX UNIQUE SCAN MTL_SYSTEM_ITEMS_TL_U1 (cr=4 pr=0 pw=0 time=96 us cost=2 size=13 card=1)(object id 12484137)
             1          1          1           TABLE ACCESS BY INDEX ROWID HR_ALL_ORGANIZATION_UNITS (cr=3 pr=0 pw=0 time=1246 us cost=1 size=7 card=1)
             1          1          1            INDEX UNIQUE SCAN HR_ORGANIZATION_UNITS_PK (cr=2 pr=0 pw=0 time=24 us cost=0 size=0 card=1)(object id 250158)
             1          1          1          INDEX UNIQUE SCAN HR_ALL_ORGANIZATION_UNTS_TL_PK (cr=2 pr=0 pw=0 time=275 us cost=0 size=7 card=1)(object id 689101)
             1          1          1         TABLE ACCESS BY INDEX ROWID MTL_PARAMETERS (cr=2 pr=0 pw=0 time=38 us cost=1 size=8 card=1)
             1          1          1          INDEX UNIQUE SCAN MTL_PARAMETERS_U1 (cr=1 pr=0 pw=0 time=15 us cost=0 size=0 card=1)(object id 9847)
             1          1          1        TABLE ACCESS BY INDEX ROWID GL_CODE_COMBINATIONS (cr=4 pr=2 pw=0 time=27531 us cost=2 size=57 card=1)
             1          1          1         INDEX UNIQUE SCAN GL_CODE_COMBINATIONS_U1 (cr=3 pr=1 pw=0 time=19925 us cost=1 size=0 card=1)(object id 51426)
             1          1          1       TABLE ACCESS BY INDEX ROWID MTL_ITEM_LOCATIONS (cr=4 pr=1 pw=0 time=7758 us cost=3 size=24 card=1)
             1          1          1        INDEX RANGE SCAN MTL_ITEM_LOCATIONS_U1 (cr=3 pr=0 pw=0 time=51 us cost=2 size=0 card=1)(object id 9761)
             1          1          1      TABLE ACCESS BY INDEX ROWID HR_ORGANIZATION_INFORMATION (cr=3 pr=0 pw=0 time=85 us cost=2 size=28 card=1)
             1          1          1       INDEX RANGE SCAN HR_ORGANIZATION_INFORMATIO_FK2 (cr=2 pr=0 pw=0 time=29 us cost=1 size=0 card=2)(object id 5379798)
             1          1          1     TABLE ACCESS BY INDEX ROWID HR_ORGANIZATION_INFORMATION (cr=3 pr=0 pw=0 time=25 us cost=1 size=25 card=1)
             1          1          1      INDEX RANGE SCAN HR_ORGANIZATION_INFORMATIO_FK2 (cr=2 pr=0 pw=0 time=11 us cost=1 size=0 card=1)(object id 5379798)
             1          1          1    INDEX FULL SCAN GL_SETS_OF_BOOKS_U2 (cr=1 pr=0 pw=0 time=69 us cost=1 size=4 card=1)(object id 1380842)
             1          1          1   BUFFER SORT (cr=2 pr=0 pw=0 time=110 us cost=55 size=0 card=1)
             1          1          1    TABLE ACCESS FULL FND_PRODUCT_GROUPS (cr=2 pr=0 pw=0 time=59 us cost=3 size=0 card=1)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      library cache lock                              2        0.00          0.00
      library cache pin                               2        0.00          0.00
      Disk file operations I/O                      249        0.00          0.00
      db file sequential read                     58819        2.61        714.28
      gc cr grant 2-way                            5198        0.16          4.52
      gc current grant busy                           1        0.00          0.00
      KJC: Wait for msg sends to complete           517        0.00          0.05
      library cache: mutex X                        433        0.01          0.04
      gc cr grant congested                          28        0.08          0.18
      latch: ges resource hash list                   5        0.00          0.00
      gc current block 2-way                        513        0.11          0.61
      gc current block congested                      2        0.00          0.00
      latch: gc element                              16        0.00          0.01
      latch: cache buffers chains                     4        0.00          0.00
      latch: object queue header operation            3        0.00          0.00
    ********************************************************************************

    Explain Plan for the query
    SELECT STATEMENT, GOAL = ALL_ROWS               Cost=56     Cardinality=1     Bytes=219
    MERGE JOIN CARTESIAN               Cost=56     Cardinality=1     Bytes=219
      NESTED LOOPS               Cost=53     Cardinality=1     Bytes=219
       NESTED LOOPS               Cost=52     Cardinality=1     Bytes=215
        NESTED LOOPS               Cost=51     Cardinality=1     Bytes=190
         NESTED LOOPS               Cost=49     Cardinality=1     Bytes=162
          NESTED LOOPS               Cost=46     Cardinality=1     Bytes=138
           NESTED LOOPS               Cost=44     Cardinality=1     Bytes=81
            NESTED LOOPS               Cost=43     Cardinality=1     Bytes=73
             NESTED LOOPS               Cost=43     Cardinality=2     Bytes=132
              VIEW     Object owner=APPS     Object name=CST_INV_DISTRIBUTION_V     Cost=41     Cardinality=2     Bytes=118
               UNION-ALL                         
                NESTED LOOPS OUTER               Cost=20     Cardinality=1     Bytes=291
                 NESTED LOOPS               Cost=18     Cardinality=1     Bytes=255
                  NESTED LOOPS               Cost=18     Cardinality=1     Bytes=251
                   MERGE JOIN CARTESIAN               Cost=14     Cardinality=1     Bytes=192
                    NESTED LOOPS OUTER               Cost=12     Cardinality=1     Bytes=156
                     NESTED LOOPS               Cost=10     Cardinality=1     Bytes=120
                      NESTED LOOPS OUTER               Cost=9     Cardinality=1     Bytes=113
                       NESTED LOOPS               Cost=8     Cardinality=1     Bytes=106
                        NESTED LOOPS               Cost=6     Cardinality=1     Bytes=93
                         NESTED LOOPS               Cost=4     Cardinality=1     Bytes=83
                          NESTED LOOPS               Cost=4     Cardinality=1     Bytes=80
                           TABLE ACCESS BY INDEX ROWID     Object owner=INV     Object name=MTL_MATERIAL_TRANSACTIONS     Cost=4     Cardinality=1     Bytes=76
                            INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_MATERIAL_TRANSACTIONS_U1     Cost=3     Cardinality=1     
                           INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_TRANSACTION_TYPES_U1     Cost=0     Cardinality=191     Bytes=764
                          INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_TXN_SOURCE_TYPES_U1     Cost=0     Cardinality=18     Bytes=54
                         INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_SYSTEM_ITEMS_B_U1     Cost=2     Cardinality=73632445     Bytes=736324450
                        INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_SYSTEM_ITEMS_TL_U1     Cost=2     Cardinality=73652390     Bytes=957481070
                       TABLE ACCESS BY INDEX ROWID     Object owner=INV     Object name=MTL_PARAMETERS     Cost=1     Cardinality=470     Bytes=3290
                        INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_PARAMETERS_U1     Cost=0     Cardinality=1     
                      TABLE ACCESS BY INDEX ROWID     Object owner=INV     Object name=MTL_PARAMETERS     Cost=1     Cardinality=470     Bytes=3290
                       INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_PARAMETERS_U1     Cost=0     Cardinality=1     
                     INDEX RANGE SCAN     Object owner=APPLSYS     Object name=FND_LOOKUP_VALUES_U1     Cost=2     Cardinality=1     Bytes=36
                    BUFFER SORT               Cost=12     Cardinality=1     Bytes=36
                     INDEX RANGE SCAN     Object owner=APPLSYS     Object name=FND_LOOKUP_VALUES_U1     Cost=2     Cardinality=1     Bytes=36
                   TABLE ACCESS BY INDEX ROWID     Object owner=INV     Object name=MTL_TRANSACTION_ACCOUNTS     Cost=4     Cardinality=1     Bytes=59
                    INDEX RANGE SCAN     Object owner=INV     Object name=MTL_TRANSACTION_ACCOUNTS_N1     Cost=3     Cardinality=3     
                  INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_PARAMETERS_U1     Cost=0     Cardinality=1     Bytes=4
                 INDEX RANGE SCAN     Object owner=APPLSYS     Object name=FND_LOOKUP_VALUES_U1     Cost=2     Cardinality=1     Bytes=36
                NESTED LOOPS               Cost=21     Cardinality=1     Bytes=288
                 NESTED LOOPS               Cost=19     Cardinality=1     Bytes=275
                  NESTED LOOPS               Cost=17     Cardinality=1     Bytes=265
                   NESTED LOOPS               Cost=17     Cardinality=1     Bytes=261
                    NESTED LOOPS OUTER               Cost=16     Cardinality=1     Bytes=254
                     NESTED LOOPS               Cost=15     Cardinality=1     Bytes=247
                      NESTED LOOPS               Cost=15     Cardinality=1     Bytes=243
                       NESTED LOOPS OUTER               Cost=15     Cardinality=1     Bytes=240
                        NESTED LOOPS               Cost=13     Cardinality=1     Bytes=204
                         NESTED LOOPS               Cost=9     Cardinality=1     Bytes=131
                          NESTED LOOPS OUTER               Cost=7     Cardinality=1     Bytes=95
                           TABLE ACCESS BY INDEX ROWID     Object owner=INV     Object name=MTL_TRANSACTION_ACCOUNTS     Cost=5     Cardinality=1     Bytes=59
                            INDEX RANGE SCAN     Object owner=INV     Object name=MTL_TRANSACTION_ACCOUNTS_N1     Cost=4     Cardinality=3     
                           INDEX RANGE SCAN     Object owner=APPLSYS     Object name=FND_LOOKUP_VALUES_U1     Cost=2     Cardinality=1     Bytes=36
                          INDEX RANGE SCAN     Object owner=APPLSYS     Object name=FND_LOOKUP_VALUES_U1     Cost=2     Cardinality=1     Bytes=36
                         TABLE ACCESS BY INDEX ROWID     Object owner=INV     Object name=MTL_MATERIAL_TRANSACTIONS     Cost=4     Cardinality=1     Bytes=73
                          INDEX RANGE SCAN     Object owner=INV     Object name=MTL_MATERIAL_TRANSACTIONS_N23     Cost=3     Cardinality=1     
                        INDEX RANGE SCAN     Object owner=APPLSYS     Object name=FND_LOOKUP_VALUES_U1     Cost=2     Cardinality=1     Bytes=36
                       INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_TXN_SOURCE_TYPES_U1     Cost=0     Cardinality=1     Bytes=3
                      INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_TRANSACTION_TYPES_U1     Cost=0     Cardinality=1     Bytes=4
                     TABLE ACCESS BY INDEX ROWID     Object owner=INV     Object name=MTL_PARAMETERS     Cost=1     Cardinality=1     Bytes=7
                      INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_PARAMETERS_U1     Cost=0     Cardinality=1     
                    TABLE ACCESS BY INDEX ROWID     Object owner=INV     Object name=MTL_PARAMETERS     Cost=1     Cardinality=1     Bytes=7
                     INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_PARAMETERS_U1     Cost=0     Cardinality=1     
                   INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_PARAMETERS_U1     Cost=0     Cardinality=1     Bytes=4
                  INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_SYSTEM_ITEMS_B_U1     Cost=2     Cardinality=1     Bytes=10
                 INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_SYSTEM_ITEMS_TL_U1     Cost=2     Cardinality=1     Bytes=13
              TABLE ACCESS BY INDEX ROWID     Object owner=HR     Object name=HR_ALL_ORGANIZATION_UNITS     Cost=1     Cardinality=1     Bytes=7
               INDEX UNIQUE SCAN     Object owner=HR     Object name=HR_ORGANIZATION_UNITS_PK     Cost=0     Cardinality=1     
             INDEX UNIQUE SCAN     Object owner=HR     Object name=HR_ALL_ORGANIZATION_UNTS_TL_PK     Cost=0     Cardinality=1     Bytes=7
            TABLE ACCESS BY INDEX ROWID     Object owner=INV     Object name=MTL_PARAMETERS     Cost=1     Cardinality=1     Bytes=8
             INDEX UNIQUE SCAN     Object owner=INV     Object name=MTL_PARAMETERS_U1     Cost=0     Cardinality=1     
           TABLE ACCESS BY INDEX ROWID     Object owner=GL     Object name=GL_CODE_COMBINATIONS     Cost=2     Cardinality=1     Bytes=57
            INDEX UNIQUE SCAN     Object owner=GL     Object name=GL_CODE_COMBINATIONS_U1     Cost=1     Cardinality=1     
          TABLE ACCESS BY INDEX ROWID     Object owner=INV     Object name=MTL_ITEM_LOCATIONS     Cost=3     Cardinality=1     Bytes=24
           INDEX RANGE SCAN     Object owner=INV     Object name=MTL_ITEM_LOCATIONS_U1     Cost=2     Cardinality=1     
         TABLE ACCESS BY INDEX ROWID     Object owner=HR     Object name=HR_ORGANIZATION_INFORMATION     Cost=2     Cardinality=1     Bytes=28
          INDEX RANGE SCAN     Object owner=HR     Object name=HR_ORGANIZATION_INFORMATIO_FK2     Cost=1     Cardinality=2     
        TABLE ACCESS BY INDEX ROWID     Object owner=HR     Object name=HR_ORGANIZATION_INFORMATION     Cost=1     Cardinality=1     Bytes=25
         INDEX RANGE SCAN     Object owner=HR     Object name=HR_ORGANIZATION_INFORMATIO_FK2     Cost=1     Cardinality=1     
       INDEX FULL SCAN     Object owner=GL     Object name=GL_SETS_OF_BOOKS_U2     Cost=1     Cardinality=1     Bytes=4
      BUFFER SORT               Cost=55     Cardinality=1     
       TABLE ACCESS FULL     Object owner=APPLSYS     Object name=FND_PRODUCT_GROUPS     Cost=3     Cardinality=1     

  • Urgent Help required in Tunning this query

    I have table ACCOUNT SPONSOR HOMESTORE ASH with more than 30 million rows.
    My batch daily need to update or insert into this table from a temporary table TEMP_HSTRALCT. The data for temporary table is populated by below query which selects from two tables TRANSACTION POINTS and REDEMPTIONS.However both these tables are partitioned on date time and is run daily and this is running for hours.
    Can anyone please help me on tuning this query
    INSERT INTO temp_hstralct
    (tmp_n_collector_account_num, tmp_v_location_id,
    tmp_v_sponsor_id, tmp_v_source_file_name,
    tmp_n_psc_insert_ind, tmp_n_psc_update_ind,
    tmp_n_transaction_amount, tmp_n_transaction_points,
    tmp_n_acc_insert_ind, tmp_n_ash_insert_ind,
    tmp_n_col_insert_ind, tmp_n_check_digit,
    tmp_n_collector_issue_num, tmp_n_csl_insert_ind,
    tmp_v_offer_code, tmp_n_psa_insert_ind)
    SELECT DISTINCT trp_n_collector_account_num account_num,
    trp_v_location_id location_id,
    trp_v_sponsor_id sponsor_id,
    trp_c_creation_user batch_id, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0
    FROM transaction_points, ACCOUNT, locations_master,homestores
    WHERE hsr_v_accrual_allowed = 'Y'
    AND trp_n_collector_account_num = ACCOUNT.acc_n_account_num(+)
    AND ( ( ( ACCOUNT.acc_v_account_type = 'C'
    OR ACCOUNT.acc_v_account_type IS NULL
    AND hsr_v_b2c_accounts = 'Y'
    OR ( ACCOUNT.acc_v_account_type = 'B'
    AND hsr_v_nfb_accounts = 'Y'
    OR ( ACCOUNT.acc_v_account_type = 'H'
    AND hsr_v_hybrid_accounts = 'Y'
    AND trp_d_creation_date_time BETWEEN SYSDATE-3
    AND SYSDATE
    AND trp_v_sponsor_id = 'JSAINSBURY'
    AND trp_v_location_id =
    locations_master.lnm_v_location_id
    AND locations_master.lnm_v_partner_id = 'JSAINSBURY'
    AND ( ( ( (INSTR
    (hsr_v_store_status,
    locations_master.lnm_c_location_status
    ) > 0
    AND (INSTR
    (hsr_v_store_type,
    locations_master.lnm_c_location_type
    ) > 0
    AND hsr_v_homestore_assignment = 'ST'
    OR ( ( locations_master.lnm_c_homestore_ind =
    'Y'
    AND (INSTR
    (hsr_v_store_status,
    locations_master.lnm_c_location_status
    ) > 0
    AND hsr_v_homestore_assignment = 'HS'
    UNION ALL
    SELECT DISTINCT rdm_n_collector_account_num account_num,
    rdm_v_location_id location_id,
    rom_v_supplier_id sponsor_id,
    rdm_c_creation_user batch_id, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0
    FROM redemption_details,
    reward_offer_master,
    ACCOUNT,
    locations_master,
    HOMESTORES
    WHERE hsr_v_redemption_allowed = 'Y'
    AND rdm_n_collector_account_num = ACCOUNT.acc_n_account_num(+)
    AND ( ( ( ACCOUNT.acc_v_account_type = 'C'
    OR ACCOUNT.acc_v_account_type IS NULL
    AND hsr_v_b2c_accounts = 'Y'
    OR ( ACCOUNT.acc_v_account_type = 'B'
    AND hsr_v_nfb_accounts = 'Y'
    OR ( ACCOUNT.acc_v_account_type = 'H'
    AND hsr_v_hybrid_accounts = 'Y'
    AND rdm_d_creation_date_time BETWEEN SYSDATE-3
    AND SYSDATE
    AND rom_v_reward_offer_id = rdm_v_reward_id
    AND rom_v_supplier_id = 'JSAINSBURY'
    AND rdm_v_location_id =
    locations_master.lnm_v_location_id
    AND locations_master.lnm_v_partner_id ='JSAINSBURY'
    AND ( ( ( (INSTR
    (hsr_v_store_status,
    locations_master.lnm_c_location_status
    ) > 0
    AND (INSTR
    (hsr_v_store_type,
    locations_master.lnm_c_location_type
    ) > 0
    AND hsr_v_homestore_assignment = 'ST'
    OR ( ( locations_master.lnm_c_homestore_ind =
    'Y'
    AND (INSTR
    (hsr_v_store_status,
    locations_master.lnm_c_location_status
    ) > 0
    AND hsr_v_homestore_assignment = 'HS'
    );

    I have copied the explain as it is and can you please try pasting in the text pad.Can you let me know whether parallel hint on this will speed up the select queries.
              Plan
              INSERT STATEMENT CHOOSECost: 410,815 Bytes: 2,798,394 Cardinality: 15,395                                                        
                   32 UNION-ALL                                                   
                        15 SORT UNIQUE Cost: 177,626 Bytes: 2,105,592 Cardinality: 11,896                                              
                             14 FILTER                                         
                                  13 HASH JOIN Cost: 177,312 Bytes: 2,105,592 Cardinality: 11,896                                    
                                       2 TABLE ACCESS BY INDEX ROWID LMHOLTP.LOCATIONS_MASTER Cost: 37 Bytes: 23,184 Cardinality: 966                               
                                            1 INDEX RANGE SCAN NON-UNIQUE LMHOLTP.IX_LOCATIONS_MASTER_3 Cost: 3 Cardinality: 1                          
                                       12 FILTER                               
                                            11 HASH JOIN OUTER                          
                                                 8 MERGE JOIN CARTESIAN Cost: 155,948 Bytes: 702,656,660 Cardinality: 4,845,908                     
                                                      3 TABLE ACCESS FULL LMHOLTP.HOMESTORES Cost: 2 Bytes: 104 Cardinality: 1                
                                                      7 BUFFER SORT Cost: 155,946 Bytes: 198,682,228 Cardinality: 4,845,908                
                                                           6 PARTITION RANGE ITERATOR Partition #: 12           
                                                                5 TABLE ACCESS BY LOCAL INDEX ROWID LMHOLTP.TRANSACTION_POINTS Cost: 155,946 Bytes: 198,682,228 Cardinality: 4,845,908 Partition #: 12      
                                                                     4 INDEX RANGE SCAN NON-UNIQUE LMHOLTP.IX_TRANSACTION_POINTS_1 Cost: 24,880 Cardinality: 6,978,108 Partition #: 12
                                                 10 PARTITION RANGE ALL Partition #: 15 Partitions accessed #1 - #5                    
                                                      9 TABLE ACCESS FULL LMHOLTP.ACCOUNT Cost: 6,928 Bytes: 68,495,680 Cardinality: 8,561,960 Partition #: 15 Partitions accessed #1 - #5               
                        31 SORT UNIQUE Cost: 233,189 Bytes: 692,802 Cardinality: 3,499                                              
                             30 FILTER                                         
                                  29 FILTER                                    
                                       28 NESTED LOOPS OUTER                               
                                            24 HASH JOIN Cost: 226,088 Bytes: 664,810 Cardinality: 3,499                          
                                                 16 TABLE ACCESS FULL LMHOLTP.REWARD_OFFER_MASTER Cost: 8 Bytes: 2,280 Cardinality: 114                     
                                                 23 HASH JOIN Cost: 226,079 Bytes: 8,327,280 Cardinality: 48,984                     
                                                      20 TABLE ACCESS BY INDEX ROWID LMHOLTP.LOCATIONS_MASTER Cost: 37 Bytes: 432 Cardinality: 18                
                                                           19 NESTED LOOPS Cost: 39 Bytes: 2,304 Cardinality: 18           
                                                                17 TABLE ACCESS FULL LMHOLTP.HOMESTORES Cost: 2 Bytes: 104 Cardinality: 1      
                                                                18 INDEX RANGE SCAN NON-UNIQUE LMHOLTP.IX_LOCATIONS_MASTER_3 Cost: 3 Cardinality: 966      
                                                      22 PARTITION RANGE ITERATOR Partition #: 28                
                                                           21 TABLE ACCESS FULL LMHOLTP.REDEMPTION_DETAILS Cost: 226,019 Bytes: 261,636,270 Cardinality: 6,229,435 Partition #: 28           
                                            27 PARTITION RANGE ITERATOR Partition #: 30                          
                                                 26 TABLE ACCESS BY LOCAL INDEX ROWID LMHOLTP.ACCOUNT Cost: 2 Bytes: 8 Cardinality: 1 Partition #: 30                     
                                                      25 INDEX UNIQUE SCAN UNIQUE LMHOLTP.CO_PK_ACCOUNT Cost: 1 Cardinality: 1 Partition #: 30

  • Help required regarding tunning the query mentioned

    HI all ,
    Query mentioned below takes around 1 hr to complete . It's being used by the autoconfig kindly me in tunning it ..
    QUery :
    UPDATE WF_ITEM_ATTRIBUTE_VALUES WIAV SET WIAV.TEXT_VALUE = REPLACE(WIAV.TEXT_VALUE,:B1,:B2)
    WHERE (WIAV.ITEM_TYPE, WIAV.NAME) = (SELECT WIA.ITEM_TYPE, WIA.NAME
    FROM WF_ITEM_ATTRIBUTES WIA WHERE WIA.TYPE = 'URL'
    AND WIA.ITEM_TYPE = WIAV.ITEM_TYPE
    AND WIA.NAME = WIAV.NAME)
    AND WIAV.TEXT_VALUE IS NOT NULL
    AND INSTR(WIAV.TEXT_VALUE
    , :B1) > 0
    Plan :*
    <pre>
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | UPDATE STATEMENT | | 453 | 14496 | 284K|
    | 1 | UPDATE | WF_ITEM_ATTRIBUTE_VALUES | | | |
    |* 2 | FILTER | | | | |
    |* 3 | TABLE ACCESS FULL | WF_ITEM_ATTRIBUTE_VALUES | 453 | 14496 | 282K|
    |* 4 | TABLE ACCESS BY INDEX ROWID| WF_ITEM_ATTRIBUTES | 1 | 33 | 2 |
    |* 5 | INDEX UNIQUE SCAN | WF_ITEM_ATTRIBUTES_PK | 1 | | 1 |
    Predicate Information (identified by operation id):
    2 - filter(("SYS_ALIAS_2"."ITEM_TYPE","SYS_ALIAS_2"."NAME")= (SELECT /*+ */
    "WIA"."ITEM_TYPE","WIA"."NAME" FROM "APPLSYS"."WF_ITEM_ATTRIBUTES" "WIA" WHERE
    "WIA"."NAME"=:B1 AND "WIA"."ITEM_TYPE"=:B2 AND "WIA"."TYPE"='URL'))
    3 - filter("SYS_ALIAS_2"."TEXT_VALUE" IS NOT NULL AND
    INSTR("SYS_ALIAS_2"."TEXT_VALUE",:Z)>0)
    4 - filter("WIA"."TYPE"='URL')
    5 - access("WIA"."ITEM_TYPE"=:B1 AND "WIA"."NAME"=:B2)
    </pre>
    Index :*
    <pre>
    INDEX_NAME COLUMN_NAME
    APPLSYS WF_ITEM_ATTRIBUTE_VALUES_PK 1 ITEM_TYPE
    2 ITEM_KEY
    3 NAME
    </pre>
    regds
    Rahul
    Edited by: RahulG on Jan 2, 2009 10:47 PM
    Edited by: RahulG on Jan 2, 2009 10:48 PM

    RahulG wrote:
    HI all ,
    Query mentioned below takes around 1 hr to complete . It's being used by the autoconfig kindly me in tunning it ..
    A few notes:
    1. Your query is using bind variables. If you're already on 9i or later (probably 9iR2 according to plan output), this statement will be subject to bind variable peeking and therefore the output of EXPLAIN PLAN is only of limited use, since the actual execution plan might be different and/or might be based on different cardinality estimates based on the actual bind values peeked at hard parse time. You can use the V$SQL_PLAN view to get the actual execution plan(s) if the statement is still cached in the shared pool, from 10g on DBMS_XPLAN.DISPLAY_CURSOR is available for that purpose.
    2. The execution plan posted suggests that only 453 rows will correspond to the filter criteria (but, as mentioned in 1. is based on an unknown bind variable value when using EXPLAIN PLAN), and probably therefore the optimizer didn't unnest the subquery but runs this as recursive FILTER query potentially for each row passing the filter criteria on the driving table WF_ITEM_ATTRIBUTE_VALUES. Depending on the actual number of rows this might be inefficient, and unnesting the subquery and turning it into a join might be more appropriate. This might accomplished e.g. by providing more representative statistics to the optimizer (are the statistics up-to-date?).
    Although you can't change the SQL you could try this manually by using the UNNEST hint to see if it makes any difference in the execution plan (and run time):
    WHERE (WIAV.ITEM_TYPE, WIAV.NAME) = (SELECT /*+ UNNEST */ WIA.ITEM_TYPE, WIA.NAME
    ...3. The composite index WF_ITEM_ATTRIBUTE_VALUES_PK can only be used on the first column ITEM_TYPE for effective index access, the NAME column would have to be used as filter on all index leaf blocks that would be found using a range scan on ITEM_TYPE. This might be quite inefficient, and/or might lead to a lot of rows/blocks that need to be visited in the table using this index access path.
    4. You could try to trace the execution by enabling extended SQL trace, e.g. using the (undocumented) DBMS_SUPPORT package in 9i. Running the "tkprof" utility on the generated trace file tells you the actual row source cardinalities (which can then be compared to the estimates of the optimizer) and - if the "waits" have been enabled - what your statement has waited for most.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • SQL query tunning help

    Hi All,
    Could you please help me out the below SQL query tuning .
    Temp table is having 1 Million records
    Master table is having 60 Million records
    Query :
    SELECT B.*,U.ID, SD, LE, LAE
    FROM client.Temp B, client.Master
    U WHERE U.policyno = B.policyno
    AND B.UPFLAG = 0
    1.     Indexes are created on both email columns and Upflag for both tables.
    2.     Gathered DBMS Stats for MASTER Table
    Data is loading 100k/hour on production .

    When your query takes too long ...
    When your query takes too long ...
    HOW TO: Post a SQL statement tuning request - template posting
    HOW TO: Post a SQL statement tuning request - template posting

  • Want help on Citical Tune Query

    ADDM suggested
    SQL statements consuming significant database time were found.
    RECOMMENDATION 1: SQL Tuning, 17% benefit (698 seconds)
    ACTION: Run SQL Tuning Advisor on the SQL statement with SQL_ID
    "2zcnyf9ypc2g7".
    RELEVANT OBJECT: SQL statement with SQL_ID 2zcnyf9ypc2g7 and
    PLAN_HASH 1170350465
    SELECT user_id, relation,status, to_char(ctime, :"SYS_B_0") as
    creation_at, to_char(utime, :"SYS_B_1") as last_modified_date
    FROM page_user WHERE page_id = :"SYS_B_2" AND upper(relation) =
    sys_context(:"SYS_B_3", :"SYS_B_4") AND upper(relation) =
    sys_context(:"SYS_B_5", :"SYS_B_6") AND upper(status) =
    sys_context(:"SYS_B_7", :"SYS_B_8") order by utime DESC
    Recommendations for SQL ID:2zcnyf9ypc2g7
    Only one recommendation should be implemented.
    SQL Text
    SELECT user_id, relation,status, to_char(ctime, :"SYS_B_0") as creation_at, to_char(utime, :"SYS_B_1") as last_modified_date FROM page_user WHERE page_id = :"SYS_B_2" AND upper(relation) = sys_contex...
    Select Recommendation
    Select     Type     Findings     Recommendations     Rationale     Benefit (%)     New Explain Plan     Compare Explain Plans
         Restructure SQL     The predicate UPPER("PAGE_USER"."RELATION")=SYS_CONTEXT(:B1,:B2) used at line ID 3 of the execution plan contains an expression on indexed column "RELATION". This expression prevents the optimizer from efficiently using indices on table "PAGES"."PAGE_USER".     Rewrite the predicate into an equivalent form to take advantage of indices. Alternatively, create a function-based index on the expression.     The optimizer is unable to use an index if the predicate is an inequality condition or if there is an expression or an implicit data type conversion on the indexed column.     
    Text
         SELECT user_id, relation,status, to_char(ctime, :"SYS_B_0") as creation_at, to_char(utime, :"SYS_B_1") as last_modified_date
    FROM page_user WHERE page_id = :"SYS_B_2" AND upper(relation) = sys_context(:"SYS_B_3", :"SYS_B_4") AND upper(relation) = sys_context(:"SYS_B_5", :"SYS_B_6") AND upper(status) = sys_context(:"SYS_B_7", :"SYS_B_8") order by utime DESC
    Details
    Select the plan hash value to see the details below.          Plan Hash Value     
         Statistics     Activity     
         Plan     
         Tuning Information     
         Data Source          Snapshot (4413)
         Capture Time          12-Mar-2010 16:30:33
         Parsing Schema          PAGES
         Optimizer Mode          ALL_ROWS
    Expand All | Collapse All
    Operation     Object     Object Type     Order     Rows     Size (KB)     Cost     Time (sec)     CPU Cost     I/O Cost
    [Select to collapse] SELECT STATEMENT
         5     0     0.000     5     0     0     0
    [Select to collapse] FILTER
         4     0     0.000     0     0     0     0
    [Select to collapse] SORT ORDER BY
         3     1     0.039     5     1     19,417,919     4
    [Select to collapse] TABLE ACCESS BY INDEX ROWID
         PAGE_USER     TABLE     2     1     0.039     4     1     37,794     4
    INDEX RANGE SCAN
         USER_PAGE_UK1     INDEX (UNIQUE)     1     1     0.000     3     1     30,364     3

    user8764012 wrote:
    Sir,
    Asking how to implement the advise provided by ADDM or also if you have a better suggestion to decrease the cost of the query
    SELECT user_id, relation,status, to_char(ctime, :"SYS_B_0") as
    creation_at, to_char(utime, :"SYS_B_1") as last_modified_date
    FROM page_user WHERE page_id = :"SYS_B_2" AND upper(relation) =
    sys_context(:"SYS_B_3", :"SYS_B_4") AND upper(relation) =
    sys_context(:"SYS_B_5", :"SYS_B_6") AND upper(status) =
    sys_context(:"SYS_B_7", :"SYS_B_8") order by utime DESC
    Restructure SQLThe predicate UPPER("PAGE_USER"."RELATION")=SYS_CONTEXT(:B1,:B2) used at line ID 3 of the execution plan contains an expression on
    indexed column "RELATION". This expression prevents the optimizer from efficiently using indices on table "PAGES"."PAGE_USER".     Rewrite the
    predicate into an equivalent form to take advantage of indices. Alternatively, create a function-based index on the expression.     The optimizer is unable to use an
    index if the predicate is an inequality condition or if there is an expression or an implicit data type conversion on the indexed column.The message is tellong you that although you have an index on RELATION the idex can't be used because you are changing the value with a function. You can do a couple of things:
    1. remove the UPPER() function from the RELATION clause elements (predicates) finding another way to force the columns to match
    2. use a function based index, based on upper(relation) something like (untested)
    create index fb_index on page_user (upper(relation));This may or may not help in the long run as function-based indexes only work when certain intialization parmeters are set (QUERY_REWRITE_ENABLED). You can read about function-based indexes in the documentation.

  • Using substr function loses index. Query tune help

    Hi
    when i use substr function in the join condition it loses index and the query is slow. How to fix this problem or tune this query. These are the lines in the query.
    and substr(a.invoice_num,1,9) = l.invoice_num
    and substr(c.invoice_num,1,9) = mgr_apprv_lst.user_key
    and substr(c.invoice_num,1,9) = pbl_apprv_lst.user_key
    select
    pap.full_name employe_name,
         k.SEGMENT1 ||'.' ||k.segment2 Cost_Center,
         a.invoice_num Invoice_Number,
         b.item_description Line_Item,
         b.amount Amount,
         cc.trx_id Corporate_Card_Transaction_Id,
         cc.transaction_date Date_Charge_Incurred,
         cc.posted_date Date_Charge_Posted_To_USBank,
         cc.creation_date Date_Posted_To_IExpense,
         a.creation_date Expense_Report_Creation_Date,
         l.report_submitted_date Expense_Report_Submitted_Date,
         mgr_apprv_lst.activity_begin_date Managers_Approval_Begin_Date,
         mgr_apprv_lst.activity_end_date Managers_Approval_End_Date,
         pbl_apprv_lst.activity_begin_date AP_Approval_Begin_Date,
         pbl_apprv_lst.activity_end_date AP_Approval_End_Date,
         e.check_date Payment_Date_To_USBank,
         e.check_number Payment_Number,
         mgr_apprv_lst.activity_result_display_name Managers_Process_Result,
         pbl_apprv_lst.activity_result_display_name AP_Process_Result
    from
         ap_checks_all e,
         ap_invoice_payments_all d,
         ap_invoices_all c,
    ap_expense_report_headers_all a,
         ap_credit_card_trxns_all cc,
         per_all_people_f pap,
         ap_expense_report_headers_all l,
         ap_expense_report_lines_all b,
         gl_code_combinations k,
         (select ias1.user_key,
         ias1.activity_result_display_name,
         ias1.activity_begin_date,
         ias1.activity_end_date
    from wf_item_activity_statuses_v ias1,
    (select c1.invoice_num
         from ap_checks_all e1,
         ap_invoice_payments_all d1,
         ap_invoices_all c1
         where trunc(e1.check_date) between nvl(:From_Date, trunc(e1.check_date))
         and nvl(:To_Date, trunc(e1.check_date))
    and e1.org_id = 141
    and e1.void_date IS null
    and d1.check_id = e1.check_id
         and c1.invoice_id = d1.invoice_id) inv_lst1
    where ias1.item_type = 'APEXP'
    and ias1.user_key = inv_lst1.invoice_num
    and ias1.activity_name = 'AP_MANAGER_APPROVAL_PROCESS') mgr_apprv_lst,
    (select ias2.user_key,
         ias2.activity_result_display_name,
         ias2.activity_begin_date,
         ias2.activity_end_date
    from wf_item_activity_statuses_v ias2,
    (select c2.invoice_num
         from ap_checks_all e2,
         ap_invoice_payments_all d2,
         ap_invoices_all c2
         where trunc(e2.check_date) between nvl(:From_Date, trunc(e2.check_date))
         and nvl(:To_Date, trunc(e2.check_date))
    and e2.org_id = 141
    and e2.void_date IS null
    and d2.check_id = e2.check_id
         and c2.invoice_id = d2.invoice_id) inv_lst2
    where ias2.item_type = 'APEXP'
    and ias2.user_key = inv_lst2.invoice_num
    and ias2.activity_name = 'AP_PAYABLES_APPROVAL_PROCESS') pbl_apprv_lst
    where
    trunc(e.check_date) between nvl(:From_Date, trunc(e.check_date))
    and nvl(:To_Date, trunc(e.check_date))
    and e.org_id = 141
    and e.void_date IS null
    and d.check_id = e.check_id
    and c.invoice_id = d.invoice_id
    and a.invoice_num = c.invoice_num
    and a.source = 'CREDIT CARD'
    and a.employee_id = nvl(:Emp_id,a.employee_id)
    and a.report_header_id = b.report_header_id
    and cc.trx_id = b.credit_card_trx_id
    and pap.person_id = a.employee_id
    and pap.effective_start_date <= trunc(sysdate)
    and pap.effective_end_date >= trunc(sysdate)
    and k.code_combination_id = b.code_combination_id
    and k.segment2 between nvl(:From_Cost_Center,k.segment2)
    and nvl(:To_Cost_Center,k.segment2)
    and substr(a.invoice_num,1,9) = l.invoice_num
    and substr(c.invoice_num,1,9) = mgr_apprv_lst.user_key
    and substr(c.invoice_num,1,9) = pbl_apprv_lst.user_key

    Hi
    If I understood correctly your logic, and if the columns involved are of type varchar2, you can use the like operator:
    and a.invoice_num like l.invoice_num || '%'
    and c.invoice_num like mgr_apprv_lst.user_key  || '%'
    and c.invoice_num like pbl_apprv_lst.user_key  || '%'In this case, Oracle will be able to use the indexes. If they are numeric, you need to do something like:
    and a.invoice_num between l.invoice_num * 1000000
                                and l.invoice_num * 1000000 + 999999I hope this makes sense...
    Luis

  • Query Tune Kindly Help

    this query is giving high cost pls help.
    SELECT DISTINCT
    SI.ORG_ID
    ,SI.ID SI_NO
    ,JO.ID JOB_NO
    ,JO.BOOKING_REF_NO
    ,ORGSERPO.DESCRIPTION ETA_POL
    ,TSCH.VESSEL_1||TSCH.VOYAGE_1 VESSEL_VOYAGE_1
    ,TSCH.ETD_1
    ,ORGSERPO1.DESCRIPTION POD
    ,TSCH.ETA_1
    ,TSCH.VESSEL_2||TSCH.VOYAGE_2 VESSEL_VOYAGE_2
    ,TSCH.ETD_2
    ,ORGSERPO2.DESCRIPTION POD2
    ,TSCH.ETA_2
    ,TSCH.VESSEL_3||TSCH.VOYAGE_3 VESSEL_VOYAGE_3
    ,TSCH.ETA_3
    ,TSCH.ETD_3
    ,ORGSERPO3.DESCRIPTION POD3
    ,ORGSERPO4.DESCRIPTION FINAL_DESTINATION
    ,ORGP.SHORT_NAME CARRIER_SHORT_NAME
    ,ORGP1.SHORT_NAME CONSIGNEE_SHORT_NAME
    ,ORGP2.SHORT_NAME FACTORY_SHORT_NAME
    ,JO.SHIPMENT_TYPE
    ,SUBD.DESCRIPTION PRODUCT_TYPE ,
    Pshm05.Get_SI_Forwarder(jo.org_id,jo.id) Forwarder,
    JO.POL_TERMS||JO.POD_TERMS,
    decode(po.ext_sys_ref_no,po.trans_id_1,po.id,po.ext_sys_ref_no),
    SI.ORGP_ID,
    pshm07.Get_Cont_count(pal.org_id,pal.id,'20F') f20,
    pshm07.Get_Cont_count(pal.org_id,pal.id,'40F') f40,
    pshm07.Get_Cont_count(pal.org_id,pal.id,'40H') h40,
    pshm07.Get_Cont_count(pal.org_id,pal.id,'45F') f45,
    sum(palcsi.qty) QTY,
    sum(palcsi.gross_weight) WEIGHT,
    sum(palcsi.volume) M3,
    (si.instruction_1||si.instruction_2||si.instruction_3||si.instruction_4||si.instruction_5
    ||si.instruction_6||si.instruction_7||si.instruction_8||si.instruction_9||si.instruction_10) INSTRUCTIONS ,
    TSCH.ETA_POL,
    PAL.ID,
    PAL.EXT_SYS_REF_NO
    FROM TRANSPORT_SCHEDULES TSCH,
    TRANSPORT_ORDERS SI,
    JOB_ORDERS JO,
    PURCHASE_ORDERS PO,
    PACKING_LISTS PAL,
    PALCS_ITEMS PALCSI,
    ORG_SERVICE_POINTS ORGSERPO,
    ORG_SERVICE_POINTS ORGSERPO1,
    ORG_SERVICE_POINTS ORGSERPO2,
    ORG_SERVICE_POINTS ORGSERPO3,
    ORG_SERVICE_POINTS ORGSERPO4,
    ORG_PARTIES ORGP,
    ORG_PARTIES ORGP1,
    ORG_PARTIES ORGP2,
    SUBJECT_DOMAINS SUBD
    WHERE TSCH.ORG_ID = JO.ORG_ID
    AND TSCH.ID = JO.TSCH_ID
    AND JO.ORG_ID = PAL.EXT_SYS_REF_ORG_ID
    AND JO.ID = PAL.TRANS_ID_1
    AND PAL.ORG_ID = PALCSI.PALCS_PAL_ORG_ID
    AND PAL.ID = PALCSI.PALCS_PAL_ID
    AND PALCSI.PALCS_PAL_ORG_ID = PO.ORG_ID
    AND PALCSI.TRANS_ID_1 = PO.ID
    AND JO.ORG_ID = SI.ORG_ID
    AND JO.ID = SI.TRANS_ID_1
    AND TSCH.ORG_ID = ORGSERPO.ORG_ID
    AND TSCH.ORGSERPO_ID = ORGSERPO.ID
    AND TSCH.ORG_ID = ORGSERPO1.ORG_ID
    AND TSCH.ORGSERPO_ID_1 = ORGSERPO1.ID
    AND TSCH.ORG_ID = ORGSERPO2.ORG_ID (+)
    AND TSCH.ORGSERPO_ID_2 = ORGSERPO2.ID (+)
    AND TSCH.ORG_ID = ORGSERPO3.ORG_ID (+)
    AND TSCH.ORGSERPO_ID_3 = ORGSERPO3.ID (+)
    AND TSCH.ORG_ID = ORGSERPO4.ORG_ID
    AND TSCH.ORGSERPO_ID_4 = ORGSERPO4.ID
    AND TSCH.ORG_ID = ORGP.ORG_ID
    AND TSCH.ORGP_ID_5 = ORGP.ID
    AND PAL.ORG_ID = ORGP1.ORG_ID
    AND PAL.ORGP_ID_2 = ORGP1.ID
    AND SI.ORG_ID = ORGP2.ORG_ID
    AND SI.ORGP_ID = ORGP2.ID
    AND PO.TRANS_TYPE = SUBD.ID
    AND SUBD.SUB_ID = 'PRODUCT_TYPE'
    AND SI.TRANS_TYPE          = 'JO_FACT'
    GROUP BY
    SI.ORG_ID
    ,SI.ID
    ,JO.ID
    ,JO.BOOKING_REF_NO
    ,ORGSERPO.DESCRIPTION
    ,TSCH.VESSEL_1
    ,TSCH.VOYAGE_1
    ,TSCH.ETD_1
    ,ORGSERPO1.DESCRIPTION
    ,TSCH.ETA_1
    ,TSCH.VESSEL_2
    ,TSCH.VOYAGE_2
    ,TSCH.ETD_2
    ,ORGSERPO2.DESCRIPTION
    ,TSCH.ETA_2
    ,TSCH.VESSEL_3
    ,TSCH.VOYAGE_3
    ,TSCH.ETA_3
    ,TSCH.ETD_3
    ,ORGSERPO3.DESCRIPTION
    ,ORGSERPO4.DESCRIPTION
    ,ORGP.SHORT_NAME
    ,ORGP1.SHORT_NAME
    ,ORGP2.SHORT_NAME
    ,JO.SHIPMENT_TYPE
    ,SUBD.DESCRIPTION,
    Pshm05.Get_SI_Forwarder(jo.org_id,jo.id),
    JO.POL_TERMS,
    JO.POD_TERMS,
    decode(po.ext_sys_ref_no,po.trans_id_1,po.id,po.ext_sys_ref_no),
    SI.ORGP_ID,
    pshm07.Get_Cont_count(pal.org_id,pal.id,'20F'),
    pshm07.Get_Cont_count(pal.org_id,pal.id,'40F'),
    pshm07.Get_Cont_count(pal.org_id,pal.id,'40H'),
    pshm07.Get_Cont_count(pal.org_id,pal.id,'45F'),
    (si.instruction_1||si.instruction_2||si.instruction_3||si.instruction_4||si.instruction_5
    ||si.instruction_6||si.instruction_7||si.instruction_8||si.instruction_9||si.instruction_10,
    TSCH.ETA_POL,
    PAL.ID,
    PAL.EXT_SYS_REF_NO)

    i got PRE thanks
    <Pre>
    select *
    from
    v_si_schedule Where Rownum < 10
    call count cpu elapsed disk query current rows
    Parse 1 0.91 0.88 0 0 0 0
    Execute 1 0.00 0.00 0 0 0 0
    Fetch 1 37.11 36.93 6202 7794 0 9
    total 3 38.02 37.82 6202 7794 0 9
    Misses in library cache during parse: 1
    Optimizer goal: ALL_ROWS
    Rows Row Source Operation
    9 COUNT STOPKEY (cr=1745575 pr=6243 pw=0 time=60273765 us)
    9 VIEW (cr=1745575 pr=6243 pw=0 time=60273759 us)
    9 SORT UNIQUE STOPKEY (cr=1745575 pr=6243 pw=0 time=60273731 us)
    24125 SORT GROUP BY (cr=1745575 pr=6243 pw=0 time=60177004 us)
    99836 HASH JOIN (cr=7794 pr=6202 pw=0 time=3451945 us)
    3953 TABLE ACCESS FULL ORG_SERVICE_POINTS (cr=61 pr=59 pw=0 time=233 us)
    99836 HASH JOIN RIGHT OUTER (cr=7733 pr=6143 pw=0 time=3147141 us)
    3953 TABLE ACCESS FULL ORG_SERVICE_POINTS (cr=61 pr=0 pw=0 time=36 us)
    99836 HASH JOIN RIGHT OUTER (cr=7672 pr=6143 pw=0 time=2942252 us)
    3953 TABLE ACCESS FULL ORG_SERVICE_POINTS (cr=61 pr=0 pw=0 time=49 us)
    99836 HASH JOIN (cr=7611 pr=6143 pw=0 time=2637117 us)
    3953 TABLE ACCESS FULL ORG_SERVICE_POINTS (cr=61 pr=0 pw=0 time=50 us)
    99836 HASH JOIN (cr=7550 pr=6143 pw=0 time=2331803 us)
    3953 TABLE ACCESS FULL ORG_SERVICE_POINTS (cr=61 pr=0 pw=0 time=48 us)
    99836 HASH JOIN (cr=7489 pr=6143 pw=0 time=2026580 us)
    3413 TABLE ACCESS FULL ORG_PARTIES (cr=122 pr=93 pw=0 time=100 us)
    99836 HASH JOIN (cr=7367 pr=6050 pw=0 time=1719269 us)
    6112 TABLE ACCESS FULL TRANSPORT_SCHEDULES (cr=248 pr=245 pw=0 time=6301 us)
    100271 HASH JOIN (cr=7119 pr=5805 pw=0 time=1300940 us)
    3413 TABLE ACCESS FULL ORG_PARTIES (cr=122 pr=1 pw=0 time=99 us)
    100684 HASH JOIN (cr=6997 pr=5804 pw=0 time=1098029 us)
    5655 TABLE ACCESS FULL TRANSPORT_ORDERS (cr=1067 pr=13 pw=0 time=22723 us)
    84236 HASH JOIN (cr=5930 pr=5791 pw=0 time=1089549 us)
    6415 TABLE ACCESS FULL JOB_ORDERS (cr=310 pr=307 pw=0 time=6611 us)
    84236 HASH JOIN (cr=5620 pr=5484 pw=0 time=816414 us)
    3413 TABLE ACCESS FULL ORG_PARTIES (cr=122 pr=0 pw=0 time=59 us)
    84236 HASH JOIN (cr=5498 pr=5484 pw=0 time=557678 us)
    17884 TABLE ACCESS FULL PACKING_LISTS (cr=1005 pr=1001 pw=0 time=18094 us)
    93201 HASH JOIN (cr=4493 pr=4483 pw=0 time=462268 us)
    25081 HASH JOIN (cr=1326 pr=1322 pw=0 time=102379 us)
    8 TABLE ACCESS BY INDEX ROWID SUBJECT_DOMAINS (cr=7 pr=7 pw=0 time=178 us)
    8 INDEX RANGE SCAN SUBD_PK (cr=2 pr=2 pw=0 time=97 us)(object id 198829)
    25081 TABLE ACCESS FULL PURCHASE_ORDERS (cr=1319 pr=1315 pw=0 time=50367 us)
    93201 TABLE ACCESS FULL PALCS_ITEMS (cr=3167 pr=3161 pw=0 time=93374 us)
    unable to set optimizer goal
    ORA-01986: OPTIMIZER_GOAL is obsolete
    parse error offset: 33
    Rows Execution Plan
    0 SELECT STATEMENT GOAL: ALL_ROWS
    9 COUNT (STOPKEY)
    9 VIEW OF 'V_SI_SCHEDULE' (VIEW)
    9 SORT (UNIQUE STOPKEY)
    24125 SORT (GROUP BY)
    99836 HASH JOIN
    3953 TABLE ACCESS GOAL: ANALYZED (FULL) OF
    'ORG_SERVICE_POINTS' (TABLE)
    99836 HASH JOIN (RIGHT OUTER)
    3953 TABLE ACCESS GOAL: ANALYZED (FULL) OF
    'ORG_SERVICE_POINTS' (TABLE)
    99836 HASH JOIN (RIGHT OUTER)
    3953 TABLE ACCESS GOAL: ANALYZED (FULL) OF
    'ORG_SERVICE_POINTS' (TABLE)
    99836 HASH JOIN
    3953 TABLE ACCESS GOAL: ANALYZED (FULL) OF
    'ORG_SERVICE_POINTS' (TABLE)
    99836 HASH JOIN
    3953 TABLE ACCESS GOAL: ANALYZED (FULL) OF
    'ORG_SERVICE_POINTS' (TABLE)
    99836 HASH JOIN
    3413 TABLE ACCESS GOAL: ANALYZED (FULL) OF
    'ORG_PARTIES' (TABLE)
    99836 HASH JOIN
    6112 TABLE ACCESS GOAL: ANALYZED (FULL) OF
    'TRANSPORT_SCHEDULES' (TABLE)
    100271 HASH JOIN
    3413 TABLE ACCESS GOAL: ANALYZED (FULL) OF
    'ORG_PARTIES' (TABLE)
    100684 HASH JOIN
    5655 TABLE ACCESS GOAL: ANALYZED (FULL)
    OF 'TRANSPORT_ORDERS' (TABLE)
    84236 HASH JOIN
    6415 TABLE ACCESS GOAL: ANALYZED (FULL)
    OF 'JOB_ORDERS' (TABLE)
    84236 HASH JOIN
    3413 TABLE ACCESS GOAL: ANALYZED
    (FULL) OF 'ORG_PARTIES' (TABLE)
    84236 HASH JOIN
    17884 TABLE ACCESS GOAL: ANALYZED
    (FULL) OF 'PACKING_LISTS' (TABLE)
    93201 HASH JOIN
    25081 HASH JOIN
    8 TABLE ACCESS GOAL:
    ANALYZED (BY INDEX ROWID) OF
    'SUBJECT_DOMAINS' (TABLE)
    8 INDEX GOAL: ANALYZED
    (RANGE SCAN) OF 'SUBD_PK' (INDEX (UNIQUE))
    25081 TABLE ACCESS GOAL:
    ANALYZED (FULL) OF 'PURCHASE_ORDERS' (TABLE)
    93201 TABLE ACCESS GOAL: ANALYZED
    (FULL) OF 'PALCS_ITEMS' (TABLE)
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call count cpu elapsed disk query current rows
    Parse 14 1.84 1.81 3 21 0 0
    Execute 16 0.00 0.00 0 0 0 6
    Fetch 96 74.72 74.49 13598 15603 0 9113
    total 126 76.56 76.30 13601 15624 0 9119
    Misses in library cache during parse: 4
    Misses in library cache during execute: 1
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call count cpu elapsed disk query current rows
    Parse 86 0.06 0.05 0 25 0 0
    Execute 998985 25.06 23.86 38 617 0 0
    Fetch 1000325 24.25 23.09 1782 3480045 0 980187
    total 1999396 49.37 47.01 1820 3480687 0 980187
    Misses in library cache during parse: 30
    Misses in library cache during execute: 29
    18 user SQL statements in session.
    84 internal SQL statements in session.
    102 SQL statements in session.
    5 statements EXPLAINed in this session.
    Sort options: default
    1 session in tracefile.
    18 user SQL statements in trace file.
    84 internal SQL statements in trace file.
    102 SQL statements in trace file.
    36 unique SQL statements in trace file.
    5 SQL statements EXPLAINed using schema:
    schema.prof$plan_table
    Default table was used.
    Table was created.
    Table was dropped.
    2000131 lines in trace file.
    <Pre>

  • Can any one help me to tune this query

    This is the query.
    ~~~~~~~~~~
    SELECT
    S_CONTACT.ROW_ID,
    S_CONTACT.MODIFICATION_NUM,
    S_CONTACT.LAST_UPD
    FROM
    S_CONTACT,
    S_CONTACT_FNX,
    S_ETL_I_IMG_118 IMG
    WHERE
    IMG.ROW_ID = S_CONTACT_FNX.ROW_ID
    AND
    S_CONTACT_FNX.PAR_ROW_ID = S_CONTACT.ROW_ID
    AND NOT EXISTS
    ( SELECT 'X'
    FROM
    S_ETL_I_IMG_12 IMG1
    WHERE
    IMG1.ROW_ID = S_CONTACT.ROW_ID
    UNION ALL
    SELECT
    S_CONTACT.ROW_ID,
    S_CONTACT.MODIFICATION_NUM,
    S_CONTACT.LAST_UPD
    FROM
    S_CONTACT,
    S_ETL_I_IMG_109 IMG
    WHERE
    IMG.ROW_ID = S_CONTACT.PR_SPECIALTY_ID
    AND NOT EXISTS
    ( SELECT 'X'
    FROM
    S_ETL_I_IMG_12 IMG1
    WHERE
    IMG1.ROW_ID = S_CONTACT.ROW_ID
    UNION ALL
    SELECT
    S_CONTACT.ROW_ID,
    S_CONTACT.MODIFICATION_NUM,
    S_CONTACT.LAST_UPD
    FROM
    S_CONTACT,
    S_ETL_I_IMG_113 IMG
    WHERE
    IMG.ROW_ID = S_CONTACT.MED_SPEC_ID
    AND NOT EXISTS
    ( SELECT 'X'
    FROM
    S_ETL_I_IMG_12 IMG1
    WHERE
    IMG1.ROW_ID = S_CONTACT.ROW_ID
    UNION ALL
    SELECT
    S_CONTACT.ROW_ID,
    S_CONTACT.MODIFICATION_NUM,
    S_CONTACT.LAST_UPD
    FROM
    S_CONTACT,
    S_ETL_I_IMG_125 IMG
    WHERE
    IMG.ROW_ID = S_CONTACT.REGION_ID
    AND NOT EXISTS
    ( SELECT 'X'
    FROM
    S_ETL_I_IMG_12 IMG1
    WHERE
    IMG1.ROW_ID = S_CONTACT.ROW_ID
    Below is the explain plan
    ~~~~~~~~~~~~~~~~~~~~~
    PLAN_TABLE_OUTPUT
    Plan hash value: 363891185
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 4 | 334 | | 214K(100)| 00:42:50 |
    | 1 | UNION-ALL | | | | | | |
    |* 2 | HASH JOIN ANTI | | 1 | 64 | | 122 (1)| 00:00:02 |
    | 3 | NESTED LOOPS | | 3518 | 178K| | 119 (0)| 00:00:02 |
    | 4 | NESTED LOOPS | | 3518 | 98504 | | 13 (0)| 00:00:01 |
    | 5 | INDEX FULL SCAN | S_ETL_I_IMG_118_M2 | 3518 | 35180 | | 1 (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    | 6 | TABLE ACCESS BY INDEX ROWID| S_CONTACT_FNX | 1 | 18 | | 1 (0)| 00:00:01 |
    |* 7 | INDEX UNIQUE SCAN | S_CONTACT_FNX_P1 | 1 | | | 1 (0)| 00:00:01 |
    | 8 | TABLE ACCESS BY INDEX ROWID | S_CONTACT | 1 | 24 | | 1 (0)| 00:00:01 |
    |* 9 | INDEX UNIQUE SCAN | S_CONTACT_P1 | 1 | | | 1 (0)| 00:00:01 |
    | 10 | INDEX FULL SCAN | S_ETL_I_IMG_12_M2 | 94772 | 1110K| | 2 (0)| 00:00:01 |
    | 11 | NESTED LOOPS | | 1 | 70 | | 214K (1)| 00:42:49 |
    | 12 | MERGE JOIN ANTI | | 1 | 38 | | 214K (1)| 00:42:49 |
    |* 13 | TABLE ACCESS BY INDEX ROWID | S_CONTACT | 72253 | 1834K| | 213K (1)| 00:42:43 |
    | 14 | INDEX FULL SCAN | S_CONTACT_P1 | 57M| | | 2904 (1)| 00:00:35 |
    |* 15 | SORT UNIQUE | | 94772 | 1110K| 3736K| 441 (2)| 00:00:06 |
    | 16 | INDEX FULL SCAN | S_ETL_I_IMG_12_M2 | 94772 | 1110K| | 2 (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |* 17 | INDEX RANGE SCAN | S_ETL_I_IMG_109_M2 | 1 | 32 | | 1 (0)| 00:00:01 |
    | 18 | NESTED LOOPS | | 1 | 100 | | 3 (0)| 00:00:01 |
    | 19 | NESTED LOOPS ANTI | | 1 | 68 | | 2 (0)| 00:00:01 |
    | 20 | TABLE ACCESS BY INDEX ROWID | S_CONTACT | 1 | 56 | | 1 (0)| 00:00:01 |
    |* 21 | INDEX FULL SCAN | S_CONTACT_F58 | 1 | | | 1 (0)| 00:00:01 |
    |* 22 | INDEX RANGE SCAN | S_ETL_I_IMG_12_M2 | 94772 | 1110K| | 1 (0)| 00:00:01 |
    |* 23 | INDEX RANGE SCAN | S_ETL_I_IMG_113_M2 | 1 | 32 | | 1 (0)| 00:00:01 |
    | 24 | NESTED LOOPS ANTI | | 1 | 100 | | 3 (0)| 00:00:01 |
    | 25 | NESTED LOOPS | | 1 | 88 | | 2 (0)| 00:00:01 |
    | 26 | TABLE ACCESS BY INDEX ROWID | S_CONTACT | 1 | 56 | | 1 (0)| 00:00:01 |
    |* 27 | INDEX FULL SCAN | S_CONTACT_F62 | 1 | | | 1 (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |* 28 | INDEX RANGE SCAN | S_ETL_I_IMG_125_M2 | 1 | 32 | | 1 (0)| 00:00:01 |
    |* 29 | INDEX RANGE SCAN | S_ETL_I_IMG_12_M2 | 94772 | 1110K| | 1 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    2 - access("IMG1"."ROW_ID"="S_CONTACT"."ROW_ID")
    7 - access("IMG"."ROW_ID"="S_CONTACT_FNX"."ROW_ID")
    9 - access("S_CONTACT_FNX"."PAR_ROW_ID"="S_CONTACT"."ROW_ID")
    13 - filter("S_CONTACT"."PR_SPECIALTY_ID" IS NOT NULL)
    PLAN_TABLE_OUTPUT
    15 - access("IMG1"."ROW_ID"="S_CONTACT"."ROW_ID")
    filter("IMG1"."ROW_ID"="S_CONTACT"."ROW_ID")
    17 - access("IMG"."ROW_ID"="S_CONTACT"."PR_SPECIALTY_ID")
    21 - filter("S_CONTACT"."MED_SPEC_ID" IS NOT NULL)
    22 - access("IMG1"."ROW_ID"="S_CONTACT"."ROW_ID")
    23 - access("IMG"."ROW_ID"="S_CONTACT"."MED_SPEC_ID")
    27 - filter("S_CONTACT"."REGION_ID" IS NOT NULL)
    28 - access("IMG"."ROW_ID"="S_CONTACT"."REGION_ID")
    29 - access("IMG1"."ROW_ID"="S_CONTACT"."ROW_ID")

    PLAN_TABLE_OUTPUT
    Plan hash value: 363891185
    | Id  | Operation                       | Name               | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                |                    |     4 |   334 |       |   214K(100)| 00:42:50 |
    |   1 |  UNION-ALL                      |                    |       |       |       |            |          |
    |*  2 |   HASH JOIN ANTI                |                    |     1 |    64 |       |   122   (1)| 00:00:02 |
    |   3 |    NESTED LOOPS                 |                    |  3518 |   178K|       |   119   (0)| 00:00:02 |
    |   4 |     NESTED LOOPS                |                    |  3518 | 98504 |       |    13   (0)| 00:00:01 |
    |   5 |      INDEX FULL SCAN            | S_ETL_I_IMG_118_M2 |  3518 | 35180 |       |     1   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |   6 |      TABLE ACCESS BY INDEX ROWID| S_CONTACT_FNX      |     1 |    18 |       |     1   (0)| 00:00:01 |
    |*  7 |       INDEX UNIQUE SCAN         | S_CONTACT_FNX_P1   |     1 |       |       |     1   (0)| 00:00:01 |
    |   8 |     TABLE ACCESS BY INDEX ROWID | S_CONTACT          |     1 |    24 |       |     1   (0)| 00:00:01 |
    |*  9 |      INDEX UNIQUE SCAN          | S_CONTACT_P1       |     1 |       |       |     1   (0)| 00:00:01 |
    |  10 |    INDEX FULL SCAN              | S_ETL_I_IMG_12_M2  | 94772 |  1110K|       |     2   (0)| 00:00:01 |
    |  11 |   NESTED LOOPS                  |                    |     1 |    70 |       |   214K  (1)| 00:42:49 |
    |  12 |    MERGE JOIN ANTI              |                    |     1 |    38 |       |   214K  (1)| 00:42:49 |
    |* 13 |     TABLE ACCESS BY INDEX ROWID | S_CONTACT          | 72253 |  1834K|       |   213K  (1)| 00:42:43 |
    |  14 |      INDEX FULL SCAN            | S_CONTACT_P1       |    57M|       |       |  2904   (1)| 00:00:35 |
    |* 15 |     SORT UNIQUE                 |                    | 94772 |  1110K|  3736K|   441   (2)| 00:00:06 |
    |  16 |      INDEX FULL SCAN            | S_ETL_I_IMG_12_M2  | 94772 |  1110K|       |     2   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |* 17 |    INDEX RANGE SCAN             | S_ETL_I_IMG_109_M2 |     1 |    32 |       |     1   (0)| 00:00:01 |
    |  18 |   NESTED LOOPS                  |                    |     1 |   100 |       |     3   (0)| 00:00:01 |
    |  19 |    NESTED LOOPS ANTI            |                    |     1 |    68 |       |     2   (0)| 00:00:01 |
    |  20 |     TABLE ACCESS BY INDEX ROWID | S_CONTACT          |     1 |    56 |       |     1   (0)| 00:00:01 |
    |* 21 |      INDEX FULL SCAN            | S_CONTACT_F58      |     1 |       |       |     1   (0)| 00:00:01 |
    |* 22 |     INDEX RANGE SCAN            | S_ETL_I_IMG_12_M2  | 94772 |  1110K|       |     1   (0)| 00:00:01 |
    |* 23 |    INDEX RANGE SCAN             | S_ETL_I_IMG_113_M2 |     1 |    32 |       |     1   (0)| 00:00:01 |
    |  24 |   NESTED LOOPS ANTI             |                    |     1 |   100 |       |     3   (0)| 00:00:01 |
    |  25 |    NESTED LOOPS                 |                    |     1 |    88 |       |     2   (0)| 00:00:01 |
    |  26 |     TABLE ACCESS BY INDEX ROWID | S_CONTACT          |     1 |    56 |       |     1   (0)| 00:00:01 |
    |* 27 |      INDEX FULL SCAN            | S_CONTACT_F62      |     1 |       |       |     1   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |* 28 |     INDEX RANGE SCAN            | S_ETL_I_IMG_125_M2 |     1 |    32 |       |     1   (0)| 00:00:01 |
    |* 29 |    INDEX RANGE SCAN             | S_ETL_I_IMG_12_M2  | 94772 |  1110K|       |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("IMG1"."ROW_ID"="S_CONTACT"."ROW_ID")
       7 - access("IMG"."ROW_ID"="S_CONTACT_FNX"."ROW_ID")
       9 - access("S_CONTACT_FNX"."PAR_ROW_ID"="S_CONTACT"."ROW_ID")
      13 - filter("S_CONTACT"."PR_SPECIALTY_ID" IS NOT NULL)
    PLAN_TABLE_OUTPUT
      15 - access("IMG1"."ROW_ID"="S_CONTACT"."ROW_ID")
           filter("IMG1"."ROW_ID"="S_CONTACT"."ROW_ID")
      17 - access("IMG"."ROW_ID"="S_CONTACT"."PR_SPECIALTY_ID")
      21 - filter("S_CONTACT"."MED_SPEC_ID" IS NOT NULL)
      22 - access("IMG1"."ROW_ID"="S_CONTACT"."ROW_ID")
      23 - access("IMG"."ROW_ID"="S_CONTACT"."MED_SPEC_ID")
      27 - filter("S_CONTACT"."REGION_ID" IS NOT NULL)
      28 - access("IMG"."ROW_ID"="S_CONTACT"."REGION_ID")
      29 - access("IMG1"."ROW_ID"="S_CONTACT"."ROW_ID")

  • Sql query tunning, need help!

    below is the sql that runs very very slow:
    SELECT h.STAT_HIST_ID, h.WF_ACTN, h.USR_ACTN,
          h.WF_CHNG_DATA, h.USR_CHNG_DATA, h.PRCSG_TM, h.UPD_LOGIN, h.UPD_DT,
          RTRIM(c.LAST_NM || ', ' || c.FIRST_NM || ' ' || c.MIDDLE_INITIAL)
          FROM WF_STAT_HIST h, CSE_USER_DATA_VW c WHERE h.WRK_ITM_ID = 'GT1MPTG01ATBZP'
          AND h.UPD_LOGIN = c.USER_NM (+) ORDER BY h.UPD_DT ;Here is its index:
    all_indexes:
    SCGDBA     WF_STAT_HIST_INDX_ARCH     NORMAL     SCGDBA     WF_STAT_HIST     TABLE     NONUNIQUE     DISABLED          IMS_I
    SCGDBA     PK_WF_STAT_HIST     NORMAL     SCGDBA     WF_STAT_HIST     TABLE     UNIQUE     DISABLED          SCG_I
    SCGDBA     WF_STAT_HIST_IDX1     NORMAL     SCGDBA     WF_STAT_HIST     TABLE     NONUNIQUE     DISABLED          SCG_I
    all_ind_columns:
    SCGDBA     WF_STAT_HIST_INDX_ARCH     SCGDBA     WF_STAT_HIST     ARCHIVEDT     1     7     0     ASC
    SCGDBA     PK_WF_STAT_HIST     SCGDBA     WF_STAT_HIST     STAT_HIST_ID     1     22     0     ASC
    SCGDBA     WF_STAT_HIST_IDX1     SCGDBA     WF_STAT_HIST     WF_ACTN     1     50     50     ASC
    SCGDBA     WF_STAT_HIST_IDX1     SCGDBA     WF_STAT_HIST     USR_ACTN     2     50     50     ASCHere is its explain plan:
    Plan hash value: 479056202
    | Id  | Operation           | Name             | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |                  |   216 | 30456 | 70864   (2)| 00:14:11 |
    |   1 |  SORT ORDER BY      |                  |   216 | 30456 | 70864   (2)| 00:14:11 |
    |*  2 |   HASH JOIN OUTER   |                  |   216 | 30456 | 70863   (2)| 00:14:11 |
    |*  3 |    TABLE ACCESS FULL| WF_STAT_HIST     |   216 | 24840 | 70857   (2)| 00:14:11 |
    |   4 |    TABLE ACCESS FULL| CSE_USER_DATA_VW |  1013 | 26338 |     6   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("H"."UPD_LOGIN"="C"."USER_NM"(+))
       3 - filter("H"."WRK_ITM_ID"='GT1MPTG01ATBZP')Could you guys take a look and tell me what the problem might be?
    I can`t give you TKPROF, because I got no access to that trace files!
    Any thoughts would be appreciated:-)
    Edited by: PhoenixBai on Sep 27, 2009 3:13 PM

    Pl post the output of the following
    select count(*) from wf_stat_hist;
    select count (distinct wrk_itm_id) from wf_stat_hist;
    select count (distinct upd_login) from wf_stat_hist;Your code is performing poorly because your WHERE clause is searching on a column on WF_STAT_HIST that is not indexed. Hopefully the output of the above code will determine which column (WRK_ITM_ID or UPD_LOGIN) is a better candidate to be indexed on. If neither of these columns is a good candidate, you may have to change the WHERE clause to be more selective rather than do a full table scan as the plan indicates.
    HTH
    Srini

  • Please help me to tune this PL/SQL...

    Hi everyone,
        I have a SQL query which runs ok when i run it individually but the same query if
    i use it in a procedure.The procedure is hanging up.Could someone please help to tune this
    SQL query and please check my procedure why is it hanging up.
    SQL Query
    =========
    SELECT active_members.member_nbr,
      active_members.name_last,
      active_members.name_first,
      active_members.name_middle,
      active_members.dob,
      active_members.sex,
      active_members.subsciber_nbr,
      active_members.ssn,
      active_members.name_suffix,
      active_members.class_x,
      active_members.aff_nbr,
    CASE
    WHEN TRIM(active_members.class_x) = 'SE' THEN
        (SELECT DISTINCT(mssp.member_nbr)
         FROM member_span mssp
         WHERE SUBSTR(mssp.member_nbr,    1,    9) = SUBSTR(active_members.member_nbr,    1,    9)
         AND mssp.class_x = 'SP'
         AND rownum = 1)
       WHEN TRIM(active_members.class_x) = 'SP' THEN
          (SELECT DISTINCT(mssp.member_nbr)
           FROM member_span mssp
           WHERE SUBSTR(mssp.member_nbr,    1,    9) = SUBSTR(active_members.member_nbr,    1,    9)
           AND mssp.class_x = 'SE'
           AND rownum = 1)
      ELSE
        NULL
       END)
    spouse_member_nbr,
      active_members.division_nbr,
      active_members.ymdeff,
      active_members.ymdend,
      active_members.actual_ymd_enddt,
      active_members.email_id,
      active_members.network_id,
      active_members.insurance_company_code,
      active_members.cob_flag,
      active_members.vip_flag,
      active_members.pre_x_flag,
      active_members.region,
      active_contracts.language_x,
      active_contracts.corp_nbr,
      active_members.group_nbr,
      active_members.non_erisa_status
    FROM
      (SELECT mb_active.member_nbr,
         mb_active.contract_nbr,
         mb_active.name_last,
         mb_active.name_first,
         mb_active.name_middle,
         ms_active.ymdeff,
         ms_active.ymdend,
         to_char(to_date(
       CASE
       WHEN LENGTH(mb_active.ymdbirth) = 8 THEN mb_active.ymdbirth
       ELSE NULL
       END,    'YYYYMMDD'),    'MM/DD/YYYY') dob,
         mb_active.sex,
         to_char(to_date(ms_active.ymdeff,    'YYYYMMDD'),    'MM/DD/YYYY') ymdeff_formatted,
         to_char(to_date(ms_active.ymdend,    'YYYYMMDD'),    'MM/DD/YYYY') ymdend_formatted,
         ms_active.void,
       CASE
       WHEN SUBSTR(mb_active.member_nbr,    10,    2) = '00' THEN mb_active.member_nbr
       ELSE SUBSTR(mb_active.member_nbr,    1,    9) || '00'
       END) subsciber_nbr,
         mb_active.ssn,
         mb_active.name_suffix,
         ms_active.class_x,
         ms_active.aff_nbr,
         ms_active.division_nbr,
       CASE
       WHEN TRIM(ms_active.ymdend) = '99991231' THEN NULL
       ELSE to_char(to_date(ms_active.ymdend,    'YYYYMMDD'),    'MM/DD/YYYY')
       END) actual_ymd_enddt,
       CASE
       WHEN TRIM(ms_active.business_unit) = '01' THEN ms_active.business_unit || '-' || ms_active.prog_nbr
       WHEN TRIM(ms_active.business_unit) = '03' THEN ms_active.business_unit || '-' || ms_active.prog_nbr || '-' || ms_active.carrier
       ELSE NULL
       END) network_id,
         ms_active.business_unit || '-' || ms_active.prog_nbr || '-' || ms_active.carrier insurance_company_code,
          (SELECT DISTINCT(email)
         FROM dbo.av_mem_email
         WHERE dbo.av_mem_email.member_nbr = mb_active.member_nbr
         AND rownum = 1)
      email_id,
         mb_active.lr_response cob_flag,
         mb_active.record_nbr vip_flag,
         ms_active.pre_exist pre_x_flag,
         ms_active.region region,
         ms_active.group_nbr,
       CASE
       WHEN
        (SELECT TRIM(div.div_status)
         FROM division div
         WHERE TRIM(div.division_nbr) = TRIM(ms_active.division_nbr)) = 'NULL' THEN
          'Y'
         ELSE
          'N'
         END)
      non_erisa_status
       FROM member mb_active,
         member_span ms_active
       WHERE mb_active.member_nbr = ms_active.member_nbr
       AND(20090707 BETWEEN ms_active.ymdeff
       AND ms_active.ymdend
       AND TRIM(ms_active.void) IS NULL
    active_members,
        (SELECT DISTINCT(contract.contract_nbr),
         contract.language_x,
         contract_span.corp_nbr
       FROM contract,
         contract_span
       WHERE contract.contract_nbr = contract_span.contract_nbr
       AND(20090707 BETWEEN contract_span.ymdeff
       AND contract_span.ymdend)
       AND TRIM(contract_span.void) IS
      NULL)
    active_contracts
    WHERE TRIM(active_members.contract_nbr) = TRIM(active_contracts.contract_nbr);
    Taking around 6 minute to run and it returns """"268267"""" records
    Explain Plan for the above SQL:
    ===============================
    "PLAN_TABLE_OUTPUT"
    "Plan hash value: 379550299"
    "| Id  | Operation                      | Name          | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |"
    "|   0 | SELECT STATEMENT               |               |  2609K|   659M|       | 91679   (3)| 00:18:21 |"
    "|   1 |  HASH UNIQUE                   |               |     1 |    16 |       | 54461   (2)| 00:10:54 |"
    "|*  2 |   COUNT STOPKEY                |               |       |       |       |            |          |"
    "|*  3 |    TABLE ACCESS FULL           | MEMBER_SPAN   | 12891 |   201K|       | 54459   (2)| 00:10:54 |"
    "|   4 |    HASH UNIQUE                 |               |     1 |    16 |  2424K| 54736   (2)| 00:10:57 |"
    "|*  5 |     COUNT STOPKEY              |               |       |       |       |            |          |"
    "|*  6 |      TABLE ACCESS FULL         | MEMBER_SPAN   | 51541 |   805K|       | 54459   (2)| 00:10:54 |"
    "|   7 |  HASH UNIQUE                   |               |     1 |    50 |       |    64   (4)| 00:00:01 |"
    "|*  8 |   COUNT STOPKEY                |               |       |       |       |            |          |"
    "|*  9 |    TABLE ACCESS FULL           | AV_MEM_EMAIL  |     1 |    50 |       |    63   (2)| 00:00:01 |"
    "|* 10 |  TABLE ACCESS FULL             | DIVISION      |     1 |    14 |       |     3   (0)| 00:00:01 |"
    "|* 11 |  HASH JOIN                     |               |  2609K|   659M|       | 91679   (3)| 00:18:21 |"
    "|  12 |   VIEW                         |               |   581 | 12782 |       |  8184   (4)| 00:01:39 |"
    "|  13 |    HASH UNIQUE                 |               |   581 | 26145 |       |  8184   (4)| 00:01:39 |"
    "|  14 |     TABLE ACCESS BY INDEX ROWID| CONTRACT      |     1 |    14 |       |     2   (0)| 00:00:01 |"
    "|  15 |      NESTED LOOPS              |               |   581 | 26145 |       |  8183   (4)| 00:01:39 |"
    "|* 16 |       TABLE ACCESS FULL        | CONTRACT_SPAN |   581 | 18011 |       |  7019   (5)| 00:01:25 |"
    "|* 17 |       INDEX RANGE SCAN         | CONTRACT_IX1  |     1 |       |       |     1   (0)| 00:00:01 |"
    "|* 18 |   HASH JOIN                    |               |   449K|   104M|    39M| 83466   (2)| 00:16:42 |"
    "|* 19 |    TABLE ACCESS FULL           | MEMBER_SPAN   |   449K|    34M|       | 54964   (3)| 00:11:00 |"
    "|  20 |    TABLE ACCESS FULL           | MEMBER        |  1436K|   221M|       | 14664   (2)| 00:02:56 |"
    "Predicate Information (identified by operation id):"
    "   2 - filter(ROWNUM=1)"
    "   3 - filter(SUBSTR("MSSP"."MEMBER_NBR",1,9)=SUBSTR(:B1,1,9) AND "MSSP"."CLASS_X"='SP')"
    "   5 - filter(ROWNUM=1)"
    "   6 - filter(SUBSTR("MSSP"."MEMBER_NBR",1,9)=SUBSTR(:B1,1,9) AND "MSSP"."CLASS_X"='SE')"
    "   8 - filter(ROWNUM=1)"
    "   9 - filter("AV_MEM_EMAIL"."MEMBER_NBR"=:B1)"
    "  10 - filter(TRIM("DIV"."DIVISION_NBR")=TRIM(:B1))"
    "  11 - access(TRIM("MB_ACTIVE"."CONTRACT_NBR")=TRIM("ACTIVE_CONTRACTS"."CONTRACT_NBR"))"
    "  16 - filter("CONTRACT_SPAN"."YMDEFF"<=20090707 AND TRIM("CONTRACT_SPAN"."VOID") IS NULL AND "
    "              "CONTRACT_SPAN"."YMDEND">=20090707)"
    "  17 - access("CONTRACT"."CONTRACT_NBR"="CONTRACT_SPAN"."CONTRACT_NBR")"
    "  18 - access("MB_ACTIVE"."MEMBER_NBR"="MS_ACTIVE"."MEMBER_NBR")"
    "  19 - filter(TRIM("MS_ACTIVE"."VOID") IS NULL AND "MS_ACTIVE"."YMDEFF"<=20090707 AND "
    "              "MS_ACTIVE"."YMDEND">=20090707)"
    SAME SQL IN A PROCEDURE..IT IS HANGING UP
    ========================================
    create or replace PROCEDURE TEST_CURRENT_PCP_SPAN is
    EXTRACTED_STRING VARCHAR2(32767);
    FILEHANDLER UTL_FILE.FILE_TYPE;
    test_str varchar2(100);
    pcp_eff_date number(10);
    file_name varchar2(50);
       CURSOR MEMBERS
       IS
    SELECT active_members.member_nbr,
      active_members.name_last,
      active_members.name_first,
      active_members.name_middle,
      active_members.dob,
      active_members.sex,
      active_members.subsciber_nbr,
      active_members.ssn,
      active_members.name_suffix,
      active_members.class_x,
      active_members.aff_nbr,
    CASE
    WHEN TRIM(active_members.class_x) = 'SE' THEN
        (SELECT DISTINCT(mssp.member_nbr)
         FROM member_span mssp
         WHERE SUBSTR(mssp.member_nbr,    1,    9) = SUBSTR(active_members.member_nbr,    1,    9)
         AND mssp.class_x = 'SP'
         AND rownum = 1)
       WHEN TRIM(active_members.class_x) = 'SP' THEN
          (SELECT DISTINCT(mssp.member_nbr)
           FROM member_span mssp
           WHERE SUBSTR(mssp.member_nbr,    1,    9) = SUBSTR(active_members.member_nbr,    1,    9)
           AND mssp.class_x = 'SE'
           AND rownum = 1)
      ELSE
        NULL
       END)
    spouse_member_nbr,
      active_members.division_nbr,
      active_members.ymdeff,
      active_members.ymdend,
      active_members.actual_ymd_enddt,
      active_members.email_id,
      active_members.network_id,
      active_members.insurance_company_code,
      active_members.cob_flag,
      active_members.vip_flag,
      active_members.pre_x_flag,
      active_members.region,
      active_contracts.language_x,
      active_contracts.corp_nbr,
      active_members.group_nbr,
      active_members.non_erisa_status
    FROM
      (SELECT mb_active.member_nbr,
         mb_active.contract_nbr,
         mb_active.name_last,
         mb_active.name_first,
         mb_active.name_middle,
         ms_active.ymdeff,
         ms_active.ymdend,
         to_char(to_date(
       CASE
       WHEN LENGTH(mb_active.ymdbirth) = 8 THEN mb_active.ymdbirth
       ELSE NULL
       END,    'YYYYMMDD'),    'MM/DD/YYYY') dob,
         mb_active.sex,
         to_char(to_date(ms_active.ymdeff,    'YYYYMMDD'),    'MM/DD/YYYY') ymdeff_formatted,
         to_char(to_date(ms_active.ymdend,    'YYYYMMDD'),    'MM/DD/YYYY') ymdend_formatted,
         ms_active.void,
       CASE
       WHEN SUBSTR(mb_active.member_nbr,    10,    2) = '00' THEN mb_active.member_nbr
       ELSE SUBSTR(mb_active.member_nbr,    1,    9) || '00'
       END) subsciber_nbr,
         mb_active.ssn,
         mb_active.name_suffix,
         ms_active.class_x,
         ms_active.aff_nbr,
         ms_active.division_nbr,
       CASE
       WHEN TRIM(ms_active.ymdend) = '99991231' THEN NULL
       ELSE to_char(to_date(ms_active.ymdend,    'YYYYMMDD'),    'MM/DD/YYYY')
       END) actual_ymd_enddt,
       CASE
       WHEN TRIM(ms_active.business_unit) = '01' THEN ms_active.business_unit || '-' || ms_active.prog_nbr
       WHEN TRIM(ms_active.business_unit) = '03' THEN ms_active.business_unit || '-' || ms_active.prog_nbr || '-' || ms_active.carrier
       ELSE NULL
       END) network_id,
         ms_active.business_unit || '-' || ms_active.prog_nbr || '-' || ms_active.carrier insurance_company_code,
          (SELECT DISTINCT(email)
         FROM dbo.av_mem_email
         WHERE dbo.av_mem_email.member_nbr = mb_active.member_nbr
         AND rownum = 1)
      email_id,
         mb_active.lr_response cob_flag,
         mb_active.record_nbr vip_flag,
         ms_active.pre_exist pre_x_flag,
         ms_active.region region,
         ms_active.group_nbr,
       CASE
       WHEN
        (SELECT TRIM(div.div_status)
         FROM division div
         WHERE TRIM(div.division_nbr) = TRIM(ms_active.division_nbr)) = 'NULL' THEN
          'Y'
         ELSE
          'N'
         END)
      non_erisa_status
       FROM member mb_active,
         member_span ms_active
       WHERE mb_active.member_nbr = ms_active.member_nbr
       AND(20090707 BETWEEN ms_active.ymdeff
       AND ms_active.ymdend
       AND TRIM(ms_active.void) IS NULL
    active_members,
        (SELECT DISTINCT(contract.contract_nbr),
         contract.language_x,
         contract_span.corp_nbr
       FROM contract,
         contract_span
       WHERE contract.contract_nbr = contract_span.contract_nbr
       AND(20090707 BETWEEN contract_span.ymdeff
       AND contract_span.ymdend)
       AND TRIM(contract_span.void) IS
      NULL)
    active_contracts
    WHERE TRIM(active_members.contract_nbr) = TRIM(active_contracts.contract_nbr);
      TYPE MEM IS TABLE OF MEMBERS%ROWTYPE INDEX BY PLS_INTEGER;
      TABLE_MEM MEM;
    MEMBER_ADDR   MGONZALEZ.CPKG_UTIL.ADDR;
    BEGIN 
       test_str := '''A10000213'''||','||'''A10000213''';
       insert into test_number_char(str) values ('start time of MEMBER_LOAD_CURRENT_PCP_SPAN '||to_char(sysdate,'MM/DD/YYYY HH24:MI:SS'));
       commit;
       file_name := 'member_load'||to_char(sysdate,'YYYYMMDDHH24MI')||'.txt';
       FILEHANDLER := UTL_FILE.FOPEN('AVMED_UTL_FILE',file_name, 'W',10000);
       insert into test_number_char(str) values ('start time of opening members cursor(before open members command) '||to_char(sysdate,'MM/DD/YYYY HH24:MI:SS'));
       commit;
       OPEN MEMBERS;
    LOOP
          FETCH MEMBERS
             BULK COLLECT INTO TABLE_MEM LIMIT 1000 ;
           EXIT WHEN TABLE_MEM.COUNT = 0;
    insert into test_number_char(str) values ('start time of outer loop '||to_char(sysdate,'MM/DD/YYYY HH24:MI:SS'));
    commit;
          FOR i IN 1 .. TABLE_MEM.COUNT
          LOOP
          EXTRACTED_STRING := TRIM(TABLE_MEM(i).MEMBER_NBR)||'| '||     
                              TRIM(TABLE_MEM(i).NAME_LAST)||'| '||      
                            TRIM(TABLE_MEM(i).NAME_FIRST)||'| '||      
                             TRIM(TABLE_MEM(i).NAME_MIDDLE)||'| '||   
                             TRIM(TABLE_MEM(i).ssn)||'| '||            
                             TABLE_MEM(i).subsciber_nbr||'| '||        
                             TRIM(TABLE_MEM(i).class_x)||'| '||         
                             TRIM(TABLE_MEM(i).DOB)||'| '||             
                             TRIM(TABLE_MEM(i).SEX)||'| ' ;             
              EXTRACTED_STRING   :=
                    EXTRACTED_STRING ||
                  TRIM(TABLE_MEM(i).aff_nbr)||'| '||                         
                                pcp_eff_date||'| '||                 
              TABLE_MEM(i).actual_ymd_enddt||'| '||                        
                  TRIM(TABLE_MEM(i).division_nbr)||'| '||                    
                  ' '||'| '||                                               
                  ' '||'| '||                                                  
                  ' '||'| '||                                                 
                  TABLE_MEM(i).network_id||'| '||                              
                  ' '||'| '||                                                  
                  ' '||'| '||                                                  
                  ' '||'| '||                                                  
                  ' '||'| '||                                                 
                  ' '||'| '||                                                  
                 TRIM(TABLE_MEM(i).name_suffix)||'| '||                       
                 ' '||'| '||                                                   
                 TRIM(TABLE_MEM(i).spouse_member_nbr)||'| '||                  
                 ' '||'| '||                                                   
                 ' '||'| '||                                                   
                 ' '||'| '||                                                  
                 ' '||'| '||                                                   
                 ' '||'| '||                                                  
                 ' '||'| '||                                                   
                 ' '||'| '||                                                   
                 ' '||'| '||                                                   
                 ' '||'| '||                                                   
                 ' '||'| '||                                                   
                 ' '||'| '||                                                   
                 ' '||'| '||                                                  
                 ' '||'| '||                                                   
                TRIM(TABLE_MEM(i).email_id)||'| '||                                
                TABLE_MEM(i).Insurance_company_code||'| '||                    
                TABLE_MEM(i).group_nbr||'| '||                                 
                TABLE_MEM(i).language_x||'| '||                               
                TABLE_MEM(i).region||'| '||                                    
                TABLE_MEM(i).corp_nbr||'| '||                                  
                TABLE_MEM(i).non_erisa_status||'| '||                          
                TABLE_MEM(i).cob_flag||'| '||                                  
                TABLE_MEM(i).pre_x_flag||'| '||                                
                TABLE_MEM(i).vip_flag                                       
                 EXTRACTED_STRING   := rtrim(EXTRACTED_STRING,' ');
            UTL_FILE.PUT_LINE(FILEHANDLER,EXTRACTED_STRING,TRUE);
            EXTRACTED_STRING := NULL;
            pcp_eff_date := NULL;
          END LOOP;
          insert into test_number_char(str) values ('end time of outer loop '||to_char(sysdate,'MM/DD/YYYY HH24:MI:SS'));
    commit;
    END LOOP;
    close members;
    insert into test_number_char(str) values ('end time of opening members cursor '||to_char(sysdate,'MM/DD/YYYY HH24:MI:SS'));
    commit;
    commit;
       UTL_FILE.FCLOSE(FILEHANDLER);
       insert into test_number_char(str) values ('End time of MEMBER_LOAD_CURRENT_PCP_SPAN '||to_char(sysdate,'MM/DD/YYYY HH24:MI:SS'));
       commit;
       EXCEPTION
          WHEN OTHERS
          THEN
             DBMS_OUTPUT.put_line(   'ERROR getting members '
                                  || SQLCODE
                                  || ' '
                                  || SQLERRM);
    END ;
    In my Test table which i am inserting to check the times...
    I am geting on these 2 records after that it hangs up...
    start time of MEMBER_LOAD_CURRENT_PCP_SPAN 07/08/2009 11:41:21
    start time of opening members cursor(before open members command) 07/08/2009 11:41:21I have to call some other functions for each member to get additional details thats the reason i am going for Procedure.Instead it is just a simple SQL
    Thanks in advance

    It is taking lot of timeYou could perhaps split it up in smaller, isolated parts.
    Running certain steps separate.
    ..is it possible to find out the issues without running the proc?Other than have other people on OTN give their ideas/share experiences?
    Not that I'm aware of.
    There are lots of statistical views, you might be able to deduct from their data, but I personally prefer running the procedure and just trace it. But I'm always willing to learn new approaches, btw.
    Still, you have 2 things to look at, at least:
    - avoid loops in loops if possible
    - check your predicates, if you apply a function, you lose the index, unless you create a function based index.
    edit
    One more thing (how could I overlook that):
    You commit your instrumentation code ( insert into test_number_char(str) ) IN the loop.
    Please remove commit in your loops...
    Commit only once, at the end of your transaction.
    Never commit in a loop.
    (Preferrably the client commits)
    And remove every commit in your loop...
    Edited by: hoek on Jul 8, 2009 8:03 PM

Maybe you are looking for