Please tune the query

Hi folks..pls tune/rewrite my query
SELECT
bu_code,bu_type,cust_no ,cur_code,sales_date,receipt_no,till_no,card_no,invoice_total,amount_of_goods,(invoice_total - amount_of_goods) AS amount_of_non_goods,
pay_in_advance AS amounts_of_advance_pay,amount_of_discounts, Error_flag
FROM
(select
            distinct  'STO' AS BU_TYPE,
workinv.tot_cust_no AS  cust_no,
workinv.comp_code as comp_code,
workinv.cash_no as till_no,
workinv.receipt_no  as receipt_no,
workinv.sales_date as sales_date,
workinv.cur_code as cur_code,
invhead.acct_usr_no as card_no,
invhead.inv_no as inv_no,
invhead.sto_no as bu_code, (SELECT MAX (DECODE (e.sum_code, 'TOTAL', e.amount_incl))
                                          FROM invoice_sums_t e
                                          WHERE e.inv_no = invsums.inv_no
                                          AND e.comp_code = invsums.comp_code) AS invoice_total,
                                         (SELECT MAX (DECODE (e.sum_code, 'PIA', e.amount_incl))
                                           FROM invoice_sums_t e
                                           WHERE e.inv_no = invsums.inv_no
                                          AND e.comp_code = invsums.comp_code) AS pay_in_advance,
                                         (SELECT SUM(e.amount_incl)
                                          FROM invoice_sums_t e
                                          WHERE E.SUM_CODE LIKE 'GOODS0%'
                                          AND e.inv_no = invsums.inv_no
                                          AND e.comp_code = invsums.comp_code) AS amount_of_goods,
                                         (SELECT SUM(e.amount_incl)
                                          FROM invoice_sums_t e
                                         WHERE E.SUM_CODE LIKE 'DISCOUNT0%'
                                          AND e.inv_no = invsums.inv_no
                                          AND e.comp_code = invsums.comp_code) AS amount_of_discounts ,
                                  CASE workinv.error_flag WHEN 'H' THEN 'Y' ELSE 'N' END
                                  AS Error_flag,
                                  WORKINV.ERROR_FLAG AS invoice_on_hold
FROM  work_invoice_info_t workinv,
          invoice_header_t invhead,
          invoice_sums_t invsums,
          i_invoice_info_t_log invlog,
          o_pam_document_header_log_t opdhlt
WHERE  invhead.comp_code= workinv.comp_code
AND TRIM(workinv.Tot_cust_no) =TRIM(invlog.tot_cust_no)
AND TRIM (workinv.sto_no) = invhead.sto_no
AND TRIM (workinv.sales_date) =TO_CHAR (invhead.sales_date, 'YYMMDD')
AND TRIM (workinv.cash_no) =TO_NUMBER (TRIM (invhead.cash_no))
AND TRIM (workinv.receipt_no) =TO_NUMBER (TRIM (invhead.receipt_no))
AND invhead.comp_code = invsums.comp_code
AND invhead.inv_no = invsums.inv_no
AND TRIM(workinv.sto_no) = invlog.sto_no
AND TRIM(workinv.receipt_no) = invlog.receipt_no
AND TRIM(workinv.cash_no) = invlog.cash_no
AND TRIM(workinv.sales_date) = invlog.sales_date)dear folks am debugging the code as step by step
i have taken inline query and selecting 1 as column from joining the same tables used in the above query
select
   1
FROM  work_invoice_info_t workinv,
          invoice_header_t invhead,
          invoice_sums_t invsums,
          i_invoice_info_t_log invlog,
          o_pam_document_header_log_t opdhlt
WHERE  invhead.comp_code= workinv.comp_code
AND TRIM(workinv.Tot_cust_no) =TRIM(invlog.tot_cust_no) --*if iam firing only this much then output is coming --in 2sec*
AND TRIM (workinv.sto_no) = invhead.sto_no -- if i add the below 2 cols then it is taking lot of time(half an hr)
AND TRIM (workinv.sales_date) =TO_CHAR (invhead.sales_date, 'YYMMDD')Hence should i create indexes on both 'sto_no' and 'sales_date' cols ?
please shed some light on this

