Help tuning NESTED LOOPS OUTER joins

Hello,
I have inherited this nasty query (below) that is taking an awful time to complete (more than 2 hrs a day)
The worst bit is that I need to outer join my fact table so many times as I need bit’s and pieces from other tables/mviews.
When I look at the explain plan I see that this situation means that the cbo is doing several NESTED LOOPS OUTER join operations. I understand that these nested loops mean going through every row in my primary table to see if there is a match in the secondary table (much smaller) which makes it extremely inefficient, is this right?
The stats on the tables are all refreshed daily.
Any ideas on how I can improve the performance here?
Thanks in advance!
The query:
explain plan for
SELECT x.user_id AS user_id,
x.login_name AS login_name,
c.date_of_birth AS date_of_birth,
x.registration_site AS registration_site,
x.organisation AS organisation,
c.user_title AS user_title,
c.first_name AS first_name,
c.last_name AS last_name,
x.email_address AS email_address,
x.user_status AS user_status,
x.user_privilege AS user_access_privilege,
x.date_registration AS date_registration,
x.affiliate_id AS affiliate_id,
x.mobile_number AS mobile_number,
x.optional_parameter AS vt_number,
gud.display_name AS chat_name,
REPLACE (s4.address_line_1, ',', '') AS address_line_1,
REPLACE (s4.address_line_2, ',', '') AS address_line_2,
REPLACE (s4.town, ',', '') AS town,
REPLACE (s4.county, ',', '') AS county,
REPLACE (s4.postcode, ',', '') AS postcode,
s4.country AS country,
s3.last_login AS last_login_date,
x.email_send_newsletter AS email_send_newsletter,
x.email_give_details_thirdparty AS email_give_details_thirdparty,
NVL (ia.cash_balance, 0) AS current_cash_balance,
NVL (ia.bonus_balance, 0) AS current_bonus_balance,
x.external_affiliate_id AS external_affiliate_id,
r.currency_code AS currency,
NVL (ia.points_balance, 0) AS current_loyalty_points_balance,
p.status AS buyer_status,
NVL (ia.bi_bonus_balance, 0) AS current_bi_bonus_balance,
NVL (ia.pending_balance, 0) AS current_pending_balance,
l.level_name AS current_loyalty_level,
l.date_level_achieved AS date_level_achieved,
NVL (l.current_period_loyalty_points, 0) AS current_period_loyalty_points,
r.region AS user_region,
x.registration_platform AS registration_platform,
x.external_user_name AS external_user_name,
c.home_number AS home_number,
pr.code AS reg_promo_code,
g.date_first_buy AS date_first_buy
FROM gl_user_registrations x,
gl_region r,
MVW_USER_BALANCES ia,
gl_customers c,
gl_user_display_names gud,
gl_user_last_login s3,
(SELECT z.user_id AS user_id,
z.address_line_1 AS address_line_1,
z.address_line_2 AS address_line_2,
z.town AS town,
z.county AS county,
z.postcode AS postcode,
z.country AS country
FROM gl_user_addresses z
WHERE z.is_current = 1) s4,
gl_user_buyer_mapping upm,
gl_buyer p,
mvw_user_loyalty_points l,
MVW_USER_PROMO_CODE_REG pr,
MVW_USER_FIRST_BUY_DATE g
WHERE x.base_region = r.region
AND x.user_id = ia.user_id (+)
AND x.customer_id = c.customer_id(+)
AND x.user_id = gud.user_id (+)
AND x.user_id = s4.user_id (+)
AND x.user_id = s3.user_id (+)
AND x.user_id = upm.user_id (+)
AND upm.buyer_id = p.buyer_id
AND x.user_id = l.user_id (+)
AND x.user_id = pr.user_id (+)
AND x.user_id = g.user_id (+);
select * from table(dbms_xplan.display);
Plan hash value: 2158171613
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
| 0 | SELECT STATEMENT | | 100 | 63100 | 135 (1)| 00:00:01 |
| 1 | NESTED LOOPS OUTER | | 100 | 63100 | 135 (1)| 00:00:01 |
| 2 | NESTED LOOPS OUTER | | 100 | 60600 | 120 (1)| 00:00:01 |
| 3 | NESTED LOOPS OUTER | | 100 | 57100 | 105 (1)| 00:00:01 |
| 4 | NESTED LOOPS OUTER | | 100 | 55400 | 90 (2)| 00:00:01 |
| 5 | NESTED LOOPS OUTER | | 100 | 53600 | 70 (2)| 00:00:01 |
|* 6 | HASH JOIN | | 100 | 47000 | 55 (2)| 00:00:01 |
| 7 | TABLE ACCESS FULL | GL_REGION | 18 | 252 | 2 (0)| 00:00:01 |
| 8 | NESTED LOOPS OUTER | | 100 | 22800 | 52 (0)| 00:00:01 |
| 9 | NESTED LOOPS OUTER | | 100 | 19700 | 47 (0)| 00:00:01 |
| 10 | NESTED LOOPS OUTER | | 100 | 17600 | 37 (0)| 00:00:01 |
| 11 | NESTED LOOPS | | 100 | 15800 | 27 (0)| 00:00:01 |
| 12 | NESTED LOOPS | | 102 | 2754 | 17 (0)| 00:00:01 |
| 13 | TABLE ACCESS FULL | GL_BUYER | 6143K| 64M| 2 (0)| 00:00:01 |
| 14 | TABLE ACCESS BY INDEX ROWID| GL_USER_BUYER_MAPPING | 1 | 16 | 1 (0)| 00:00:01 |
|* 15 | INDEX RANGE SCAN | GL_USER_BUYER_MAPPPING_IX | 1 | | 1 (0)| 00:00:01 |
| 16 | TABLE ACCESS BY INDEX ROWID | GL_USER_REGISTRATIONS | 1 | 131 | 1 (0)| 00:00:01 |
|* 17 | INDEX UNIQUE SCAN | PK_GL_USER_REGISTRATIONS | 1 | | 1 (0)| 00:00:01 |
| 18 | TABLE ACCESS BY INDEX ROWID | GL_USER_LAST_LOGIN | 1 | 18 | 1 (0)| 00:00:01 |
|* 19 | INDEX UNIQUE SCAN | GL_USER_LAST_LOGIN_PK | 1 | | 1 (0)| 00:00:01 |
| 20 | TABLE ACCESS BY INDEX ROWID | GL_USER_DISPLAY_NAMES | 1 | 21 | 1 (0)| 00:00:01 |
|* 21 | INDEX UNIQUE SCAN | PK_GL_USER_DISPLAY_NAMES | 1 | | 1 (0)| 00:00:01 |
| 22 | TABLE ACCESS BY INDEX ROWID | GL_CUSTOMERS | 1 | 31 | 1 (0)| 00:00:01 |
|* 23 | INDEX UNIQUE SCAN | PK_GL_CUSTOMERS | 1 | | 1 (0)| 00:00:01 |
|* 24 | TABLE ACCESS BY INDEX ROWID | GL_USER_ADDRESSES | 1 | 66 | 1 (0)| 00:00:01 |
|* 25 | INDEX RANGE SCAN | IX_GL_USER_ADDRESSES1 | 1 | | 1 (0)| 00:00:01 |
| 26 | MAT_VIEW ACCESS BY INDEX ROWID | MVW_USER_FIRST_BUY_DATE | 1 | 18 | 1 (0)| 00:00:01 |
|* 27 | INDEX RANGE SCAN | MVW_USER_FS_DATE_IDX | 1 | | 1 (0)| 00:00:01 |
| 28 | MAT_VIEW ACCESS BY INDEX ROWID | MVW_USER_PROMO_CODE_REG | 1 | 17 | 1 (0)| 00:00:01 |
|* 29 | INDEX RANGE SCAN | MVW_USER_PROMO_CODE_IDX | 1 | | 1 (0)| 00:00:01 |
| 30 | MAT_VIEW ACCESS BY INDEX ROWID | MVW_USER_LOYALTY_POINTS | 1 | 35 | 1 (0)| 00:00:01 |
|* 31 | INDEX RANGE SCAN | MVW_USER_LYP_IDX | 1 | | 1 (0)| 00:00:01 |
| 32 | MAT_VIEW ACCESS BY INDEX ROWID | MVW_USER_BALANCES | 1 | 25 | 1 (0)| 00:00:01 |
|* 33 | INDEX RANGE SCAN | MVW_USER_BALANCES_IDX | 1 | | 1 (0)| 00:00:01 |
Predicate Information (identified by operation id):
6 - access("X"."BASE_REGION"="R"."REGION")
15 - access("UPM"."BUYER_ID"="P"."BUYER_ID")
17 - access("X"."USER_ID"="UPM"."USER_ID")
19 - access("X"."USER_ID"="S3"."USER_ID"(+))
21 - access("X"."USER_ID"="GUD"."USER_ID"(+))
23 - access("X"."CUSTOMER_ID"="C"."CUSTOMER_ID"(+))
24 - filter("Z"."IS_CURRENT"(+)=1)
25 - access("X"."USER_ID"="Z"."USER_ID"(+))
27 - access("X"."USER_ID"="G"."USER_ID"(+))
29 - access("X"."USER_ID"="PR"."USER_ID"(+))
31 - access("X"."USER_ID"="L"."USER_ID"(+))
33 - access("X"."USER_ID"="IA"."USER_ID"(+))

Hi,
1) What you are saying about nested loops is true about any join (except, of course, cartesian joins): you are taking rows from rowsource A and find matching rows from rowsource B. This doesn't make a join method efficient or inefficient.
2) The plan you posted does not indicate any performance problem whatsoever. I know you have one, but it's not possible to address it without having any information about it. Trace it, get dbms_xplan.display_cursor dump with rowsource stats, or real-time SQL monitoring report (if your version and license allow it) and post the results here, then we'd be able to help
3) One efficient way to perform queries of your type (big fact table joined to a bunch of small dimension tables) is star transformation, but there are certain pre-requisites for that (like bitmap indexes on FK constraints) -- please read the documentation on star queries/transformations and see if that is an option for you
Best regards,
Nikolay

