Do I need to tune the base query of my materialized view ?

Hi gurus,
We implement materialized view (FAST REFRESH ON COMMIT) on base table used in OLTP system. In fact the MV itself is also queried by the OLTP system itself, interactively.
Currently user complain that after they input transaction, they see that the MV is not refresh as soon as they commit the transaction.
(it takes 5 to 10 minutes before they see the update on the MV)
The query of the MV is attached below, it consists of union all of two queries but actually the real query has 13 queries on a UNION ALL.
The question is :
Do I need to tune the query that forms the MV ?
Does it impact the refresh time of the MV ?
Thank you for your help,
xtanto
SELECT GRNH.DOC_CODE ||' '|| GRNH.GRN_NO, GRNH.GRN_DATE, GRNH.REGS_CODE,
F_Convert_Qty_K(GRND.PRODUCT, GRND.QTY, GRND.UOM) QTY_IN, 0 QTY_OUT, 0 QTY_ADJ, 'N/A'.....
FROM GRN_LOCAL_D GRND
          JOIN GRN_LOCAL_H GRNH ON GRNH.GRNH_ID = GRND.GRNH_ID
          WHERE GRND.PRODUCT IS NOT NULL AND GRNH.WH_CODE IS NOT NULL
UNION ALL
SELECT GRNH.DOC_CODE ||' '|| GRNH.GRN_NO, GRNH.GRN_DATE, GRNH.REGS_CODE,
F_Convert_Qty_K(GRND.PRODUCT_B, GRND.QTY_B, GRND.UOM_B) QTY_IN, 0 QTY_OUT, 0 QTY_ADJ, 'N/A'...
FROM GRN_LOCAL_D GRND
JOIN GRN_LOCAL_H GRNH ON GRNH.GRNH_ID = GRND.GRNH_ID
WHERE GRND.PRODUCT_B IS NOT NULL AND GRNH.WH_CODE IS NOT NULL
UNION ALL
     ......

Hi Justin & APC,
Are they seeing a 5-10 minute delay in being able to commit their transaction?NO, the commit itself is completed normally, but after that when they go to the page (this is webbased app) that display data from the MV, the newly committed transactionis not there yet. Only after 5-10 minutes we can see the new data.
What does the F_Convert_Qty_K() function do?It is a function that convert the quantity from whatever Unit Of Measurement (UOM) into the smallest UOM. Below is the code.
So the question remains:
why intermittently theere is delay before the new data visible in the MV ?
Thanks you,
xtanto
CREATE OR REPLACE FUNCTION F_Convert_Qty (pProduct VARCHAR2, pQty NUMBER, pUOM VARCHAR2)
RETURN NUMBER
IS
vQtyBase NUMBER(13,5);
BEGIN
SELECT CASE WHEN pUOM = ( SELECT UOM_BASE FROM PRODUCTS WHERE PRODUCT = pProduct)
          THEN pQty
     ELSE
               SELECT ROUND(pQty * Coefficient / Divisor, 5)
               FROM (
                         SELECT Coefficient, Divisor FROM CONVERT_UOM
                         WHERE PRODUCT = pProduct AND UOM_CONVERT = pUOM
                         ) tmp
          END INTO vQtyBase FROM DUAL;
--RETURN (vQtyBase) ;
RETURN ( NVL(vQtyBase,0) ) ;
END F_Convert_Qty;
/