newbie wrote:
..so how can i tune please share ideasTuning is a vast area. Many people spend their entire working lives tuning other people's code. Those people make fine livings from their work. They couldn't do that if it was merely a matter of squinting at some shonky piece of SQL and saying, "Ah, that's the badger!" No, tuning requires a great deal of context and additional information. Explain plans, statistcs, metadata, right down to what version of the database you're using.
Now, you already have been provided with links to helpful threads: these explain how you can proceed in collecting this information and investigating your problem. The sooner you start reading those links the sooner you can start diagnosing the poor performance.
If you still can't crack it, by all means post here again. But don't bother until you have gathered all the ibnformation you need to [post so that we can understand your situation.
Cheers, APC                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Undo_tablespace and undo_retetion or tune the query  which one to increase

    hi all,
    In my logs file s
    ORA-01555 caused by SQL statement below (SQL ID: 9nc0n06yryhbk, Query Duration=165122 sec, SCN: 0x05ff.062f3363):
    Tue Feb 5 02:26:39 2008
    SELECT /*+ FIRST_ROWS */ /*+ ORDERED */ B.GID ,K.ELEMENT_TYPE ,K.DATA_SOURCE_GID ,K.PROD_ID ,K.OPTION_CD ,K.MCC ,K.SPN ,K.REGION_CD ,K.WW_CD ,K.COUNTRY_CD ,K.ERROR ,B.GBATCH_ID
    ,B.PERIOD_SEQ_NUM ,B.ACTION ,B.ERROR B_ERROR ,B.COST ,B.INPUT_FILE_ROW_NUM ,B.ACTION_STATUS ,B.ACTION_TIMESTAMP FROM T_INPUT_BUCKET B, T_COS_INPUT_KEY K WHERE B.ACTION_STATUS =
    'initial' AND B.GINPUT_KEY_ID = K.GID AND B.GBATCH_ID = :B1 AND ROWNUM < 8001
    Tue Feb 5 02:35:21 2008
    Thread 2 advanced to log sequence 42907
    Mon Feb 4 09:10:55 2008
    ORA-01555 caused by SQL statement below (SQL ID: 9nc0n06yryhbk, Query Duration=104081 sec, SCN: 0x05ff.05ebc008):
    Mon Feb 4 09:10:55 2008
    SELECT /*+ FIRST_ROWS */ /*+ ORDERED */ B.GID ,K.ELEMENT_TYPE ,K.DATA_SOURCE_GID ,K.PROD_ID ,K.OPTION_CD ,K.MCC ,K.SPN ,K.REGION_CD ,K.WW_CD ,K.COUNTRY_CD ,K.ERROR ,B.GBATCH_ID
    ,B.PERIOD_SEQ_NUM ,B.ACTION ,B.ERROR B_ERROR ,B.COST ,B.INPUT_FILE_ROW_NUM ,B.ACTION_STATUS ,B.ACTION_TIMESTAMP FROM T_INPUT_BUCKET B, T_COS_INPUT_KEY K WHERE B.ACTION_STATUS =
    'initial' AND B.GINPUT_KEY_ID = K.GID AND B.GBATCH_ID = :B1 AND ROWNUM < 8001
    Mon Feb 4 09:14:08 2008
    ===============================================
    and my undo_retention
    Current usage:
    UNDO_01 96736 11596 12 88
    UNDO_02 96736 9357 10 90
    NAME TYPE VALUE
    undo_management string AUTO
    undo_retention integer 36000
    can anyone please guide me which one is best to increase undo_retention or undo_tablespace
    or tune the query?
    my database version is
    Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bi
    PL/SQL Release 10.2.0.2.0 - Production
    "CORE     10.2.0.2.0     Production"
    TNS for HPUX: Version 10.2.0.2.0 - Production
    NLSRTL Version 10.2.0.2.0 - Production
    thanks in advance

    IMO best is to
    1) tune the query to minimize time and resource use;
    2) set the undo_retention to size the undo tablespace for the required 'consistent read' rebuild requirements;
    3) set the retention guarantee appropriately
    4) size the undo tablespace based on the required size, probably dictated by 2)
    Why is this an 'either one or other' question? When driving a car and looking for best fuel efficiency, you tune up the car, drive properly AND use the right fuel. You don't just pick one and leave it at that.

  • The query processor ran out of stack space during query optimization. Please simplify the query

    Can you suggest me that what should i do in this case.
    Actually i am having one table that is a MasterTable.I am referring this table in more than 300 tables that means i am having foreign key of this primary key in 300+ tables.
    due to this i am getting following error during deleting any row,
    doesn't matter that data is existing in reference table or not.
    Error that i am getting is 
    "The query processor ran out of stack space during query optimization. Please simplify the query"
    Can you suggest me that what should i do to avoid this error,because i am unable to delete this entry.
    Apart from it,i am getting performance problem too,so is it due to such huge FK on it.
    Please suggest me on following points
    1. Is it worst way to handle it,if yes then please suggest me solution for it.
    2. If it is a correct way then what should i do if getting error during deleting any record.
    3. Is it right to create Foreign key on each table where i am saving data of this master. if no then how to manage integrity.
    4. What people do in huge database when they wants to create foreign key for any primary key.
    5. Can you suggest me that how DBA's are handling this in big database,where they are having huge no. of tables.

    The most common reason of getting such error is having more than 253 foreign key constraints on a table. 
    The max limit is documented here:
    http://msdn.microsoft.com/en-us/library/ms143432(SQL.90).aspx 
    Although a table can contain an unlimited number of FOREIGN KEY constraints, the recommended maximum is 253. Depending on the hardware configuration hosting SQL Server, specifying additional foreign key constraints may be expensive for the query
    optimizer to process. If you are on 32 bit, then you might want to move to 64 bit to get little bigger stack space but eventually having 300 FK is not something which would work in long run.
    Balmukund Lakhani | Please mark solved if I've answered your question, vote for it as helpful to help other users find a solution quicker
    This posting is provided "AS IS" with no warranties, and confers no rights.
    My Blog |
    Team Blog | @Twitter
    Author: SQL Server 2012 AlwaysOn -
    Paperback, Kindle

  • How to tune the query...?

    Hi all,
    I am having a table with millions of records and the query is taking hours
    time. How to tune the query apart from doing the following things.
    1. Creating or Deleting indexes.
    2. Using Bind variables.
    3. Using Hints.
    4. Updating the Statitics regurarly.
    Actually, i have asked this question in interview how to tune the query.
    I told him the above 4 things. Then he told, these are not working, then
    how you will tune this query.
    Thanks in advance,
    Pal

    user546710 wrote:
    Actually, i have asked this question in interview how to tune the query.
    I told him the above 4 things. Then he told, these are not working, then
    how you will tune this query.It actually depends on the scenario/problem given.
    You may want to read this first.
    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

  • Guide me to tune the query

    Hi All,
    I need to tune the query which is taking more than 1 hour to execute over 8 Lakhs of record.
    SQL> explain plan for SELECT C.aci_cust_code      cust_code,
    2 C.aci_cust_name cust_name,
    3      R.NAME ruledefination,
    4 B.RULECODE ALERTS,
    5 A.custom1 tran_id,
    6 TD_get_value('AMLTRANTYPE', RTRIM(A.custom17)) trantype,
    7 A.CUSTOM18 tran_nature,
    8 A.custom25 tran_date,
    9 A.messageno messageno,
    10 TD_get_value('AMLTRANSTATUS', A.status) msgstatus,
    11 D.acai_acct_type acct_type,
    12 A.custom19 acct_number,
    13 A.CURRENCY CURRENCY,
    14 A.priorityamount amount,
    15 A.operator USERNAME,
    16 A.msgdb_id msgdb_id,
    17 A.msg_mode_in msg_mode_in
    18 FROM MSGDB A,
    19 MSGALERTS B,
    20 AML_CUST_INFO C,
    21      AML_CUST_ACC_INFO D,
    22 RULETBL2 R,
    23           (SELECT tdkey FROM tabledetails WHERE tdidcode = 'AML-INCLUDEQ' ) amlqueues
    24 WHERE A.msgdb_id = B.msgdb_id AND
    25 A.queueid = amlqueues.tdkey AND
    26           A.MSG_MODE_IN = 'AML-TRANS' AND
    27 A.custom15 = C.aci_cust_code AND
    28 A.CUSTOM19=D.ACAI_ACCT_NUMBER(+) AND
    29 TO_CHAR(A.custom25,'YYYYMMDD') BETWEEN
    30      TO_CHAR(TO_DATE('2011/01/01','YYYY/MM/DD'),'YYYYMMDD')
    31 AND TO_CHAR(TO_DATE('2011/01/31','YYYY/MM/DD'),'YYYYMMDD')
    32 AND B.RULECODE = R.RULECODE
    33 ORDER BY A.custom25, msgdb_id,B.rulecode;
    Explained.
    PLAN_TABLE_OUTPUT
    Plan hash value: 1081661146
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 173K| 30M| | 12697 (2)| 00:02:33 |
    | 1 | SORT ORDER BY | | 173K| 30M| 66M| 12697 (2)| 00:02:33 |
    |* 2 | HASH JOIN | | 173K| 30M| | 5580 (4)| 00:01:07 |
    | 3 | VIEW | index$_join$_005 | 3395 | 81480 | | 42 (3)| 00:00:01 |
    |* 4 | HASH JOIN | | | | | | |
    | 5 | INDEX FAST FULL SCAN | IDX_RCODE | 3395 | 81480 | | 10 (0)| 00:00:01 |
    | 6 | INDEX FAST FULL SCAN | SYS_C0040836 | 3395 | 81480 | | 31 (0)| 00:00:01 |
    |* 7 | HASH JOIN | | 1737 | 276K| | 5534 (4)| 00:01:07 |
    |* 8 | HASH JOIN | | 559 | 86645 | | 4575 (3)| 00:00:55 |
    |* 9 | HASH JOIN OUTER | | 448 | 56000 | | 4463 (3)| 00:00:54 |
    | 10 | NESTED LOOPS | | 448 | 47040 | | 4404 (3)| 00:00:53 |
    |* 11 | TABLE ACCESS BY INDEX ROWID| MSGDB | 451 | 35178 | | 4403 (3)| 00:00:53 |
    |* 12 | INDEX RANGE SCAN | I_MODEDATE | 2292 | | | 4323 (3)| 00:00:52 |
    |* 13 | INDEX UNIQUE SCAN | PK_TABLEDETAIL | 1 | 27 | | 0 (0)| 00:00:01 |
    | 14 | INDEX FAST FULL SCAN | ACC_NUMBER_TYPE | 58947 | 1151K| | 58 (4)| 00:00:01 |
    | 15 | TABLE ACCESS FULL | AML_CUST_INFO | 18340 | 537K| | 111 (1)| 00:00:02 |
    | 16 | TABLE ACCESS FULL | MSGALERTS | 868K| 6782K| | 944 (4)| 00:00:12 |
    There is no index on RULECODE of MSGALERTS and RULETBL2 table.
    Could yu guys guide me how to tune this query with or without creating any new index.
    Thanks,

    To emphasise what hoek has said regarding dates, NEVER compare dates with dates by converting them to strings (or numbers). By doing so, you remove vital information from the optimizer.
    For example, what is the difference between "31st Dec 2010" and "1st Jan 2011"? Easy, they're dates, that's 1 day.
    But what's the difference between "20101231" and "20110101"? Easy: 20110101 - 20101231 = 8870.
    That makes the difference between the optimizer guessing 1 row or 8870 rows... a fairly big difference, I think you'll agree, which could well impact on the plan the optimizer chooses.
    One other point - leaving the clause as dates gives:
    AND    a.custom25 BETWEEN TO_DATE('2011/01/01', 'YYYY/MM/DD')
                          AND TO_DATE('2011/01/31', 'YYYY/MM/DD') which excludes any dates on 31st Jan 2011 except midnight, eg. 10am on 31st Jan 2011 won't be returned by your query.
    If you're after rows for a given month, then you could do:
    AND    trunc(a.custom25, 'mm') = TO_DATE('01/01/2011', 'dd/mm/yyyy')

  • How to tune the query for duplicate records while joining the two tables

    hi,i am executing the query which has retrieving multiple tables,in which one of them has duplicate record,how to get single record

    Not enough info...subject says "tune" the query, message says "write" the query...and where is actual query that you had tried ?

  • How to tune the query and difference between CBO AND RBO.. Which is good

    Hello Friends,
    Here are some questions I have pls reply back with complete description and url if any ..
    1)How Did you tune Query,
    2)What approach you take to tune query? Do you use Hints?
    3)Where did you tune the query and what are the issue with query?
    4)What is difference between RBO and CBO? where u use RBO and CBO.
    5)Give some information about hash join?
    6) Using explain plan how do u know where the bottle neck in query .. how u will identify where the bottle neck is from explain plan .
    thanks/Kumar

    Hi,
    kumar73 wrote:
    Hello Friends,
    Here are some questions I have pls reply back with complete description and url if any ..
    1)How Did you tune Query, Use EXPLAIN PLAN to see exactly where it is spending its time, and address those areas.
    See the forum FAQ
    SQL and PL/SQL FAQ
    "3. How to improve the performance of my query?"
    2)What approach you take to tune query? Do you use Hints?Hints can help.
    Even more helpful is writing the SQL efficiently (avoiding multiple scans of the same table, filtering early, using built-in rather than user-defined functions, ...), creating and using indexes, and, for large tables, partitioning.
    Table design can have a big impact on performace.
    Look for ways to do part of what you need before the query. This includes denormalizing (when appropriate), the kind of pre-digesting that often takes place in data warehouses, function-based indexes, and, starting in Oracle 11, virtual columns.
    3)Where did you tune the query and what are the issue with query?Either this question is a vague summary of the entire thread, or I don't understand it. Can you re-phrase this part?
    4)What is difference between RBO and CBO? where u use RBO and CBO.Basically, use RBO if you have Oracle 7 or earlier.

  • 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.

  • Please tune this query.

    Hi Experts,
    My below query is taking long time.
    [code]SELECT FAX_LIST.*
        FROM (SELECT /*+ use_nl(fax, src)  */
                    ROW_NUMBER () OVER (ORDER BY fax.ID ASC NULLS FIRST) RN,
                     fax.ACCOUNT_TYPE,
                     fax.BU_FILE_LOCATION,
                     fax.COUNT_PAGES_RECEIVED,
                     NVL (fax.CUSTOMER_NAME, fax.SENDER_NAME) AS CUSTOMER_NAME,
                     fax.FAX_SOURCE,
                     fax.CUSTOMER_NUMBER,
                     fax.CUSTOMER_OMEGA_NUMBER,
                     fax.GENIFAX_RECIPIENT_ID,
                     fax.ID AS FAX_ID,
                     fax.DATE_RECEIVED AS FAX_RECEIVED,
                     fax.IS_LOCKED,
                     fax.LOCKED_BY,
                     fax.ORIGINATOR_CSI,
                     fax.MARGIN,
                     fax.PAYMENT_TYPE,
                     fax.PRIORITY_CODE,
                     fax.PRIORITY_VALUE,
                     FROM_TZ (fax.DATE_RECEIVED, 'UTC')
                        AT TIME ZONE fax.LOCAL_TZ_NAME
                        AS DATE_RECEIVED,
                     fax.SALES_PERSON,
                     fax.SENDER_EMAIL,
                     fax.SENDER_NAME,
                     fax.SUBJECT,
                     fax.WORKGROUP_ID,
                     fax.LOCKED_TIME,
                     src.DESCRIPTION,
                     src.FAX_NUMBER,
                     src.WORKFLOW_ID,
                     fax.CREATED_BY,
                     fax.CREATED_DATE,
                     fax.UPDATE_DATE,
                     fax.UPDATED_BY,
                     fax.RESERVED_BY,
                     fax.PRICE_TO_ORDER,
                     fax.SKU_COUNT_TO_ORDER,
                     NVL (ORL.GET_FTH_WTR (fax.LAST_TRANSITION_ID).CHANGED_BY,
                        CASE
                           WHEN fax.LAST_TRANSITION_ID IS NULL
                                AND fax.GENIFAX_RECIPIENT_ID IS NOT NULL
                           THEN
                              'ORL FEEDER'
                           ELSE
                              'Admin'
                        END)
                        AS LAST_USER,
                     FROM_TZ (
                        NVL (ORL.GET_FTH_WTR (fax.LAST_TRANSITION_ID).CHANGED_DATE,
                             fax.DATE_RECEIVED),
                        'UTC')
                        AT TIME ZONE fax.LOCAL_TZ_NAME
                        AS MOVE_DATETIME,
                     NVL (ORL.GET_FTH_WTR (fax.LAST_TRANSITION_ID).REASON,
                          'Reroute')
                        AS MOVE_REASON,
                     NVL (
                        (SELECT fw.DESCRIPTION
                           FROM ORL.WORKGROUP_TRANSITION wt, ORL.WORKGROUP fw
                          WHERE wt.ID =
                                   ORL.GET_FTH_WTR (fax.LAST_TRANSITION_ID).WORKGROUP_TRANSITION_ID
                                AND fw.ID = wt.CURRENT_WORKGROUP_ID),
                        CASE
                           WHEN fax.LAST_TRANSITION_ID IS NULL
                                AND fax.GENIFAX_RECIPIENT_ID IS NOT NULL
                           THEN
                              'ORL FEEDER STAGING'
                           ELSE
                              'N/A'
                        END)
                        AS OLD_STATUS,
                     (SELECT MAX (PURCHASE_ORDER_NUMBER)
                        FROM ORL.FAX_OFFER_DETAIL
                       WHERE FAX_ID = fax.ID)
                        AS MAXPO,
                     (SELECT CASE COUNT (PURCHASE_ORDER_NUMBER)
                                WHEN 0 THEN NULL
                                ELSE COUNT (PURCHASE_ORDER_NUMBER)
                             END
                                AS POCOUNT
                        FROM ORL.FAX_OFFER_DETAIL
                       WHERE FAX_ID = fax.ID)
                        AS POCOUNT,
                     (SELECT SUM (VALUE) AS ORDER_VALUE
                        FROM ORL.FAX_OFFER_DETAIL
                       WHERE FAX_ID = fax.ID)
                        AS ORDER_VALUE,
                     fax.SALESPERSON_NAME,
                     fax.GROUP_NAME,
                     fax.ROLE_NAME,
                     fax.EMAIL,
                     fax.SALES_CHANNEL
                FROM (SELECT fax.*,
                             map.ORACLE_TZ_NAME AS LOCAL_TZ_NAME,
                             ORL.GET_SALESPERSON (map.ORG_ID, fax.SALES_PERSON).SALESPERSON_NAME
                                AS SALESPERSON_NAME,
                             ORL.GET_SALESPERSON (map.ORG_ID, fax.SALES_PERSON).GROUP_NAME
                                AS GROUP_NAME,
                             ORL.GET_SALESPERSON (map.ORG_ID, fax.SALES_PERSON).ROLE_NAME
                                AS ROLE_NAME,
                             ORL.GET_SALESPERSON (map.ORG_ID, fax.SALES_PERSON).EMAIL
                                AS EMAIL,
                             ORL.GET_SALESPERSON (map.ORG_ID, fax.SALES_PERSON).SALES_CHANNEL
                                AS SALES_CHANNEL
                        FROM APPS_GLOBAL.GLOBAL_BU_MAPPING map,
                             (SELECT *
                                FROM ORL.FAX_HEADER FH
                               WHERE FH.WORKGROUP_ID = 262) fax
                       WHERE map.GEDIS = 'Y'
                             AND map.BU_ID = (SELECT BUID
                                                FROM ORL.WORKGROUP
                                               WHERE ID = fax.WORKGROUP_ID)
                             AND ORL.GET_SALESPERSON (map.ORG_ID, fax.SALES_PERSON).SALESPERSON_NAME =
                                    'A_CARRICK') fax,
                     (SELECT *
                        FROM ORL.FAX_SOURCE FS
                       WHERE FS.WORKFLOW_ID IN
                                (SELECT  /*+ CARDINALITY(t, 1) */
                                       TO_NUMBER (
                                           COLUMN_VALUE)
                                           AS COLUMN_VALUE
                                   FROM TABLE (
                                           SplitClob ('1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
            16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
            32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
            48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
            64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
            80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
            96, 97, 98', ',')) t)) src
               WHERE src.ID(+) = fax.FAX_SOURCE) FAX_LIST
       WHERE RN BETWEEN 1 AND 100
    ORDER BY RN ASC;[/code]
    In my query the following three functions are using.
    ORL.GET_FTH_WTR
    ORL.GET_SALESPERSON
    APPS_GLOBAL.SplitClob
    [code]CREATE OR REPLACE FUNCTION ORL.GET_FTH_WTR(p_LAST_TRANSITION_ID NUMBER)
            RETURN ORL.FTH_WTR_T
            DETERMINISTIC
        IS
            v_REASON nvarchar2(1024 char);
            v_WORKGROUP_TRANSITION_ID number;
            v_CHANGED_BY nvarchar2(64 char);
            v_CHANGED_DATE timestamp(6);
        BEGIN
        SELECT
            WTR.REASON,
            wtr.WORKGROUP_TRANSITION_ID,
            fth.CHANGED_BY,
            fth.CHANGED_DATE
        INTO
            v_REASON,
            v_WORKGROUP_TRANSITION_ID,
            v_CHANGED_BY,
            v_CHANGED_DATE
        FROM
            ORL.FAX_TRANSITION_HISTORY fth,
            ORL.WORKGROUP_TRANSITION_REASON wtr
        WHERE
             fth.ID = p_LAST_TRANSITION_ID
            AND wtr.ID(+) = fth.TRANSITION_REASON_ID;
        RETURN ORL.FTH_WTR_T(v_CHANGED_BY, v_CHANGED_DATE, v_REASON, v_WORKGROUP_TRANSITION_ID);
        EXCEPTION
            WHEN NO_DATA_FOUND THEN
            RETURN ORL.FTH_WTR_T(NULL, NULL, NULL, NULL);
        END GET_FTH_WTR;
    CREATE OR REPLACE function ORL.GET_SALESPERSON(ORG_ID number, SALESPERSON_ID number)
        return ORL.SALESPERSON_T
        deterministic
    is
        apps_bu             varchar2(30);
        salesperson_name    varchar2(150 char);
        email               varchar2(70 char);
        sales_channel       varchar2(60 char);
        role_name           varchar2(60 char);
        group_name          varchar2(60 char);
    begin
        select OWNER_NAME into apps_bu
          from APPS_GLOBAL.GLOBAL_BU_MAPPING
         where ORG_ID = GET_SALESPERSON.ORG_ID;
        execute immediate
        replace('
            select SALESPERSON_NAME
                 , EMAIL
                 , SALES_CHANNEL
                 , ROLE_NAME
                 , GROUP_NAME
              from APPS_**.ORL_ACTIVE_SALESPERSON
             where SALESPERSON_ID = :1
      and  rownum = 1
                ', 'APPS_**', apps_bu)
        into salesperson_name, email, sales_channel, role_name, group_name
        using SALESPERSON_ID;
        return SALESPERSON_T(ORG_ID, SALESPERSON_ID, salesperson_name, email, sales_channel, role_name, group_name);
    exception
        when no_data_found then
            return SALESPERSON_T(null, null, null, null, null, null, null);
    end GET_SALESPERSON;
    CREATE OR REPLACE function APPS_GLOBAL.SplitClob
        p_clob          clob
      , p_delimiter     varchar2 := ','
    return StringTable
    deterministic
    pipelined
    as
        v_current_pos   pls_integer := 1;
        v_delimiter_pos pls_integer;
    begin
        if (p_clob is not NULL) and (p_delimiter is not NULL) then
            while v_current_pos <= length(p_clob) loop
                v_delimiter_pos := instr(p_clob, p_delimiter, v_current_pos);
                if  v_delimiter_pos < 1  then   -- no more delimiters
                    v_delimiter_pos := length(p_clob) + 1;
                end if;
                pipe row( to_char( substr(p_clob,
                                          v_current_pos,
                                          v_delimiter_pos - v_current_pos) ) );
                v_current_pos := v_delimiter_pos + length(p_delimiter);
            end loop;
        end if;
    end SplitClob;
    CREATE OR REPLACE TYPE SALESPERSON_T  AS OBJECT
      SALESPERSON_ID        number(15)
    , SALESPERSON_NUMBER    varchar2(150 char)
    , FIRST_NAME            varchar2(20 char)
    , LAST_NAME             varchar2(40 char)
    , SALES_CHANNEL         varchar2(60 char)
    , ORG_ID                number(15)
    , USER_NAME             varchar2(61 char)
    , EFFECTIVE_START_DATE  date
    , EFFECTIVE_END_DATE    date
    , STATUS_FLAG           varchar2(1 char)
    , EMAIL                 varchar2(70 char)
    , WORK_TELEPHONE        varchar2(60 char)
    , MANAGERS_NAME         varchar2(50 char)
    , FAX_NO                varchar2(60 char)
    , SALESPERSON_NAME      varchar2(30 char)
    , TERRITORY             varchar2(40 char)
    , FO_LOGON              varchar2(150 char)
    , BO_LOGON              varchar2(150 char)
    , SUB_CHANNEL           varchar2(25 char)
    , BUSINESS_SEGMENT      varchar2(3 char)
    , DISCOUNT_NAME         varchar2(30 char)
    , RESPONSIBILITY_ID     number
    , RESPONSIBILITY_KEY    varchar2(30 char)
    CREATE OR REPLACE TYPE STRINGTABLE as table of varchar2(4000);[/code]
    The total number of records in each table.
    [code]SELECT COUNT(*) FROM ORL.FAX_HEADER FH --4397829
    SELECT COUNT(*) FROM APPS_GLOBAL.GLOBAL_BU_MAPPING map --31
    SELECT COUNT(*) FROM ORL.WORKGROUP_TRANSITION  --6735
    SELECT COUNT(*) FROM ORL.WORKGROUP fw --1495
    SELECT COUNT(*) FROM ORL.FAX_OFFER_DETAIL --5904039
    SELECT COUNT(*) FROM  ORL.FAX_SOURCE--2368 --2457[/code]
    Indexes on the columns.
    [code]ORL.WORKGROUP_TRANSITION(ID),
    ORL.WORKGROUP(ID),
    ORL.FAX_OFFER_DETAIL(FAX_ID),
    ORL.FAX_HEADER(WORKGROUP_ID).[/code]
    Please help me to tune this query.
    Thanks in advance.

    Hi,
    Thanks for your reply.
    For split the numbers into different rows , we are sending randomly.
    It's not constant numbers.We have used bind variables.
    For testing purpose I have hard coded the values.
    How to do this split without using user defined function.
    I am sending the actual query along with execution plan without any hints.
    [code]SELECT   FAX_LIST.*
      FROM   (SELECT   ROW_NUMBER () OVER (ORDER BY fax.ID ASC) RN,
                       fax.ACCOUNT_TYPE,
                       fax.BU_FILE_LOCATION,
                       fax.COUNT_PAGES_RECEIVED,
                       NVL (fax.CUSTOMER_NAME, fax.SENDER_NAME) AS CUSTOMER_NAME,
                       fax.FAX_SOURCE,
                       fax.CUSTOMER_NUMBER,
                       fax.CUSTOMER_OMEGA_NUMBER,
                       fax.GENIFAX_RECIPIENT_ID,
                       fax.ID AS FAX_ID,
                       fax.DATE_RECEIVED AS FAX_RECEIVED,
                       fax.IS_LOCKED,
                       fax.LOCKED_BY,
                       fax.ORIGINATOR_CSI,
                       fax.MARGIN,
                       fax.PAYMENT_TYPE,
                       fax.PRIORITY_CODE,
                       fax.PRIORITY_VALUE,
                       FROM_TZ (fax.DATE_RECEIVED, 'UTC') AT TIME ZONE map.ORACLE_TZ_NAME AS DATE_RECEIVED,
                       fax.SALES_PERSON,
                       fax.SENDER_EMAIL,
                       fax.SENDER_NAME,
                       fax.SUBJECT,
                       fax.WORKGROUP_ID,
                       fax.LOCKED_TIME,
                       src.DESCRIPTION,
                       src.FAX_NUMBER,
                       src.WORKFLOW_ID,
                       fax.CREATED_BY,
                       fax.CREATED_DATE,
                       fax.UPDATE_DATE,
                       fax.UPDATED_BY,
                       fax.RESERVED_BY,
                       fax.PRICE_TO_ORDER,
                       fax.SKU_COUNT_TO_ORDER,
                       NVL (
                          ORL.GET_FTH_WTR (fax.LAST_TRANSITION_ID).CHANGED_BY,
                          CASE
                             WHEN fax.LAST_TRANSITION_ID IS NULL
                                  AND fax.GENIFAX_RECIPIENT_ID IS NOT NULL
                             THEN
                                'ORL FEEDER'
                             ELSE
                                'Admin'
                          END
                          AS LAST_USER,
                       FROM_TZ (NVL (ORL.GET_FTH_WTR (fax.LAST_TRANSITION_ID).CHANGED_DATE,fax.DATE_RECEIVED),'UTC')
                       AT TIME ZONE map.ORACLE_TZ_NAME AS MOVE_DATETIME,
                       NVL (ORL.GET_FTH_WTR (fax.LAST_TRANSITION_ID).REASON,'Reroute')AS MOVE_REASON,
                       NVL ((SELECT   fw.DESCRIPTION
                             FROM   ORL.WORKGROUP_TRANSITION wt, ORL.WORKGROUP fw
                            WHERE   wt.ID =
                                       ORL.GET_FTH_WTR (
                                          fax.LAST_TRANSITION_ID
                                       ).WORKGROUP_TRANSITION_ID
                                    AND fw.ID = wt.CURRENT_WORKGROUP_ID),
                          CASE
                             WHEN fax.LAST_TRANSITION_ID IS NULL
                                  AND fax.GENIFAX_RECIPIENT_ID IS NOT NULL
                             THEN
                                'ORL FEEDER STAGING'
                             ELSE
                                'N/A'
                          END
                          AS OLD_STATUS,
                       (SELECT   MAX (PURCHASE_ORDER_NUMBER)
                          FROM   ORL.FAX_OFFER_DETAIL
                         WHERE   FAX_ID = fax.ID)
                          AS MAXPO,
                       (SELECT   CASE COUNT (PURCHASE_ORDER_NUMBER)
                                    WHEN 0 THEN NULL
                                    ELSE COUNT (PURCHASE_ORDER_NUMBER)
                                 END
                                    AS POCOUNT
                          FROM   ORL.FAX_OFFER_DETAIL
                         WHERE   FAX_ID = fax.ID)
                          AS POCOUNT,
                       (SELECT   SUM (VALUE) AS ORDER_VALUE
                          FROM   ORL.FAX_OFFER_DETAIL
                         WHERE   FAX_ID = fax.ID) AS ORDER_VALUE,
                       ORL.GET_SALESPERSON (map.ORG_ID,fax.SALES_PERSON).SALESPERSON_NAME AS SALESPERSON_NAME,
                       ORL.GET_SALESPERSON (map.ORG_ID,fax.SALES_PERSON).GROUP_NAME AS GROUP_NAME,
                       ORL.GET_SALESPERSON (map.ORG_ID,fax.SALES_PERSON).ROLE_NAME AS ROLE_NAME,
                       ORL.GET_SALESPERSON (map.ORG_ID, fax.SALES_PERSON).EMAIL AS EMAIL,
                       ORL.GET_SALESPERSON (map.ORG_ID, fax.SALES_PERSON).SALES_CHANNEL AS SALES_CHANNEL
                FROM   ORL.FAX_HEADER fax,
                       APPS_GLOBAL.GLOBAL_BU_MAPPING map,
                       ORL.FAX_SOURCE src
               WHERE       fax.WORKGROUP_ID = :WORKGROUP_ID
                       AND map.GEDIS = 'Y'
                       AND map.BU_ID = (SELECT   BUID
                                          FROM   ORL.WORKGROUP
                                         WHERE   ID = fax.WORKGROUP_ID)
                       AND ORL.GET_SALESPERSON (map.ORG_ID,fax.SALES_PERSON).GROUP_NAME =:SALES_TEAM
                       AND ORL.GET_SALESPERSON (map.ORG_ID,fax.SALES_PERSON
                          ).SALESPERSON_NAME = :SALESPERSON_NAME
                       AND src.WORKFLOW_ID IN
                                (SELECT TO_NUMBER (COLUMN_VALUE) AS COLUMN_VALUE
                                   FROM table(SplitClob (:WORKFLOW_ID,:WORKFLOW_ID_delim)) t)
                       AND src.ID(+) = fax.FAX_SOURCE) FAX_LIST
    WHERE   RN BETWEEN 1 AND 100;
    Execution Plan
    | Id  | Operation                               | Name                    | Rows  | Bytes | Cost (%CPU)|
    |   0 | SELECT STATEMENT                        |                         |     2 | 12092 | 88923   (1)|
    |   1 |  NESTED LOOPS                           |                         |     1 |    38 |     3   (0)|
    |   2 |   TABLE ACCESS BY INDEX ROWID           | WORKGROUP_TRANSITION    |     1 |     9 |     2   (0)|
    |   3 |    INDEX UNIQUE SCAN                    | PK_WORKGROUP_TRANSITION |     1 |       |     1   (0)|
    |   4 |   TABLE ACCESS BY INDEX ROWID           | WORKGROUP               |  1482 | 42978 |     1   (0)|
    |   5 |    INDEX UNIQUE SCAN                    | PK_WORKGROUP            |     1 |       |     0   (0)|
    |   6 |  SORT AGGREGATE                         |                         |     1 |    16 |            |
    |   7 |   TABLE ACCESS BY INDEX ROWID           | FAX_OFFER_DETAIL        |     1 |    16 |     5   (0)|
    |   8 |    INDEX RANGE SCAN                     | FAX_OFFER_DETAIL_IDX1   |     1 |       |     3   (0)|
    |   9 |  SORT AGGREGATE                         |                         |     1 |    16 |            |
    |  10 |   TABLE ACCESS BY INDEX ROWID           | FAX_OFFER_DETAIL        |     1 |    16 |     5   (0)|
    |  11 |    INDEX RANGE SCAN                     | FAX_OFFER_DETAIL_IDX1   |     1 |       |     3   (0)|
    |  12 |  SORT AGGREGATE                         |                         |     1 |    11 |            |
    |  13 |   TABLE ACCESS BY INDEX ROWID           | FAX_OFFER_DETAIL        |     1 |    11 |     5   (0)|
    |  14 |    INDEX RANGE SCAN                     | FAX_OFFER_DETAIL_IDX1   |     1 |       |     3   (0)|
    |  15 |  VIEW                                   |                         |     2 | 12092 | 88923   (1)|
    |  16 |   WINDOW SORT PUSHED RANK               |                         |     2 |  1378 | 88923   (1)|
    |  17 |    NESTED LOOPS                         |                         |       |       |            |
    |  18 |     NESTED LOOPS                        |                         |     2 |  1378 | 88920   (1)|
    |  19 |      NESTED LOOPS                       |                         | 18420 |    11M| 70490   (1)|
    |  20 |       HASH JOIN RIGHT SEMI              |                         |    69 |  3657 |    49   (3)|
    |  21 |        COLLECTION ITERATOR PICKLER FETCH| SPLITCLOB               |  8168 | 16336 |    29   (0)|
    |  22 |        TABLE ACCESS FULL                | FAX_SOURCE              |  2409 |   119K|    19   (0)|
    |  23 |       TABLE ACCESS BY INDEX ROWID       | FAX_HEADER              |   268 |   160K|  2854   (1)|
    |  24 |        INDEX RANGE SCAN                 | FAX_HEADER_FS_IDX       |  4345 |       |     7   (0)|
    |  25 |      INDEX RANGE SCAN                   | GLOBAL_BU_MAPPING_BUID  |     1 |       |     0   (0)|
    |  26 |       TABLE ACCESS BY INDEX ROWID       | WORKGROUP               |     1 |     8 |     2   (0)|
    |  27 |        INDEX UNIQUE SCAN                | PK_WORKGROUP            |     1 |       |     1   (0)|
    |  28 |     TABLE ACCESS BY INDEX ROWID         | GLOBAL_BU_MAPPING       |     1 |    24 |     1   (0)|
    Note
       - 'PLAN_TABLE' is old version
    Statistics
         894400  recursive calls
             60  db block gets
        7402741  consistent gets
              0  physical reads
              0  redo size
          46309  bytes sent via SQL*Net to client
            430  bytes received via SQL*Net from client
              8  SQL*Net roundtrips to/from client
         848304  sorts (memory)
              0  sorts (disk)
            100  rows processed[/code]
    Please help me.
    Thanks in advance.

  • Please tune my query written in PL/SQL.

    Hi there,
    I really appreciate you if could tune my query.
    Here I am using tow tables PRDT_MASTER with 7 thosound records, REG_SUM with 50 records.
    I get nearly 10 thosound records to my cursor.
    From these 10 thosound records I have to prepare an SQL STATEMENT with dynamic sql.
    That query selects sum() from ACTUALDATA table (This table contains nearly 75thosound records).
    Then that data has to be inserted in to another table PROD_BRAND.
    I had a predesigned tables where i can't change or create any index, Infact no tables any no index. There is no primary key on the columns also.
    Now my problem is while i execute this procedure it is taking nearly 1 hour. I don't know why it is taking that much time. Is it because of dynamic sql and without any indexes?
    Or IS IT NECESSARY for me to change anything???
    Is there any alteranative way for me to over come from this problem....
    Your help is really appreciatable bench mark for me.
    I HAVE A TYPE FETCHCURSOR FOR REFCURSOR.
    PROCEDURE PROD_MASTER_PRO
         (DATE1      IN DATE
         ,DATE2 IN DATE
         ,TYPE     IN VARCHAR2
         )      AS
              MAINCUR                MYPACK.FETCHCURSOR;
         COU                     NUMBER(20);
         V_SUM                    NUMBER(20);
              V_SBUCODE               VARCHAR2(255);
              V_CATCODE                VARCHAR2(255);
              V_BRANDCODE               VARCHAR2(255);
              V_PRODCODE           VARCHAR2(255);
              V_TYPE                    VARCHAR2(10):= UPPER(TYPE);          
              REGNAME                    REG_SUM.REGION%TYPE;
              CONDITION               REG_SUM.COND%TYPE;
              QRY                         VARCHAR2(2000);                                                       
         BEGIN
    --//This is for different catcodes codes
              OPEN MAINCUR FOR
              SELECT DISTINCT SBUCODE,CATCODE,PRODCODE,REGION ,COND
              FROM PRDT_MASTER, REG_SUM
              WHERE PRDT_MASTER.SBUCODE=REG_SUM.SUB
              AND PRDT_MASTER.PRODCODE IS NOT NULL     
              ORDER BY SBUCODE,CATCODE,PRODCODE;
              LOOP FETCH MAINCUR INTO V_SBUCODE,V_CATCODE,V_PRODCODE,REGNAME,CONDITION;
              EXIT WHEN MAINCUR%NOTFOUND;
                   --SELECT NVL(SUM(GROSS),0) INTO V_SUM FROM ACTUALDATA WHERE PROD_CODE=V_PRODCODE
                   --AND (TRUNC(INV_DATE) BETWEEN  DATE1 AND DATE2);
                   QRY:=     'SELECT NVL(SUM(GROSS),0) FROM ACTUALDATA     ';               
                   QRY:=     QRY||'     WHERE PROD_CODE= :V_PRODCODE_BIND ';     
                   QRY:=     QRY||'     AND (TRUNC(INV_DATE) BETWEEN :DATE1_BIND AND :DATE2_BIND      )';
                   QRY:=     QRY||'     AND '||CONDITION;
                   EXECUTE IMMEDIATE QRY INTO V_SUM     USING V_PRODCODE ,DATE1,DATE2;
                   INSERT INTO PROD_BRAND
                   (     PROD_CODE,     SBUCODE ,     CODE ,
                        SUM ,     TYPE ,     CODE_TYPE,
                        REGION     
                   )     VALUES
                   (     V_PRODCODE,     V_SBUCODE,     V_CATCODE,
                        V_SUM,          PROD_MASTER_PRO.TYPE,     'THERAPY',
                        REGNAME     
              END LOOP;
              CLOSE MAINCUR;          
              COMMIT;
         END;
    regards,
    Khaleel.

    Parsing SQL is complex. Parsing SQL dynamically at run-time inside a FCAG policy function to determine what predicate to add, is a terribly bad idea. Performance wise and security wise.
    Can you be more specific (basic example) of what you are trying to achieve? And more importantly, what business requirement you are attempting to solve with this approach?
    Perhaps if we understand the full details, we can better assist you.

  • Tunning the query

    Hi all,
    Please help me in tuning this query:
    select tab1.col1, tab1.col2, tab1.col3, tab2.col1, sum(tab1.col4), avg(tab1.col5), tab2.col2, tab2.col3, tab2.col4, tab2.col5
    from table1 tab1 , table2 tab2
    where tab2.col6 = tab1.col6 and
    to_char(tab2.col3, 'yyyy') = to_char(sysdate, 'yyyy')
    and tab2.col7=tab1.col2
    and tab2.col7 in ('11','12')
    group by tab1.col1, tab1.col2, tab1.col3, tab2.col1, tab2.col2, tab2.col3, tab2.col4, tab2.col5
    <br>
    Operation     Object Name     Rows     Bytes     Cost     Object Node     In/Out     PStart     PStop
    SELECT STATEMENT Optimizer Mode=CHOOSE          1 K          11456                     
    SORT GROUP BY          1 K     80 K     11456                     
    HASH JOIN          1 K     80 K     11419                     
    TABLE ACCESS FULL     tab2     1 K     49 K     3562                     
    TABLE ACCESS FULL     tab1     401 K     11 M     7847      
    <br>

    Hi,
    If I use
    tab2.col3 >= TRUNC(SYSDATE) AND tab2.col3 < TRUNC(TRUNC(sysdate) + 366)
    Then the total query is returning only 15 rows where as if I use
    to_char(tab2.col3, 'yyyy') = to_char(sysdate, 'yyyy')...
    then the query returns more than 70,000 rows.
    As you suggested I have created an index on
    tab2 (col3,col7,col6,col1,col2,col4,col5) and also on
    tab1(col2,col1,col3,col4,col5)
    This drastically reduced the cost, The explain plan is as follows:
    Operation     Object Name     Rows     Bytes     Cost     Object Node     In/Out     PStart     PStop
    SELECT STATEMENT Optimizer Mode=CHOOSE          1 K          84                     
    SORT GROUP BY          1 K     80 K     84                     
    HASH JOIN          1 K     80 K     47                     
    INDEX FULL SCAN     tab2_id3     1 K     49 K     26                     
    INLIST ITERATOR                                        
    INDEX RANGE SCAN     tab1_id5     401 K     11 M     11

  • Please give the query to find out primary key in table in Sql plus

    Dear friends,
    Please give me the query to find out the primary key in Sql plus.

    hi
    SQL> DESC user_constraints
    Name                                                                                                  
    OWNER                                                                                                 
    CONSTRAINT_NAME                                                                                       
    CONSTRAINT_TYPE                                                                                       
    TABLE_NAME                                                                                            
    SEARCH_CONDITION                                                                                      
    R_OWNER                                                                                               
    R_CONSTRAINT_NAME                                                                                     
    DELETE_RULE                                                                                           
    STATUS                                                                                                
    DEFERRABLE                                                                                            
    DEFERRED                                                                                              
    VALIDATED                                                                                             
    GENERATED                                                                                             
    BAD                                                                                                   
    RELY                                                                                                  
    LAST_CHANGE                                                                                           
    INDEX_OWNER                                                                                           
    INDEX_NAME                                                                                            
    INVALID                                                                                               
    VIEW_RELATED                                                                                          
    SQL> SELECT constraint_name,table_name,r_constraint_name,status
      2  FROM user_constraints WHERE constraint_type='P';
    CONSTRAINT_NAME                TABLE_NAME                     R_CONSTRAINT_NAME              STATUS
    SYS_C003141                    CUSTOMERS                                                     ENABLED
    PK_DEPT                        DEPT                                                          ENABLED
    SYS_C003139                    SALESREPS                                                     ENABLEDKhurram

  • Please explain the query?

    hello all,
    please explain below query used in solution below, thanks in advance!
    ELECT MAX(P1.ET) AS ST, P2.ST AS ET
    FROM XYZ AS P1
    INNER JOIN XYZ AS P2 ON (P1.ST < P2.ST)
    GROUP BY P2.ST
    HAVING MAX(P1.ET) < P2.ST
    IF OBJECT_ID('XYZ') IS NOT NULL
    DROP TABLE XYZ
    GO
    CREATE TABLE XYZ
    id int identity(1,1),
    ST smalldatetime NOT NULL,
    ET smalldatetime NOT NULL
    GO
    INSERT INTO XYZ (ST, ET)
    VALUES ('2010-01-01 9:00AM', '2010-01-01 10:00AM')
    INSERT INTO XYZ (ST, ET)
    VALUES ('2010-01-01 9:00AM', '2010-01-01 12:00PM')
    INSERT INTO XYZ (ST, ET)
    VALUES ('2010-01-01 1:00PM', '2010-01-01 2:00PM')
    INSERT INTO XYZ (ST, ET)
    VALUES ('2010-01-01 3:00PM', '2010-01-01 5:00PM')
    INSERT INTO XYZ (ST, ET)
    VALUES ('2010-01-01 11:00AM', '2010-01-01 12:00PM')
    GO
    WITH Gaps(Gap) AS
    SELECT COALESCE(SUM(DATEDIFF(MINUTE,ST,ET)), 0)
    FROM (
    SELECT MAX(P1.ET) AS ST, P2.ST AS ET
    FROM XYZ AS P1
    INNER JOIN XYZ AS P2 ON (P1.ST < P2.ST)
    GROUP BY P2.ST
    HAVING MAX(P1.ET) < P2.ST
    ) gaps
    SELECT (
    COALESCE(DATEDIFF(MINUTE, MIN(ST), MAX(ET)), 0)
    - (SELECT Gap FROM Gaps)
    ) / 60.0 TotalHrs
    FROM XYZ

    SELECT MAX(P1.ET) AS ST, P2.ST AS ET
    FROM XYZ AS P1
    INNER JOIN XYZ AS P2 ON (P1.ST < P2.ST)
    GROUP BY P2.ST
    HAVING MAX(P1.ET) < P2.ST
    Finds all of the gaps (that is time that is not in any interval in your original data.  To see how it works, let's look at an example.  I'm going to use data that is a little different than your original data because your data has no gaps. 
    The query still works if you have no gaps, but it is easier to see what it is doing if the data has some gaps.  Also, I'm going to explicitly set the id column instead of making it an identity.  This will make it a little easier to identify each
    row in the following explanation. So the data I'm going to work with is
    CREATE TABLE XYZ
    id int,
    ST smalldatetime NOT NULL,
    ET smalldatetime NOT NULL
    GO
    INSERT INTO XYZ (id, ST, ET)
    VALUES (1, '2010-01-01 9:00AM', '2010-01-01 10:00AM')
    INSERT INTO XYZ (id, ST, ET)
    VALUES (2, '2010-01-01 9:00AM', '2010-01-01 12:00PM')
    INSERT INTO XYZ (id, ST, ET)
    VALUES (3, '2010-01-02 1:00PM', '2010-01-02 2:00PM')
    INSERT INTO XYZ (id, ST, ET)
    VALUES (4, '2010-01-03 3:00PM', '2010-01-03 5:00PM')
    INSERT INTO XYZ (id, ST, ET)
    VALUES (5, '2010-01-03 7:00PM', '2010-01-03 9:00PM')
    Notice that the gaps here are from row 2 to row 3 (12PM on the 1st to 1PM on the 2nd) and row 3 to row 4 (2PM on the 2nd to 3PM on the 3rd) and row 4 to row 5 (5PM on the 3rd to 7PM on the 3rd).  So that's what the above subquery should be finding for
    us.
    To see what a query you don't understand is doing, simplify it to the smallest part you can and see what it returns and then build it up to the final query.  So the simplest thing we can do is just the from clause.  That gives us
    SELECT *
    FROM XYZ AS P1
    INNER JOIN XYZ AS P2 ON (P1.ST < P2.ST)
    /* That gives us the result
    1 2010-01-01 09:00:00 2010-01-01 10:00:00 3 2010-01-02 13:00:00 2010-01-02 14:00:00
    2 2010-01-01 09:00:00 2010-01-01 12:00:00 3 2010-01-02 13:00:00 2010-01-02 14:00:00
    1 2010-01-01 09:00:00 2010-01-01 10:00:00 4 2010-01-03 15:00:00 2010-01-03 17:00:00
    2 2010-01-01 09:00:00 2010-01-01 12:00:00 4 2010-01-03 15:00:00 2010-01-03 17:00:00
    3 2010-01-02 13:00:00 2010-01-02 14:00:00 4 2010-01-03 15:00:00 2010-01-03 17:00:00
    1 2010-01-01 09:00:00 2010-01-01 10:00:00 5 2010-01-03 19:00:00 2010-01-03 21:00:00
    2 2010-01-01 09:00:00 2010-01-01 12:00:00 5 2010-01-03 19:00:00 2010-01-03 21:00:00
    3 2010-01-02 13:00:00 2010-01-02 14:00:00 5 2010-01-03 19:00:00 2010-01-03 21:00:00
    4 2010-01-03 15:00:00 2010-01-03 17:00:00 5 2010-01-03 19:00:00 2010-01-03 21:00:00
    Now we want to Group by P2.ST and get the MAX(P1.ET) and P2.ST, so that gives us
    SELECT MAX(P1.ET) AS ST, P2.ST AS ET
    FROM XYZ AS P1
    INNER JOIN XYZ AS P2 ON (P1.ST < P2.ST)
    GROUP BY P2.ST
    /* Result is
    2010-01-01 12:00:00 2010-01-02 13:00:00
    2010-01-02 14:00:00 2010-01-03 15:00:00
    2010-01-03 17:00:00 2010-01-03 19:00:00
    Now with this sample data there are no rows in the output with MAX(P1.ET) > P2.ST.  But if there was one, you would not want that row because it is not a real gap (obviously, a gap can't start today and end yesterday).  (If you want to see how
    you could get a case like that, add a row 6 to the sample data with a ST of 2010-01-01 7:00PM and an ET of 2010-01-03 9:00PM.)
    So we add a HAVING MAX(P1.ET) < P2.ST to remove those cases.
    That leaves us with all of the gaps.  So then with
    SELECT COALESCE(SUM(DATEDIFF(MINUTE,ST,ET)), 0)
    FROM (
    SELECT MAX(P1.ET) AS ST, P2.ST AS ET
    FROM XYZ AS P1
    INNER JOIN XYZ AS P2 ON (P1.ST < P2.ST)
    GROUP BY P2.ST
    HAVING MAX(P1.ET) < P2.ST
    ) gaps
    we get the total amount of time in all gaps.  Then the final result is just the time from the earliest ST to the latest ET minus the total time from the gap.
    Tom

  • Request for tunning the query

    Hi,
    Can anyone help me on the below query while improving performance. WHen i executed in TOAD 8.6.1 it is taking cost 8890. becoz of joins & some table are scanning fully eventhough there are some indexes on it.
    If possible please rewrite the below query in anyotherway.
    SELECT
    SR.*,
    frozen_quote.*,
    WORKORDER.pscdate,
    WORKORDER.ascdate,
    WORKORDER.targstartdate,
    WORKORDER.targcompdate,
    WORKORDER.schedfinish,
    WORKORDER.actfinish,
    WORKORDER.estdur,
    WORKORDER.wonum,
    WORKORDER.MPRN,
    WORKORDER.sihousename AS wositehousename,
    WORKORDER.sihouseno AS wositehouseno,
    WORKORDER.sistreet AS wositestreet,
    WORKORDER.sicounty AS wositecounty,
    WORKORDER.siposttown AS wositeposttown,
    WORKORDER.sipostcode AS wositepostcode,
    WORKORDER.workorderid
    FROM (maximo.SR
    INNER JOIN
    (maximo.RELATEDRECORD
    INNER JOIN maximo.WORKORDER
    ON RELATEDRECORD.relatedreckey=(
    CASE
    WHEN WORKORDER.parent IS NOT NULL
    THEN WORKORDER.parent
    ELSE WORKORDER.wonum
    END
              AND RELATEDRECORD.orgid=WORKORDER.orgid
    AND RELATEDRECORD.siteid=WORKORDER.siteid
              AND RELATEDRECORD.relatedrecclass='WORKORDER'
    ON SR.ticketid=RELATEDRECORD.recordkey
    AND SR.orgid=RELATEDRECORD.orgid
    AND SR.siteid=RELATEDRECORD.siteid
    AND RELATEDRECORD.class='SR')
    LEFT JOIN
    frozen_quote@gqmfof
    ON SR.ticketid = CUSTOMER_ENQUIRY_REF
    AND SR.quotever = QUOTE_VERSION
    Regards,
    Arjun.

    Check the plan of the non ansii version below against the plan of your version.
    Sometimes they might be different as I remember hearing somewhere. The probability is not very high though as using ansii syntax some care
    must be taken specifying predicates so the compared versions I heard about might well not be equivalent.
    If the plans are the same and having indexes on linking columns in place I don't see what else could be done as accessing a remote database
    can well be the major contribution the slow response you're experiencing.
    select y.*,
           f.*
      from (select s.*,
                   x.pscdate,x.ascdate,x.targstartdate,x.targcompdate,x.schedfinish,x.actfinish,x.estdur,x.wonum,x.mprn,
                   x.sihousename wositehousename,x.sihouseno wositehouseno,x.sistreet wositestreet,
                   x.sicounty wositecounty,x.siposttown wositeposttown,x.sipostcode wositepostcode,
                   x.workorderid
              from (select r.recordkey,r.orgid,r.siteid,r.class,
                           w.pscdate,w.ascdate,w.targstartdate,w.targcompdate,w.schedfinish,w.actfinish,w.estdur,w.wonum,w.mprn,
                           w.sihousename wositehousename,w.sihouseno wositehouseno,w.sistreet wositestreet,
                           w.sicounty wositecounty,w.siposttown wositeposttown,w.sipostcode wositepostcode,
                           w.workorderid
                      from relatedrecord r,
                           workorder w
                     where r.relatedreckey = case when w.parent is null then w.wonum else w.parent end
                       and r.orgid = w.orgid
                       and r.siteid = w.siteid
                       and r.relatedrecclass = 'WORKORDER'
                   ) x,
                   sr s
             where x.recordkey = s.ticketid
               and x.orgid = s.orgid
               and x.siteid = s.siteid
               and x.class = 'SR'
           ) y,
           frozen_quote@gqmfof f
    where y.ticketid = f.customer_enquiry_ref
       and y.quotever = f.quote_versionRegards
    Etbin

  • Tune the query

    hi,
    can any one tell me how to tune the below query. i am using oracle10.2.0.1.0 and this query take 5 mins to fetch the 10000 record.
    select
    nvl(w.range_num,v.range_num),
    w.min_capacity,
    w.max_capacity,
    w.price,
    v.min_capacity,
    v.max_capacity,
    v.price
    from TABLE( GET_VECTOR(20,'W') ) w
    full outer join TABLE( GET_VECTOR(20,'V') ) v
    on v.range_num = w.range_num;

    CREATE OR REPLACE function GET_VECTOR (arg_key number, arg_type varchar2)
    return VECTOR_TAB pipelined
    IS
    cursor cur2(in_key number) is
    select rownum, min_capacity, max_capacity, price
    from vol_v
    where key = in_key;
    order by min_capacity;
    out_rec PRICE_VEC := PRICE_VEC(NULL,NULL,NULL,NULL);
    BEGIN
    if (arg_type = 'V') then
    open cur2 (arg_key);
    LOOP
    fetch cur2 into
    out_rec.range_num,
    out_rec.min_capacity,
    out_rec.max_capacity,
    out_rec.price;
    exit when cur2%NOTFOUND;
    pipe row(out_rec);
    END LOOP;
    close cur2;
    end if;
    return;
    END GET_VECTOR;
    Edited by: user11272074 on Oct 28, 2009 10:22 PM
    Edited by: user11272074 on Oct 28, 2009 10:23 PM

Maybe you are looking for

  • Cinema display causing freezes and kernel panics?

    Okay, if anyone has experienced this before I would like to know. I've been having these powerbook freezes at night., and occasional kernel panics during the day. I usualy leave my computer on all night, but when I check it in the morning it's pretty

  • How to Restrict Return Sales Order with reference to a cancelled invoice

    SAP Standard is allowing to create Return Sales Order with reference to a cancelled invoice which practically should not be allowed. Has any body worked on this problem and what could be the possible solutions so that return sales orders can not be c

  • SP Not firing

    Hi I am new to SP.I written a code which is executed at back end succesfully but its not firing at front end. I used this SP to restrict the user to change the unit price(Comes automatically from item master) for a particular item group in PO.its not

  • How to change IM chat heading color?

    Is there a way to change the color of the text " ____ is typing... " This post was transferred from its previous location to create its own new topic here; its subject and/or title has been edited to differentiate the post from other inquiries and to

  • Soundblaster XFI surround 5.1 usb problem in Mac OS Lion.

    It worked perfectly in snow leopard, but in Lion 2 of my right side speakers are not working. Even using the MIDI Utilities software the right side speaker can't detect correctly. What is the solution? I can't enjoy surround songs using my card and s