Similar Messages

  • Tuning a left outer join

    Hello All,
    Good Afternoon!! Thought I will post some interesting findings of mine while I was given the task of reviewing and finding tuning scope for some complex pl/sql codes. In one of them, I found a weird way of doing a Left Outer Join against a table and they haven't used any hints typically used for joining operations (such as Ordered), but instead they used a Parallel with a table alias to the driven table, which I think is being rendered useless when it runs. This is what it looks like -
    SELECT /*+ PARALLEL(V) */ DISTINCT
             CASE WHEN y.u_dc_run_op IS NOT NULL THEN 1
             ELSE 0 END
        FROM (select 1 sw from dual) x
                LEFT OUTER JOIN
                   (SELECT V.U_DC_RUN_OPT, v.u_dc_run_pend
                      FROM dview v, u_dc_process_ctrl u
               WHERE v.u_dc_run_opt = u.opt
                AND  v.u_dc_run_pend = 1
                AND  u.process_wk = (TO_CHAR(SYSDATE,'WW') + 0)
                AND  TRIM(v.u_dc_run_opt) IS NOT NULL) y
                    On x.sw = y.u_dc_run_pend;
    Oracle is running on - Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production.
    The inner table itself is a result of another join against a 100M heavy table with another 100K light table (see below for their table definitions). Cost of the above query and Explain Plan results are as below -
    PLAN_TABLE_OUTPUT
    SQL_ID 0rpsxqtvvcmsx, child number 0
    SELECT /*+ PARALLEL(V) */ DISTINCT          CASE WHEN
    y.u_dc_run_op IS NOT NULL THEN 1          ELSE 0 END     FROM
    (select 1 sw from dual) x             LEFT OUTER JOIN
    (SELECT V.U_DC_RUN_OPT_SET, v.u_dc_run_pend FROM
    dview v, u_dc_process_ctrl u            WHERE v.u_dc_run_opt =
    u.opt AND v.u_dc_run_pend = 1             AND
    u.process_wk = (TO_CHAR(SYSDATE,'WW') + 0)             AND
    TRIM(v.u_dc_run_opt) IS NOT NULL) y On x.sw =
    y.u_dc_run_pend
    Plan hash value: 49153038
    | Id  | Operation | Name | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    | 0 | SELECT STATEMENT | |       | |  1444K(100)| |       |       |
    | 1 |  HASH UNIQUE | |     1 |    19 |  1444K  (3)| 00:01:55 | |       |
    | 2 |   NESTED LOOPS OUTER | |     1 |    19 |  1444K  (3)| 00:01:55 | |       |
    | 3 |    TABLE ACCESS FULL            | DUAL |     1 |     2 |     3   (0)| 00:00:01 |       |       |
    |* 4 |    VIEW | |     1 |    17 |  1444K  (3)| 00:01:55 | |       |
    |* 5 |     HASH JOIN | |     1 |   122 |  1444K  (3)| 00:01:55 |       |       |
    | 6 |      TABLE ACCESS BY INDEX ROWID| U_DC_PROCESS_CTRL    |     1 | 115 |     0 (0)| |       |       |
    |* 7 |       INDEX RANGE SCAN          | U_DC_PROCESS_CTRL_PK |     1 |       |     0 (0)| |       |       |
    | 8 |      PARTITION HASH ALL         |                      | 283K|  1937K|  1444K  (3)| 00:01:55 |     1 |    64 |
    |* 9 |       TABLE ACCESS FULL         | DVIEW |   283K|  1937K|  1444K  (3)| 00:01:55 |     1 |    64 |
    Predicate Information (identified by operation id):
    4 - filter("Y"."U_DC_RUN_PEND"=1)
    5 - access("V"."U_DC_RUN_OPT"="U"."OPT")
    7 - access("U"."PROCESS_WK"=TO_NUMBER(TO_CHAR(SYSDATE@!,'WW'))+0)
    9 - filter(("V"."U_DC_RUN_PEND"=1 AND TRIM("V"."U_DC_RUN_OPT") IS NOT NULL))
    SQL_ID 0rpsxqtvvcmsx, child number 1
    SELECT /*+ PARALLEL(V) */ DISTINCT          CASE WHEN
    y.u_dc_run_opt IS NOT NULL THEN 1          ELSE 0 END     FROM
    (select 1 sw from dual) x             LEFT OUTER JOIN
    (SELECT V.U_DC_RUN_OPT, v.u_dc_run_pend FROM
    dview v, u_dc_process_ctrl u            WHERE v.u_dc_run_opt =
    u.opt AND v.u_dc_run_pend = 1             AND
    u.process_wk = (TO_CHAR(SYSDATE,'WW') + 0)             AND
    TRIM(v.u_dc_run_opt) IS NOT NULL) y On x.sw =
    y.u_dc_run_pend
    Plan hash value: 49153038
    | Id  | Operation | Name | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    | 0 | SELECT STATEMENT | |       | | 1444K(100)| |       |       |
    | 1 |  HASH UNIQUE | |     1 |    19 |  1444K  (3)| 00:01:55 | |       |
    | 2 |   NESTED LOOPS OUTER | |     1 |    19 |  1444K  (3)| 00:01:55 | |       |
    | 3 |    TABLE ACCESS FULL            | DUAL |     1 |     2 | 3   (0)| 00:00:01 | |       |
    |* 4 | VIEW | |     1 |    17 |  1444K  (3)| 00:01:55 | |       |
    |* 5 |     HASH JOIN | |     1 |   122 |  1444K  (3)| 00:01:55 |       |       |
    | 6 |      TABLE ACCESS BY INDEX ROWID| U_DC_PROCESS_CTRL    |  4069 | 456K|     0 (0)|          | |       |
    |* 7 |       INDEX RANGE SCAN          | U_DC_PROCESS_CTRL_PK |     1 |       |     0 (0)| |       |       |
    | 8 |      PARTITION HASH ALL | |  5459K|    36M|  1444K  (3)| 00:01:55 |     1 |    64 |
    |* 9 |       TABLE ACCESS FULL         | DVIEW |  5459K|    36M|  1444K  (3)| 00:01:55 |     1 |    64 |
    Predicate Information (identified by operation id):
    4 - filter("Y"."U_DC_RUN_PEND"=1)
    5 - access("V"."U_DC_RUN_OPT"="U"."OPT")
    7 - access("U"."PROCESS_WK"=TO_NUMBER(TO_CHAR(SYSDATE@!,'WW'))+0)
    9 - filter(("V"."U_DC_RUN_PEND"=1 AND TRIM("V"."U_DC_RUN_OPT") IS NOT NULL))
    Note
    - cardinality feedback used for this statement
    Here's the syntax how DView and u_dc_process_ctrl tables are created -
    CREATE TABLE "A"."DVIEW"
       ( "DUNIT" VARCHAR2(50 CHAR),
      "DGROUP" VARCHAR2(50 CHAR),
      "LOC" VARCHAR2(50 CHAR),
      "U_DC_RUN_OPT" VARCHAR2(50 CHAR) DEFAULT ' ',
      "U_DC_RUN_PEND" NUMBER(1,0) DEFAULT 0
    Please note that we have DView with 64 partitions on DUNIT as a key. Approximate volume of DVIEW is about 100M.
    CREATE TABLE "A"."U_DC_PROCESS_CTRL"
       ( "PROCESS_WK" NUMBER(2,0),
      "PROCESS_LVL" VARCHAR2(10 CHAR),
      "ASSRT" VARCHAR2(50 CHAR),
      "ITEM" VARCHAR2(50 CHAR),
      "CNTRY" VARCHAR2(50 CHAR),
      "OPT" VARCHAR2(50 CHAR),
      "PROCESS_DT" DATE,
      "EXCEPTION" VARCHAR2(255 CHAR) DEFAULT ' '
    U_DC_PROCESS_CTRL is a non-partitioned table and has less than 10k records in it.
    The problem is, this apparently simple query is running for 26 minutes and I think we can avoid doing the outer join or use an ORDERED hint instead of a PARALLEL hint to the query.
    Appreciate any inputs to the above. Thanks much!!
    Thanks,
    Sanders.

    I'm looking directly at your first plan output.  The highlighted columns don't match.
    SQL_ID 0rpsxqtvvcmsx, child number 0
    SELECT /*+ PARALLEL(V) */ DISTINCT         
    CASE WHEN y.u_dc_run_op IS NOT NULL
    THEN 1         
    ELSE 0
    END    
    FROM (select 1 sw from dual) x            
    LEFT OUTER JOIN (SELECT V.U_DC_RUN_OPT_SET, v.u_dc_run_pend
    FROM    
    Forget that for now.  You say the query runs in 26 minutes.  I don't know if that's good or bad.  You're joining to a table with 100 million rows and 64 partitions and then doing a distinct on the results.  Depending on your hardware, the load, etc. that might not be too bad.
    Also...what's the business logic for this query?  The only column returned is a case statement that can only result in 0 or 1.  And then a distinct is applied to that, so at most this query can return 2 rows.  How many rows would it return without the distinct?  Joining to dual is a little weird but I guess whoever coded this wanted to guarantee at least 1 row returned.  Are the cardinality estimates correct?
    > and they haven't used any hints typically used for joining operations
    That's good.  Typically you should never use hints like this in production code.  They are poison.

  • Nested loop, merge join and harsh join

    Can any one tell me the difference/relationship between nested loop, harsh join and merge join...Thanx

    Check Oracle Performance Tuning Guide
    13.6 Understanding Joins
    http://download-west.oracle.com/docs/cd/B19306_01/server.102/b14211/optimops.htm#i51523

  • Nested Left Outer Join : Data Set

    Hi All
    I am bit confused about data set used by Nested Left outer join.
    Can anyone help me.
    Here is sample data:
    Tables (Name, 3 Column each, total rows and matched rows if any):
         Table 1          
         A     B     C
         Total 20 Rows          
         Table 2          
         A     D     E
         Total 50 Rows and 10 Matching on      2.A = 1.A     
         Table 3          
         D     M     N
         Total 15 Rows and 15 Matching on 3.D = 2.D     
         Table 4          
         M     X     Y
         Total 20 Rows and 10 Matching on 4.M = 3.M     
    Sql
    select *
    From Table 1
    Left Outer Join on Table 2 on
                   2.A = 1.A
    -- Data set 1 will contain 20 Rows (10 matching and 10 non matching)
    Left Outer Join on Table 3 on
                   3.D = 2.D
    -- What will be data set? 20 Rows of Data set 1 or 15 Matching Rows?
    Left Outer Join on Table 4 on
                   4.M = 3.M
    -- What will be data set? X Rows of Data set 2 or 10 Matching Rows?
    Please have a look and clear my understanding.

    SeshuGiri wrote:
    I have two tables defined (below). Emp table has data and there is no data in Emp_Type table yet! Right now it is empty.
    I want to write a query that returns data from both the tables even though there is no data in Emp_type table. I am using left outer join but it returning nothing. Anyone can help?
    select *
    from emp e
    left outer join emp_Type t
    on e.empid = t.empid
    WHERE t.type_id = 1
    and t.end_date is null;
    The join is including all rows from emp, just like you want.
    The WHERE clause is discarding all of those rows. Since all the columns from emp_type (alias t) are NULL, the condition "t.type_id = 1" in the WHERE clause is never true.
    Perhaps you meant to include all those conditions in the join conditions, like this:
    select *
      from emp e
      left outer join emp_Type t
        on e.empid = t.empid
       and t.type_id = 1
       and t.end_date is null;Edited by: Frank Kulash on Jan 30, 2012 3:56 PM

  • Need help with nested loop (c:forEach) tags. Can I break from inner loop?

    Hi all, I have this annoying problem and I am looking for any suggestions.
    I have 2 select boxes. One is for all available users, and second - for selected users (designated as admins). The list of all users is available in a collection (2 properties userId and userName displayed in the code below). The list of admins contains only userId (as strings).
    I have no problem with populating selected users (admins) list, reusing pretty much the same logic below, but I cannot find a way to break out from the nested loop once the match is found, to avoid repetitions leading to incorrect display of results.
    <select name=available>
    <c:forEach items="${users}" var="user" varStatus="outer">
        <c:forEach items="${adminIds}" var="adminId" varStatus="inner">
            <c:if test="${user.userId!=adminId">
                 <option value="<c:out value="${user.userId}" />"><c:out value="${user.userFullName}"/></option>
            </c:if>
        </c:forEach>
    </c:forEach>
    </select>
    <select name=selected>
    <c:forEach items="${users}" var="user" varStatus="outer">
        <c:forEach items="${adminIds}" var="adminId" varStatus="inner">
            <c:if test="${user.userId==adminId">
                 <option value="<c:out value="${user.userId}" />"><c:out value="${user.userFullName}"/></option>
            </c:if>
        </c:forEach>
    </c:forEach>
    </select>Can anyone help, please? I am also restricted to JSP 1.2

    Double post: http://forum.java.sun.com/thread.jspa?threadID=707950&tstart=0

  • Help Required in full outer Join

    I feel the below query can be changed to full outer join. But, I've not been able to do so.
    I require your help in changing it to full outer join. My current query is
    SELECT CLAIMNO,'1' INDX FROM D_CLAIM@CMS2PROD
    WHERE clntsys=76500 and facility=76501 and filecreatedt='18-feb-2011' and fileupdatedt is null
    MINUS
    SELECT CLAIMNO,'1' FROM D_CLAIM
    WHERE clntsys=76500 and facility=76501 and filecreatedt='18-feb-2011' and fileupdatedt is null
    UNION
    SELECT CLAIMNO,'2' FROM D_CLAIM
    WHERE clntsys=76500 and facility=76501 and filecreatedt='18-feb-2011' and fileupdatedt is null
    MINUS
    SELECT CLAIMNO,'2' FROM D_CLAIM@cms2prod
    WHERE clntsys=76500 and facility=76501 and filecreatedt='18-feb-2011' and fileupdatedt is null

    donisback wrote:
    I feel the below query can be changed to full outer join. But, I've not been able to do so.
    I require your help in changing it to full outer join. My current query is
    SELECT CLAIMNO,'1' INDX FROM D_CLAIM@CMS2PROD
    WHERE clntsys=76500 and facility=76501 and filecreatedt='18-feb-2011' and fileupdatedt is null
    MINUS
    SELECT CLAIMNO,'1' FROM D_CLAIM
    WHERE clntsys=76500 and facility=76501 and filecreatedt='18-feb-2011' and fileupdatedt is null
    UNION
    SELECT CLAIMNO,'2' FROM D_CLAIM
    WHERE clntsys=76500 and facility=76501 and filecreatedt='18-feb-2011' and fileupdatedt is null
    MINUS
    SELECT CLAIMNO,'2' FROM D_CLAIM@cms2prod
    WHERE clntsys=76500 and facility=76501 and filecreatedt='18-feb-2011' and fileupdatedt is null
    I do not think that query is doing what you think that it is doing - on first inspection, it was not doing what I thought either due to the order in which the UNION and MINUS operators are performed. If the FILECREATEDT column is defined as a DATE, your query is relying on an implicit date conversion - in such a case, you should replace:
    filecreatedt='18-feb-2011'With:
    filecreatedt=TO_DATE('18-feb-2011','DD-MON-YYYY')Now, building a simple model to explain what is happening, we create two tables with 10 rows each. The first table has C1 values that increase by 2, while the second has C1 values that increase by 3:
    CREATE TABLE T1 AS
    SELECT
      ROWNUM*2 C1,
      TRUNC(SYSDATE)+ROWNUM*2 C2
    FROM
      DUAL
    CONNECT BY
      LEVEL<=10;
    CREATE TABLE T2 AS
    SELECT
      ROWNUM*3 C1,
      TRUNC(SYSDATE)+ROWNUM*3 C2
    FROM
      DUAL
    CONNECT BY
      LEVEL<=10;It appears that the intended result of your query is to obtain a distinct list of those rows that are in each table that are not in both tables - the UNION ALL minus the intersection of the rows in two tables. However, that is not what you are achieving with that query. To demonstrate, the two halves of your query:
    SELECT
      C1,
      C2
    FROM
      T1
    MINUS
    SELECT
      C1,
      C2
    FROM
      T2;
    C1 C2
    2 28-FEB-11
    4 02-MAR-11
    8 06-MAR-11
    10 08-MAR-11
    14 12-MAR-11
    16 14-MAR-11
    20 18-MAR-11
    SELECT
      C1,
      C2
    FROM
      T2
    MINUS
    SELECT
      C1,
      C2
    FROM
      T1;
    C1 C2
    3 01-MAR-11
    9 07-MAR-11
    15 13-MAR-11
    21 19-MAR-11
    24 22-MAR-11
    27 25-MAR-11
    30 28-MAR-11As can be seen by the above, each half returned 7 rows - there are 7 rows in each table that is not in the other table. Common sense would state that if we UNION these two results (assuming no duplicate values in each table), we would see 14 rows:
    SELECT
      C1,
      C2
    FROM
      T1
    MINUS
    SELECT
      C1,
      C2
    FROM
      T2
    UNION
    SELECT
      C1,
      C2
    FROM
      T2
    MINUS
    SELECT
      C1,
      C2
    FROM
      T1;
    C1 C2
    3 01-MAR-11
    9 07-MAR-11
    15 13-MAR-11
    21 19-MAR-11
    24 22-MAR-11
    27 25-MAR-11
    30 28-MAR-11Only 7 rows? Let's try again with the help of inline views to control the order in which the MINUS and UNION operators are processed:
    SELECT
    FROM
      (SELECT
        C1,
        C2
      FROM
        T1
      MINUS
      SELECT
        C1,
        C2
      FROM
        T2)
    UNION
    SELECT
    FROM
      (SELECT
        C1,
        C2
      FROM
        T2
      MINUS
      SELECT
        C1,
        C2
      FROM
        T1);
    C1 C2
    2 28-FEB-11
    3 01-MAR-11
    4 02-MAR-11
    8 06-MAR-11
    9 07-MAR-11
    10 08-MAR-11
    14 12-MAR-11
    15 13-MAR-11
    16 14-MAR-11
    20 18-MAR-11
    21 19-MAR-11
    24 22-MAR-11
    27 25-MAR-11
    30 28-MAR-11Note that the above returned 14 rows. We can do the same using just two outer joins:
    SELECT
      T1.C1,
      T1.C2
    FROM
      T1,
      T2
    WHERE
      T1.C1=T2.C1(+)
      AND T2.C1 IS NULL
    UNION
    SELECT
      T2.C1,
      T2.C2
    FROM
      T1,
      T2
    WHERE
      T2.C1=T1.C1(+)
      AND T1.C1 IS NULL;
    C1 C2
    2 28-FEB-11
    3 01-MAR-11
    4 02-MAR-11
    8 06-MAR-11
    9 07-MAR-11
    10 08-MAR-11
    14 12-MAR-11
    15 13-MAR-11
    16 14-MAR-11
    20 18-MAR-11
    21 19-MAR-11
    24 22-MAR-11
    27 25-MAR-11
    30 28-MAR-11Or we can do it with a full outer join and a MINUS operator:
    SELECT
      NVL(T1.C1,T2.C1) C1,
      NVL2(T1.C1,T1.C2,T2.C2) C2
    FROM
      T1 FULL OUTER JOIN T2
        ON T1.C1=T2.C1
    MINUS
    SELECT
      T1.C1,
      T1.C2
    FROM
      T1,
      T2
    WHERE
      T1.C1=T2.C1;
    C1 C2
    2 28-FEB-11
    3 01-MAR-11
    4 02-MAR-11
    8 06-MAR-11
    9 07-MAR-11
    10 08-MAR-11
    14 12-MAR-11
    15 13-MAR-11
    16 14-MAR-11
    20 18-MAR-11
    21 19-MAR-11
    24 22-MAR-11
    27 25-MAR-11
    30 28-MAR-11Or just with a full outer join with a WHERE clause:
    SELECT
      NVL(T1.C1,T2.C1) C1,
      NVL2(T1.C1,T1.C2,T2.C2) C2
    FROM
      T1 FULL OUTER JOIN T2
        ON T1.C1=T2.C1
    WHERE
      (T1.C1 IS NULL
        OR T2.C1 IS NULL);
    C1 C2
    3 01-MAR-11
    9 07-MAR-11
    15 13-MAR-11
    21 19-MAR-11
    24 22-MAR-11
    27 25-MAR-11
    30 28-MAR-11
    8 06-MAR-11
    20 18-MAR-11
    2 28-FEB-11
    10 08-MAR-11
    4 02-MAR-11
    14 12-MAR-11
    16 14-MAR-11With the above knowledge, you should be able to fix your SQL statement to produce the expected results.
    Charles Hooper
    Co-author of "Expert Oracle Practices: Oracle Database Administration from the Oak Table"
    http://hoopercharles.wordpress.com/
    IT Manager/Oracle DBA
    K&M Machine-Fabricating, Inc.

  • Help Required with an OUTER JOIN Query

    Hi,
    I need a list of records carrying UserID and ALL SectionIDs and SectionTitles he/she is associated
    with so I created following query:
    SELECT UsersSections.UserID, Sections.SectionID, Sections.SectionTitle
    FROM UsersSections, Sections
    WHERE UsersSections.SectionID(+) = Sections.SectionID AND UsersSections.UserID = 1
    Where my tables are:
    - UsersSections (UserID, SectionID)
    - Sections (SectionID, SectionTitle)
    The problem is that if I exclude WHERE UserID = '1' clause the query return the desired result i.e. ALL Sections
    And ALL Users associated with the any Section(s). But I need results for a particular UserID but
    Including WHERE UserID = '1' clause only return records for that User only not the sections he/she belongs to which was the purpose of using OUTER JOIN.
    Any help will be highly appreciated.
    Thanks.
    AKG

    userssections.userid (+) = 1

  • Help to rewrite left outer join

    I have the query below running on Db2 AND SQL SERVER 2005 with the syntax as shown. I cannot find a way to make Oracle work with this syntax.
    Can you, please help me do this?
    I need to keep all database statements the same for all databases and in this case I cannot implement this one.
    Regular statement that I do not want to use anymore because executes additional filters:
    SELECT
    s.conflict_id as source_id,
    s.disp_comments --some more fields going here
    FROM sep_conflict s
    left outer join app_activity_history h hist
    on s.conflict_id = hist.source_idNew syntax for SQL server and db2 that I need analog for Oracle:
    SELECT
    s.conflict_id as source_id,
    s.disp_comments --some more fields going here
    FROM sep_conflict s
    left outer join (select source_id from app_activity_history h )as hist (source_id)
    on s.conflict_id = hist.source_idThanks a lot for the help, mj

    Your second query looks similar to this;
    SQL> with sep_conflict as (
       select 1 conflict_id, 1 disp_comments from dual union all
       select 2 conflict_id, 2 disp_comments from dual),
         app_activity_history as (
       select 1 source_id from dual union all
       select null source_id from dual)
    /* End of test data */
    SELECT
       s.conflict_id source_id, s.disp_comments, hist.source_id
    FROM sep_conflict s
    left outer join (select source_id
         from app_activity_history) hist
    on s.conflict_id = hist.source_id
    SOURCE_ID DISP_COMMENTS  SOURCE_ID
             1             1          1
             2             2          
    2 rows selected.

  • URGENT - need help with ansi/iso outer joins

    Hi,
    I am currently preparing for the OCP sql exam for the 9i developer track and I think a statement is printed wrong in my study book, please could somebody confirm the following:-
    Oracle Outer Join syntax
    from tab_a, tab_b
    where a.col_1 (+) = b.col_1
    ANSI/ISO Equivalent
    from tab_a a left outer join tab_b b
    on a.col_1 = b.col_1
    Should n't the above be a right outer join
    Please could somebody confirm or explain if I am wrong.
    Thanks in anticipation.
    Simon
    Note. The book is OCP Introduction to 9i sql (1Z0-007) page 115 (table 3-1) - author Jason Couchman

    It seems so....
    See
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_103a.htm#2107297

  • Help with union or outer join...

    I am trying to select records from two tables to display in one view. I want to show all of table A (Report) if the records in Report have no records in table B (Restriction). However, if my bind parameter (hard-coded for now) UserID matches the Restriction.EMPLOYEE_ID, then the Report can be shown, otherwise it must be omitted.
    I tried Select * from Report where Report.Row_Id NOT IN (Select Report_Id from Restriction) OR (Report.Row_Id = Restriction.Report_Id AND Restriction.Employee_Id = :UserID)
    If there is a Restriction record in the Restriction table, the query works. However, if the Restriction table is empty, I get no rows. There are 6 rows in the Report table (with no corresponding Restriction row). These should show up.
    Note, this is a simplified version of my tables.
    Any ideas?
    I tried to check if the Restriction table is empty, but am not sure how to include or use that in the WHERE clause.
    THANKS!

    I got it working. My working query is:
    SELECT Report.ROW_ID,
    Report.TITLE,
    Report.DESCRIPTION
    FROM REPORT Report,
    RESTRICTION Restriction
    WHERE (REPORT.ROW_ID = Restriction.REPORT_ID
    AND RESTRICTION.EMPLOYEE_ID = 1000) // hard coded #
    UNION
    select Report.ROW_ID,
    Report.TITLE,
    Report.DESCRIPTION
    FROM
    REPORT Report
    WHERE Report.ROW_ID NOT IN (SELECT Restriction.REPORT_ID FROM RESTRICTION Restriction);
    I think the problem was in the "NOT IN (SELECT..." portion somehow... anyway thanks for your time!

  • Need help further tuning view source for outer join

    I have been working on tuning views for use in Discoverer for some time, and I have greatly improved upon what was there, but it is still not where I need it to be. There are 2 views the users join together in Discoverer - one for contract lines, and one for contract flexfields. Run as a 1 to 1 join on contract number, performance is great. However, as soon as I have an outer join on flexfields, the performance is awful. We are talking a difference of under a minute to hours and hours. I have to be able to perform an outer join because there can be contracts without flexfields. Can anyone suggest an alternative method to get the data or further tuning? I will paste both the contract lines and contract flexfields source - I have tuned the flexfields but have done nothing to date with the lines.
    CREATE OR REPLACE VIEW XXDBD_CONTRACT_FLEXFIELDS AS
    SELECT core.contract_id, core.service_id, core.contract_number, core.service_line, core.service, core.product_line, core.equipment, core.UL_Certificate_And_End_Date, core.MAF, core.Termination_Penalty_Percentage, core.multi_year, core.multi_year_effective_dates, core.terms_multi_year, core.SerLineRenPricingMethod, core.ren_line_change, core.zone, core.add_invoice_display, core.add_subgrouping, re.diebold_price, attr.coverage_hours, attr.reaction_times, attr.resolution_times, attr.repair_times, tr.performance_requirement, attr.penalty, attr.penalty_amount, attr.penalty_bonus, attr.mon_break_start, attr.mon_break_end, attr.tues_break_start, attr.tues_break_end, attr.wed_break_start, attr.wed_break_end, attr.thu_break_start, attr.thu_break_end, attr.fri_break_start, attr.fri_break_end, attr.sat_break_start, attr.sat_break_end, attr.sun_break_start, attr.sun_break_end, attr.split_covering, attr.cash_handling
    FROM (SELECT aa.ID Contract_id,
    aa.contract_number,
    dd.id Service_ID ,
    dd.cle_id dd_cle_id,
    dd.line_number service_line,
    xxdbd_Disco_Service_Contract.GetServNameInv
    (dd.id) Service,
    dd.line_number ||'.'||ee.line_number Product_Line,
    xxdbd_Disco_Service_Contract.GetEqpNoInvoice(ee.id)
    Equipment,
    DECODE(dd.attribute_category,'Service Contracts',
    NVL(xxdbd_Disco_Service_Contract.GetContractMasterProperty('DBD_OKS_50_CHARS', dd.attribute1),dd.attribute1),'') UL_Certificate_And_End_Date,
    dd.attribute2 MAF,
    DECODE(dd.attribute_category,'Service Contracts',NVL(xxdbd_Disco_Service_Contract.GetContractMasterProperty('DBD_OKS_NUMERIC', dd.attribute3),dd.attribute3),'') Termination_Penalty_Percentage,
    DECODE(dd.attribute_category,'Service Contracts', DECODE(NVL(xxdbd_Disco_Service_Contract.GetContractMasterProperty('DBD_OKS_MULTIYEAR', dd.attribute5),dd.attribute5),
    'N','No Multi-Year',
    'Y','Multi-Year, Years not Known',
    'Y1','Multi-Year for 1 Year',
    'Y2','Multi-Year for 2 Year',
    'Y3','Multi-Year for 3 Year',
    'Y4','Multi-Year for 4 Year',
    'Y5','Multi-Year for 4 Year',dd.attribute5),'')Multi_Year,
    dd.attribute4 Multi_Year_Effective_Dates,
    DECODE(dd.attribute_category,'Service Contracts', NVL(xxdbd_Disco_Service_Contract.GetContractMasterProperty('DBD_OKS_450_CHARS', dd.attribute9),dd.attribute9),'') Terms_Multi_Year,
    DECODE(dd.attribute_category,'Service Contracts', DECODE(NVL(xxdbd_Disco_Service_Contract.GetContractMasterProperty('DBD_OKS_RENEWAL_PRICING', dd.attribute6),dd.attribute6),
    'MP', 'DBD Markup Percent',
    'CP', 'DBD Contract Price',
    'AI', 'DBD Amount Increase',
    'AD', 'DBD Amount Decrease',
    'TA', 'DBD Target Amount',
    'FR', 'DBD Flat Rate',dd.attribute6),'') SerLineRenPricingMethod,
    DECODE(dd.attribute_category,'Service Contracts', NVL(xxdbd_Disco_Service_Contract.GetContractMasterProperty('DBD_OKS_NUMERIC', dd.attribute7),dd.attribute7),'') Ren_Line_Change,
    DECODE(dd.attribute_category,'Service Contracts', DECODE(NVL(xxdbd_Disco_Service_Contract.GetContractMasterProperty('DBD_OKS_ZONE', dd.attribute8),dd.attribute8),
    'DNA1','DNA Zone 1',
    'DNA2','DNA Zone 2',
    'DNA3','DNA Zone 3',
    'BRAZIL1','Brazil Zone 1 (50 KM)',
    'BRAZIL2','Brazil Zone 2 (80 KM)',
    'BRAZIL3','Brazil Zone 3 (200 KM)',dd.attribute8),'')Zone,
    DECODE(dd.attribute11, 'N','None','SC','Sub Component', 'SN', 'Serial Number', 'SNSC', 'Serial Number and Sub-Component') Add_Invoice_Display,
    DECODE(dd.attribute10, 'SI','Service Item', 'CP','Covered Product', 'PC','Product Category') Add_SubGrouping,
    dd.attribute12 Diebold_Price,
    ee.id ee_id,
    ee.cle_id ee_cle_id
    FROM okc_k_headers_b aa,
    okc_k_lines_b dd,
    okc_k_lines_b ee
    -- xxdbd_temp_flex_contract tfc
    WHERE aa.id = dd.DNZ_CHR_ID
    AND dd.CLE_ID IS NULL
    AND dd.id = ee.cle_id
    AND ee.DNZ_CHR_ID = aa.id
    AND ee.LSE_ID =9
    AND dd.LSE_ID =1
    -- and aa.contract_number = 'NL0000014'
    -- and aa.contract_number in (select contract_number from xxdbd_flex_contract)
    -- AND tfc.contract_number = aa.contract_number
    ) core,
    (SELECT h.contract_number,
    DECODE(l.attribute_category,
    'Coverage Break', xxdbd_get_sib_cont_id(xxdbd_get_parent_cle_id(l.cle_id,2)),
    'Business Process',xxdbd_get_sib_cont_id(xxdbd_get_parent_cle_id(l.cle_id,1)),
    'Coverage Template Header',xxdbd_get_sib_cont_id(l.cle_id),
    'Transaction Type', xxdbd_get_sib_cont_id(xxdbd_get_parent_cle_id(l.cle_id,2)),null) ee_id,
    DECODE(l.attribute_category, 'Business Process', l.attribute1) Coverage_Hours,
    DECODE(l.attribute_category, 'Business Process', l.attribute2) Reaction_Times,
    DECODE(l.attribute_category, 'Business Process', l.attribute3) Resolution_Times,
    DECODE(l.attribute_category, 'Business Process', l.attribute4) Repair_Times,
    DECODE(l.attribute_category, 'Business Process', DECODE(l.attribute5,
    'RA', 'REACTION'
    , 'RS', 'RESOLUTION'
    , 'RR', 'REACTION & RESOLUTION'
    , 'NR', 'NO REQUIREMENT',
    l.attribute5)) Performance_Requirement,
    DECODE(l.attribute_category, 'Coverage Template Header', l.attribute1) Penalty,
    DECODE(l.attribute_category, 'Coverage Template Header', l.attribute2) Penalty_Amount,
    DECODE(l.attribute_category, 'Coverage Template Header', l.attribute3) Penalty_Bonus,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute1) Mon_Break_Start,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute2) Mon_Break_End,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute3) Tues_Break_Start,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute4) Tues_Break_End,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute5) Wed_Break_Start,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute6) Wed_Break_End,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute7) Thu_Break_Start,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute8) Thu_Break_End,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute9) Fri_Break_Start,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute10) Fri_Break_End,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute11) Sat_Break_Start,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute12) Sat_Break_End,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute13) Sun_Break_Start,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute14) Sun_Break_End,
    DECODE(l.attribute_category, 'Transaction Type', l.attribute1) Split_Covering,
    DECODE(l.attribute_category, 'Transaction Type', l.attribute2) Cash_Handling
    from okc_k_lines_b l , okc_k_headers_b h--, xxdbd_temp_flex_contract tfc
    where l.attribute_category in ('Coverage Break', 'Business Process', 'Coverage Template Header','Transaction Type')
    and h.id = l.dnz_chr_id
    -- and h.contract_number in (select contract_number from xxdbd_flex_contract)
    -- and tfc.contract_number = h.contract_number
    ) attr
    where core.ee_id = attr.ee_id (+)
    and core.contract_number = attr.contract_number (+);
    create or replace view xxdbd_contract_lines as
    select aa.id Contract_id,
    bb.id Service_id,
    aa.CONTRACT_NUMBER,
    F1.USER_NAME Created_By,
    F2.USER_NAME LastUpdated_By,
    bb.LINE_NUMBER Service_Line_No,
    bb.LINE_NUMBER ||'.'|| cc.LINE_NUMBER Product_Line_No,
    xxdbd_Disco_Service_Contract.GetServNameInv(bb.id) Service,
    xxdbd_Disco_Service_Contract.GetServDescInv(bb.id) Service_Desc,
    xxdbd_Disco_Service_Contract.GetServicePrice(bb.id) Service_Price,
    bb.PRICE_UNIT Service_List_Price,
    bb.CURRENCY_CODE,
    aa.SCS_CODE Contract_Type,
    bb.STS_CODE Service_Status,
    bb.TRN_CODE Term_Code,
    bb.START_DATE Service_start,
    bb.END_DATE Service_end,
    TO_NUMBER(OKS_ENT_UTIL_PVT.get_billtoshipto(Null, bb.id, 'OKX_BILLTO' )) SERVICE_BillToSite,
    xxdbd_Disco_Service_Contract.GetLocAccount(TO_NUMBER(OKS_ENT_UTIL_PVT.get_billtoshipto(Null, bb.id, 'OKX_BILLTO' ))) Bill_Account,
    xxdbd_Disco_Service_Contract.GetLocation(TO_NUMBER(OKS_ENT_UTIL_PVT.get_billtoshipto(NULL, bb.id, 'OKX_BILLTO' ))) Service_BillTo,
    TO_NUMBER(OKS_ENT_UTIL_PVT.get_billtoshipto(NULL, bb.id, 'OKX_SHIPTO' )) SERVICE_ShipToSite ,
    xxdbd_Disco_Service_Contract.GetLocation(TO_NUMBER(OKS_ENT_UTIL_PVT.get_billtoshipto(NULL, bb.id, 'OKX_SHIPTO' ))) Service_Ship_To,
    xxdbd_Disco_Service_Contract.GetLocAccount(TO_NUMBER(OKS_ENT_UTIL_PVT.get_billtoshipto(NULL, bb.id, 'OKX_SHIPTO' ))) Ship_Account,
    bb.DATE_RENEWED,
    bb.DATE_TERMINATED,
    cc.START_DATE Eqp_Start,
    cc.END_DATE Eqp_End,
    xxdbd_Disco_Service_Contract.GetEqpNoInvoice(cc.id) Eqp_No,
    xxdbd_Disco_Service_Contract.GetEqpDescInvoice(cc.ID) Eqp_Desc,
    xxdbd_Disco_Service_Contract.GetEqpQuantityInvoice(cc.id) Eqp_Quan,
    xxdbd_Disco_Service_Contract.GetEqpSerialNoInvoice(cc.id) Eqp_Serial,
    xxdbd_Disco_Service_Contract.GetCustomerCt(aa.id, bb.id) Cust_Contact,
    DD.ORGANIZATION_ID,
    dd.INSTALL_ADDRESS,
    dd.INSTALL_DATE,
    dd.INSTALL_SITE_ID INSTALL_SITE_USE_ID,
    dd.PARTY_SITE_NAME INSTALL_SITE_NAME,
    dd.PARTY_SITE_NUMBER INSTALL_SITE_NUMBER
    ,cii.inventory_item_id
    ,cii.inv_master_organization_id
    ,aa.authoring_org_id
    ,cc.id equipment_id
    ,TO_NUMBER(replace(bb.attribute12,',','')) annual_contract_amt
    ,ou.name operating_unit
    ,ou.organization_id operating_unit_id
    ,substr(xxdbd_ra_utility.Get_BusinessProcess(cc.cle_id),1,100) business_process
    ,cii.instance_id
    ,cii.instance_number
    from okc_k_headers_b aa
    ,okc_k_lines_b bb
    ,okc_k_lines_b cc
    ,fnd_user f1
    ,fnd_user f2
    ,csi_item_instances cii
    ,okc_k_items items
    ,hr_all_organization_units ou
    ,xxdbd_oks_install_info_v dd
    where aa.id = bb.dnz_chr_id
    and bb.cle_id is null
    and cc.cle_id = bb.id
    and cc.dnz_chr_id = aa.id
    and f1.user_id = bb.created_by
    and f2.user_id = bb.last_updated_by
    and cc.lse_id in (9,25,18,40)
    and dd.line_id (+) = cc.id
    and items.cle_id = cc.id
    and cii.instance_id = items.object1_id1
    and aa.authoring_org_id = ou.organization_id (+);
    Here are the explain plans from TOAD:
    Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
    SELECT STATEMENT Optimizer Mode=CHOOSE 6 49124
    NESTED LOOPS OUTER 6 80 K 49124
    VIEW 6 80 K 49112
    HASH JOIN 6 1 K 49112
    HASH JOIN 17 K 2 M 20214
    TABLE ACCESS FULL OKC.OKC_K_HEADERS_B 5 K 175 K 37
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 17 K 1 M 20162
    INDEX SKIP SCAN XXDBD.XXDBD_OKC_K_LINES_B_N10 39 17085
    TABLE ACCESS FULL OKC.OKC_K_LINES_B 502 K 34 M 27803
    VIEW PUSHED PREDICATE 1 107 2
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 42 3 K 216
    NESTED LOOPS 50 5 K 219
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_HEADERS_B 1 33 3
    INDEX RANGE SCAN OKC.OKC_K_HEADERS_B_U2 1 2
    INDEX RANGE SCAN OKC.OKC_K_LINES_B_N2 1 K 32
    Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
    SELECT STATEMENT Optimizer Mode=CHOOSE 245 63309
    NESTED LOOPS 245 291 K 63309
    NESTED LOOPS OUTER 245 286 K 63064
    NESTED LOOPS 245 80 K 62574
    HASH JOIN 245 74 K 61839
    HASH JOIN 245 71 K 61756
    HASH JOIN OUTER 245 68 K 61673
    HASH JOIN 245 60 K 61664
    HASH JOIN 205 K 32 M 28046
    TABLE ACCESS FULL OKC.OKC_K_HEADERS_B 5 K 244 K 37
    TABLE ACCESS FULL OKC.OKC_K_LINES_B 205 K 23 M 27803
    TABLE ACCESS FULL OKC.OKC_K_LINES_B 2 M 168 M 27803
    TABLE ACCESS FULL HR.HR_ALL_ORGANIZATION_UNITS 2 K 64 K 8
    TABLE ACCESS FULL APPLSYS.FND_USER 13 K 172 K 81
    TABLE ACCESS FULL APPLSYS.FND_USER 13 K 172 K 81
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_ITEMS 1 26 3
    INDEX RANGE SCAN OKC.OKC_K_ITEMS_N1 1 2
    VIEW APPS.XXDBD_OKS_INSTALL_INFO_V 1 861 2
    UNION-ALL PARTITION
    NESTED LOOPS 1 167 9
    NESTED LOOPS 1 108 8
    NESTED LOOPS 1 85 7
    NESTED LOOPS 1 51 6
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 1 25 3
    INDEX UNIQUE SCAN OKC.OKC_K_LINES_B_U1 1 2
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_ITEMS 1 26 3
    INDEX RANGE SCAN OKC.OKC_K_ITEMS_N1 1 2
    TABLE ACCESS BY INDEX ROWID CSI.CSI_ITEM_INSTANCES 1 34 1
    INDEX UNIQUE SCAN CSI.CSI_ITEM_INSTANCES_U01 1
    TABLE ACCESS BY INDEX ROWID AR.HZ_PARTY_SITES 1 23 1
    INDEX UNIQUE SCAN AR.HZ_PARTY_SITES_U1 1
    TABLE ACCESS BY INDEX ROWID AR.HZ_LOCATIONS 1 59 1
    INDEX UNIQUE SCAN AR.HZ_LOCATIONS_U1 1
    NESTED LOOPS 1 144 8
    NESTED LOOPS 1 85 7
    NESTED LOOPS 1 51 6
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 1 25 3
    INDEX UNIQUE SCAN OKC.OKC_K_LINES_B_U1 1 2
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_ITEMS 1 26 3
    INDEX RANGE SCAN OKC.OKC_K_ITEMS_N1 1 2
    TABLE ACCESS BY INDEX ROWID CSI.CSI_ITEM_INSTANCES 1 34 1
    INDEX UNIQUE SCAN CSI.CSI_ITEM_INSTANCES_U01 1
    TABLE ACCESS BY INDEX ROWID AR.HZ_LOCATIONS 1 59 1
    INDEX UNIQUE SCAN AR.HZ_LOCATIONS_U1 1
    NESTED LOOPS 1 161 8
    NESTED LOOPS 1 85 7
    NESTED LOOPS 1 51 6
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 1 25 3
    INDEX UNIQUE SCAN OKC.OKC_K_LINES_B_U1 1 2
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_ITEMS 1 26 3
    INDEX RANGE SCAN OKC.OKC_K_ITEMS_N1 1 2
    TABLE ACCESS BY INDEX ROWID CSI.CSI_ITEM_INSTANCES 1 34 1
    INDEX UNIQUE SCAN CSI.CSI_ITEM_INSTANCES_U01 1
    TABLE ACCESS BY INDEX ROWID AR.HZ_PARTIES 1 76 1
    INDEX UNIQUE SCAN AR.HZ_PARTIES_U1 1
    TABLE ACCESS BY INDEX ROWID CSI.CSI_ITEM_INSTANCES 1 21 1
    INDEX UNIQUE SCAN CSI.CSI_ITEM_INSTANCES_U01 1
    And here is the SQL to join:
    select * from xxdbd_contract_lines l, xxdbd_contract_flexfields f
    where f.service_id (+) = l.service_id
    and f.contract_number (+) = l.contract_number
    and l.contract_number = 'NL0000014'
    Operation Object Name Rows Bytes Cost Object Node In/Out PStart PStop
    SELECT STATEMENT Optimizer Mode=CHOOSE 1 49221
    HASH JOIN OUTER 1 38 K 49221
    VIEW APPS.XXDBD_CONTRACT_LINES 1 19 K 96
    NESTED LOOPS OUTER 1 1 K 96
    NESTED LOOPS 1 358 94
    NESTED LOOPS 1 345 93
    NESTED LOOPS 1 332 92
    NESTED LOOPS 1 311 91
    NESTED LOOPS 1 285 88
    NESTED LOOPS 448 72 K 88
    NESTED LOOPS OUTER 1 78 4
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_HEADERS_B 1 46 3
    INDEX RANGE SCAN OKC.OKC_K_HEADERS_B_U2 1 2
    TABLE ACCESS BY INDEX ROWID HR.HR_ALL_ORGANIZATION_UNITS 1 32 1
    INDEX UNIQUE SCAN HR.HR_ORGANIZATION_UNITS_PK 1
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 378 32 K 84
    INDEX RANGE SCAN XXDBD.XXDBD_OKC_K_LINES_B_N10 378 16
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 1 119
    INDEX RANGE SCAN OKC.OKC_K_LINES_B_N2 1 K 32
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_ITEMS 1 26 3
    INDEX RANGE SCAN OKC.OKC_K_ITEMS_N1 1 2
    TABLE ACCESS BY INDEX ROWID CSI.CSI_ITEM_INSTANCES 1 21 1
    INDEX UNIQUE SCAN CSI.CSI_ITEM_INSTANCES_U01 1
    TABLE ACCESS BY INDEX ROWID APPLSYS.FND_USER 1 13 1
    INDEX UNIQUE SCAN APPLSYS.FND_USER_U1 1
    TABLE ACCESS BY INDEX ROWID APPLSYS.FND_USER 1 13 1
    INDEX UNIQUE SCAN APPLSYS.FND_USER_U1 1
    VIEW APPS.XXDBD_OKS_INSTALL_INFO_V 1 861 2
    UNION-ALL PARTITION
    NESTED LOOPS 1 167 9
    NESTED LOOPS 1 108 8
    NESTED LOOPS 1 85 7
    NESTED LOOPS 1 51 6
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 1 25 3
    INDEX UNIQUE SCAN OKC.OKC_K_LINES_B_U1 1 2
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_ITEMS 1 26 3
    INDEX RANGE SCAN OKC.OKC_K_ITEMS_N1 1 2
    TABLE ACCESS BY INDEX ROWID CSI.CSI_ITEM_INSTANCES 1 34 1
    INDEX UNIQUE SCAN CSI.CSI_ITEM_INSTANCES_U01 1
    TABLE ACCESS BY INDEX ROWID AR.HZ_PARTY_SITES 1 23 1
    INDEX UNIQUE SCAN AR.HZ_PARTY_SITES_U1 1
    TABLE ACCESS BY INDEX ROWID AR.HZ_LOCATIONS 1 59 1
    INDEX UNIQUE SCAN AR.HZ_LOCATIONS_U1 1
    NESTED LOOPS 1 144 8
    NESTED LOOPS 1 85 7
    NESTED LOOPS 1 51 6
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 1 25 3
    INDEX UNIQUE SCAN OKC.OKC_K_LINES_B_U1 1 2
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_ITEMS 1 26 3
    INDEX RANGE SCAN OKC.OKC_K_ITEMS_N1 1 2
    TABLE ACCESS BY INDEX ROWID CSI.CSI_ITEM_INSTANCES 1 34 1
    INDEX UNIQUE SCAN CSI.CSI_ITEM_INSTANCES_U01 1
    TABLE ACCESS BY INDEX ROWID AR.HZ_LOCATIONS 1 59 1
    INDEX UNIQUE SCAN AR.HZ_LOCATIONS_U1 1
    NESTED LOOPS 1 161 8
    NESTED LOOPS 1 85 7
    NESTED LOOPS 1 51 6
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 1 25 3
    INDEX UNIQUE SCAN OKC.OKC_K_LINES_B_U1 1 2
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_ITEMS 1 26 3
    INDEX RANGE SCAN OKC.OKC_K_ITEMS_N1 1 2
    TABLE ACCESS BY INDEX ROWID CSI.CSI_ITEM_INSTANCES 1 34 1
    INDEX UNIQUE SCAN CSI.CSI_ITEM_INSTANCES_U01 1
    TABLE ACCESS BY INDEX ROWID AR.HZ_PARTIES 1 76 1
    INDEX UNIQUE SCAN AR.HZ_PARTIES_U1 1
    VIEW APPS.XXDBD_CONTRACT_FLEXFIELDS 6 112 K 49124
    NESTED LOOPS OUTER 6 80 K 49124
    VIEW 6 80 K 49112
    HASH JOIN 6 1 K 49112
    HASH JOIN 17 K 2 M 20214
    TABLE ACCESS FULL OKC.OKC_K_HEADERS_B 5 K 175 K 37
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 17 K 1 M 20162
    INDEX SKIP SCAN XXDBD.XXDBD_OKC_K_LINES_B_N10 39 17085
    TABLE ACCESS FULL OKC.OKC_K_LINES_B 502 K 34 M 27803
    VIEW PUSHED PREDICATE 1 107 2
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_LINES_B 42 3 K 216
    NESTED LOOPS 50 5 K 219
    TABLE ACCESS BY INDEX ROWID OKC.OKC_K_HEADERS_B 1 33 3
    INDEX RANGE SCAN OKC.OKC_K_HEADERS_B_U2 1 2
    INDEX RANGE SCAN OKC.OKC_K_LINES_B_N2 1 K 32

    DECODE(l.attribute_category, 'Coverage Template Header', l.attribute3) Penalty_Bonus,
    DECODE(l.attribute_category, 'Coverage Break', l.attribute1) Mon_Break_Start,
    DECODE(l.attribute_category, 'Transaction Type', l.attribute1) Split_Covering,Uh oh, the dreaded entity attibute value, or generic, data model.
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:10678084117056
    I am afraid slow performance is a built in feature of this database design, not much you can do in queries.
    You could possibly create the views as materialized views and query those instead.
    Quote from the linked article
    But, how does it perform? Miserably, terribly, horribly. A simple "select
    first_name, last_name from person" query is transformed into a 3-table join with
    aggregates and all. Further, if the attributes are "NULLABLE" - that is, there
    might not be a row in OBJECT_ATTRIBUTES for some attributes, you may have to
    outer join instead of just joining which in some cases can remove more optimal
    query plans from consideration.
    Writing queries might look pretty straightforward, but it's impossible to do in
    a performant fashion.

  • Outer join with nested tables

    I am dealing with a nested table (I simplified the case
    for purpose of posting):
    CREATE TABLE boris_main_tab (
    IND_SSN          VARCHAR2(9) PRIMARY KEY,
    children          B_CHILDREN_TBL,
    ) nested table children stored as....
    where B_CHILDREN_TBL is defined like this:
    create or replace type b_children_type as object (
         child_ssn               VARCHAR2(9),
         child_first_name          VARCHAR2(20),
         child_last_name          VARCHAR2(20),
         child_dob               date
    create or replace type b_children_tbl as table of b_children_type;
    if I want to display person's ssn along with his/her children information I do like this:
    SELECT m.ind_ssn, c.child_ssn, c.child_first_name
    FROM boris_main_tab m,
    TABLE(m.children) c
    This is a statement I can find everywhere. But there is a caveat here, they
    forgot to mention. This is really an inner join, so I don't get childless
    people. Can you, guys, help me with the outer join syntax?
    I mean, of course, I found the obvious solution to make this inner join
    into a view and then join it with the boris_main_tab again this time using the
    regular outer join syntax. But it seems to me there has to be something simplier than that.
    But I can't find it. It really hurting me, since I have a few nested table
    columsn and people want to see the records where I need to mention a few of
    them, sort of like
    from boris_main_tab m, TABLE(m.children) c, TABLE(m.spouses) s
    where c.child_last_name <> m.spouse.last_name
    in cases like this the fact that EACH of these joins is inner join really
    hurts the logic.
    Respectfully,
    Boris

    Hi Borris,
    Found the following in the Oracle Documentation under: Oracle8i Application Developer's Guide - Object-Relational Features Release 2 (8.1.6)
    2 Managing Oracle Objects / Using Collections / Collection Unnesting
    URL: http://www.znow.com/sales/oracle/appdev.816/a76976/adobjmng.htm#1002885
    Oracle8i also supports the following syntax to produce outer-join results:
    SELECT d.*, e.* FROM depts d, TABLE(d.emps)(+) e;
    The (+) indicates that the dependent join between DEPTS and D.EMPS should be NULL-augmented. That is, there > will be rows of DEPTS in the output for which D.EMPS is NULL or empty, with NULL values for columns
    corresponding to D.EMPS.

  • Need help with WITH Clause and Outer-Joins

    Hi,
    I have been struggling to understand these queries.
    C:\>sqlplus /nolog
    SQL*Plus: Release 10.2.0.1.0 - Production on Thu Oct 20 15:28:33 2011
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    SQL> conn hr@xe
    Enter password:
    Connected.
    SQL> with week as ( select * from (select 1 item, 10 qty, 1 week from dual ))
      2  select main.item
      3       , week1.qty qty1
      4       , week2.qty qty2
      5    from week week1
      6       , week week2
      7       , ( select 1 item from dual ) main
      8   where main.item = week1.item (+)
      9     and week1.week (+) = 1
    10     and main.item = week2.item (+)
    11     and week2.week (+) = 2
    12     ;
          ITEM       QTY1       QTY2
             1
    SQL> with week as ( select 1 item, 10 qty, 1 week from dual )
      2  select main.item
      3       , week1.qty qty1
      4       , week2.qty qty2
      5    from week week1
      6       , week week2
      7       , ( select 1 item from dual ) main
      8   where main.item = week1.item (+)
      9     and week1.week (+) = 1
    10     and main.item = week2.item (+)
    11     and week2.week (+) = 2
    12     ;
          ITEM       QTY1       QTY2
             1         10
    SQL>I don't understand why the first query won't show the result for QTY1. The only difference they have is that the first uses an additional inline view.
    Can someone please explain the reason behind.
    Thanks,
    Allen
    Edited by: Allen Sandiego on Oct 20, 2011 3:31 PM
    Enclosed in CODE tags.

    Also in 10.2.0.4.0. The predicate part contains a clue about the transformation
    mhouri > select * from v$version;
    BANNER                                                                         
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi               
    PL/SQL Release 10.2.0.4.0 - Production                                         
    CORE     10.2.0.4.0     Production                                                     
    TNS for Solaris: Version 10.2.0.4.0 - Production                               
    NLSRTL Version 10.2.0.4.0 - Production                                         
    mhouri > with week as ( select * from (select 1 item, 10 qty, 1 week from dual ))
      2        select
      3               main.item
      4             , week1.qty qty1
      5             , week2.qty qty2
      6          from week week1
      7             , week week2
      8             , ( select 1 item from dual ) main
      9         where main.item = week1.item (+)
    10           and week1.week (+) = 1
    11          and main.item = week2.item (+)
    12          and week2.week (+) = 2;
          ITEM       QTY1       QTY2                                                                                       
             1                                                                                                             
    mhouri > select * from table(dbms_xplan.display_cursor);
    | Id  | Operation                  | Name                        | Rows  | Bytes | Cost (%CPU)| Time     |             
    |   0 | SELECT STATEMENT           |                             |       |       |     8 (100)|          |             
    |   1 |  TEMP TABLE TRANSFORMATION |                             |       |       |            |          |             
    |   2 |   LOAD AS SELECT           |                             |       |       |            |          |             
    |   3 |    FAST DUAL               |                             |     1 |       |     2   (0)| 00:00:01 |             
    |   4 |   MERGE JOIN OUTER         |                             |     1 |    18 |     6   (0)| 00:00:01 |             
    |   5 |    NESTED LOOPS OUTER      |                             |     1 |     9 |     4   (0)| 00:00:01 |             
    |   6 |     FAST DUAL              |                             |     1 |       |     2   (0)| 00:00:01 |             
    |*  7 |     VIEW                   |                             |     1 |     9 |     2   (0)| 00:00:01 |             
    |   8 |      TABLE ACCESS FULL     | SYS_TEMP_0FD9D6631_72948EFD |     1 |    39 |     2   (0)| 00:00:01 |             
    |   9 |    BUFFER SORT             |                             |     1 |     9 |     4   (0)| 00:00:01 |             
    |* 10 |     VIEW                   |                             |     1 |     9 |     2   (0)| 00:00:01 |             
    |  11 |      TABLE ACCESS FULL     | SYS_TEMP_0FD9D6631_72948EFD |     1 |    39 |     2   (0)| 00:00:01 |             
    Predicate Information (identified by operation id):                                                                    
       7 - filter(("WEEK1"."ITEM"=1 AND "WEEK1"."WEEK"=1))                                                                 
      10 - filter(("WEEK2"."ITEM"=1 AND "WEEK2"."WEEK"=2))                                                                 
    33 rows selected.
    mhouri > with week as ( select * from (select 1 item, 10 qty, 1 week from dual ))
      2        select /*+ no_query_transformation */
      3               main.item
      4             , week1.qty qty1
      5             , week2.qty qty2
      6          from week week1
      7             , week week2
      8             , ( select 1 item from dual ) main
      9         where main.item = week1.item (+)
    10           and week1.week (+) = 1
    11          and main.item = week2.item (+)
    12          and week2.week (+) = 2;
          ITEM       QTY1       QTY2                                                                                       
             1         10                                                                                                  
    mhouri > select * from table(dbms_xplan.display_cursor);
    | Id  | Operation                  | Name                        | Rows  | Bytes | Cost (%CPU)| Time     |             
    |   0 | SELECT STATEMENT           |                             |       |       |     9 (100)|          |             
    |   1 |  TEMP TABLE TRANSFORMATION |                             |       |       |            |          |             
    |   2 |   LOAD AS SELECT           |                             |       |       |            |          |             
    |   3 |    VIEW                    |                             |     1 |     9 |     2   (0)| 00:00:01 |             
    |   4 |     FAST DUAL              |                             |     1 |       |     2   (0)| 00:00:01 |             
    |*  5 |   HASH JOIN OUTER          |                             |     1 |    21 |     7  (15)| 00:00:01 |             
    |*  6 |    HASH JOIN OUTER         |                             |     1 |    12 |     5  (20)| 00:00:01 |             
    |   7 |     VIEW                   |                             |     1 |     3 |     2   (0)| 00:00:01 |             
    |   8 |      FAST DUAL             |                             |     1 |       |     2   (0)| 00:00:01 |             
    |*  9 |     VIEW                   |                             |     1 |     9 |     2   (0)| 00:00:01 |             
    |  10 |      TABLE ACCESS FULL     | SYS_TEMP_0FD9D6630_72948EFD |     1 |     9 |     2   (0)| 00:00:01 |             
    |* 11 |    VIEW                    |                             |     1 |     9 |     2   (0)| 00:00:01 |             
    |  12 |     TABLE ACCESS FULL      | SYS_TEMP_0FD9D6630_72948EFD |     1 |     9 |     2   (0)| 00:00:01 |             
    Predicate Information (identified by operation id):                                                                    
       5 - access("MAIN"."ITEM"="WEEK2"."ITEM")                                                                            
       6 - access("MAIN"."ITEM"="WEEK1"."ITEM")                                                                            
       9 - filter("WEEK1"."WEEK"=1)                                                                                        
      11 - filter("WEEK2"."WEEK"=2)                                                                                        
    36 rows selected.Best regards
    Mohamed Houri

  • Outer Join Performance Issue

    Dear All,
    Please help me in tuning the below query as it is including the outer join and is going for full table scans.
    Query :
    SELECT
    T27.CONFLICT_ID,
    T27.LAST_UPD,
    T27.CREATED,
    T27.LAST_UPD_BY,
    T27.CREATED_BY,
    T27.MODIFICATION_NUM,
    T27.ROW_ID,
    T24.ATTRIB_39,
    T27.REMIT_ADDR_ORG_ID,
    T27.REMIT_ORG_EXT_ID,
    T16.NAME,
    T25.ACCNT_TYPE_CD,
    T27.RECAL_TAX_SRV_FLG,
    T27.PROJ_ID,
    T8.PROJ_NUM,
    T8.BU_ID,
    T5.NAME,
    T8.INTEGRATION_ID,
    T12.CURCY_CD,
    T25.PR_BL_ADDR_ID,
    T25.URL,
    T27.TTL_INVC_AMT,
    T27.INVC_TYPE_CD,
    T27.TTL_PD_AMT,
    T3.CG_ASSSET_ID,
    T17.ASSET_NUM,
    T27.VENDR_INVOICE_NUM,
    T4.TOT_QTY_SHIP,
    T4.TOT_EXTND_PRICE,
    T27.ACCNT_ID,
    T25.INTEGRATION_ID,
    T25.NAME,
    T25.BU_ID,
    T25.AVAIL_CREDIT_AMT,
    T10.NAME,
    T27.AGREEMENT_ID,
    T4.TOT_EXTND_TAX,
    T27.STMT_SOURCE_CD,
    T4.SRC_INVLOC_ID,
    T27.STATUS_CD,
    T4.TOT_QTY_BONUS,
    T27.X_DEPOSIT_AMT,
    T27.COMMENTS,
    T27.INVC_FULLY_PAID_DT,
    T26.SEQ_NUM,
    T27.ELEMENT_ID,
    T26.INSCLM_ID,
    T14.INSCLAIM_NUM,
    T27.BL_PER_ID,
    T27.INS_CLAIM_ID,
    T27.FN_ACCNT_ID,
    T27.CUSTOMER_REF_NUM,
    T27.TTL_NONREC_AMT,
    T25.OU_NUM,
    T24.ATTRIB_39,
    T27.AMT_CURCY_CD,
    T2.CCNUM_ENCRPKEY_REF,
    T18.PR_DEPOSIT_ID,
    T19.DISCNT_RULE_CD,
    T27.ORDER_ID,
    T4.STATUS_CHG_FLG,
    T25.MAIN_PH_NUM,
    T25.MAIN_FAX_PH_NUM,
    T27.DELINQUENT_FLG,
    T15.LOGIN,
    T25.PR_POSTN_ID,
    T4.ORDER_NUM,
    T22.ADDR,
    T22.ZIPCODE,
    T27.INVC_NUM,
    T27.INVC_DT,
    T22.COUNTRY,
    T22.CITY,
    T27.BL_ADDR_ID,
    T23.NAME,
    T27.POSTED_DT,
    T20.NAME,
    T27.BL_PERIOD_ID,
    T27.GOODS_DLVRD_TS,
    T23.NET_DAYS,
    T27.PAYMENT_TERM_ID,
    T23.DUE_DT,
    T27.DUE_DT,
    T27.VOID_REASON_TEXT,
    T27.DEPT_CD,
    T24.ATTRIB_60,
    T24.ATTRIB_28,
    T21.AMT,
    T1.STATE,
    T1.ADDR,
    T1.ADDR_LINE_2,
    T1.COUNTRY,
    T1.CITY,
    T1.ZIPCODE,
    T11.LOGIN,
    T21.ROW_ID,
    T9.ROW_ID,
    T1.ROW_ID,
    T13.ROW_ID,
    T7.ROW_ID
    FROM
    SIEBEL.S_ADDR_PER T1,
    SIEBEL.S_PTY_PAY_PRFL T2,
    SIEBEL.S_INVLOC T3,
    SIEBEL.S_ORDER T4,
    SIEBEL.S_ORG_EXT T5,
    SIEBEL.S_POSTN T6,
    SIEBEL.S_PARTY T7,
    SIEBEL.S_PROJ T8,
    SIEBEL.S_CON_ADDR T9,
    SIEBEL.S_ORG_EXT T10,
    SIEBEL.S_USER T11,
    SIEBEL.S_DOC_QUOTE T12,
    SIEBEL.S_ACCNT_POSTN T13,
    SIEBEL.S_INS_CLAIM T14,
    SIEBEL.S_USER T15,
    SIEBEL.S_ORG_EXT T16,
    SIEBEL.S_ASSET T17,
    SIEBEL.S_ORDER_TNTX T18,
    SIEBEL.S_ORG_EXT_TNTX T19,
    SIEBEL.S_PERIOD T20,
    SIEBEL.S_DEPOSIT_TNT T21,
    SIEBEL.S_ADDR_PER T22,
    SIEBEL.S_PAYMENT_TERM T23,
    SIEBEL.S_ORG_EXT_X T24,
    SIEBEL.S_ORG_EXT T25,
    SIEBEL.S_INSCLM_ELMNT T26,
    SIEBEL.S_INVOICE T27
    WHERE
    T25.BU_ID = T10.PAR_ROW_ID (+) AND
    T26.INSCLM_ID = T14.ROW_ID (+) AND
    T27.ELEMENT_ID = T26.ROW_ID (+) AND
    T27.LAST_UPD_BY = T15.PAR_ROW_ID (+) AND
    T4.QUOTE_ID = T12.ROW_ID (+) AND
    T3.CG_ASSSET_ID = T17.ROW_ID (+) AND
    T27.BL_ADDR_ID = T22.ROW_ID (+) AND
    T8.BU_ID = T5.PAR_ROW_ID (+) AND
    T27.PER_PAY_PRFL_ID = T2.ROW_ID (+) AND
    T27.REMIT_ORG_EXT_ID = T16.PAR_ROW_ID (+) AND
    T27.PROJ_ID = T8.ROW_ID (+) AND
    T27.BL_PERIOD_ID = T20.ROW_ID (+) AND
    T27.PAYMENT_TERM_ID = T23.ROW_ID (+) AND
    T12.BU_ID = T19.PAR_ROW_ID (+) AND
    T27.ACCNT_ID = T25.PAR_ROW_ID (+) AND
    T27.ORDER_ID = T18.ROW_ID (+) AND
    T4.SRC_INVLOC_ID = T3.ROW_ID (+) AND
    T27.ORDER_ID = T4.ROW_ID (+) AND
    T27.ACCNT_ID = T24.PAR_ROW_ID (+) AND
    T18.PR_DEPOSIT_ID = T21.ROW_ID (+) AND
    T27.BL_ADDR_ID = T9.ADDR_PER_ID (+) AND
    T27.ACCNT_ID = T9.ACCNT_ID (+) AND
    T27.BL_ADDR_ID = T1.ROW_ID (+) AND
    T25.PR_POSTN_ID = T13.POSITION_ID (+) AND
    T25.ROW_ID = T13.OU_EXT_ID (+) AND
    T13.POSITION_ID = T7.ROW_ID (+) AND
    T13.POSITION_ID = T6.PAR_ROW_ID (+) AND
    T6.PR_EMP_ID = T11.PAR_ROW_ID (+) AND
    (T27.INVC_TYPE_CD = :1) AND
    (T27.DEPT_CD = :2);
    Explan Plan Output :
    PLAN_TABLE_OUTPUT
    Plan hash value: 3132260827
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 1958 | 1896K (11)| 00:50:46 |
    | 1 | NESTED LOOPS OUTER | | 1 | 1958 | 1896K (11)| 00:50:46 |
    | 2 | NESTED LOOPS OUTER | | 1 | 1922 | 1896K (11)| 00:50:46 |
    | 3 | NESTED LOOPS OUTER | | 1 | 1885 | 1896K (11)| 00:50:46 |
    | 4 | NESTED LOOPS OUTER | | 1 | 1861 | 1896K (11)| 00:50:46 |
    | 5 | NESTED LOOPS OUTER | | 1 | 1849 | 1896K (11)| 00:50:46 |
    | 6 | NESTED LOOPS OUTER | | 1 | 1817 | 1896K (11)| 00:50:46 |
    | 7 | NESTED LOOPS OUTER | | 1 | 1792 | 1896K (11)| 00:50:46 |
    | 8 | NESTED LOOPS OUTER | | 1 | 1771 | 1896K (11)| 00:50:46 |
    | 9 | NESTED LOOPS OUTER | | 1 | 1739 | 1896K (11)| 00:50:46 |
    | 10 | NESTED LOOPS OUTER | | 1 | 1483 | 1896K (11)| 00:50:46 |
    | 11 | NESTED LOOPS OUTER | | 1 | 1451 | 1896K (11)| 00:50:46 |
    | 12 | NESTED LOOPS OUTER | | 1 | 1419 | 1896K (11)| 00:50:46 |
    | 13 | NESTED LOOPS OUTER | | 1 | 1361 | 1896K (11)| 00:50:46 |
    | 14 | NESTED LOOPS OUTER | | 1 | 1276 | 1896K (11)| 00:50:46 |
    | 15 | NESTED LOOPS OUTER | | 1 | 1202 | 1896K (11)| 00:50:46 |
    | 16 | NESTED LOOPS OUTER | | 1 | 1108 | 1896K (11)| 00:50:46 |
    | 17 | NESTED LOOPS OUTER | | 1 | 1087 | 1896K (11)| 00:50:46 |
    | 18 | NESTED LOOPS OUTER | | 1 | 1040 | 1896K (11)| 00:50:46 |
    | 19 | NESTED LOOPS OUTER | | 1 | 939 | 1896K (11)| 00:50:46 |
    | 20 | NESTED LOOPS OUTER | | 1 | 894 | 1896K (11)| 00:50:46 |
    | 21 | NESTED LOOPS OUTER | | 1 | 868 | 1896K (11)| 00:50:46 |
    | 22 | NESTED LOOPS OUTER | | 1 | 843 | 1896K (11)| 00:50:46 |
    | 23 | NESTED LOOPS OUTER | | 1 | 824 | 1896K (11)| 00:50:46 |
    | 24 | NESTED LOOPS OUTER | | 1 | 690 | 1896K (11)| 00:50:46 |
    | 25 | NESTED LOOPS OUTER | | 1 | 613 | 1896K (11)| 00:50:46 |
    | 26 | NESTED LOOPS OUTER | | 1 | 457 | 1896K (11)| 00:50:46 |
    |* 27 | TABLE ACCESS FULL | S_INVOICE | 1 | 269 | 1896K (11)| 00:50:46 |
    | 28 | TABLE ACCESS BY INDEX ROWID| S_PROJ | 1 | 188 | 1 (0)| 00:00:01 |
    |* 29 | INDEX UNIQUE SCAN | S_PROJ_P1 | 1 | | 1 (0)| 00:00:01 |
    | 30 | TABLE ACCESS BY INDEX ROWID | S_PAYMENT_TERM | 1 | 156 | 1 (0)| 00:00:01 |
    |* 31 | INDEX UNIQUE SCAN | S_PAYMENT_TERM_P1 | 1 | | 1 (0)| 00:00:01 |
    | 32 | TABLE ACCESS BY INDEX ROWID | S_INSCLM_ELMNT | 1 | 77 | 1 (0)| 00:00:01 |
    |* 33 | INDEX UNIQUE SCAN | S_INSCLM_ELMNT_P1 | 1 | | 1 (0)| 00:00:01 |
    | 34 | TABLE ACCESS BY INDEX ROWID | S_INS_CLAIM | 1 | 134 | 1 (0)| 00:00:01 |
    |* 35 | INDEX UNIQUE SCAN | S_INS_CLAIM_P1 | 1 | | 1 (0)| 00:00:01 |
    | 36 | TABLE ACCESS BY INDEX ROWID | S_PERIOD | 1 | 19 | 1 (0)| 00:00:01 |
    |* 37 | INDEX UNIQUE SCAN | S_PERIOD_P1 | 1 | | 1 (0)| 00:00:01 |
    | 38 | TABLE ACCESS BY INDEX ROWID | S_USER | 1 | 25 | 2 (0)| 00:00:01 |
    |* 39 | INDEX UNIQUE SCAN | S_USER_U2 | 1 | | 1 (0)| 00:00:01 |
    | 40 | TABLE ACCESS BY INDEX ROWID | S_ORDER_TNTX | 1 | 26 | 2 (0)| 00:00:01 |
    |* 41 | INDEX UNIQUE SCAN | S_ORDER_TNTX_P1 | 1 | | 1 (0)| 00:00:01 |
    | 42 | TABLE ACCESS BY INDEX ROWID | S_DEPOSIT_TNT | 1 | 45 | 1 (0)| 00:00:01 |
    |* 43 | INDEX UNIQUE SCAN | S_DEPOSIT_TNT_P1 | 1 | | 1 (0)| 00:00:01 |
    | 44 | TABLE ACCESS BY INDEX ROWID | S_ORDER | 1 | 101 | 2 (0)| 00:00:01 |
    |* 45 | INDEX UNIQUE SCAN | S_ORDER_P1 | 1 | | 1 (0)| 00:00:01 |
    | 46 | TABLE ACCESS BY INDEX ROWID | S_INVLOC | 1 | 47 | 1 (0)| 00:00:01 |
    |* 47 | INDEX UNIQUE SCAN | S_INVLOC_P1 | 1 | | 1 (0)| 00:00:01 |
    | 48 | TABLE ACCESS BY INDEX ROWID | S_DOC_QUOTE | 1 | 21 | 1 (0)| 00:00:01 |
    |* 49 | INDEX UNIQUE SCAN | S_DOC_QUOTE_P1 | 1 | | 1 (0)| 00:00:01 |
    | 50 | TABLE ACCESS BY INDEX ROWID | S_ORG_EXT_TNTX | 1 | 94 | 1 (0)| 00:00:01 |
    |* 51 | INDEX RANGE SCAN | S_ORG_EXT_TNTX_U1 | 1 | | 1 (0)| 00:00:01 |
    | 52 | TABLE ACCESS BY INDEX ROWID | S_PTY_PAY_PRFL | 1 | 74 | 1 (0)| 00:00:01 |
    |* 53 | INDEX UNIQUE SCAN | S_PTY_PAY_PRFL_P1 | 1 | | 1 (0)| 00:00:01 |
    | 54 | TABLE ACCESS BY INDEX ROWID | S_ADDR_PER | 1 | 85 | 2 (0)| 00:00:01 |
    |* 55 | INDEX UNIQUE SCAN | S_ADDR_PER_P1 | 1 | | 1 (0)| 00:00:01 |
    | 56 | TABLE ACCESS BY INDEX ROWID | S_ADDR_PER | 1 | 58 | 1 (0)| 00:00:01 |
    |* 57 | INDEX UNIQUE SCAN | S_ADDR_PER_P1 | 1 | | 1 (0)| 00:00:01 |
    | 58 | TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 32 | 1 (0)| 00:00:01 |
    |* 59 | INDEX UNIQUE SCAN | S_ORG_EXT_U3 | 1 | | 1 (0)| 00:00:01 |
    | 60 | TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 32 | 1 (0)| 00:00:01 |
    |* 61 | INDEX UNIQUE SCAN | S_ORG_EXT_U3 | 1 | | 1 (0)| 00:00:01 |
    | 62 | TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 256 | 2 (0)| 00:00:01 |
    |* 63 | INDEX UNIQUE SCAN | S_ORG_EXT_U3 | 1 | | 1 (0)| 00:00:01 |
    | 64 | TABLE ACCESS BY INDEX ROWID | S_ACCNT_POSTN | 1 | 32 | 3 (0)| 00:00:01 |
    |* 65 | INDEX RANGE SCAN | S_ACCNT_POSTN_U1 | 1 | | 2 (0)| 00:00:01 |
    | 66 | TABLE ACCESS BY INDEX ROWID | S_POSTN | 1 | 21 | 1 (0)| 00:00:01 |
    |* 67 | INDEX UNIQUE SCAN | S_POSTN_U2 | 1 | | 1 (0)| 00:00:01 |
    | 68 | TABLE ACCESS BY INDEX ROWID | S_USER | 1 | 25 | 2 (0)| 00:00:01 |
    |* 69 | INDEX UNIQUE SCAN | S_USER_U2 | 1 | | 1 (0)| 00:00:01 |
    | 70 | TABLE ACCESS BY INDEX ROWID | S_ORG_EXT | 1 | 32 | 2 (0)| 00:00:01 |
    |* 71 | INDEX UNIQUE SCAN | S_ORG_EXT_U3 | 1 | | 1 (0)| 00:00:01 |
    |* 72 | INDEX UNIQUE SCAN | S_PARTY_P1 | 1 | 12 | 1 (0)| 00:00:01 |
    | 73 | TABLE ACCESS BY INDEX ROWID | S_ASSET | 1 | 24 | 2 (0)| 00:00:01 |
    |* 74 | INDEX UNIQUE SCAN | S_ASSET_P1 | 1 | | 2 (0)| 00:00:01 |
    | 75 | TABLE ACCESS BY INDEX ROWID | S_ORG_EXT_X | 1 | 37 | 2 (0)| 00:00:01 |
    |* 76 | INDEX RANGE SCAN | S_ORG_EXT_X_U1 | 1 | | 2 (0)| 00:00:01 |
    | 77 | TABLE ACCESS BY INDEX ROWID | S_CON_ADDR | 1 | 36 | 3 (0)| 00:00:01 |
    |* 78 | INDEX RANGE SCAN | S_CON_ADDR_U1 | 1 | | 2 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    27 - filter("T27"."DEPT_CD"=:2 AND "T27"."INVC_TYPE_CD"=:1)
    29 - access("T27"."PROJ_ID"="T8"."ROW_ID"(+))
    31 - access("T27"."PAYMENT_TERM_ID"="T23"."ROW_ID"(+))
    33 - access("T27"."ELEMENT_ID"="T26"."ROW_ID"(+))
    35 - access("T26"."INSCLM_ID"="T14"."ROW_ID"(+))
    37 - access("T27"."BL_PERIOD_ID"="T20"."ROW_ID"(+))
    39 - access("T27"."LAST_UPD_BY"="T15"."PAR_ROW_ID"(+))
    41 - access("T27"."ORDER_ID"="T18"."ROW_ID"(+))
    43 - access("T18"."PR_DEPOSIT_ID"="T21"."ROW_ID"(+))
    45 - access("T27"."ORDER_ID"="T4"."ROW_ID"(+))
    47 - access("T4"."SRC_INVLOC_ID"="T3"."ROW_ID"(+))
    49 - access("T4"."QUOTE_ID"="T12"."ROW_ID"(+))
    51 - access("T12"."BU_ID"="T19"."PAR_ROW_ID"(+))
    53 - access("T27"."PER_PAY_PRFL_ID"="T2"."ROW_ID"(+))
    55 - access("T27"."BL_ADDR_ID"="T1"."ROW_ID"(+))
    57 - access("T27"."BL_ADDR_ID"="T22"."ROW_ID"(+))
    59 - access("T8"."BU_ID"="T5"."PAR_ROW_ID"(+))
    61 - access("T27"."REMIT_ORG_EXT_ID"="T16"."PAR_ROW_ID"(+))
    63 - access("T27"."ACCNT_ID"="T25"."PAR_ROW_ID"(+))
    65 - access("T25"."ROW_ID"="T13"."OU_EXT_ID"(+) AND "T25"."PR_POSTN_ID"="T13"."POSITION_ID"(+))
    67 - access("T13"."POSITION_ID"="T6"."PAR_ROW_ID"(+))
    69 - access("T6"."PR_EMP_ID"="T11"."PAR_ROW_ID"(+))
    71 - access("T25"."BU_ID"="T10"."PAR_ROW_ID"(+))
    72 - access("T13"."POSITION_ID"="T7"."ROW_ID"(+))
    74 - access("T3"."CG_ASSSET_ID"="T17"."ROW_ID"(+))
    76 - access("T27"."ACCNT_ID"="T24"."PAR_ROW_ID"(+))
    78 - access("T27"."BL_ADDR_ID"="T9"."ADDR_PER_ID"(+) AND "T27"."ACCNT_ID"="T9"."ACCNT_ID"(+))
    filter("T27"."ACCNT_ID"="T9"."ACCNT_ID"(+))
    117 rows selected.
    We are using 10.2.0.3 oracle version.

    Hi
    according to the explain plan, > 99% of the cost of the query is coming from a single operation -- step 27, full scan of S_INVOICE table.
    This probably means that there are no usable indexes on DEPT_CD and/or INVC_TYPE_CD.
    So start by tuning SELECT * FROM S_INVOICE T27 WHERE ("T27"."DEPT_CD"=:2 AND "T27"."INVC_TYPE_CD"=:1)
    BTW the plan shows that 1 row is to be returned, while Oracle actually returns 117 -- this means that the optimizer estimates are not very reliable here.
    Best regards,
    Nikolay

  • Workspace Manager 10.1.0.4 and Outer Joins

    We experience the following Problem:
    We have a schema containing several Tables, one of them includes a SDO_GEOMETRY column (some Tables are about 2 million rows in size). We have to use some outer - joins in our statements, unfortunately the database - model is a generic one.
    The outer joins seem to work fine when the schema is not version - enabled, the performance is ok. As soon as we version - enable the schema, the explain plans for the statements with outer joins radically change, there are several "full table access" - paths for large tables (including the one with the geometry column).
    Statistics are up to date (executed dbms_stats.gather_schema_stats() with cascade => true).
    Any Ideas?
    cheers,
    Nothi

    Hi Ben,
    Thanx for your fast answer!
    This is the Statement:
    SELECT ress_exemp.id as ress_exemp_id, ress_exemp.ress_klasse_id as
    ress_exemp_ress_klasse_id, ress_exemp.ress_standort_id as
    ress_exemp_ress_standort_id, ress_exemp.ortsnetz_id as
    ress_exemp_ortsnetz_id, ress_exemp.asb_id as ress_exemp_asb_id,
    ress_exemp.netzbezirk_id as ress_exemp_netzbezirk_id,
    TO_CHAR(ress_exemp.gueltig_von,'dd.mm.yyyy hh24:mi:ss') as
    ress_exemp_gueltig_von, TO_CHAR(ress_exemp.gueltig_bis,'dd.mm.yyyy
    hh24:mi:ss') as ress_exemp_gueltig_bis, ress_exemp.gf_aktion as
    ress_exemp_gf_aktion, ress_exemp.gdv as ress_exemp_gdv, ress_exemp.sp as
    ress_exemp_sp, ress_exemp.status as ress_exemp_status, ress_exemp.banr as
    ress_exemp_banr, ress_exemp.bezeichnung as ress_exemp_bezeichnung,
    ress_exemp.parent_id as ress_exemp_parent_id , GEHAEUSE.*, GEOMETRIE.*,
    NETZBEZIRK.*, LOKATION.ZEILE_1, ress_standort.id as rs_id,
    ress_standort.lokation_id as rs_lokation_id, ress_standort.geometrie_id as
    rs_geometrie_id, ress_standort.relative_position as rs_rel_position,
    ress_standort.verortung as rs_verortung, ress_standort.datenqu as
    rs_datenqu, ress_standort.name_datenqu as rs_name_datenqu ,
    cast(multiset(select * from RESS_EXEMP_GIS where ress_exemp_id=ress_exemp.id) as TYPE_RESS_EXEMP_GIS_LISTE) as Darstellung
    from ress_exemp, GEHAEUSE, RESS_STANDORT, GEOMETRIE, NETZBEZIRK, LOKATION
    WHERE ress_exemp.id = GEHAEUSE.id
    AND ress_exemp.netzbezirk_id=NETZBEZIRK.id(+)
    AND ress_exemp.ress_standort_id=ress_standort.id(+)
    AND ress_standort.geometrie_id = geometrie.id(+)
    AND ress_standort.lokation_id = lokation.id(+)
    AND ress_exemp.id in (select /*+ cardinality(nlist 10) */ * from TABLE(cast(:b_ids as TYPE_NUMBER_LISTE)) nlist)
    This is the plan (from trace) fro the above sql, not version enabled:
    Rows Row Source Operation
    1 NESTED LOOPS OUTER (cr=16 pr=5 pw=0 time=27663 us)
    1 NESTED LOOPS OUTER (cr=12 pr=2 pw=0 time=15850 us)
    1 NESTED LOOPS OUTER (cr=12 pr=2 pw=0 time=15828 us)
    1 NESTED LOOPS OUTER (cr=8 pr=1 pw=0 time=7964 us)
    1 NESTED LOOPS (cr=8 pr=1 pw=0 time=7945 us)
    1 NESTED LOOPS (cr=4 pr=0 pw=0 time=123 us)
    1 SORT UNIQUE (cr=0 pr=0 pw=0 time=67 us)
    1 COLLECTION ITERATOR PICKLER FETCH (cr=0 pr=0 pw=0 time=18 us)
    1 TABLE ACCESS BY INDEX ROWID RESS_EXEMP (cr=4 pr=0 pw=0 time=50 us)
    1 INDEX UNIQUE SCAN PK_RESS_EXEMP (cr=3 pr=0 pw=0 time=29 us)(object id 160705)
    1 TABLE ACCESS BY INDEX ROWID GEHAEUSE (cr=4 pr=1 pw=0 time=7811 us)
    1 INDEX UNIQUE SCAN PK_GEHAEUSE (cr=3 pr=0 pw=0 time=13 us)(object id 160765)
    0 TABLE ACCESS BY INDEX ROWID NETZBEZIRK (cr=0 pr=0 pw=0 time=10 us)
    0 INDEX UNIQUE SCAN PK_NETZBEZIRK (cr=0 pr=0 pw=0 time=5 us)(object id 160771)
    1 TABLE ACCESS BY INDEX ROWID RESS_STANDORT (cr=4 pr=1 pw=0 time=7848 us)
    1 INDEX UNIQUE SCAN PK_RESS_STANDORT (cr=3 pr=0 pw=0 time=14 us)(object id 160701)
    0 TABLE ACCESS BY INDEX ROWID GEOMETRIE (cr=0 pr=0 pw=0 time=9 us)
    0 INDEX UNIQUE SCAN PK_GEOMETRIE (cr=0 pr=0 pw=0 time=4 us)(object id 160694)
    1 TABLE ACCESS BY INDEX ROWID LOKATION (cr=4 pr=3 pw=0 time=11838 us)
    1 INDEX UNIQUE SCAN PK_LOKATION (cr=3 pr=2 pw=0 time=7320 us)(object id 160692)
    Takes about 0.05 seconds to execute.
    Plan (from trace) after version - enabling and gather_schema_stats:
    Rows Row Source Operation
    1 FILTER (cr=249798 pr=313734 pw=84427 time=192750716 us)
    1 HASH JOIN RIGHT SEMI (cr=249798 pr=313734 pw=84427 time=240955926 us)
    1 COLLECTION ITERATOR PICKLER FETCH (cr=0 pr=0 pw=0 time=21 us)
    688292 HASH JOIN RIGHT OUTER (cr=249798 pr=313734 pw=84427 time=285035131 us)
    21610 VIEW (cr=235 pr=0 pw=0 time=172975 us)
    21610 FILTER (cr=235 pr=0 pw=0 time=108142 us)
    21610 TABLE ACCESS FULL NETZBEZIRK_LT (cr=235 pr=0 pw=0 time=43305 us)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN WM$NEXTVER_TABLE_NV_INDX (cr=0 pr=0 pw=0 time=0 us)(object id 9186)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$VERSION_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8896)
    0 VIEW (cr=0 pr=0 pw=0 time=0 us)
    0 UNION-ALL (cr=0 pr=0 pw=0 time=0 us)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8917)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN WM$VERSION_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8896)
    0 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8917)
    688292 HASH JOIN RIGHT OUTER (cr=249563 pr=313734 pw=84427 time=279469137 us)
    515484 VIEW (cr=19385 pr=0 pw=0 time=6701465 us)
    515484 FILTER (cr=5140 pr=0 pw=0 time=2577569 us)
    515506 TABLE ACCESS FULL GEOMETRIE_LT (cr=5102 pr=0 pw=0 time=1546659 us)
    0 FILTER (cr=3 pr=0 pw=0 time=115 us)
    1 INDEX RANGE SCAN WM$NEXTVER_TABLE_NV_INDX (cr=2 pr=0 pw=0 time=38 us)(object id 9186)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=1 pr=0 pw=0 time=25 us)
    0 INDEX UNIQUE SCAN WM$VERSION_PK (cr=1 pr=0 pw=0 time=16 us)(object id 8896)
    1 VIEW (cr=35 pr=0 pw=0 time=958 us)
    1 UNION-ALL (cr=35 pr=0 pw=0 time=894 us)
    1 FILTER (cr=24 pr=0 pw=0 time=378 us)
    1 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=22 pr=0 pw=0 time=263 us)(object id 8917)
    2 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=4 pr=0 pw=0 time=62 us)
    2 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=2 pr=0 pw=0 time=24 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    2 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=4 pr=0 pw=0 time=62 us)
    2 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=2 pr=0 pw=0 time=24 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 NESTED LOOPS (cr=11 pr=0 pw=0 time=290 us)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=11 pr=0 pw=0 time=225 us)
    0 INDEX RANGE SCAN WM$VERSION_PK (cr=11 pr=0 pw=0 time=151 us)(object id 8896)
    0 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8917)
    672794 HASH JOIN OUTER (cr=230178 pr=295905 pw=67004 time=197075574 us)
    672794 HASH JOIN RIGHT OUTER (cr=40108 pr=77885 pw=38990 time=92436750 us)
    690002 VIEW (cr=6208 pr=6139 pw=0 time=5649517 us)
    690002 FILTER (cr=6208 pr=6139 pw=0 time=4269507 us)
    690021 TABLE ACCESS FULL RESS_STANDORT_LT (cr=6175 pr=6139 pw=0 time=2199551 us)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN WM$NEXTVER_TABLE_NV_INDX (cr=0 pr=0 pw=0 time=0 us)(object id 9186)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$VERSION_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8896)
    0 VIEW (cr=33 pr=0 pw=0 time=774 us)
    0 UNION-ALL (cr=33 pr=0 pw=0 time=719 us)
    0 FILTER (cr=22 pr=0 pw=0 time=268 us)
    0 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=20 pr=0 pw=0 time=144 us)(object id 8917)
    2 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=4 pr=0 pw=0 time=80 us)
    2 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=2 pr=0 pw=0 time=44 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    2 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=4 pr=0 pw=0 time=80 us)
    2 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=2 pr=0 pw=0 time=44 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 NESTED LOOPS (cr=11 pr=0 pw=0 time=236 us)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=11 pr=0 pw=0 time=178 us)
    0 INDEX RANGE SCAN WM$VERSION_PK (cr=11 pr=0 pw=0 time=115 us)(object id 8896)
    0 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8917)
    672794 HASH JOIN (cr=33900 pr=55205 pw=22449 time=60265506 us)
    672792 TABLE ACCESS FULL GEHAEUSE_LT (cr=7219 pr=7206 pw=0 time=10207784 us)
    2331315 TABLE ACCESS FULL RESS_EXEMP_LT (cr=26681 pr=25550 pw=0 time=35088531 us)
    6289491 VIEW (cr=190070 pr=190006 pw=0 time=94568502 us)
    6289491 FILTER (cr=190070 pr=190006 pw=0 time=81989512 us)
    6289491 TABLE ACCESS FULL LOKATION_LT (cr=190070 pr=190006 pw=0 time=63121025 us)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN WM$NEXTVER_TABLE_NV_INDX (cr=0 pr=0 pw=0 time=0 us)(object id 9186)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$VERSION_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8896)
    0 VIEW (cr=0 pr=0 pw=0 time=0 us)
    0 UNION-ALL (cr=0 pr=0 pw=0 time=0 us)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8917)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN WM$VERSION_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8896)
    0 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8917)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN WM$NEXTVER_TABLE_NV_INDX (cr=0 pr=0 pw=0 time=0 us)(object id 9186)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$VERSION_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8896)
    0 VIEW (cr=0 pr=0 pw=0 time=0 us)
    0 UNION-ALL (cr=0 pr=0 pw=0 time=0 us)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8917)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN WM$VERSION_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8896)
    0 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8917)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN WM$NEXTVER_TABLE_NV_INDX (cr=0 pr=0 pw=0 time=0 us)(object id 9186)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$VERSION_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8896)
    0 VIEW (cr=0 pr=0 pw=0 time=0 us)
    0 UNION-ALL (cr=0 pr=0 pw=0 time=0 us)
    0 FILTER (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8917)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 TABLE ACCESS BY INDEX ROWID WM$WORKSPACES_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX UNIQUE SCAN WM$WORKSPACES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8893)
    0 NESTED LOOPS (cr=0 pr=0 pw=0 time=0 us)
    0 TABLE ACCESS BY INDEX ROWID WM$VERSION_TABLE (cr=0 pr=0 pw=0 time=0 us)
    0 INDEX RANGE SCAN WM$VERSION_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8896)
    0 INDEX UNIQUE SCAN MODIFIED_TABLES_PK (cr=0 pr=0 pw=0 time=0 us)(object id 8917)
    Rather long, sorry. As you can see, there are several TABLE ACCESS FULL - paths for large tables, causing a lot of user I/O.
    I also tried to use method_opt => 'FOR ALL COLUMNS SIZE 20', unfortunately it dindn't really change the plan.
    Have you got any ideas left?
    thank you for your help, anything can take me further
    regards,
    Nothi

Maybe you are looking for