Similar Messages

  • Need to tune the sql query

    Hi,
    PLease help me to tune the query
    select primary_rep,
    rep_ssn,
    nvl(product_type_desc, 'UNKNOWN') as productName,
    ROUND(sum(contributions)) as contribution,
    ROUND(sum(withdrawls)) as withdrawls,
    ROUND(sum(netflow)) as netflow
    from dev.NETFLOW_VIEW_TSS_P
    where bd = 'TSS'
    and actvtydate between '01-Jan-2011' and '30-Sep-2011'     
    and rep_ssn IN (select tax_id from broker_view where broker_id = '600468')
    group by primary_rep, rep_ssn, nvl(product_type_desc, 'UNKNOWN');
    explain plan details below
    | Id  | Operation                                     | Name                        | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT                              |                             |    79 |   158K|       | 74348   (1)| 00:14:53 |       |       |
    |   1 |  HASH GROUP BY                                |                             |    79 |   158K|       | 74348   (1)| 00:14:53 |       |       |
    |*  2 |   HASH JOIN                                   |                             |    79 |   158K|       | 74347   (1)| 00:14:53 |       |       |
    |   3 |    VIEW                                       | VW_NSO_1                    |     1 |     6 |       |    18  (17)| 00:00:01 |       |       |
    |   4 |     HASH UNIQUE                               |                             |     1 |   100 |       |    18  (17)| 00:00:01 |       |       |
    |   5 |      NESTED LOOPS OUTER                       |                             |     1 |   100 |       |    17  (12)| 00:00:01 |       |       |
    |   6 |       MERGE JOIN CARTESIAN                    |                             |     1 |    92 |       |    17  (12)| 00:00:01 |       |       |
    |   7 |        NESTED LOOPS OUTER                     |                             |     1 |    71 |       |    15  (14)| 00:00:01 |       |       |
    |   8 |         NESTED LOOPS OUTER                    |                             |     1 |    67 |       |    12  (17)| 00:00:01 |       |       |
    |*  9 |          HASH JOIN OUTER                      |                             |     1 |    63 |       |    10  (20)| 00:00:01 |       |       |
    |  10 |           NESTED LOOPS OUTER                  |                             |     1 |    56 |       |     6   (0)| 00:00:01 |       |       |
    |  11 |            NESTED LOOPS OUTER                 |                             |     1 |    52 |       |     4   (0)| 00:00:01 |       |       |
    |  12 |             TABLE ACCESS BY INDEX ROWID       | AFFILIATE                   |     1 |    45 |       |     2   (0)| 00:00:01 |       |       |
    |* 13 |              INDEX UNIQUE SCAN                | AFFILIATE_PK                |     1 |       |       |     1   (0)| 00:00:01 |       |       |
    |* 14 |             TABLE ACCESS FULL                 | PORTAL_BROKER               |     1 |     7 |       |     2   (0)| 00:00:01 |       |       |
    |  15 |            VIEW PUSHED PREDICATE              |                             |     1 |     4 |       |     2   (0)| 00:00:01 |       |       |
    |  16 |             NESTED LOOPS                      |                             |     1 |    28 |       |     2   (0)| 00:00:01 |       |       |
    |  17 |              NESTED LOOPS                     |                             |     1 |    21 |       |     2   (0)| 00:00:01 |       |       |
    |* 18 |               TABLE ACCESS BY INDEX ROWID     | LOCATION_GROUP_TYPE_DESC    |     1 |     5 |       |     1   (0)| 00:00:01 |       |       |
    |* 19 |                INDEX UNIQUE SCAN              | LOCATION_GROUP_TYPE_DESC_PK |     1 |       |       |     0   (0)| 00:00:01 |       |       |
    |* 20 |               INDEX RANGE SCAN                | LOCATION_GROUP_UK           |     1 |    16 |       |     1   (0)| 00:00:01 |       |       |
    |* 21 |              INDEX UNIQUE SCAN                | CONTACT_METHOD_PK           |     1 |     7 |       |     0   (0)| 00:00:01 |       |       |
    |  22 |           VIEW                                |                             |     1 |     7 |       |     3  (34)| 00:00:01 |       |       |
    |  23 |            HASH UNIQUE                        |                             |     1 |    11 |       |     3  (34)| 00:00:01 |       |       |
    |* 24 |             INDEX RANGE SCAN                  | AFFILIATE_TYPE_PK           |     1 |    11 |       |     2   (0)| 00:00:01 |       |       |
    |  25 |          VIEW PUSHED PREDICATE                |                             |     1 |     4 |       |     2   (0)| 00:00:01 |       |       |
    |  26 |           NESTED LOOPS                        |                             |     1 |    28 |       |     2   (0)| 00:00:01 |       |       |
    |  27 |            NESTED LOOPS                       |                             |     1 |    21 |       |     2   (0)| 00:00:01 |       |       |
    |* 28 |             TABLE ACCESS BY INDEX ROWID       | LOCATION_GROUP_TYPE_DESC    |     1 |     5 |       |     1   (0)| 00:00:01 |       |       |
    |* 29 |              INDEX UNIQUE SCAN                | LOCATION_GROUP_TYPE_DESC_PK |     1 |       |       |     0   (0)| 00:00:01 |       |       |
    |* 30 |             INDEX RANGE SCAN                  | LOCATION_GROUP_UK           |     1 |    16 |       |     1   (0)| 00:00:01 |       |       |
    |* 31 |            INDEX UNIQUE SCAN                  | CONTACT_METHOD_PK           |     1 |     7 |       |     0   (0)| 00:00:01 |       |       |
    |  32 |         VIEW PUSHED PREDICATE                 |                             |     1 |     4 |       |     3   (0)| 00:00:01 |       |       |
    |  33 |          NESTED LOOPS OUTER                   |                             |     1 |    35 |       |     3   (0)| 00:00:01 |       |       |
    |  34 |           NESTED LOOPS                        |                             |     1 |    32 |       |     3   (0)| 00:00:01 |       |       |
    |  35 |            NESTED LOOPS                       |                             |     1 |    22 |       |     2   (0)| 00:00:01 |       |       |
    |* 36 |             TABLE ACCESS BY INDEX ROWID       | LOCATION_GROUP_TYPE_DESC    |     1 |     5 |       |     1   (0)| 00:00:01 |       |       |
    |* 37 |              INDEX UNIQUE SCAN                | LOCATION_GROUP_TYPE_DESC_PK |     1 |       |       |     0   (0)| 00:00:01 |       |       |
    |* 38 |             INDEX RANGE SCAN                  | LOCATION_GROUP_UK           |     1 |    17 |       |     1   (0)| 00:00:01 |       |       |
    |  39 |            TABLE ACCESS BY INDEX ROWID        | ADDRESS                     |     1 |    10 |       |     1   (0)| 00:00:01 |       |       |
    |* 40 |             INDEX UNIQUE SCAN                 | ADDRESS_PK                  |     1 |       |       |     0   (0)| 00:00:01 |       |       |
    |* 41 |           INDEX UNIQUE SCAN                   | PROV_STDSC_PK               |     1 |     3 |       |     0   (0)| 00:00:01 |       |       |
    |  42 |        BUFFER SORT                            |                             |     1 |    21 |       |    14  (15)| 00:00:01 |       |       |
    |* 43 |         INDEX RANGE SCAN                      | I_BROKER_BKBRCMB            |     1 |    21 |       |     2   (0)| 00:00:01 |       |       |
    |* 44 |       INDEX UNIQUE SCAN                       | BROKER_BRANCH_PK            |     1 |     8 |       |     0   (0)| 00:00:01 |       |       |
    |  45 |    VIEW                                       | NETFLOW_VIEW_TSS_P          |   391K|   766M|       | 74325   (1)| 00:14:52 |       |       |
    |  46 |     UNION-ALL                                 |                             |       |       |       |            |          |       |       |
    |* 47 |      HASH JOIN RIGHT OUTER                    |                             | 11645 |  1671K|       | 49023   (1)| 00:09:49 |       |       |
    |  48 |       VIEW                                    |                             |     1 |    38 |       | 13602   (1)| 00:02:44 |       |       |
    |* 49 |        FILTER                                 |                             |       |       |       |            |          |       |       |
    |  50 |         TABLE ACCESS FULL                     | SALES_REPORT_REP_MAPPING    |  9023 |   326K|       |    58   (2)| 00:00:01 |       |       |
    |* 51 |         FILTER                                |                             |       |       |       |            |          |       |       |
    |  52 |          SORT GROUP BY NOSORT                 |                             |     1 |    11 |       |     3   (0)| 00:00:01 |       |       |
    |  53 |           TABLE ACCESS BY INDEX ROWID         | SALES_REPORT_REP_MAPPING    |     1 |    11 |       |     3   (0)| 00:00:01 |       |       |
    |* 54 |            INDEX RANGE SCAN                   | I_SAL_REP_MAP_REPID         |     1 |       |       |     2   (0)| 00:00:01 |       |       |
    |  55 |       NESTED LOOPS                            |                             | 11645 |  1239K|       | 35420   (1)| 00:07:06 |       |       |
    |* 56 |        HASH JOIN RIGHT OUTER                  |                             | 11645 |   898K|       | 12112   (1)| 00:02:26 |       |       |
    |  57 |         INDEX FAST FULL SCAN                  | I_VENDORS_ACCTLOC           |   986 |  3944 |       |     2   (0)| 00:00:01 |       |       |
    |* 58 |         HASH JOIN RIGHT OUTER                 |                             | 11645 |   852K|       | 12109   (1)| 00:02:26 |       |       |
    |* 59 |          MAT_VIEW ACCESS FULL                 | SECS_DESC                   | 26777 |   418K|       |  3082   (1)| 00:00:37 |       |       |
    |* 60 |          FILTER                               |                             |       |       |       |            |          |       |       |
    |* 61 |           HASH JOIN RIGHT OUTER               |                             | 11645 |   670K|       |  9026   (1)| 00:01:49 |       |       |
    |  62 |            MAT_VIEW ACCESS FULL               | ENTRYCODES                  |  1640 | 11480 |       |     8   (0)| 00:00:01 |       |       |
    |* 63 |            HASH JOIN                          |                             | 34936 |  1774K|       |  9017   (1)| 00:01:49 |       |       |
    |* 64 |             INDEX FULL SCAN                   | I_CODE                      |    30 |   420 |       |     1   (0)| 00:00:01 |       |       |
    |  65 |             PARTITION RANGE ALL               |                             |   342K|    12M|       |  9013   (1)| 00:01:49 |     1 |    20 |
    |  66 |              TABLE ACCESS BY LOCAL INDEX ROWID| BKPG                        |   342K|    12M|       |  9013   (1)| 00:01:49 |     1 |    20 |
    |* 67 |               INDEX RANGE SCAN                | I_BKPG_ACT_REC_IDX          |   342K|       |       |  1412   (1)| 00:00:17 |     1 |    20 |
    |  68 |        TABLE ACCESS BY INDEX ROWID            | ACCT_CUBE                   |     1 |    30 |       |     2   (0)| 00:00:01 |       |       |
    |* 69 |         INDEX UNIQUE SCAN                     | ACCT_CUBE_PK                |     1 |       |       |     1   (0)| 00:00:01 |       |       |
    |* 70 |      HASH JOIN RIGHT OUTER                    |                             |   379K|    52M|       | 25303   (1)| 00:05:04 |       |       |
    |  71 |       VIEW                                    |                             |     1 |    38 |       | 13602   (1)| 00:02:44 |       |       |
    |* 72 |        FILTER                                 |                             |       |       |       |            |          |       |       |
    |  73 |         TABLE ACCESS FULL                     | SALES_REPORT_REP_MAPPING    |  9023 |   326K|       |    58   (2)| 00:00:01 |       |       |
    |* 74 |         FILTER                                |                             |       |       |       |            |          |       |       |
    |  75 |          SORT GROUP BY NOSORT                 |                             |     1 |    11 |       |     3   (0)| 00:00:01 |       |       |
    |  76 |           TABLE ACCESS BY INDEX ROWID         | SALES_REPORT_REP_MAPPING    |     1 |    11 |       |     3   (0)| 00:00:01 |       |       |
    |* 77 |            INDEX RANGE SCAN                   | I_SAL_REP_MAP_REPID         |     1 |       |       |     2   (0)| 00:00:01 |       |       |
    |* 78 |       HASH JOIN                               |                             |   379K|    39M|    33M| 11696   (2)| 00:02:21 |       |       |
    |* 79 |        HASH JOIN                              |                             |   379K|    28M|       |  3210   (2)| 00:00:39 |       |       |
    |* 80 |         INDEX FAST FULL SCAN                  | I_VENDORS_ACCTLOC           |   986 |  3944 |       |     2   (0)| 00:00:01 |       |       |
    |* 81 |         HASH JOIN                             |                             |   379K|    27M|    14M|  3204   (2)| 00:00:39 |       |       |
    |  82 |          INDEX FAST FULL SCAN                 | SECS_DESC_PK                |   744K|  6545K|       |   457   (3)| 00:00:06 |       |       |
    |* 83 |          FILTER                               |                             |       |       |       |            |          |       |       |
    |* 84 |           HASH JOIN RIGHT OUTER               |                             |   379K|    24M|       |   569   (3)| 00:00:07 |       |       |
    |  85 |            MAT_VIEW ACCESS FULL               | MFENTRYCODES                |  6853 | 61677 |       |    15   (0)| 00:00:01 |       |       |
    |  86 |            PARTITION RANGE ALL                |                             |  1138K|    62M|       |   542   (1)| 00:00:07 |     1 |    15 |
    |* 87 |             TABLE ACCESS BY LOCAL INDEX ROWID | MFBKPG                      |  1138K|    62M|       |   542   (1)| 00:00:07 |     1 |    15 |
    |* 88 |              INDEX RANGE SCAN                 | I_MFBKPGP_ACTDT_ACCT_TST    |   904 |       |       |   107   (0)| 00:00:02 |     1 |    15 |
    |  89 |        INDEX FAST FULL SCAN                   | I_ACCT_CUBE_REPID_MKT       |  1952K|    52M|       |  3096   (2)| 00:00:38 |       |       |
    Predicate Information (identified by operation id):
       2 - access("REP_SSN"="$nso_col_1")
       9 - access("A"."AFFILIATE_ID"="MGR"."AFFILIATE_ID"(+))
      13 - access("A"."AFFILIATE_ID"='600468')
      14 - filter("PORTAL_BROKER"."BROKER_ID"(+)='600468')
      18 - filter("LT"."ADDRESS_CONTACT_IND"='C')
      19 - access("LT"."LOCATION_GROUP_TYPE_CODE"='WF')
      20 - access("L"."LOCATION_GROUP_TYPE_CODE"='WF' AND "L"."AFFILIATE_ID"="A"."AFFILIATE_ID")
           filter("L"."CONTACT_METHOD_ID" IS NOT NULL)
      21 - access("L"."CONTACT_METHOD_ID"="B"."CONTACT_METHOD_ID")
      24 - access("AFFILIATE_ID"='600468')
           filter("AFFILIATE_TYPE"='BBE' OR "AFFILIATE_TYPE"='BRM' OR "AFFILIATE_TYPE"='ISP')
      28 - filter("LT"."ADDRESS_CONTACT_IND"='C')
      29 - access("LT"."LOCATION_GROUP_TYPE_CODE"='WT')
      30 - access("L"."LOCATION_GROUP_TYPE_CODE"='WT' AND "L"."AFFILIATE_ID"="A"."AFFILIATE_ID")
           filter("L"."CONTACT_METHOD_ID" IS NOT NULL)
      31 - access("L"."CONTACT_METHOD_ID"="B"."CONTACT_METHOD_ID")
      36 - filter("LT"."ADDRESS_CONTACT_IND"='A')
      37 - access("LT"."LOCATION_GROUP_TYPE_CODE"='WM')
      38 - access("L"."LOCATION_GROUP_TYPE_CODE"='WM' AND "L"."AFFILIATE_ID"="A"."AFFILIATE_ID")
           filter("L"."ADDRESS_ID" IS NOT NULL)
      40 - access("L"."ADDRESS_ID"="A"."ADDRESS_ID")
      41 - access("A"."PROVINCE_STATE_CODE"="S"."PROVINCE_STATE_CODE"(+))
      43 - access("B"."BROKER_ID"='600468')
      44 - access("B"."BRANCH_ID"="BR"."BRANCH_ID"(+))
      47 - access("B"."REPID"="K"."REPID"(+))
      49 - filter( EXISTS (SELECT 0 FROM DEV."SALES_REPORT_REP_MAPPING" "SALES_REPORT_REP_MAPPING" WHERE "REPID"=:B1 GROUP BY "REPID" HAVING
                  SUM(NVL("PCT",100))=100))
      51 - filter(SUM(NVL("PCT",100))=100)
      54 - access("REPID"=:B1)
      56 - access(NVL("V"."VENDOR_CD"(+),'xxx')=NVL("VENDOR_CD",'yyy'))
      58 - access("CUSIP"(+)="A"."CUSIP")
      59 - filter("COMM_SECTYPE"(+)='MF')
      60 - filter(NVL("Z"."PERF_INCLUDE_PORTFOLIO",'xx')='Y')
      61 - access("A"."ENTRYCODE"="Z"."ENTRYCODE"(+))
      63 - access("CODE_IN"=SUBSTR("A"."ACCT",1,3))
      64 - access("CODE_TYPE"='NETFLOW')
           filter("CODE_TYPE"='NETFLOW')
      67 - access("A"."ACTVTYDATE">=TO_DATE(' 2011-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND "A"."ACTVTYDATE"<=TO_DATE(' 2011-09-30
                  00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
      69 - access("B"."ACCOUNTKEY"='11,,,'||"A"."ACCT")
      70 - access("A"."REPID"="K"."REPID"(+))
      72 - filter( EXISTS (SELECT 0 FROM DEV."SALES_REPORT_REP_MAPPING" "SALES_REPORT_REP_MAPPING" WHERE "REPID"=:B1 GROUP BY "REPID" HAVING
                  SUM(NVL("PCT",100))=100))
      74 - filter(SUM(NVL("PCT",100))=100)
      77 - access("REPID"=:B1)
      78 - access("A"."ACCOUNTKEY"='20,'||"B"."VENDOR_CD"||','||"B"."FUNDNO"||','||"B"."ACCT")
      79 - access("V"."VENDOR_CD"="B"."VENDOR_CD")
      80 - filter("V"."VENDOR_CD"<>'HNR' AND "V"."VENDOR_CD"<>'CNL' AND "V"."VENDOR_CD"<>'IRE' AND "V"."VENDOR_CD"<>'WLR' AND
                  "V"."VENDOR_CD"<>'WLP' AND "V"."VENDOR_CD"<>'PER' AND "V"."VENDOR_CD"<>'BHV')
      81 - access("SD"."CUSIP"="B"."CUSIP")
      83 - filter(NVL("E"."PERF_INCLUDE_PORTFOLIO",'xx')='Y')
      84 - access("B"."ENTRYCODE"="E"."ENTRYCODE"(+))
      87 - filter("B"."VENDOR_CD"<>'HNR' AND "B"."VENDOR_CD"<>'CNL' AND "B"."VENDOR_CD"<>'IRE' AND "B"."VENDOR_CD"<>'WLR' AND
                  "B"."VENDOR_CD"<>'WLP' AND "B"."VENDOR_CD"<>'PER' AND "B"."VENDOR_CD"<>'BHV')
      88 - access(SYS_OP_DESCEND("ACTVTYDATE")>=HEXTORAW('8790F6E1FEF8FEFAFF')  AND SYS_OP_DESCEND("ACTVTYDATE")<=HEXTORAW('8790FEF8FEF8FEFAFF')
           filter(SYS_OP_UNDESCEND(SYS_OP_DESCEND("ACTVTYDATE"))>=TO_DATE(' 2011-01-01 00:00:00', 'syyyy-mm-dd hh24:mi:ss') AND
                  SYS_OP_UNDESCEND(SYS_OP_DESCEND("ACTVTYDATE"))<=TO_DATE(' 2011-09-30 00:00:00', 'syyyy-mm-dd hh24:mi:ss'))
    158 rows selected.Thanks

    So this is a VIEW with I think 18 tables (I may have missed one or two), some of which are referenced more than one. Some of these tables have tens of miilions of rows. What exactly are you expecting from us?
    I guess this is a data warehouse or BI query. Sometimes such queries just take an age to run and there's nothing which can be done except result caching. Other times the queries can be tuned, but iit requires way more context and domain knowledge than you have provided.
    Please start by reading [url https://forums.oracle.com/forums/thread.jspa?threadID=2174552#9360003]this FAQ. .
    Cheers, APC

  • Need to tune the hierarchical query

    Hi Guys,
    Can you guys tune in the possible ways...as this is taking 30-40 sec.. No indexes on this table as of now.
    SELECT org_id,
           parent_id,
           organization,
    (SELECT LISTAGG(parent_id, ', ') WITHIN GROUP( ORDER BY org_id)
      FROM organization_master where org_id in(SELECT org_id
         FROM organization_master
         START WITH org_id = a.org_id
         CONNECT BY NOCYCLE prior parent_id = org_id))
          FROM t_org a
          WHERE upper(organization) like upper('%Greater%');
    Thanks in advance!
    Rgds,
    Lrk

    So this is a VIEW with I think 18 tables (I may have missed one or two), some of which are referenced more than one. Some of these tables have tens of miilions of rows. What exactly are you expecting from us?
    I guess this is a data warehouse or BI query. Sometimes such queries just take an age to run and there's nothing which can be done except result caching. Other times the queries can be tuned, but iit requires way more context and domain knowledge than you have provided.
    Please start by reading [url https://forums.oracle.com/forums/thread.jspa?threadID=2174552#9360003]this FAQ. .
    Cheers, APC

  • Need to tune the below query.

    Query below:
    I have generated the explain plan for the same and its cost is overall 2089...
    But Strange once I have removed the "ORDER SIBLINGS BY RETAILER_NM" from below then its cost is coming overall 40.
    Can U suggest me what is the best solution.
    SELECT path as Retailer_id, logical_physical_flg, parent_retailer_id, upper(retailer_nm), max_level
    FROM (SELECT A.RETAILER_ID,LOGICAL_PHYSICAL_FLG, NULL AS PARENT_RETAILER_ID, B.RETAILER_NM, a.retailer_id path,
    (LEVEL+2) AS MAX_LEVEL FROM
    RETAILER B, USER_RETAILER_MAP A WHERE USER_ID= 'ALEX.CAYLESS@GMACIO' AND
    B.RETAILER_ID=A.RETAILER_ID AND B.STATUS='ACTIVE' AND
    A.RETAILER_ID NOT IN (SELECT DISTINCT RETAILER_ID FROM
    RETAILER_HIERARCHY START WITH PARENT_RETAILER_ID IN (SELECT RETAILER_ID FROM USER_RETAILER_MAP A
    WHERE USER_ID= 'ALEX.CAYLESS@GMACIO' AND MANAGED_BY='Y') CONNECT BY PRIOR RETAILER_ID=PARENT_RETAILER_ID)
    AND MANAGED_BY='Y'
    UNION
    SELECT a.RETAILER_ID, LOGICAL_PHYSICAL_FLG, replace(sys_connect_by_path(decode(level, 1, a.parent_retailer_id), '~'), '~') parent_retailer_id, RETAILER_NM, LPAD(' ', 2*LEVEL-1)||SYS_CONNECT_BY_PATH(B.RETAILER_ID, '/') AS path, LEVEL+3 AS MAX_LEVEL
    FROM RETAILER B, RETAILER_HIERARCHY A
    WHERE B.RETAILER_ID=A.RETAILER_ID AND UPPER(B.STATUS)='ACTIVE' AND EXISTS
    (SELECT RETAILER_ID FROM USER_RETAILER_MAP C WHERE USER_ID = 'ALEX.CAYLESS@GMACIO' AND
    B.RETAILER_ID = C.RETAILER_ID AND MANAGED_BY= 'Y')
    START WITH PARENT_RETAILER_ID IN (SELECT A.RETAILER_ID FROM
    RETAILER B, USER_RETAILER_MAP A WHERE USER_ID= 'ALEX.CAYLESS@GMACIO' AND B.RETAILER_ID=A.RETAILER_ID
    AND UPPER(B.STATUS)='ACTIVE' AND A.RETAILER_ID NOT IN (SELECT DISTINCT RETAILER_ID FROM
    RETAILER_HIERARCHY START WITH PARENT_RETAILER_ID IN (SELECT RETAILER_ID FROM USER_RETAILER_MAP A
    WHERE USER_ID= 'ALEX.CAYLESS@GMACIO' AND MANAGED_BY='Y') CONNECT BY PRIOR RETAILER_ID=PARENT_RETAILER_ID)
    AND MANAGED_BY='Y') CONNECT BY PRIOR A.RETAILER_ID=PARENT_RETAILER_ID )
    START WITH PARENT_RETAILER_ID IS NULL CONNECT BY PRIOR RETAILER_ID = PARENT_RETAILER_ID
    ORDER SIBLINGS BY RETAILER_NM
    Explain Plan:
    ==========================
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 1352 | 5385K| 2089 |
    |* 1 | CONNECT BY WITH FILTERING | | | | |
    |* 2 | FILTER | | | | |
    | 3 | COUNT | | | | |
    | 4 | VIEW | | 1352 | 5385K| 40 |
    | 5 | SORT UNIQUE | | 1352 | 84128 | 40 |
    | 6 | UNION-ALL | | | | |
    |* 7 | HASH JOIN ANTI | | 16 | 1296 | 12 |
    |* 8 | HASH JOIN | | 19 | 1406 | 9 |
    | 9 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
    |* 10 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 2409 | | 1 |
    |* 11 | TABLE ACCESS FULL | RETAILER | 1594 | 70136 | 6 |
    | 12 | VIEW | VW_NSO_1 | 3 | 21 | 2 |
    |* 13 | CONNECT BY WITH FILTERING | | | | |
    | 14 | NESTED LOOPS | | | | |
    |* 15 | HASH JOIN | | 58 | 2262 | 5 |
    | 16 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
    |* 17 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
    | 18 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
    | 19 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
    | 20 | NESTED LOOPS | | | | |
    | 21 | BUFFER SORT | | 3 | 54 | |
    | 22 | CONNECT BY PUMP | | | | |
    |* 23 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
    |* 24 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |* 25 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    |* 26 | FILTER | | | | |
    |* 27 | CONNECT BY WITH FILTERING | | | | |
    |* 28 | FILTER | | | | |
    | 29 | COUNT | | | | |
    |* 30 | HASH JOIN | | 1336 | 82832 | 9 |
    | 31 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 1336 | 24048 | 2 |
    | 32 | TABLE ACCESS FULL | RETAILER | 3188 | 136K| 6 |
    | 33 | NESTED LOOPS ANTI | | 1 | 54 | 5 |
    | 34 | NESTED LOOPS | | 1 | 47 | 3 |
    |* 35 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |* 36 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    |* 37 | TABLE ACCESS BY INDEX ROWID | RETAILER | 1 | 17 | 1 |
    |* 38 | INDEX UNIQUE SCAN | XPKRETAILER | 100 | | |
    |* 39 | VIEW | VW_NSO_3 | 3 | 21 | |
    |* 40 | CONNECT BY WITH FILTERING | | | | |
    | 41 | NESTED LOOPS | | | | |
    |* 42 | HASH JOIN | | 58 | 2262 | 5 |
    | 43 | TABLE ACCESS BY INDEX ROWID| USER_RETAILER_MAP | 19 | 570 | 2 |
    |* 44 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
    | 45 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
    | 46 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
    | 47 | NESTED LOOPS | | | | |
    | 48 | BUFFER SORT | | 3 | 54 | |
    | 49 | CONNECT BY PUMP | | | | |
    |* 50 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
    |* 51 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |* 52 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    | 53 | HASH JOIN | | | | |
    | 54 | CONNECT BY PUMP | | | | |
    | 55 | COUNT | | | | |
    |* 56 | HASH JOIN | | 1336 | 82832 | 9 |
    | 57 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 1336 | 24048 | 2 |
    | 58 | TABLE ACCESS FULL | RETAILER | 3188 | 136K| 6 |
    | 59 | NESTED LOOPS ANTI | | 1 | 54 | 5 |
    | 60 | NESTED LOOPS | | 1 | 47 | 3 |
    |* 61 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |* 62 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    |* 63 | TABLE ACCESS BY INDEX ROWID | RETAILER | 1 | 17 | 1 |
    |* 64 | INDEX UNIQUE SCAN | XPKRETAILER | 100 | | |
    |* 65 | VIEW | VW_NSO_3 | 3 | 21 | |
    |* 66 | CONNECT BY WITH FILTERING | | | | |
    | 67 | NESTED LOOPS | | | | |
    |* 68 | HASH JOIN | | 58 | 2262 | 5 |
    | 69 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
    |* 70 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
    | 71 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
    | 72 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
    | 73 | NESTED LOOPS | | | | |
    | 74 | BUFFER SORT | | 3 | 54 | |
    | 75 | CONNECT BY PUMP | | | | |
    |* 76 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
    |* 77 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |* 78 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    |* 79 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |* 80 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    | 81 | HASH JOIN | | | | |
    | 82 | CONNECT BY PUMP | | | | |
    | 83 | COUNT | | | | |
    | 84 | VIEW | | 1352 | 5385K| 40 |
    | 85 | SORT UNIQUE | | 1352 | 84128 | 40 |
    | 86 | UNION-ALL | | | | |
    |* 87 | HASH JOIN ANTI | | 16 | 1296 | 12 |
    |* 88 | HASH JOIN | | 19 | 1406 | 9 |
    | 89 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
    |* 90 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 2409 | | 1 |
    |* 91 | TABLE ACCESS FULL | RETAILER | 1594 | 70136 | 6 |
    | 92 | VIEW | VW_NSO_1 | 3 | 21 | 2 |
    |* 93 | CONNECT BY WITH FILTERING | | | | |
    | 94 | NESTED LOOPS | | | | |
    |* 95 | HASH JOIN | | 58 | 2262 | 5 |
    | 96 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
    |* 97 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
    | 98 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
    | 99 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
    | 100 | NESTED LOOPS | | | | |
    | 101 | BUFFER SORT | | 3 | 54 | |
    | 102 | CONNECT BY PUMP | | | | |
    |*103 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
    |*104 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |*105 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    |*106 | FILTER | | | | |
    |*107 | CONNECT BY WITH FILTERING | | | | |
    |*108 | FILTER | | | | |
    | 109 | COUNT | | | | |
    |*110 | HASH JOIN | | 1336 | 82832 | 9 |
    | 111 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 1336 | 24048 | 2 |
    | 112 | TABLE ACCESS FULL | RETAILER | 3188 | 136K| 6 |
    | 113 | NESTED LOOPS ANTI | | 1 | 54 | 5 |
    | 114 | NESTED LOOPS | | 1 | 47 | 3 |
    |*115 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |*116 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    |*117 | TABLE ACCESS BY INDEX ROWID | RETAILER | 1 | 17 | 1 |
    |*118 | INDEX UNIQUE SCAN | XPKRETAILER | 100 | | |
    |*119 | VIEW | VW_NSO_3 | 3 | 21 | |
    |*120 | CONNECT BY WITH FILTERING | | | | |
    | 121 | NESTED LOOPS | | | | |
    |*122 | HASH JOIN | | 58 | 2262 | 5 |
    | 123 | TABLE ACCESS BY INDEX ROWID| USER_RETAILER_MAP | 19 | 570 | 2 |
    |*124 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
    | 125 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
    | 126 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
    | 127 | NESTED LOOPS | | | | |
    | 128 | BUFFER SORT | | 3 | 54 | |
    | 129 | CONNECT BY PUMP | | | | |
    |*130 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
    |*131 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |*132 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    | 133 | HASH JOIN | | | | |
    | 134 | CONNECT BY PUMP | | | | |
    | 135 | COUNT | | | | |
    |*136 | HASH JOIN | | 1336 | 82832 | 9 |
    | 137 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 1336 | 24048 | 2 |
    | 138 | TABLE ACCESS FULL | RETAILER | 3188 | 136K| 6 |
    | 139 | NESTED LOOPS ANTI | | 1 | 54 | 5 |
    | 140 | NESTED LOOPS | | 1 | 47 | 3 |
    |*141 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |*142 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    |*143 | TABLE ACCESS BY INDEX ROWID | RETAILER | 1 | 17 | 1 |
    |*144 | INDEX UNIQUE SCAN | XPKRETAILER | 100 | | |
    |*145 | VIEW | VW_NSO_3 | 3 | 21 | |
    |*146 | CONNECT BY WITH FILTERING | | | | |
    | 147 | NESTED LOOPS | | | | |
    |*148 | HASH JOIN | | 58 | 2262 | 5 |
    | 149 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 19 | 570 | 2 |
    |*150 | INDEX RANGE SCAN | INDX_USERID_MNGBY | 19 | | 1 |
    | 151 | INDEX FAST FULL SCAN | AX_RET_HIER | 1336 | 12024 | 2 |
    | 152 | TABLE ACCESS BY USER ROWID | RETAILER_HIERARCHY | | | |
    | 153 | NESTED LOOPS | | | | |
    | 154 | BUFFER SORT | | 3 | 54 | |
    | 155 | CONNECT BY PUMP | | | | |
    |*156 | INDEX FAST FULL SCAN | XPKRETAILER_HIERARCHY | 3 | 54 | 2 |
    |*157 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |*158 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    |*159 | TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP | 1 | 30 | 2 |
    |*160 | INDEX UNIQUE SCAN | XPKGSS_USER_RETAILER_MAP | 45770 | | 1 |
    Predicate Information (identified by operation id):
    1 - filter("from$_subquery$_001"."PARENT_RETAILER_ID" IS NULL)
    2 - filter("from$_subquery$_001"."PARENT_RETAILER_ID" IS NULL)
    7 - access("A"."RETAILER_ID"="VW_NSO_1"."$nso_col_1")
    8 - access("B"."RETAILER_ID"="A"."RETAILER_ID")
    10 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
    11 - filter("B"."STATUS"='ACTIVE')
    13 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A" WHERE "A"."USER_ID"='ALEX.CAYLES
    S@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY"='Y'))
    15 - access("RETAILER_HIERARCHY"."PARENT_RETAILER_ID"="A"."RETAILER_ID")
    17 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
    23 - filter("SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL)
    24 - filter("A"."MANAGED_BY"='Y')
    25 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
    26 - filter(UPPER("SYS_ALIAS_1"."STATUS")='ACTIVE' AND EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILE
    R_MAP" "C" WHERE "C"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "C"."RETAILER_ID"=:B1 AND "C"
    ."MANAGED_BY"='Y'))
    27 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A","RETAILER" "B", (SELECT /*+ */ "
    SYS_ALIAS_1"."RETAILER_ID" "$nso_col_1" FROM "RETAILER_HIERARCHY" "SYS_ALIAS_1" WHERE
    "SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL) "VW_NSO_3" WHERE "A"."RETAILER_ID"="VW_NSO_3"
    ."$nso_col_1" AND "B"."RETAILER_ID"="A"."RETAILER_ID" AND UPPER("B"."STATUS")='ACTIVE'
    AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY
    "='Y'))
    28 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A","RETAILER" "B", (SELECT /*+ */ "
    SYS_ALIAS_1"."RETAILER_ID" "$nso_col_1" FROM "RETAILER_HIERARCHY" "SYS_ALIAS_1" WHERE
    "SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL) "VW_NSO_3" WHERE "A"."RETAILER_ID"="VW_NSO_3"
    ."$nso_col_1" AND "B"."RETAILER_ID"="A"."RETAILER_ID" AND UPPER("B"."STATUS")='ACTIVE'
    AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY
    "='Y'))
    30 - access("SYS_ALIAS_1"."RETAILER_ID"="SYS_ALIAS_2"."RETAILER_ID")
    35 - filter("A"."MANAGED_BY"='Y')
    36 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
    37 - filter(UPPER("B"."STATUS")='ACTIVE')
    38 - access("B"."RETAILER_ID"="A"."RETAILER_ID")
    39 - filter("A"."RETAILER_ID"="VW_NSO_3"."$nso_col_1")
    40 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A" WHERE "A"."USER_ID"='ALEX.CAYLES
    S@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY"='Y'))
    42 - access("RETAILER_HIERARCHY"."PARENT_RETAILER_ID"="A"."RETAILER_ID")
    44 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
    50 - filter("SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL)
    51 - filter("A"."MANAGED_BY"='Y')
    52 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
    56 - access("SYS_ALIAS_1"."RETAILER_ID"="SYS_ALIAS_2"."RETAILER_ID")
    61 - filter("A"."MANAGED_BY"='Y')
    62 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
    63 - filter(UPPER("B"."STATUS")='ACTIVE')
    64 - access("B"."RETAILER_ID"="A"."RETAILER_ID")
    65 - filter("A"."RETAILER_ID"="VW_NSO_3"."$nso_col_1")
    66 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A" WHERE "A"."USER_ID"='ALEX.CAYLES
    S@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY"='Y'))
    68 - access("RETAILER_HIERARCHY"."PARENT_RETAILER_ID"="A"."RETAILER_ID")
    70 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
    76 - filter("SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL)
    77 - filter("A"."MANAGED_BY"='Y')
    78 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
    79 - filter("C"."MANAGED_BY"='Y')
    80 - access("C"."RETAILER_ID"=:B1 AND "C"."USER_ID"='ALEX.CAYLESS@GMACIO')
    87 - access("A"."RETAILER_ID"="VW_NSO_1"."$nso_col_1")
    88 - access("B"."RETAILER_ID"="A"."RETAILER_ID")
    90 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
    91 - filter("B"."STATUS"='ACTIVE')
    93 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A" WHERE "A"."USER_ID"='ALEX.CAYLES
    S@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY"='Y'))
    95 - access("RETAILER_HIERARCHY"."PARENT_RETAILER_ID"="A"."RETAILER_ID")
    97 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
    103 - filter("SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL)
    104 - filter("A"."MANAGED_BY"='Y')
    105 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
    106 - filter(UPPER("SYS_ALIAS_1"."STATUS")='ACTIVE' AND EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILE
    R_MAP" "C" WHERE "C"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "C"."RETAILER_ID"=:B1 AND "C"
    ."MANAGED_BY"='Y'))
    107 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A","RETAILER" "B", (SELECT /*+ */ "
    SYS_ALIAS_1"."RETAILER_ID" "$nso_col_1" FROM "RETAILER_HIERARCHY" "SYS_ALIAS_1" WHERE
    "SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL) "VW_NSO_3" WHERE "A"."RETAILER_ID"="VW_NSO_3"
    ."$nso_col_1" AND "B"."RETAILER_ID"="A"."RETAILER_ID" AND UPPER("B"."STATUS")='ACTIVE'
    AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY
    "='Y'))
    108 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A","RETAILER" "B", (SELECT /*+ */ "
    SYS_ALIAS_1"."RETAILER_ID" "$nso_col_1" FROM "RETAILER_HIERARCHY" "SYS_ALIAS_1" WHERE
    "SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL) "VW_NSO_3" WHERE "A"."RETAILER_ID"="VW_NSO_3"
    ."$nso_col_1" AND "B"."RETAILER_ID"="A"."RETAILER_ID" AND UPPER("B"."STATUS")='ACTIVE'
    AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY
    "='Y'))
    110 - access("SYS_ALIAS_1"."RETAILER_ID"="SYS_ALIAS_2"."RETAILER_ID")
    115 - filter("A"."MANAGED_BY"='Y')
    116 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
    117 - filter(UPPER("B"."STATUS")='ACTIVE')
    118 - access("B"."RETAILER_ID"="A"."RETAILER_ID")
    119 - filter("A"."RETAILER_ID"="VW_NSO_3"."$nso_col_1")
    120 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A" WHERE "A"."USER_ID"='ALEX.CAYLES
    S@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY"='Y'))
    122 - access("RETAILER_HIERARCHY"."PARENT_RETAILER_ID"="A"."RETAILER_ID")
    124 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
    130 - filter("SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL)
    131 - filter("A"."MANAGED_BY"='Y')
    132 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
    136 - access("SYS_ALIAS_1"."RETAILER_ID"="SYS_ALIAS_2"."RETAILER_ID")
    141 - filter("A"."MANAGED_BY"='Y')
    142 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
    143 - filter(UPPER("B"."STATUS")='ACTIVE')
    144 - access("B"."RETAILER_ID"="A"."RETAILER_ID")
    145 - filter("A"."RETAILER_ID"="VW_NSO_3"."$nso_col_1")
    146 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A" WHERE "A"."USER_ID"='ALEX.CAYLES
    S@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY"='Y'))
    148 - access("RETAILER_HIERARCHY"."PARENT_RETAILER_ID"="A"."RETAILER_ID")
    150 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')
    156 - filter("SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL)
    157 - filter("A"."MANAGED_BY"='Y')
    158 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')
    159 - filter("C"."MANAGED_BY"='Y')
    160 - access("C"."RETAILER_ID"=:B1 AND "C"."USER_ID"='ALEX.CAYLESS@GMACIO')
    Edited by: user13345267 on Jul 19, 2010 1:56 AM

    Please find formatted sql.
    SELECT path AS retailer_id,
           logical_physical_flg,
           parent_retailer_id,
           Upper(retailer_nm),
           max_level
    FROM   (SELECT a.retailer_id,
                   logical_physical_flg,
                   NULL          AS parent_retailer_id,
                   b.retailer_nm,
                   a.retailer_id path,
                   ( LEVEL + 2 ) AS max_level
            FROM   retailer b,
                   user_retailer_map a
            WHERE  user_id = 'ALEX.CAYLESS@GMACIO'
                   AND b.retailer_id = a.retailer_id
                   AND b.status = 'ACTIVE'
                   AND a.retailer_id NOT IN (SELECT DISTINCT retailer_id
                                             FROM   retailer_hierarchy
                                             START WITH parent_retailer_id IN (
                                                        SELECT
                                                        retailer_id
                                                                               FROM
                                                        user_retailer_map a
                                                                               WHERE
                                             user_id = 'ALEX.CAYLESS@GMACIO'
                                             AND managed_by = 'Y')
                                             CONNECT BY PRIOR
                                             retailer_id = parent_retailer_id)
                   AND managed_by = 'Y'
            UNION
            SELECT a.retailer_id,
                   logical_physical_flg,
                   Replace(Sys_connect_by_path(
                           Decode(LEVEL, 1, a.parent_retailer_id), '~')
                   '~')
                                                             parent_retailer_id,
                   retailer_nm,
                   Lpad(' ', 2 * LEVEL - 1)
                   ||Sys_connect_by_path(b.retailer_id, '/') AS path,
                   LEVEL + 3                                 AS max_level
            FROM   retailer b,
                   retailer_hierarchy a
            WHERE  b.retailer_id = a.retailer_id
                   AND Upper(b.status) = 'ACTIVE'
                   AND EXISTS (SELECT retailer_id
                               FROM   user_retailer_map c
                               WHERE  user_id = 'ALEX.CAYLESS@GMACIO'
                                      AND b.retailer_id = c.retailer_id
                                      AND managed_by = 'Y')
            START WITH parent_retailer_id IN (SELECT a.retailer_id
                                              FROM   retailer b,
                                                     user_retailer_map a
                                              WHERE  user_id = 'ALEX.CAYLESS@GMACIO'
                                                     AND
                                             b.retailer_id = a.retailer_id
                                                     AND Upper(b.status) = 'ACTIVE'
                                                     AND a.retailer_id NOT IN
                                                         (SELECT DISTINCT
                                                         retailer_id
                                                          FROM   retailer_hierarchy
                                             START WITH parent_retailer_id IN
                                                        SELECT
                                                        retailer_id
                                                        FROM
                                                        user_retailer_map a
                                                        WHERE
                                             user_id = 'ALEX.CAYLESS@GMACIO'
                                             AND managed_by = 'Y')
                                             CONNECT BY PRIOR
                                             retailer_id = parent_retailer_id)
                                                     AND managed_by = 'Y')
            CONNECT BY PRIOR a.retailer_id = parent_retailer_id)
    START WITH parent_retailer_id IS NULL
    CONNECT BY PRIOR retailer_id = parent_retailer_id
    ORDER SIBLINGS BY RETAILER_NM
    Execution Plan
    ====================================
    PLAN_TABLE_OUTPUT                                                                                                                  
    | Id  | Operation                                 |  Name                     | Rows  | Bytes | Cost  |                            
    |   0 | SELECT STATEMENT                          |                           |  1352 |  5385K|  2089 |                            
    |*  1 |  CONNECT BY WITH FILTERING                |                           |       |       |       |                            
    |*  2 |   FILTER                                  |                           |       |       |       |                            
    |   3 |    COUNT                                  |                           |       |       |       |                            
    |   4 |     VIEW                                  |                           |  1352 |  5385K|    40 |                            
    |   5 |      SORT UNIQUE                          |                           |  1352 | 84128 |    40 |                            
    |   6 |       UNION-ALL                           |                           |       |       |       |                            
    |*  7 |        HASH JOIN ANTI                     |                           |    16 |  1296 |    12 |                            
    |*  8 |         HASH JOIN                         |                           |    19 |  1406 |     9 |                            
    |   9 |          TABLE ACCESS BY INDEX ROWID      | USER_RETAILER_MAP         |    19 |   570 |     2 |                            
    |* 10 |           INDEX RANGE SCAN                | INDX_USERID_MNGBY         |    19 |       |     1 |                            
    |* 11 |          TABLE ACCESS FULL                | RETAILER                  |    32 |  1408 |     6 |                            
    |  12 |         VIEW                              | VW_NSO_1                  |     3 |    21 |     2 |                            
    |* 13 |          CONNECT BY WITH FILTERING        |                           |       |       |       |                            
    |  14 |           NESTED LOOPS                    |                           |       |       |       |                            
    |* 15 |            HASH JOIN                      |                           |    58 |  2262 |     5 |                            
    |  16 |             TABLE ACCESS BY INDEX ROWID   | USER_RETAILER_MAP         |    19 |   570 |     2 |                            
    |* 17 |              INDEX RANGE SCAN             | INDX_USERID_MNGBY         |    19 |       |     1 |                            
    |  18 |             INDEX FAST FULL SCAN          | AX_RET_HIER               |  1336 | 12024 |     2 |                            
    |  19 |            TABLE ACCESS BY USER ROWID     | RETAILER_HIERARCHY        |       |       |       |                            
    |  20 |           NESTED LOOPS                    |                           |       |       |       |                            
    |  21 |            BUFFER SORT                    |                           |     3 |    54 |       |                            
    |  22 |             CONNECT BY PUMP               |                           |       |       |       |                            
    |* 23 |            INDEX FAST FULL SCAN           | XPKRETAILER_HIERARCHY     |     3 |    54 |     2 |                            
    |* 24 |           TABLE ACCESS BY INDEX ROWID     | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |* 25 |            INDEX UNIQUE SCAN              | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    |* 26 |        FILTER                             |                           |       |       |       |                            
    |* 27 |         CONNECT BY WITH FILTERING         |                           |       |       |       |                            
    |* 28 |          FILTER                           |                           |       |       |       |                            
    |  29 |           COUNT                           |                           |       |       |       |                            
    |* 30 |            HASH JOIN                      |                           |  1336 | 82832 |     9 |                            
    |  31 |             INDEX FAST FULL SCAN          | XPKRETAILER_HIERARCHY     |  1336 | 24048 |     2 |                            
    |  32 |             TABLE ACCESS FULL             | RETAILER                  |  3188 |   136K|     6 |                            
    |  33 |           NESTED LOOPS ANTI               |                           |     1 |    54 |     5 |                            
    |  34 |            NESTED LOOPS                   |                           |     1 |    47 |     3 |                            
    |* 35 |             TABLE ACCESS BY INDEX ROWID   | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |* 36 |              INDEX UNIQUE SCAN            | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    |* 37 |             TABLE ACCESS BY INDEX ROWID   | RETAILER                  |     1 |    17 |     1 |                            
    |* 38 |              INDEX UNIQUE SCAN            | XPKRETAILER               |   100 |       |       |                            
    |* 39 |            VIEW                           | VW_NSO_3                  |     3 |    21 |       |                            
    |* 40 |             CONNECT BY WITH FILTERING     |                           |       |       |       |                            
    |  41 |              NESTED LOOPS                 |                           |       |       |       |                            
    |* 42 |               HASH JOIN                   |                           |    58 |  2262 |     5 |                            
    |  43 |                TABLE ACCESS BY INDEX ROWID| USER_RETAILER_MAP         |    19 |   570 |     2 |                            
    |* 44 |                 INDEX RANGE SCAN          | INDX_USERID_MNGBY         |    19 |       |     1 |                            
    |  45 |                INDEX FAST FULL SCAN       | AX_RET_HIER               |  1336 | 12024 |     2 |                            
    |  46 |               TABLE ACCESS BY USER ROWID  | RETAILER_HIERARCHY        |       |       |       |                            
    |  47 |              NESTED LOOPS                 |                           |       |       |       |                            
    |  48 |               BUFFER SORT                 |                           |     3 |    54 |       |                            
    |  49 |                CONNECT BY PUMP            |                           |       |       |       |                            
    |* 50 |               INDEX FAST FULL SCAN        | XPKRETAILER_HIERARCHY     |     3 |    54 |     2 |                            
    |* 51 |              TABLE ACCESS BY INDEX ROWID  | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |* 52 |               INDEX UNIQUE SCAN           | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    |  53 |          HASH JOIN                        |                           |       |       |       |                            
    |  54 |           CONNECT BY PUMP                 |                           |       |       |       |                            
    |  55 |           COUNT                           |                           |       |       |       |                            
    |* 56 |            HASH JOIN                      |                           |  1336 | 82832 |     9 |                            
    |  57 |             INDEX FAST FULL SCAN          | XPKRETAILER_HIERARCHY     |  1336 | 24048 |     2 |                            
    |  58 |             TABLE ACCESS FULL             | RETAILER                  |  3188 |   136K|     6 |                            
    |  59 |          NESTED LOOPS ANTI                |                           |     1 |    54 |     5 |                            
    |  60 |           NESTED LOOPS                    |                           |     1 |    47 |     3 |                            
    |* 61 |            TABLE ACCESS BY INDEX ROWID    | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |* 62 |             INDEX UNIQUE SCAN             | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    |* 63 |            TABLE ACCESS BY INDEX ROWID    | RETAILER                  |     1 |    17 |     1 |                            
    |* 64 |             INDEX UNIQUE SCAN             | XPKRETAILER               |   100 |       |       |                            
    |* 65 |           VIEW                            | VW_NSO_3                  |     3 |    21 |       |                            
    |* 66 |            CONNECT BY WITH FILTERING      |                           |       |       |       |                            
    |  67 |             NESTED LOOPS                  |                           |       |       |       |                            
    |* 68 |              HASH JOIN                    |                           |    58 |  2262 |     5 |                            
    |  69 |               TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP         |    19 |   570 |     2 |                            
    |* 70 |                INDEX RANGE SCAN           | INDX_USERID_MNGBY         |    19 |       |     1 |                            
    |  71 |               INDEX FAST FULL SCAN        | AX_RET_HIER               |  1336 | 12024 |     2 |                            
    |  72 |              TABLE ACCESS BY USER ROWID   | RETAILER_HIERARCHY        |       |       |       |                            
    |  73 |             NESTED LOOPS                  |                           |       |       |       |                            
    |  74 |              BUFFER SORT                  |                           |     3 |    54 |       |                            
    |  75 |               CONNECT BY PUMP             |                           |       |       |       |                            
    |* 76 |              INDEX FAST FULL SCAN         | XPKRETAILER_HIERARCHY     |     3 |    54 |     2 |                            
    |* 77 |             TABLE ACCESS BY INDEX ROWID   | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |* 78 |              INDEX UNIQUE SCAN            | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    |* 79 |         TABLE ACCESS BY INDEX ROWID       | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |* 80 |          INDEX UNIQUE SCAN                | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    |  81 |   HASH JOIN                               |                           |       |       |       |                            
    |  82 |    CONNECT BY PUMP                        |                           |       |       |       |                            
    |  83 |    COUNT                                  |                           |       |       |       |                            
    |  84 |     VIEW                                  |                           |  1352 |  5385K|    40 |                            
    |  85 |      SORT UNIQUE                          |                           |  1352 | 84128 |    40 |                            
    |  86 |       UNION-ALL                           |                           |       |       |       |                            
    |* 87 |        HASH JOIN ANTI                     |                           |    16 |  1296 |    12 |                            
    |* 88 |         HASH JOIN                         |                           |    19 |  1406 |     9 |                            
    |  89 |          TABLE ACCESS BY INDEX ROWID      | USER_RETAILER_MAP         |    19 |   570 |     2 |                            
    |* 90 |           INDEX RANGE SCAN                | INDX_USERID_MNGBY         |    19 |       |     1 |                            
    |* 91 |          TABLE ACCESS FULL                | RETAILER                  |    32 |  1408 |     6 |                            
    |  92 |         VIEW                              | VW_NSO_1                  |     3 |    21 |     2 |                            
    |* 93 |          CONNECT BY WITH FILTERING        |                           |       |       |       |                            
    |  94 |           NESTED LOOPS                    |                           |       |       |       |                            
    |* 95 |            HASH JOIN                      |                           |    58 |  2262 |     5 |                            
    |  96 |             TABLE ACCESS BY INDEX ROWID   | USER_RETAILER_MAP         |    19 |   570 |     2 |                            
    |* 97 |              INDEX RANGE SCAN             | INDX_USERID_MNGBY         |    19 |       |     1 |                            
    |  98 |             INDEX FAST FULL SCAN          | AX_RET_HIER               |  1336 | 12024 |     2 |                            
    |  99 |            TABLE ACCESS BY USER ROWID     | RETAILER_HIERARCHY        |       |       |       |                            
    | 100 |           NESTED LOOPS                    |                           |       |       |       |                            
    | 101 |            BUFFER SORT                    |                           |     3 |    54 |       |                            
    | 102 |             CONNECT BY PUMP               |                           |       |       |       |                            
    |*103 |            INDEX FAST FULL SCAN           | XPKRETAILER_HIERARCHY     |     3 |    54 |     2 |                            
    |*104 |           TABLE ACCESS BY INDEX ROWID     | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |*105 |            INDEX UNIQUE SCAN              | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    |*106 |        FILTER                             |                           |       |       |       |                            
    |*107 |         CONNECT BY WITH FILTERING         |                           |       |       |       |                            
    |*108 |          FILTER                           |                           |       |       |       |                            
    | 109 |           COUNT                           |                           |       |       |       |                            
    |*110 |            HASH JOIN                      |                           |  1336 | 82832 |     9 |                            
    | 111 |             INDEX FAST FULL SCAN          | XPKRETAILER_HIERARCHY     |  1336 | 24048 |     2 |                            
    | 112 |             TABLE ACCESS FULL             | RETAILER                  |  3188 |   136K|     6 |                            
    | 113 |           NESTED LOOPS ANTI               |                           |     1 |    54 |     5 |                            
    | 114 |            NESTED LOOPS                   |                           |     1 |    47 |     3 |                            
    |*115 |             TABLE ACCESS BY INDEX ROWID   | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |*116 |              INDEX UNIQUE SCAN            | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    |*117 |             TABLE ACCESS BY INDEX ROWID   | RETAILER                  |     1 |    17 |     1 |                            
    |*118 |              INDEX UNIQUE SCAN            | XPKRETAILER               |   100 |       |       |                            
    |*119 |            VIEW                           | VW_NSO_3                  |     3 |    21 |       |                            
    |*120 |             CONNECT BY WITH FILTERING     |                           |       |       |       |                            
    | 121 |              NESTED LOOPS                 |                           |       |       |       |                            
    |*122 |               HASH JOIN                   |                           |    58 |  2262 |     5 |                            
    | 123 |                TABLE ACCESS BY INDEX ROWID| USER_RETAILER_MAP         |    19 |   570 |     2 |                            
    |*124 |                 INDEX RANGE SCAN          | INDX_USERID_MNGBY         |    19 |       |     1 |                            
    | 125 |                INDEX FAST FULL SCAN       | AX_RET_HIER               |  1336 | 12024 |     2 |                            
    | 126 |               TABLE ACCESS BY USER ROWID  | RETAILER_HIERARCHY        |       |       |       |                            
    | 127 |              NESTED LOOPS                 |                           |       |       |       |                            
    | 128 |               BUFFER SORT                 |                           |     3 |    54 |       |                            
    | 129 |                CONNECT BY PUMP            |                           |       |       |       |                            
    |*130 |               INDEX FAST FULL SCAN        | XPKRETAILER_HIERARCHY     |     3 |    54 |     2 |                            
    |*131 |              TABLE ACCESS BY INDEX ROWID  | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |*132 |               INDEX UNIQUE SCAN           | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    | 133 |          HASH JOIN                        |                           |       |       |       |                            
    | 134 |           CONNECT BY PUMP                 |                           |       |       |       |                            
    | 135 |           COUNT                           |                           |       |       |       |                            
    |*136 |            HASH JOIN                      |                           |  1336 | 82832 |     9 |                            
    | 137 |             INDEX FAST FULL SCAN          | XPKRETAILER_HIERARCHY     |  1336 | 24048 |     2 |                            
    | 138 |             TABLE ACCESS FULL             | RETAILER                  |  3188 |   136K|     6 |                            
    | 139 |          NESTED LOOPS ANTI                |                           |     1 |    54 |     5 |                            
    | 140 |           NESTED LOOPS                    |                           |     1 |    47 |     3 |                            
    |*141 |            TABLE ACCESS BY INDEX ROWID    | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |*142 |             INDEX UNIQUE SCAN             | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    |*143 |            TABLE ACCESS BY INDEX ROWID    | RETAILER                  |     1 |    17 |     1 |                            
    |*144 |             INDEX UNIQUE SCAN             | XPKRETAILER               |   100 |       |       |                            
    |*145 |           VIEW                            | VW_NSO_3                  |     3 |    21 |       |                            
    |*146 |            CONNECT BY WITH FILTERING      |                           |       |       |       |                            
    | 147 |             NESTED LOOPS                  |                           |       |       |       |                            
    |*148 |              HASH JOIN                    |                           |    58 |  2262 |     5 |                            
    | 149 |               TABLE ACCESS BY INDEX ROWID | USER_RETAILER_MAP         |    19 |   570 |     2 |                            
    |*150 |                INDEX RANGE SCAN           | INDX_USERID_MNGBY         |    19 |       |     1 |                            
    | 151 |               INDEX FAST FULL SCAN        | AX_RET_HIER               |  1336 | 12024 |     2 |                            
    | 152 |              TABLE ACCESS BY USER ROWID   | RETAILER_HIERARCHY        |       |       |       |                            
    | 153 |             NESTED LOOPS                  |                           |       |       |       |                            
    | 154 |              BUFFER SORT                  |                           |     3 |    54 |       |                            
    | 155 |               CONNECT BY PUMP             |                           |       |       |       |                            
    |*156 |              INDEX FAST FULL SCAN         | XPKRETAILER_HIERARCHY     |     3 |    54 |     2 |                            
    |*157 |             TABLE ACCESS BY INDEX ROWID   | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |*158 |              INDEX UNIQUE SCAN            | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    |*159 |         TABLE ACCESS BY INDEX ROWID       | USER_RETAILER_MAP         |     1 |    30 |     2 |                            
    |*160 |          INDEX UNIQUE SCAN                | XPKGSS_USER_RETAILER_MAP  | 45770 |       |     1 |                            
    Predicate Information (identified by operation id):                                                                                
       1 - filter("from$_subquery$_001"."PARENT_RETAILER_ID" IS NULL)                                                                  
       2 - filter("from$_subquery$_001"."PARENT_RETAILER_ID" IS NULL)                                                                  
       7 - access("A"."RETAILER_ID"="VW_NSO_1"."$nso_col_1")                                                                           
       8 - access("B"."RETAILER_ID"="A"."RETAILER_ID")                                                                                 
      10 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')                                                        
      11 - filter("B"."STATUS"='ACTIVE')                                                                                               
      13 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A" WHERE "A"."USER_ID"='ALEX.CAYLES                               
                  S@GMACIO' AND "A"."RETAILER_ID"=:B1 AND "A"."MANAGED_BY"='Y'))                                                       
      15 - access("RETAILER_HIERARCHY"."PARENT_RETAILER_ID"="A"."RETAILER_ID")                                                         
      17 - access("A"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "A"."MANAGED_BY"='Y')                                                        
      23 - filter("SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL)                                                                             
      24 - filter("A"."MANAGED_BY"='Y')                                                                                                
      25 - access("A"."RETAILER_ID"=:B1 AND "A"."USER_ID"='ALEX.CAYLESS@GMACIO')                                                       
      26 - filter(UPPER("SYS_ALIAS_1"."STATUS")='ACTIVE' AND  EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILE                               
                  R_MAP" "C" WHERE "C"."USER_ID"='ALEX.CAYLESS@GMACIO' AND "C"."RETAILER_ID"=:B1 AND "C"                               
                  ."MANAGED_BY"='Y'))                                                                                                  
      27 - filter( EXISTS (SELECT /*+ */ 0 FROM "USER_RETAILER_MAP" "A","RETAILER" "B", (SELECT /*+ */ "                               
                  SYS_ALIAS_1"."RETAILER_ID" "$nso_col_1" FROM "RETAILER_HIERARCHY" "SYS_ALIAS_1" WHERE                                
                  "SYS_ALIAS_1"."PARENT_RETAILER_ID"=NULL) "VW_NSO_3" WHERE "A"."RETAILER_ID"="VW_NSO_3"                               
                  ."$nso_col_1" AND "B"."RETAILER_ID"="A"."RETAILER_ID" AND UPPER("B"."STATUS")='ACTIVE'                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 

  • Do i need to tune the redolog?

    10g R2 on AIX 5.3L
    this is a typical alert file about the redo log file switching of the day.
    Mon May 28 01:26:33 2007
    Thread 1 advanced to log sequence 24017
    Current log# 4 seq# 24017 mem# 0: /u020/apps/oracle/oradata/BAAN/redo04.log
    Mon May 28 08:04:13 2007
    Thread 1 advanced to log sequence 24018
    Current log# 5 seq# 24018 mem# 0: /u020/apps/oracle/oradata/BAAN/redo05.log
    Mon May 28 08:05:56 2007
    Thread 1 advanced to log sequence 24019
    Current log# 3 seq# 24019 mem# 0: /u020/apps/oracle/oradata/BAAN/redo03.log
    Mon May 28 08:07:29 2007
    Thread 1 advanced to log sequence 24020
    Current log# 2 seq# 24020 mem# 0: /u020/apps/oracle/oradata/BAAN/redo02.log
    Mon May 28 08:08:55 2007
    Thread 1 advanced to log sequence 24021
    Current log# 1 seq# 24021 mem# 0: /u020/apps/oracle/oradata/BAAN/redo01.log
    Mon May 28[b] 08:10:26 2007
    Thread 1 advanced to log sequence 24022
    Current log# 4 seq# 24022 mem# 0: /u020/apps/oracle/oradata/BAAN/redo04.log
    Mon May 28 08:12:05 2007
    Thread 1 advanced to log sequence 24023
    Current log# 5 seq# 24023 mem# 0: /u020/apps/oracle/oradata/BAAN/redo05.log
    Mon May 28 08:13:55 2007
    Thread 1 advanced to log sequence 24024
    Current log# 3 seq# 24024 mem# 0: /u020/apps/oracle/oradata/BAAN/redo03.log
    Mon May 28 11:31:05 2007
    Thread 1 advanced to log sequence 24025
    Current log# 2 seq# 24025 mem# 0: /u020/apps/oracle/oradata/BAAN/redo02.log
    Mon May 28 14:36:13 2007
    Thread 1 advanced to log sequence 24026
    Current log# 1 seq# 24026 mem# 0: /u020/apps/oracle/oradata/BAAN/redo01.log
    Do I need to tune the redo log? Each of redo log file is 50MB. It switched more frequent when there are not many users than real busy hours.
    null

    Select may or may not generate redo. Delayed block cleanout is one of the reasons for a query to produce redo: https://metalink.oracle.com/metalink/plsql/f?p=130:14:2631437878498686237::::p14_database_id,p14_docid,p14_show_header,p14_show_help,p14_black_frame,p14_font:NOT,40689.1,1,1,1,helvetica#aref1
    Another reason is locking the rows with "for update":
    SQL> create table t1 as select * from all_objects;
    Table created.
    SQL> set autot trace stat
    SQL> select * from t1;
    39310 rows selected.
    Statistics
              0  recursive calls
              0  db block gets
           3117  consistent gets
            538  physical reads
              0  redo size
        2524195  bytes sent via SQL*Net to client
          18612  bytes received via SQL*Net from client
           2622  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          39310  rows processed
    SQL> select * from t1 for update;
    39310 rows selected.
    Statistics
             24  recursive calls
          40020  db block gets
          43446  consistent gets
            625  physical reads
        7754052  redo size
        3501635  bytes sent via SQL*Net to client
          18612  bytes received via SQL*Net from client
           2622  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
          39310  rows processed

  • I have several macs with Intel core duo 2 operating systems. All are running os x10.6.8. Is it necessary to upgrade to Lion before upgrading to mountain lion when it comes out this summer? Do I need to have the "base" version of 10.7?

    I have several macs with Intel core duo 2 operating systems. All are running os x 10.6.8. Is it necessary to upgrade to Lion before upgrading to Mountain Lion when it appears this summer? Do I need to have the "base" version of 10.7 first?

    This is unknown, it will be up to Apple and AFAIK they haven't announced that yet.

  • I have an old Airport Extreme that I want to password protect. I being told that Airport Utility 5.6 is needed to manage the base station. When I download it and try to install that utility I told that it is not compatible with OS X 10.7.4

    I have an old Airport Extreme that I want to password protect. I being told that Airport Utility 5.6 is needed to manage the base station. When I download it and try to install that utility I told that it is not compatible with OS X 10.7.4

    The odds are that you downloaded AirPort Utility 5.6.1.....which will only work with Leopard and Snow Leopard Macs.
    Since your post indicates that you are using Lion 10.7.4, you need the correct utility for Lion. The link is below:
    AirPort Utility 5.6 for Mac OS X Lion

  • Modify query used in Materialized View

    Are there any ways to modify the query used in materialized view without dropping the materialized view. I dont think alter materialized view has such an option.
    Please provider me your suggestions.

    you have to give "ENABLE QUERY REWRITE" option then u can change your query

  • Needs to tune the query

    Hi ,
    I have a Query that needs to be tuned.
    The query joins two views with some filter condition.
    While running the individual view query with the filter condition i can able to get the results quickly within a seconds.
    But while joining the views conditions of the same criteria which i have used for the individual query takes more than 30 minute.
    i am struggling to tuning this query which was written using the views.
    Note :
    My problem is while checking the explain plan unique sort is taking more cost.
    is that i can reduce the time by giving some optimizer hints to reduce the unique sort cost for query using views?
    Thanks & regards,
    Senthur pandi M

    Hi,
    BluShadow wrote:
    957595 wrote:
    Hi ,
    I have a Query that needs to be tuned.
    The query joins two views with some filter condition.
    While running the individual view query with the filter condition i can able to get the results quickly within a seconds.
    But while joining the views conditions of the same criteria which i have used for the individual query takes more than 30 minute.
    i am struggling to tuning this query which was written using the views.
    Note :
    My problem is while checking the explain plan unique sort is taking more cost.Cost in not necessarily a good comparison to use. The cost is a figure determined on a per-query basis,The problem with cost is that it's a prediction made by the optimizer, rather than the actual measure of query performance. Optimizer often makes mistakes about expected query performance. Ironically, people normally look at query cost when it needs tuning, i.e. when the chance that optimizer made a mistake is especially high.
    In many internet forums one can see claims that cost estimates are meaningless across different queries. Such claims are unfounded. When calculated correctly, cost is quite meaningful, and in such cases there is nothing wrong about comparing cost not only for different queries, but also for different databases (if they have same optimizer settings and system stats).
    is that i can reduce the time by giving some optimizer hints to reduce the unique sort cost for query using views?Hints are not the way to improve performance. That's an overstatement. The sad truth is that in many cases there is no viable alternative to using hints. Rather than always avoid hints no matter what cost, it's better to understand how hints affect optimizer behavior, and when it's safe to use them.
    They are great for identifying where the cause of a performance issue is, but shouldn't be used in production code, as it would be like saying that you know better than Oracle how to retrieve the data, not just now, but in the future as more
    data is added and as data is deleted and replaced with new data etc. By adding hints you are effectively forcing the optimizer to execute the query in a particular way, which may be fast now, but in the future may be worse than what the optimizer can determine itself.Hints that force the optimizer to use a specific access path or a specific join method are dangerous -- because the only lock-in one part of the plan, but not the entire plan (e.g. INDEX hint only ensures that an index is used if possible, but it cannot ensure INDEX UNIQUE/RANGE SCAN, so you may end up in a situation when the optimizer is doing an expensive and meaningless INDEX FULL SCAN because of the hint that was indended to force a different, more selective, access method).
    Hints that don't do that, but rather prevent the optimizer from trying to be smart when it's better to keep things simple, are relatively safe.
    So, use the hints to identify where there are issues in the SQL or in the database design, and fix those issues, rather than leave hints in production code.As a general rule, sure. Here, however, the problem seems to be obvious -- if views are fast separately, and slow when joined, that suggests that the optimizer doesn't merge them correctly.
    Best regards,
    Nikolay

  • Tune the SQL Query need a Suggestion

    Hi,
    There is a view created which takes 17seconds to execute the query, When i split the query and execute each query takes .15 seconds to execute. Below it the query which i need to improve the performance of the code please need your suggestion in order to tweek so that time take for execution become less
    SELECT 'Parature' "Source",
    NULL "Distibutor",
    reseller_name "Reseller",
    NULL "Reseller City",
    NULL "Reseller State",
    A.Country "Reseller Country",
    DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
    NULL "Customer Name",
    NULL "Customer City",
    NULL "Customer State",
    NULL "Customer Country",
    NULL "Customer Theater",
    NULL "Sales Book Date",
    NULL "Ship Date",
    c.sales_order_number "Sales Order Number",
    C.Po_Number "PO Number",
    controller_model_number_1 "Product Name",
    TRIM (UPPER (serial_number_1)) "Product Serial Number",
    c.contract_id "Contract ID",
    product_name "Support Name",
    TO_DATE (c.contract_purchase_date) "Start Date",
    TO_DATE (c.contract_expiration_date) "Expire Date",
    NULL "Header Status",
    NULL "Line Status",
    NULL "Line Type",
    NULL "Termination Reason",
    NULL "Location_id",
    NULL "Product_id"
    FROM edb_assets c,
    edb_accounts a
    WHERE controller_model_number_1 != 'NULL'
    AND Serial_Number_1 != 'NULL'
    AND C.Amid = A.Amid(+)
    UNION
    SELECT 'Parature' "Source",
    NULL "Distibutor",
    reseller_name "Reseller",
    NULL "Reseller City",
    NULL "Reseller State",
    A.Country "Reseller Country",
    DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
    NULL "Customer Name",
    NULL "Customer City",
    NULL "Customer State",
    NULL "Customer Country",
    NULL "Customer Theater",
    NULL "Sales Book Date",
    NULL "Ship Date",
    c.sales_order_number "Sales Order Number",
    C.Po_Number "PO Number",
    controller_model_number_2 "Product Name",
    TRIM (UPPER (serial_number_2)) "Product Serial Number",
    c.contract_id "Contract ID",
    product_name "Support Name",
    TO_DATE (c.contract_purchase_date) "Start Date",
    TO_DATE (c.contract_expiration_date) "Expire Date",
    NULL "Header Status",
    NULL "Line Status",
    NULL "Line Type",
    NULL "Termination Reason",
    NULL "Location_id",
    NULL "Product_id"
    FROM edb_assets c,
    edb_accounts a
    WHERE controller_model_number_2 != 'NULL'
    AND serial_number_2 != 'NULL'
    AND C.Amid = A.Amid(+)
    UNION
    SELECT 'Parature' "Source",
    NULL "Distibutor",
    reseller_name "Reseller",
    NULL "Reseller City",
    NULL "Reseller State",
    A.Country "Reseller Country",
    DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
    NULL "Customer Name",
    NULL "Customer City",
    NULL "Customer State",
    NULL "Customer Country",
    NULL "Customer Theater",
    NULL "Sales Book Date",
    NULL "Ship Date",
    c.sales_order_number "Sales Order Number",
    C.Po_Number "PO Number",
    controller_model_number_3 "Product Name",
    TRIM (UPPER (serial_number_3)) "Product Serial Number",
    c.contract_id "Contract ID",
    product_name "Support Name",
    TO_DATE (c.contract_purchase_date) "Start Date",
    TO_DATE (c.contract_expiration_date) "Expire Date",
    NULL "Header Status",
    NULL "Line Status",
    NULL "Line Type",
    NULL "Termination Reason",
    NULL "Location_id",
    NULL "Product_id"
    FROM edb_assets c,
    edb_accounts a
    WHERE controller_model_number_3 != 'NULL'
    AND serial_number_3 != 'NULL'
    AND C.Amid = A.Amid(+)
    UNION
    SELECT 'Parature' "Source",
    NULL "Distibutor",
    reseller_name "Reseller",
    NULL "Reseller City",
    NULL "Reseller State",
    A.Country "Reseller Country",
    DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
    NULL "Customer Name",
    NULL "Customer City",
    NULL "Customer State",
    NULL "Customer Country",
    NULL "Customer Theater",
    NULL "Sales Book Date",
    NULL "Ship Date",
    c.sales_order_number "Sales Order Number",
    C.Po_Number "PO Number",
    controller_model_number_4 "Product Name",
    TRIM (UPPER (serial_number_4)) "Product Serial Number",
    c.contract_id "Contract ID",
    product_name "Support Name",
    TO_DATE (c.contract_purchase_date) "Start Date",
    TO_DATE (c.contract_expiration_date) "Expire Date",
    NULL "Header Status",
    NULL "Line Status",
    NULL "Line Type",
    NULL "Termination Reason",
    NULL "Location_id",
    NULL "Product_id"
    FROM edb_assets c,
    edb_accounts a
    WHERE controller_model_number_4 != 'NULL'
    AND serial_number_4 != 'NULL'
    AND C.Amid = A.Amid(+)
    UNION
    SELECT 'Parature' "Source",
    NULL "Distibutor",
    reseller_name "Reseller",
    NULL "Reseller City",
    NULL "Reseller State",
    A.Country "Reseller Country",
    DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
    NULL "Customer Name",
    NULL "Customer City",
    NULL "Customer State",
    NULL "Customer Country",
    NULL "Customer Theater",
    NULL "Sales Book Date",
    NULL "Ship Date",
    c.sales_order_number "Sales Order Number",
    C.Po_Number "PO Number",
    controller_model_number_5 "Product Name",
    TRIM (UPPER (serial_number_5)) "Product Serial Number",
    c.contract_id "Contract ID",
    product_name "Support Name",
    TO_DATE (c.contract_purchase_date) "Start Date",
    TO_DATE (c.contract_expiration_date) "Expire Date",
    NULL "Header Status",
    NULL "Line Status",
    NULL "Line Type",
    NULL "Termination Reason",
    NULL "Location_id",
    NULL "Product_id"
    FROM edb_assets c,
    edb_accounts a
    WHERE controller_model_number_5 != 'NULL'
    AND serial_number_5 != 'NULL'
    AND C.Amid = A.Amid(+)
    UNION
    SELECT 'ERP' "Source",
    Imv.Bill_To "Distibutor",
    Imv.Ship_To "Reseller",
    Ship_To_City "Reseller City",
    Ship_To_State "Reseller State",
    Edb2_Global.Country_Name_Theater(Imv.Ship_To_Country ,'COUNTRY') "Reseller Country",
    Edb2_Global.Country_Name_Theater(Imv.Ship_To_Country ,'THEATER') "Reseller Theater",
    Cl.Company_Name "Customer Name",
    Cl.City "Customer City",
    Cl.State "Customer State",
    Edb2_Global.Country_Name_Theater(Cl.Country,'COUNTRY') "Customer Country",
    Edb2_Global.Country_Name_Theater(Cl.Country,'THEATER') "Customer Theater",
    Imv.So_Booked_Date "Sales Book Date",
    Imv.Ship_Date "Ship Date",
    Imv.Order_Number "Sales Order Number",
    Imv.Cust_Po_Number "PO Number",
    Cp.Item_Name "Product Name",
    Cp.Product_Serial_Number "Product Serial Number",
    TO_CHAR(Imv.contract_number)"Contract ID",
    Imv.Service_Description "Support Name",
    Imv.Service_Start_Date "Start Date",
    Imv.Service_End_Date "Expire Date",
    Imv.Header_Status "Header Status",
    Imv.Line_Status "Line Status",
    Imv.Line_Type "Line Type",
    Imv.Termination_Reason "Termination Reason",
    Cl.Location_Id "Location_id",
    cp.id "Product_id"
    FROM ib_support_contracts_mv imv,
    customer_products cp,
    customer_locations cl
    WHERE Upper (Trim (Imv.Serial_Number)) = Upper (Trim (Cp.Product_Serial_Number(+)))
    AND Cp.Location_Id = Cl.Location_Id(+)
    There is a union for each and every query, Please suggest how to tweek
    Thanks
    Sudhir

    Try
    select distinct a.*
    from (SELECT 'Parature' "Source",
    NULL "Distibutor",
    reseller_name "Reseller",
    NULL "Reseller City",
    NULL "Reseller State",
    A.Country "Reseller Country",
    DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
    NULL "Customer Name",
    NULL "Customer City",
    NULL "Customer State",
    NULL "Customer Country",
    NULL "Customer Theater",
    NULL "Sales Book Date",
    NULL "Ship Date",
    c.sales_order_number "Sales Order Number",
    C.Po_Number "PO Number",
    controller_model_number_1 "Product Name",
    TRIM (UPPER (serial_number_1)) "Product Serial Number",
    c.contract_id "Contract ID",
    product_name "Support Name",
    TO_DATE (c.contract_purchase_date) "Start Date",
    TO_DATE (c.contract_expiration_date) "Expire Date",
    NULL "Header Status",
    NULL "Line Status",
    NULL "Line Type",
    NULL "Termination Reason",
    NULL "Location_id",
    NULL "Product_id"
    FROM edb_assets c,
    edb_accounts a
    WHERE controller_model_number_1 != 'NULL'
    AND Serial_Number_1 != 'NULL'
    AND C.Amid = A.Amid(+)
    union all
    SELECT 'Parature' "Source",
    NULL "Distibutor",
    reseller_name "Reseller",
    NULL "Reseller City",
    NULL "Reseller State",
    A.Country "Reseller Country",
    DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
    NULL "Customer Name",
    NULL "Customer City",
    NULL "Customer State",
    NULL "Customer Country",
    NULL "Customer Theater",
    NULL "Sales Book Date",
    NULL "Ship Date",
    c.sales_order_number "Sales Order Number",
    C.Po_Number "PO Number",
    controller_model_number_2 "Product Name",
    TRIM (UPPER (serial_number_2)) "Product Serial Number",
    c.contract_id "Contract ID",
    product_name "Support Name",
    TO_DATE (c.contract_purchase_date) "Start Date",
    TO_DATE (c.contract_expiration_date) "Expire Date",
    NULL "Header Status",
    NULL "Line Status",
    NULL "Line Type",
    NULL "Termination Reason",
    NULL "Location_id",
    NULL "Product_id"
    FROM edb_assets c,
    edb_accounts a
    WHERE controller_model_number_2 != 'NULL'
    AND serial_number_2 != 'NULL'
    AND C.Amid = A.Amid(+)
    union all
    SELECT 'Parature' "Source",
    NULL "Distibutor",
    reseller_name "Reseller",
    NULL "Reseller City",
    NULL "Reseller State",
    A.Country "Reseller Country",
    DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
    NULL "Customer Name",
    NULL "Customer City",
    NULL "Customer State",
    NULL "Customer Country",
    NULL "Customer Theater",
    NULL "Sales Book Date",
    NULL "Ship Date",
    c.sales_order_number "Sales Order Number",
    C.Po_Number "PO Number",
    controller_model_number_3 "Product Name",
    TRIM (UPPER (serial_number_3)) "Product Serial Number",
    c.contract_id "Contract ID",
    product_name "Support Name",
    TO_DATE (c.contract_purchase_date) "Start Date",
    TO_DATE (c.contract_expiration_date) "Expire Date",
    NULL "Header Status",
    NULL "Line Status",
    NULL "Line Type",
    NULL "Termination Reason",
    NULL "Location_id",
    NULL "Product_id"
    FROM edb_assets c,
    edb_accounts a
    WHERE controller_model_number_3 != 'NULL'
    AND serial_number_3 != 'NULL'
    AND C.Amid = A.Amid(+)
    union all
    SELECT 'Parature' "Source",
    NULL "Distibutor",
    reseller_name "Reseller",
    NULL "Reseller City",
    NULL "Reseller State",
    A.Country "Reseller Country",
    DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
    NULL "Customer Name",
    NULL "Customer City",
    NULL "Customer State",
    NULL "Customer Country",
    NULL "Customer Theater",
    NULL "Sales Book Date",
    NULL "Ship Date",
    c.sales_order_number "Sales Order Number",
    C.Po_Number "PO Number",
    controller_model_number_4 "Product Name",
    TRIM (UPPER (serial_number_4)) "Product Serial Number",
    c.contract_id "Contract ID",
    product_name "Support Name",
    TO_DATE (c.contract_purchase_date) "Start Date",
    TO_DATE (c.contract_expiration_date) "Expire Date",
    NULL "Header Status",
    NULL "Line Status",
    NULL "Line Type",
    NULL "Termination Reason",
    NULL "Location_id",
    NULL "Product_id"
    FROM edb_assets c,
    edb_accounts a
    WHERE controller_model_number_4 != 'NULL'
    AND serial_number_4 != 'NULL'
    AND C.Amid = A.Amid(+)
    union all
    SELECT 'Parature' "Source",
    NULL "Distibutor",
    reseller_name "Reseller",
    NULL "Reseller City",
    NULL "Reseller State",
    A.Country "Reseller Country",
    DECODE (a.state, 'APAC', 'APAC', 'EMEA', 'EMEA', NULL, 'Unknown', 'US' ) "Reseller Theater",
    NULL "Customer Name",
    NULL "Customer City",
    NULL "Customer State",
    NULL "Customer Country",
    NULL "Customer Theater",
    NULL "Sales Book Date",
    NULL "Ship Date",
    c.sales_order_number "Sales Order Number",
    C.Po_Number "PO Number",
    controller_model_number_5 "Product Name",
    TRIM (UPPER (serial_number_5)) "Product Serial Number",
    c.contract_id "Contract ID",
    product_name "Support Name",
    TO_DATE (c.contract_purchase_date) "Start Date",
    TO_DATE (c.contract_expiration_date) "Expire Date",
    NULL "Header Status",
    NULL "Line Status",
    NULL "Line Type",
    NULL "Termination Reason",
    NULL "Location_id",
    NULL "Product_id"
    FROM edb_assets c,
    edb_accounts a
    WHERE controller_model_number_5 != 'NULL'
    AND serial_number_5 != 'NULL'
    AND C.Amid = A.Amid(+)
    union all
    SELECT 'ERP' "Source",
    Imv.Bill_To "Distibutor",
    Imv.Ship_To "Reseller",
    Ship_To_City "Reseller City",
    Ship_To_State "Reseller State",
    Edb2_Global.Country_Name_Theater(Imv.Ship_To_Country ,'COUNTRY') "Reseller Country",
    Edb2_Global.Country_Name_Theater(Imv.Ship_To_Country ,'THEATER') "Reseller Theater",
    Cl.Company_Name "Customer Name",
    Cl.City "Customer City",
    Cl.State "Customer State",
    Edb2_Global.Country_Name_Theater(Cl.Country,'COUNTRY') "Customer Country",
    Edb2_Global.Country_Name_Theater(Cl.Country,'THEATER') "Customer Theater",
    Imv.So_Booked_Date "Sales Book Date",
    Imv.Ship_Date "Ship Date",
    Imv.Order_Number "Sales Order Number",
    Imv.Cust_Po_Number "PO Number",
    Cp.Item_Name "Product Name",
    Cp.Product_Serial_Number "Product Serial Number",
    TO_CHAR(Imv.contract_number)"Contract ID",
    Imv.Service_Description "Support Name",
    Imv.Service_Start_Date "Start Date",
    Imv.Service_End_Date "Expire Date",
    Imv.Header_Status "Header Status",
    Imv.Line_Status "Line Status",
    Imv.Line_Type "Line Type",
    Imv.Termination_Reason "Termination Reason",
    Cl.Location_Id "Location_id",
    cp.id "Product_id"
    FROM ib_support_contracts_mv imv,
    customer_products cp,
    customer_locations cl
    WHERE Upper (Trim (Imv.Serial_Number)) = Upper (Trim (Cp.Product_Serial_Number(+)))
    AND Cp.Location_Id = Cl.Location_Id(+)) a
    Edited by: HuaMin on May 9, 2012 2:58 PM

  • Need help on the below query.

    Hi All,
    I've a query given below..
    SELECT W.WONUM,
         W.STATUS,
         WS.CHANGEDATE,
         EH.OLD_RATE
         FROM
         WORKORDER W,
         WOSTATUS WS,
         ESTIMATE_HEADER@GQMFOF EH
    WHERE WS.CHANGEDATE BETWEEN '01-Oct-2009' AND '1-Nov-2009'
    AND W.WONUM = WS.WONUM
    AND EH.OLD_RATE = 'N'
    AND WS.WOSTATUS = 'CLOSE';
    I would like to get All the data which status =closed in the month of Oct for Old rate,
    So for this i am writing the query above. But not getting the o/p.
    It is giving me that " Table/View doesn't exist.
    There 2 schemas MAXIMO,GQMMGR..
    DBlinks are GQMFOF,MAXFOFNC..
    Can anyone help me while writing the above query...
    Regards,
    gr.

    A question was asked in your other thread. But the problem was you dint care to give an answer.
    Dont open duplicate post.
    I need help on the below problem..

  • How to tune the update query?

    HI Expert,
    Our client is facing a performance problem.
    Every alternate day they use to run a load on the database.
    Database is RAC and when they execute a load database used to get hang.
    Everytime we have to regather a stats, after that the update statement execute.
    They are also saying that the query is taking time to execute.
    previously it used to execute fast.
    It would be great if you expert help to find out the bottleneck and solutions.
    this stats i generated before creating the indexes on PRIM_IND column
    SQL> Update /*+ index(IND) */ ENT_HUB.ADDR set PRIM_IND=0 where PRIM_IND=1 and SCD_ACTV_IND=1;
    1477866 rows updated.
    Execution Plan
    Plan hash value: 2784578406
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | UPDATE STATEMENT | | 1321K| 7743K| 25185 (1)| 00:05:03 |
    | 1 | UPDATE | ADDR | | | | |
    |* 2 | TABLE ACCESS FULL| ADDR | 1321K| 7743K| 25185 (1)| 00:05:03 |
    Predicate Information (identified by operation id):
    2 - filter("PRIM_IND"=1 AND "SCD_ACTV_IND"=1)
    below stats i generated after creating the index.
    SQL> Update /*+ index(addr IND) */ ENT_HUB.ADDR set PRIM_IND=0 where PRIM_IND=1 and SCD_ACTV_IND=1;
    1478212 rows updated.
    Execution Plan
    Plan hash value: 736707583
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | UPDATE STATEMENT | | 622K| 2432K| 102K (1)| 00:20:33 |
    | 1 | UPDATE | ADDR | | | | |
    |* 2 | TABLE ACCESS BY INDEX ROWID| ADDR | 622K| 2432K| 102K (1)| 00:20:33 |
    |* 3 | INDEX RANGE SCAN | IND | 1245K| | 2382 (1)| 00:00:29 |
    Predicate Information (identified by operation id):
    2 - filter("SCD_ACTV_IND"=1)
    3 - access("PRIM_IND"=1)
    Thanks,

    user646034 wrote:
    Hi,
    Currently we are using without index.
    however we are not getting performance improvement.
    Please suggest us what can we do to achieve the performance again.
    ThanksDon't update that many rows?
    Not sure what else we can offer you for assistance, it's possible you could change the process flow of your application to not need to update the rows (possibly decode values upon the insert) or change the data model, etc....
    But that's all outside the scope of possibility based on the information you've provided.
    You're doing a LOT (relative to the number of rows in the table) of updating, that takes time and is bound by the laws of physics, we can't alter those here.

  • Need to know the base tables for the QM datasources

    Hello SAP Experts,
    I want to know the base tables for the below mentioned datasources which stores the transaction data.
    1. 2LIS_05_QE1:  Inspection Characterstics Results
    2. 2LIS_05_QE2: Inspection Characterstics Results (Quan)
    3. 2LIS_05_QVUDN: Usage decision for Inspection
    Need your inputs.
    Thanks,
    Lasya.
    Edited by: lasya john on Dec 10, 2008 8:28 PM

    Hi Lasya,
    You can use help.sap.com for this.
    If you do not find this data source there...then
    You can go to LBWE t-code in R/3 and then infront of the data source...you have maintenance option.
    Click on that ...and go inside it in the display mode.
    Here you can see a generic pool of fields on the left side which can be included in the data source........  field present in the data sources in the right side of the pool.
    For every field you have a tructure name infront of it like MCXXXX where XXXX is the table name.
    So the field is being from that particular table.
    Even I would the same thing to reply to your thread.
    You can follow the same procedure to find the table for any LO data source.
    This is accurate in 99% cases...only in very few cases like purchasing...we get one or two fields from different tables.
    Hope it helps.
    Thanks
    Ajeet

  • Need help in the following query

    Hi ,
    I have the following query to pull out data for a particular timeperiod( campaign)
    select
    da.acct_nr,smas.mrkt_id,smas.fld_sls_cmpgn_perd_id,smas.acct_key,smas.upln_acct_key,smas.awrd_sls_amt,smas.fld_net_sls_amt
    ,smas.stf_ind,da1.acct_nr,
    smas.fld_sls_cmpgn_perd_id,smas.acct_key,smas.upln_acct_key,smas.awrd_sls_amt,smas.fld_net_sls_amt
    ,smas.stf_ind,da1.acct_nr,prev.*
    From cdw.sum_mrkt_acct_sls smas
    join codi.dim_acct da
    on (smas.mrkt_id = da.mrkt_id and smas.acct_key = da.acct_key)
    join codi.dim_acct da1
    on (smas.mrkt_id = da1.mrkt_id and smas.UPLN_acct_key = da1.ACCT_KEY)
    where smas.acct_key in
    select dwnln_acct_key from codi.dim_ldrshp_genlgy
    where mrkt_id = 66 and fld_sls_cmpgn_perd_id = 20100304
    and root_upln_acct_key = (select acct_key from codi.dim_acct where acct_nr = '0032622' and mrkt_id = 66)
    and
    smas.mrkt_id = 66
    and smas.fld_sls_cmpgn_perd_id = 20100304
    and smas.sls_org_key <> -100
    order by 1
    So this query will pull out data for campaign 20100304
    No i want to modify the query to pull out data for 3 such campaigns.
    for a smas.acct_key
    so data will
    smas.acct_key all the data for 1st campaign , all the data for 2nd campaign. all the data for 3rd campaign
    Could you please help in modifying this query.
    Thanks

    How about this ??
    select da.acct_nr,
           smas.mrkt_id,
           smas.fld_sls_cmpgn_perd_id,
           smas.acct_key,
           smas.upln_acct_key,
           smas.awrd_sls_amt,
           smas.fld_net_sls_amt,
           smas.stf_ind,
           da1.acct_nr,
           smas.fld_sls_cmpgn_perd_id,
           smas.acct_key,
           smas.upln_acct_key,
           smas.awrd_sls_amt,
           smas.fld_net_sls_amt,
           smas.stf_ind,
           da1.acct_nr,
           prev.*
      From cdw.sum_mrkt_acct_sls smas
      join codi.dim_acct da on (smas.mrkt_id = da.mrkt_id and
                               smas.acct_key = da.acct_key)
      join codi.dim_acct da1 on (smas.mrkt_id = da1.mrkt_id and
                                smas.UPLN_acct_key = da1.ACCT_KEY)
    where smas.acct_key in (select dwnln_acct_key
                               from codi.dim_ldrshp_genlgy
                              where mrkt_id = 66
                                and fld_sls_cmpgn_perd_id in( 20100304,20100305,20100306)
                                and root_upln_acct_key =
                                    (select acct_key
                                       from codi.dim_acct
                                      where acct_nr = '0032622'
                                        and mrkt_id = 66))
       and smas.mrkt_id = 66
       and smas.fld_sls_cmpgn_perd_id in( 20100304,20100305,20100306)
       and smas.sls_org_key - 100
    order by 1

  • Request for tunning the below query

    Hi,
    Can any one help me on the below query while improving the performance,
    SELECT accdet, acceprec, accinvalid, accnetanal, accphy, accvalid,
    actlabcost, actlabhrs, actualcontactdate, actualfinish, actualstart,
    affecteddate, affectedemail, affectedperson, affectedphone,
    alteration, aslaiddwg, assetnum, assetorgid, assetsiteid,
    assumptions, basedet, basereq, bicounty, bidplo, bieasting,
    bihousename, bihouseno, binorthing, bipobox, bipostcode, biposttown,
    bistreet, bisubb as bisupp, boostcomp, boostcompdet, ccemail, cchouseno, ccid,
    ccname, cctel1type, cctel2type, cctelephone1, cctelephone2, cdm,
    changeby, changedate, CLASS, classstructureid, cocontact, cocounty,
    codplo, coeasment, coeasting, cohousename, conorthing, copobox,
    commodity, commoditygroup, coneasereq, consent, consents,
    copostcode, coposttown, costcon, costreet, cosubb, cpi90,
    createworelasset, customerref, custtype, depot, description, durt,
    ecvpressuretier, ecvsize, enduserid, engdifficult, exaoq, existin,
    existsdq, expid, exshq, externalrecid, extralanddetail, failurecode,
    fr1code, fr2code, fuelpovscheme, g17, gbna, glaccount,
    globalticketclass, globalticketid, govconf, govener, govenerdet,
    govhouse, hasactivity, hasld, historyflag, impact, infill,
    infoprovide, inheritstatus, internalpriority, interquote, isglobal,
    isknownerror, isknownerrordate, kioskdet, kioskreq, langcode,
    latecertdate, leadt, lengthpri, lengthpub, loadtype, LOCATION, m25,
    maindesac, mainusage, meterboxty, metercon, meterloc, meterser,
    mininforec, mininforeq, mprnno, newaoq, newpid, newsdq, newshq,
    np14, nrswa, nsgno, oldquotever, oldticketid, orgid, originsgn,
    origrecordclass, origrecordid, origrecorgid, origrecsiteid, owner,
    ownergroup, packagesent, paymethod, payterms, permittowork, physub,
    pressuretier, privateexc, problemcode, propertiesno, propertytype,
    publicexc, purgerel, quotedate, quotetype, quotever, reinforcement,
    reinforcementa, reinforcementb, relatedtoglobal, reportdate,
    reportedby, reportedemail, reportedphone, reportedpriority,
    rowstamp, sc, scj, scoreq, servicerelay, sgnbillcontact,
    sgnblkbyfin, sgncusttobill, sgncusttosite, sgndisreasoth,
    sgneasment, sgnenhance, sgneow, sgneowreq, sgngqmvalid,
    sgninfillcost, sgninfillver, sgninfprojno, sgnisstdchrg,
    sgnloadnoenter, sgnmainsreq, sgnmaxaccdate, sgnnoncont, sgnpipesiz,
    sgnpurord, sgnqdaysremain, sgnqstd, sgnquotdate, sgnquotval,
    sgnreasdis, sgntotalaoq, sgntotalshq, sgnvarreq, sicontact,
    sicounty, sidplo, sieasting, sihousename, sihouseno, sinorthing,
    sipobox, sipostcode, siposttown, sistreet, sisubb, sitecond, sitegt,
    siteid, sitel1, sitel2, siteplpro, sitevisit, solution, sos,
    sosrecdate, SOURCE, status, statusdate, subfinal, supervisor,
    supplytype, surveycarr, surveydef, surveyreas, surveyreq, surveyret,
    surveysent, targetcontactdate, targetfinish, targetstart, TEMPLATE,
    templateid, termtype, thirdpartyeas, thirdpartypipe, ticketid,
    ticketuid, totalaoq, totalpid, totalsdq, totalshq, traffictime,
    typewo, urgency, variat, vendor, customer_enquiry_ref,
    quote_version, costs, mains_infill_charge, mtr_housing_kiosk_charge,
    mtr_housing_kiosk_base_charge, specialist_reinstatement,
    easement_charge, total_quote_ex_vat, vat, total_quote_incl_vat,
    design_charge, reinforcement_charge, reinforcement_cost,
    connection_allowance, workorder.pscdate, workorder.ascdate,
    workorder.fincode, workorder.istask, workorder.status,
    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,
    grace

    Could you please provide more info.
    Refer to the following link.
    When your query takes too long ...
    thanks

Maybe you are looking for