Rewrite query

hi
i have a standard oracle report query which i ve taken from the data model
is it possible to rewrite this query without the bind variable , also the data given as output should be same when rewritten
wht does &C_vendor_dynamic_SQL stand for
SELECT /*+ ORDERED_PREDICATES */  DISTINCT (v.vendor_id)           C_vendor_id,
                   v.vendor_name                               C_vendor_name,
     DECODE(:SORT_BY_ALTERNATE, 'Y', UPPER(v.vendor_name_alt),
                   UPPER(v.vendor_name))      C_sort_vendor_name,
     v.segment1          C_vendor_num
FROM    ap_invoices i, po_vendors v
WHERE  0 < (SELECT SUM(nvl(prepay_amount_remaining,amount))
                 FROM  ap_invoice_distributions aid
                 WHERE aid.invoice_id = i.invoice_id
                 AND   aid.line_type_lookup_code IN ('ITEM','TAX')
                 AND   nvl(aid.reversal_flag,'N') <> 'Y')
AND v.vendor_id = i.vendor_id  
AND i.invoice_type_lookup_code =  'PREPAYMENT'
AND       i.cancelled_date IS NULL
&C_vendor_dynamic_SQL
ORDER BY DECODE(:SORT_BY_ALTERNATE, 'Y', UPPER(v.vendor_name_alt), UPPER(v.vendor_name))thanking in advance
Edited by: makdutakdu on Jun 21, 2010 10:54 AM

hi
thank u for the speedy response
there is after report and before report trigger and i dont see C_vendor_dynamic_SQL in both of them from the data model i see its a placeholder type column with no pl/sql formula specified
this is the code for before report trigger
function BeforeReport return boolean is
begin
/* This is the before report trigger for Oracle Payables Release 10 reports  */
DECLARE
  init_failure    EXCEPTION; 
BEGIN
  /* Start tracking report run time */
  :C_REPORT_START_DATE := sysdate;
  /* Init AOL - only necessary if AOL user exits are called           */
  /* If this is deleted, also delete SRWEXIT in After Report Trigger! */
  SRW.USER_EXIT('FND SRWINIT');
  IF (:p_debug_switch in ('y','Y')) THEN
     SRW.MESSAGE('1','After SRWINIT');
  END IF;
   /* get the set of books id and charge account id for this org */
  SELECT   ap.set_of_books_id, gl.chart_of_accounts_id
    INTO   :P_set_of_books_id, :P_chart_of_accounts_id
    FROM   ap_system_parameters ap, gl_sets_of_books gl
    WHERE  ap.set_of_books_id = gl.set_of_books_id;
  IF (:p_debug_switch in ('y','Y')) THEN
     SRW.MESSAGE('2','After initialize parameter p_set_of_books_id and p_charge_of_accounts_id');
  END IF;
  /* Get the organization name and SYSDATE from GL_SETS_OF_BOOKS */
  IF (get_company_name != TRUE) THEN  -- Call report level PL/SQL function
     RAISE init_failure;
  END IF;
  IF (:p_debug_switch in ('y','Y')) THEN
     SRW.MESSAGE('3','After Get_Company_Name');
  END IF;
  /* Get NLS strings for "All","Yes","No", and "No data exists..."  */
  IF (GET_NLS_STRINGS != TRUE) THEN -- Call report level PL/SQL function
     RAISE init_failure;
  END IF;
  IF (:p_debug_switch in ('y','Y')) THEN
     SRW.MESSAGE('4','After Get_NLS_Strings');
  END IF;
  /* Get code, precision, min.accountable unit,and descr. for base currency */
  IF (get_base_curr_data != TRUE) THEN   -- Call report level PL/SQL function
     RAISE init_failure;
  END IF;
  IF (:p_debug_switch in ('y','Y')) THEN
     SRW.MESSAGE('5','After Get_Base_Curr_Data');
  END IF;
  /* If you need to print cover page values, add the code to the existing */
  /* get_cover_page_values function and uncomment the call below.         */
  /* IF (get_cover_page_values != TRUE) THEN  */
  /*    RAISE init_failure;                   */
  /* END IF;                                  */
  /* IF (:p_debug_switch in ('y','Y')) THEN   */
  /*    SRW.MESSAGE('6','After Get_Cover_Page_Values'); */
  /* END IF;                                  */
  /* If this is a flex report, uncomment the following lines */
  /* IF (get_flexdata != TRUE) THEN             */
  /*    RAISE init_failure;                     */
  /* END IF;                                    */
  /* IF (:p_debug_switch in ('y','Y')) THEN     */
  /*    SRW.MESSAGE ('7', 'After Get_Flexdata');*/
  /* END IF;                                    */
  /* Add any custom code to the existing custom_init PL/SQL function and */
  /* uncomment the call to it below */
  IF(custom_init != TRUE) THEN             
    RAISE init_failure;                    
  END IF;                                   
  IF (:p_debug_switch in ('y','Y')) THEN   
    SRW.MESSAGE('7','After Custom_Init');  
  END IF;                                  
  /* If the debug switch is turned on, do an SRW.BREAK to show current */
  /* parameter and column assignments.                                 */
  IF (:p_debug_switch in ('y','Y')) THEN
     SRW.BREAK;
  END IF;
  /* If there have been no exceptions so far, RETURN(TRUE) */
  RETURN (TRUE);
/* Exception Handler Section.  If there is an exception, abort program */
EXCEPTION
  WHEN   OTHERS  THEN
    RAISE SRW.PROGRAM_ABORT;
END;
  return (TRUE);
end;this is for after report trigger
function AfterReport return boolean is
begin
BEGIN
   SRW.USER_EXIT('FND SRWEXIT');
   IF (:P_DEBUG_SWITCH = 'Y') THEN
      SRW.MESSAGE('20','After SRWEXIT');
   END IF;
EXCEPTION
WHEN OTHERS THEN
   RAISE SRW.PROGRAM_ABORT;
END;  return (TRUE);
end;kindly help
Edited by: makdutakdu on Jun 21, 2010 11:22 AM

Similar Messages

  • Rewriting query

    Could anyone help with rewriting this query? Result of this query will be inserted into a table. Thanks!
    SELECT tableA.PK,
    table1.amt,
    table2.amt,
    table3.amt,
    table16.value
    FROM tableA,
    (SELECT fk, NVL(value, 0) AS amt
    FROM tableB
    WHERE name = 'name1') table1,
    (SELECT fk, NVL(value, 0) AS amt
    FROM tableB
    WHERE name = 'name16') table16
    WHERE table1.fk (+) = tableA.pk
    AND table2.fk (+) = tableA.pk
    AND table16.fk (+) = tableA.pk;

    Unfortunately, you're stuck with a bit of an ugly data model. You can eliminate those subqueries, but there's not much you can do about the fact that you have to join to b 16 times.
    drop table tableb;
    drop table tablea;
    create table tablea (
      pk  number primary key);
    create table tableb (
      fk  number references tablea(pk),
      name  varchar2(30),
      value  number );
    insert into tablea values(1);
    insert into tablea values(2);
    insert into tableb values(1, 'name1', 100);
    insert into tableb values(1, 'name9', 50);
    insert into tableb values(1, 'name10', 200);
    insert into tableb values(2, 'name1', 22);
    insert into tableb values(2, 'name2', 22);
    insert into tableb values(2, 'name3', 22);
    commit;
    SELECT a.pk,
           NVL(b1.value, 0) AS amt1,
           NVL(b2.value, 0) AS amt2,
           NVL(b3.value, 0) AS amt3,
           NVL(b4.value, 0) AS amt4,
           NVL(b5.value, 0) AS amt5,
           NVL(b6.value, 0) AS amt6,
           NVL(b7.value, 0) AS amt7,
           NVL(b8.value, 0) AS amt8,
           NVL(b9.value, 0) AS amt9,
           NVL(b10.value, 0) AS amt10,
           NVL(b11.value, 0) AS amt11,
           NVL(b12.value, 0) AS amt12,
           NVL(b13.value, 0) AS amt13,
           NVL(b14.value, 0) AS amt14,
           NVL(b15.value, 0) AS amt15,
           NVL(b16.value, 0) AS amt16
      FROM tablea  a,
           tableb  b1,
           tableb  b2,
           tableb  b3,
           tableb  b4,
           tableb  b5,
           tableb  b6,
           tableb  b7,
           tableb  b8,
           tableb  b9,
           tableb  b10,
           tableb  b11,
           tableb  b12,
           tableb  b13,
           tableb  b14,
           tableb  b15,
           tableb  b16
    WHERE b1.fk(+) = a.pk
       AND b1.name(+) = 'name1'
       AND b2.fk(+) = a.pk
       AND b2.name(+) = 'name2'
       AND b3.fk(+) = a.pk
       AND b3.name(+) = 'name3'
       AND b4.fk(+) = a.pk
       AND b4.name(+) = 'name4'
       AND b5.fk(+) = a.pk
       AND b5.name(+) = 'name5'
       AND b6.fk(+) = a.pk
       AND b6.name(+) = 'name6'
       AND b7.fk(+) = a.pk
       AND b7.name(+) = 'name7'
       AND b8.fk(+) = a.pk
       AND b8.name(+) = 'name8'
       AND b9.fk(+) = a.pk
       AND b9.name(+) = 'name9'
       AND b10.fk(+) = a.pk
       AND b10.name(+) = 'name10'
       AND b11.fk(+) = a.pk
       AND b11.name(+) = 'name11'
       AND b12.fk(+) = a.pk
       AND b12.name(+) = 'name12'
       AND b13.fk(+) = a.pk
       AND b13.name(+) = 'name13'
       AND b14.fk(+) = a.pk
       AND b14.name(+) = 'name14'
       AND b15.fk(+) = a.pk
       AND b15.name(+) = 'name15'
       AND b16.fk(+) = a.pk
       AND b16.name(+) = 'name16';

  • A table is 'stuck' in the Discoverer SQL query after rewriting query.

    Hi,
    I'm using Discoverer 10.1.2.2 on an Oracle 9.2.0.6.0 DB.
    I've taken an existing Work Book and modified it. I've removed several fields as well as their table from the 'Selected Items' Window. I've also removed any references to all fields in that table in all Calculations and Conditions.
    Yet when I pull the SQL from the View: SQL Inspector That table still shows up and well as the join to it and a field from that table that I'm no longer using shows up as a field in the query. I'm not sure where else to check or what else to to do get this table out of this SQL query.
    Does anyone have any suggestions?

    Hi
    This can happen when someone has drilled inside a worksheet and saved the worksheet. The original or drilled to items are remembered,sometimes long after the drill item has been dispensed with. When this happens typically the only way to remedy the situation is to rebuild the worksheet from scratch.
    Before you get into that you do need to do one final scour to make sure that there is absolutely nothing in your worksheet that could cause the folder to be used. It could be in a long forgotten calculation. Sometimes when the only way to get from one folder to another one has to go via an intermediate folder by pulling any old item and then removing the item later. The folder willstill be used though. Could this be happening here?
    If you can rule out everything from the above paragraph then I am sorry to say but it sounds like you may have to rebuild from scratch.
    Best wishes
    Michael

  • Query Rewrite ISSUE (ANSI JOINS do not work, traditional join works ) 11gR2

    For some types of queries constructed with ANSI JOINS, materialized views are not being used.
    This is currently increasing time on various reports since we cannot control the way the queries are generated(Tableau Application generates and runs queries against the STAR Schema).
    Have tried to debug this behavior using DBMS_MVIEW.EXPLAIN_REWRITE and mv_capabilities function without any success.
    The database is configured for query rewrite: REWRITE INTEGRITY, QUERY REWRITE ENABLED and other settings are in place.
    Have successfully reproduced the issue using SH Sample schema:
    Q1 and Q2 are logically identical the only difference between them being the type of join used:
    Q1: ANSI JOIN
    Q2: Traditional join
    Below is an example that can be validated on SH sample schema.
    Any help on this will be highly appreciated.
    -- Q1: the query is generated by an app and needs to be rewritten with materialized view
    SELECT cntr.country_subregion, cust.cust_year_of_birth, COUNT(DISTINCT cust.cust_first_name)
    FROM customers cust
    INNER JOIN countries cntr
       ON cust.country_id = cntr.country_id
    GROUP BY cntr.country_subregion, cust_year_of_birth;
    -- Q2: the query with traditional join is rewritten with materialized view
    SELECT cntr.country_subregion, cust.cust_year_of_birth, COUNT(DISTINCT cust.cust_first_name)
    FROM customers cust
    INNER JOIN countries cntr
       ON cust.country_id = cntr.country_id
    GROUP BY cntr.country_subregion, cust_year_of_birth;Tested both queries with the following materialized views:
    CREATE MATERIALIZED VIEW MVIEW_TEST_1
    ENABLE QUERY REWRITE
    AS
    SELECT cntr.country_subregion, cust.cust_year_of_birth, COUNT(DISTINCT cust.cust_first_name)
    FROM customers cust
    INNER JOIN countries cntr
       ON cust.country_id = cntr.country_id
    GROUP BY cntr.country_subregion, cust_year_of_birth;
    CREATE MATERIALIZED VIEW MVIEW_TEST_2
    ENABLE QUERY REWRITE
    AS
    SELECT cntr.country_subregion, cust.cust_year_of_birth, COUNT(DISTINCT cust.cust_first_name)
    FROM customers cust,  countries cntr
    WHERE cust.country_id = cntr.country_id
    GROUP BY cntr.country_subregion, cust_year_of_birth;Explain Plans showing that Q1 does not use materialized view and Q2 uses materialized view
    SET AUTOTRACE TRACEONLY
    --Q1 does not use MVIEW_TEST_1
    SQL> SELECT cntr.country_subregion, cust.cust_year_of_birth, COUNT(DISTINCT cust.cust_first_name)
    FROM customers cust
    INNER JOIN countries cntr
       ON cust.country_id = cntr.country_id
    GROUP BY cntr.country_subregion, cust_year_of_birth;  2    3    4    5 
    511 rows selected.
    Execution Plan
    Plan hash value: 1218164197
    | Id  | Operation           | Name       | Rows  | Bytes |TempSpc| Cost (%CPU)| Time       |
    |   0 | SELECT STATEMENT      |        |   425 | 12325 |       |   916   (1)| 00:00:11 |
    |   1 |  HASH GROUP BY           |        |   425 | 12325 |       |   916   (1)| 00:00:11 |
    |   2 |   VIEW                | VM_NWVW_1 | 55500 |  1571K|       |   916   (1)| 00:00:11 |
    |   3 |    HASH GROUP BY      |        | 55500 |  1842K|  2408K|   916   (1)| 00:00:11 |
    |*  4 |     HASH JOIN           |        | 55500 |  1842K|       |   409   (1)| 00:00:05 |
    |   5 |      TABLE ACCESS FULL| COUNTRIES |    23 |   414 |       |     3   (0)| 00:00:01 |
    |   6 |      TABLE ACCESS FULL| CUSTOMERS | 55500 |   867K|       |   405   (1)| 00:00:05 |
    --Q2 uses MVIEW_TEST_2
    SQL> SELECT cntr.country_subregion, cust.cust_year_of_birth, COUNT(DISTINCT cust.cust_first_name)
    FROM customers cust,  countries cntr
    WHERE cust.country_id = cntr.country_id
    GROUP BY cntr.country_subregion, cust_year_of_birth;  2    3    4 
    511 rows selected.
    Execution Plan
    Plan hash value: 2126022771
    | Id  | Operation               | Name         | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT          |              |     511 | 21973 |       3   (0)| 00:00:01 |
    |   1 |  MAT_VIEW REWRITE ACCESS FULL| MVIEW_TEST_2 |     511 | 21973 |       3   (0)| 00:00:01 |
    ---------------------------------------------------------------------------------------------Database version 11gR1 (Tested also on 11gR2)
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE     11.2.0.1.0     Production
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production

    Thanks for the formatting tips.
    Just found an Oracle Bug which explains the above behavior.
    Unfortunately the bug will be fixed only in 12.1 Release so as a workaround will try to use traditional joins.
    For those who have metalink access see [Bug 10145667 : ERRORS TRYING TO REWRITE QUERY WITH EXACT TEXT MATCH TO MVIEW]

  • Help query rewrite

    Hi
    could you help me rewriting query without using joins
    select * from A ,B,C
    LEFT OUTER JOIN A
    ON (A.account_no = B.account_no
    AND C.id_type = B.id_type
    AND B.value = 1) ;
    thanks ,
    -Raj

    WHERE A.account_no = B.account_no(+)
    AND C.id_type = B.id_typeIf these aren't joins what are they?

  • Need to Rewrite Distinct query...

    Hi All,
    Query A:
    SELECT count(DISTINCT FIELD_SERVICE_REP) CNT1
      FROM SOP_SERVICE_REQUEST_JOB ssrj, sop_service_request ssr
    WHERE TO_DATE('06/12/2006', 'mm/dd/yyyy') BETWEEN
           SSRJ.SCHEDULED_START_DATE AND SSRJ.SCHEDULED_END_DATE
           AND field_service_rep IS NOT NULL
           AND ssr.service_request_id = ssrj.service_request_id
    Result of Query A:-
    17 --> This is correct result
    Query B:
    SELECT FIELD_SERVICE_REP, count(FIELD_SERVICE_REP) CNT2
      FROM SOP_SERVICE_REQUEST_JOB ssrj, sop_service_request ssr
    WHERE TO_DATE('06/12/2006', 'mm/dd/yyyy') BETWEEN
           SSRJ.SCHEDULED_START_DATE AND SSRJ.SCHEDULED_END_DATE
           AND field_service_rep IS NOT NULL
           AND ssr.service_request_id = ssrj.service_request_id
           GROUP BY ssrj.field_service_rep
    Result of Query B:-
    FIELD_SERVICE_REP      CNT2
    1000036                  9
    105005937          1
    113001460          1
    113001757          3
    113002205          2
    113002476          4
    113003027          2
    113003166          1
    218012616          1
    218012630          1
    312003325          1
    500916804          1
    500935725          2
    501026039          6
    501154894          1
    501243382          3
    501248836          6I need to rewrite Query A in such a way that I get rid of DISTINCT as it is consuming a lot of time. I tried to group by in Query B and count but it is not giving same result as Query A (as expected..) so how can I rewrite Query A or Query B to get result of Query A (basically count unique field service reps.) as correct result is the one shown in Query A.
    Pls. note that original query is very large and it runs on set of dates and hence DISTINCT is taking too much time
    Thanks in advance to all for ur help..
    JP

    Some sample data:
    DROP TABLE SOP_SERVICE_REQUEST;
    CREATE TABLE SOP_SERVICE_REQUEST(service_request_id number(6,0));
    INSERT
    INTO SOP_SERVICE_REQUEST
    VALUES(100);
    INSERT
    INTO SOP_SERVICE_REQUEST
    VALUES(101);
    INSERT
    INTO SOP_SERVICE_REQUEST
    VALUES(102);
    INSERT
    INTO SOP_SERVICE_REQUEST
    VALUES(103);
    INSERT
    INTO SOP_SERVICE_REQUEST
    VALUES(104);
    DROP TABLE SOP_SERVICE_REQUEST_job;
    CREATE TABLE SOP_SERVICE_REQUEST_job(service_request_id number(6,0), SCHEDULED_START_DATE date,SCHEDULED_END_DATE date,field_service_rep number(6,0));
    INSERT
    INTO SOP_SERVICE_REQUEST_job
    VALUES(100, '10-jun-06', '16-jun-06', 200);
    INSERT
    INTO SOP_SERVICE_REQUEST_job
    VALUES(101, '10-jun-06', '16-jun-06', 201);
    INSERT
    INTO SOP_SERVICE_REQUEST_job
    VALUES(102, '10-jun-06', '16-jun-06', 201);
    INSERT
    INTO SOP_SERVICE_REQUEST_job
    VALUES(103, '10-jun-06', '16-jun-06', 202);
    INSERT
    INTO SOP_SERVICE_REQUEST_job
    VALUES(104, '10-jun-06', '16-jun-06', 201);
    select * from sop_service_request
    select * from sop_service_request_job
    prompt Query A:
    SELECT count(FIELD_SERVICE_REP) CNT1
    FROM SOP_SERVICE_REQUEST_JOB ssrj, sop_service_request ssr
    WHERE TO_DATE('06/12/2006', 'mm/dd/yyyy')
    BETWEEN SSRJ.SCHEDULED_START_DATE AND SSRJ.SCHEDULED_END_DATE
    AND field_service_rep IS NOT NULL
    AND ssr.service_request_id = ssrj.service_request_id;
    prompt Query B:
    SELECT FIELD_SERVICE_REP, count(FIELD_SERVICE_REP) CNT2
    FROM SOP_SERVICE_REQUEST_JOB ssrj, sop_service_request ssr
    WHERE TO_DATE('06/12/2006', 'mm/dd/yyyy')
    BETWEEN SSRJ.SCHEDULED_START_DATE AND SSRJ.SCHEDULED_END_DATE
    AND field_service_rep IS NOT NULL
    AND ssr.service_request_id = ssrj.service_request_id
    GROUP BY ssrj.field_service_rep;
    Output:
    DROP TABLE SOP_SERVICE_REQUEST succeeded.
    CREATE TABLE succeeded.
    1 rows inserted
    1 rows inserted
    1 rows inserted
    1 rows inserted
    DROP TABLE SOP_SERVICE_REQUEST_job succeeded.
    CREATE TABLE succeeded.
    1 rows inserted
    1 rows inserted
    1 rows inserted
    1 rows inserted
    Query A:
    CNT1
    4
    1 rows selected
    Query B:
    FIELD_SERVICE_REP CNT2
    201 2
    200 1
    202 1
    3 rows selected

  • Simple query help in plsql - help

    oracle version : 10gR2
    indexes are created on each column, is there anyway to make them used while searching for the records rewriting the following query to test given data in any case (lower ,upper)...
    SELECT * FROM TX_USERS
    WHERE userid like decode( UPPER('Md'),null,userid, UPPER( 'MD')||'%' ) and
    first_name like decode(UPPER('Na'),null, first_name, UPPER( 'NA')||'%' ) AND
    LAST_name like decode(('Ra'),null, LAST_name, UPPER('RA')||'%' )
    -- list goes on..
    UPPER('Md') -- is the input values comes from form.. for example i_userid.. this query works fine .. is there anyway of getting indices used without using functional based indexing when we rewrite query like shown below??? input parameter valeus can be anything and table column values can be anything i.e. anycase (upper or lower or mix of both)..
    actual code would be
    upper(userid) like decode( UPPER(i_userid),null,userid, UPPER( i_userid)||'%' ) and
    upper(first_name) like decode(UPPER(i_first_name),null, first_name, UPPER( i_firstname)||'%' )
    if we put upper(userid) then index not used ..........anyway of rewriting using it or any other technique... or any other new way

    No, its not working... see the below..
    create table test5 as select owner, object_name, subobject_name, object_type from all_objects;
    create unique index test5_i5 on test5 (owner, object_name, subobject_name, object_type);
    select * from test5 where owner like 'SCOTT' AND OBJECT_NAME LIKE 'EMP';
    INDEX RANGE SCAN| TEST5_I5 | 4 | 248 | 1 (0)| 00:00:01 |
    but when i use
    select * from test5 where UPPER(OWNER) LIKE 'SCOTT%' AND UPPER(OBJECT_NAME) LIKE 'EMP%';
    TABLE ACCESS FULL| TEST5 | 3 | 186 | 65 (5)| 00:00:01 |
    i know it goes to full scan, i want to know is there any other way to make index used .. without using functional based indx...
    the reason is user can search any one of the column data and data is mixed case in table columns and/or conditions specified in query..
    .. any help...
    not sure how to use 'NLS_SORT=BINARY_CI' on multicolumn index and enable index used in search operation.. ANY OTHER WAY OF DOING THIS...
    requirements is
    mixed (lower,upper) data stored in db columns and mixed case data searched, 5 columns specified in where condition, data may be provided in search conditon to one or two or to all 5 columns in mixed case... matching records need to be returned.. suggest a good way of doing this... thnx

  • Query tuning : you can do it yourself

    Hello,
    This thread is not a question.
    How tune my query ?
    My query didn't use indexes why ?
    I have indexes on table, stats are up-to-date why Oracle does a full scan on table ?
    What are the hint which I can use ?
    etc...
    I would like try to answer to many such questions posted in this forum about query tuning.
    And explain that tuning is not always complicated, is not always reserved to some consultants, is not always solved by hints usage, and not require to buy some books which would give some magic solutions.
    By this thread, I would explain to people which have some query performance issues, that the solution is maybe here, in front of their eyes, inside the query itself. The solution may come from their own side, and that they can be happy to solve such question themself.
    I'll develop here below a case from a real word situation encountered some time ago.

    At this point, remove this huge and nightmarish hint. We'll use it only if no other ways may found.
    First, a look into the data model to see if the joins may be rewrite differently.
    Original joins :
        dw.AIRPORT_ROUTING_ID = ar.AIRPORT_ROUTING_ID and
        dw.COUNTRY_ROUTING_ID = cor.COUNTRY_ROUTING_ID and
        dw.REGION_ROUTING_ID = rr.REGION_ROUTING_ID and
        dw.CITY_ROUTING_ID  = cr.CITY_ROUTING_ID andAnd indeed, the join may be rewrite as below :
        and dw.AIRPORT_ROUTING_ID = ar.AIRPORT_ROUTING_ID
        and ar.CITY_ROUTING_ID    = cr.CITY_ROUTING_ID
        and cr.COUNTRY_ROUTING_ID = cor.COUNTRY_ROUTING_ID 
        and cor.REGION_ROUTING_ID = rr.REGION_ROUTING_IDNote the aliases were change here. Is it complicated to try to rewrite query like that ?
    Secondly, we will try to see how avoid or, at least, workaround the all OR conditions. It would be well if we could merge all the FROM (bind variable :a) in one column, same for all TO (bind variable :b), unfortunately, the data model cannot be change (of course). Ok, we will try to work with a temporary table by combining all the possiblities between the two conditions.
    create global temporary table REGION_ROUTING_TMP
    on commit preserve rows
    as
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_FROM as REGION_FROM, REGION_STOP1 as REGION_TO
    from   REGION_ROUTING
    where  1=2;And an index based on the two mains criteria of the query may help :
    create index IDX_REGION_ROUTING_TMP on REGION_ROUTING_TMP(REGION_FROM,REGION_TO);Then we'll populate table :
    insert into REGION_ROUTING_TMP
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_FROM as REGION_FROM, REGION_STOP1 as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_FROM as REGION_FROM, REGION_STOP2 as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_FROM as REGION_FROM, REGION_STOP3 as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_FROM as REGION_FROM, REGION_TO as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP1 as REGION_FROM, REGION_STOP2 as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP1 as REGION_FROM, REGION_STOP3 as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP1 as REGION_FROM, REGION_TO as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP2 as REGION_FROM, REGION_STOP3 as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP2 as REGION_FROM, REGION_TO as REGION_TO
    from   REGION_ROUTING
    union
    select REGION_ROUTING_NAMES, REGION_ROUTING_ID, REGION_STOP3 as REGION_FROM, REGION_TO as REGION_TO
    from   REGION_ROUTING;The insert take near 9 seconds, which is a reasonnable elapse time.
    At this point, the query become :
    Select
       ap.AIRPORT_PAIR,  
       dw.DELIVERY_PERIOD,
       dw.TOTAL_PAX As Demand,
       od.GLOBAL_TOTAL_PAX as Total_OD_Demand,
       dw.REPORTED_PAX As ReportedPax,
       ap.AIRPORT_FROM,
       ap.AIRPORT_TO,
       ap.CITY_FROM,
       ap.CITY_TO,
       ap.COUNTRY_FROM_NAME,
       ap.COUNTRY_TO_NAME,
       ap.REGION_FROM_NAME,
       ap.REGION_TO_NAME,
       ar.AIRPORT_ROUTING,
       cr.CITY_ROUTING,
       cor.COUNTRY_ROUTING_NAMES,
       rr.REGION_ROUTING_NAMES,
       ar.NUMBER_OF_STOP,
       dw.PERCENT_OF_TOTAL_PAX_VS_OD,
       dw.AIRLINE1,
       dw.AIRLINE2,
       dw.AIRLINE3,
       dw.AIRLINE4,
       dw.NUMBER_OF_AIRLINE,
       dw.AIRCRAFTCLASS_NAME,
       dw.FARE
    From
       REGION_ROUTING_TMP rr, -- here we use now the temporary table instead of REGION_ROUTING table
       DETAILED_FLIGHTS dw,
       AIRPORT_PAIR ap,
       AIRPORT_ROUTING ar,
       CITY_ROUTING cr,
       COUNTRY_ROUTING cor,
       OD od
    where
            dw.DELIVERY_PERIOD  in ('2006-09','2006-08','2006-07')
    and dw.AIRPORT_PAIR_ID    = ap.AIRPORT_PAIR_ID
    and dw.OD_ID              = od.OD_ID
    and dw.AIRPORT_ROUTING_ID = ar.AIRPORT_ROUTING_ID
    and ar.CITY_ROUTING_ID    = cr.CITY_ROUTING_ID
    and     cr.COUNTRY_ROUTING_ID = cor.COUNTRY_ROUTING_ID 
    and cor.REGION_ROUTING_ID = rr.REGION_ROUTING_ID
    and rr.REGION_FROM        = '7'  |
    and rr.REGION_TO          = '8'  |-> these two lines replace all the OR conditions;And explain plan :
    | Id  | Operation                             |  Name                          | Rows  | Bytes | Cost  | Pstart| Pstop |
    |   0 | SELECT STATEMENT                      |                                |   469 |   174K|  3462 |       |       |
    |   1 |  NESTED LOOPS                         |                                |   469 |   174K|  3462 |       |       |
    |   2 |   NESTED LOOPS                        |                                |   458 |   166K|  3004 |       |       |
    |   3 |    NESTED LOOPS                       |                                |   454 |   127K|  2096 |       |       |
    |   4 |     NESTED LOOPS                      |                                |   258 | 58308 |   548 |       |       |
    |   5 |      NESTED LOOPS                     |                                |   246 | 48216 |    56 |       |       |
    |   6 |       NESTED LOOPS                    |                                |    26 |  4420 |     4 |       |       |
    |   7 |        TABLE ACCESS BY INDEX ROWID    | REGION_ROUTING_TMP             |     1 |   123 |   
    |*  8 |         INDEX RANGE SCAN              | IDX_REGION_ROUTING_TMP         |     1 |       |     1 |       | 
    |   9 |        TABLE ACCESS BY INDEX ROWID    | COUNTRY_ROUTING                |    32 |  1504 |     2
    |* 10 |         INDEX RANGE SCAN              | IX9_COUNTRY_ROUTING            |    32 |       |     1 |       | 
    |  11 |       TABLE ACCESS BY INDEX ROWID     | CITY_ROUTING                   |     9 |   234 |     2 | 
    |* 12 |        INDEX RANGE SCAN               | IX9_CITY_ROUTING               |    12 |       |     1 |    
    |  13 |      TABLE ACCESS BY INDEX ROWID      | AIRPORT_ROUTING                |     1 |    30 |     2
    |* 14 |       INDEX RANGE SCAN                | IX10_AIRPORT_ROUTING           |     1 |       |     1 |   
    |* 15 |     TABLE ACCESS BY GLOBAL INDEX ROWID| DETAILED_FLIGHTS               |     2 |   122 |   
    |* 16 |      INDEX RANGE SCAN                 | IX3_DETAILED_FLIGHTS           |     9 |       |     2 |    
    |  17 |    TABLE ACCESS BY INDEX ROWID        | AIRPORT_PAIR                   |     1 |    85 |     2 |  
    |* 18 |     INDEX RANGE SCAN                  | IX1_AIRPORT_PAIR               |     1 |       |     1 |       |
    |  19 |   TABLE ACCESS BY INDEX ROWID         | OD                             |     1 |    10 |     1 |       |   
    |* 20 |    INDEX UNIQUE SCAN                  | PK_OD                          |     1 |       |       |       |       |
    ----------------------------------------------------------------------------------------------------Ouf, this sound like better, isn't it ? Was it complicated to arrive as such result ?
    Ok, now launch the query and see the elapse time :
    104103 rows selected.
    Elapsed: 00:09:00.12
    Statistics
              0  recursive calls
              0  db block gets
        1214845  consistent gets
         272481  physical reads
              0  redo size
       11164355  bytes sent via SQL*Net to client
         257032  bytes received via SQL*Net from client
           6942  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
         104103  rows processedWoaw, developer is now very happy, less than 10 minutes instead of one hour... and without modify anything else in database and server settings, without add indexes, without add any hints...
    Ok, now the problem is in the number of returned lines. Have you see the number of return client/server ? We'll now to try to reduce this one. Increasing the number of line returned by fetch :
    set arraysize 5000
    --run the query
    104103 rows selected.
    Elapsed: 00:02:25.49
    Statistics
              0  recursive calls
              0  db block gets
        1150893  consistent gets
         271432  physical reads
              0  redo size
       11018641  bytes sent via SQL*Net to client
           1013  bytes received via SQL*Net from client
             22  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
         104103  rows processedOk, the number of retunr client/server is now low, and elapse time is ok user.

  • How to rewrite sql statement?

    Hello my query goes like this:
    select a, b, c
    from (select 5 a , null b, null c from dual
    union all
    select null, 4, null from dual
    union all
    select 10, 3, null from dual) test_tab;
    and i wanna get result
    5 null null
    null 4 null
    10 null null
    null 3 null
    How can i rewrite query without changing the structure of a table?
    Regards,
    Igor

    Your data ->
    select 10, 3, null from dualAnd, your expected output ->
    10 null null
    null 3 nullWhat is the logic behind this split?
    Please explain.
    Regards.
    Satyaki De.

  • Update only one select query field

    hello
    how i can update select query result field in original table.
    update table1 set field_1 from(select field_1 from table 1,table2,table3,table4 where table1.field_1=table1.field_1 and table2.field_2=table3.field_2 and table4.field_3=table1.field_4)
    like that.is it possible!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!can u please help me to rewrite query/
    select query returns result like that from different tables
    lets example field_1 field_2 field_3 field_4
    TIGER 1 V A
    TIGER 2 F B
    TIGER 3 R C
    I need to update 'TIGER' instead of 'LION' in original table.
    THANKS

    Maybe something like
    update table1
       set beast = (select animal
                      from <table_list>
                     where <predicates>
    where beast = 'LION'when your query returns a single row
    or when multiple rows are returned
    update (select t1.beast,t2.animal
              from (select beast,
                           <join_columns_list>
                      from table1
                     where beast = 'LION'
                   ) t1,
                   (select animal,
                           <join_columns_list>
                      from <table_list>
                     where <predicates>
                   ) t2
             where t1.<join_columns_list> = t2.<join_columns_list>
       set beast = animalRegards
    Etbin

  • Poor performance while join of 2 comprehensive large views and small table

    Hi,
    The following SQL statement has been identified to perform poorly. It currently takes up to 6 seconds to execute, but it's supposed to take ~30-40ms at most.
    This is the statement(all bind variables change to numbers):
    SELECT v__96.connector_objectid, v__96.connector_classid, v__96.from_objectid,
           v__96.to_objectid, v__96.from_classid, v__96.to_classid,
           v__96.from_firstunit, v__96.to_firstunit, v__96.number_of_units,
           tmp_trace.first_unit, tmp_trace.last_unit, v__96.inv_status_number,
           tmp_trace.first_unit, tmp_trace.last_unit, v__96.answers,
           v__96.priority, v__97.first_unit, v__97.n_units,
           v__97.mid_span_distance
      FROM ne.tmp_trace,
           (SELECT b.objectid, b.answers, b.connector_classid,
                   b.connector_objectid, b.from_classid, b.from_objectid,
                   b.to_classid, b.to_objectid, b.from_firstunit, b.to_firstunit,
                   b.number_of_units, b.inv_status_number, b.splice_closure_name,
                   b.work_order_name, b.work_order_item_number,
                   b.inventory_status_code, b.priority
              FROM ne.connection b
             WHERE b.objectid NOT IN (
                      SELECT /*+ HASH_AJ */
                             sde_deletes_row_id
                        FROM ne.d96
                       WHERE deleted_at IN (
                                SELECT l.lineage_id
                                  FROM sde.state_lineages l
                                 WHERE l.lineage_name = 2
                                   AND l.lineage_id <= 115)
                         AND sde_state_id = 0)
            UNION ALL
            SELECT a.objectid, a.answers, a.connector_classid,
                   a.connector_objectid, a.from_classid, a.from_objectid,
                   a.to_classid, a.to_objectid, a.from_firstunit, a.to_firstunit,
                   a.number_of_units, a.inv_status_number, a.splice_closure_name,
                   a.work_order_name, a.work_order_item_number,
                   a.inventory_status_code, a.priority
              FROM ne.a96 a, sde.state_lineages sl
             WHERE (a.objectid, a.sde_state_id) NOT IN (
                      SELECT /*+ HASH_AJ */
                             sde_deletes_row_id, sde_state_id
                        FROM ne.d96
                       WHERE deleted_at IN (
                                SELECT l.lineage_id
                                  FROM sde.state_lineages l
                                 WHERE l.lineage_name = 2
                                   AND l.lineage_id <= 115)
                         AND sde_state_id > 0)
               AND a.sde_state_id = sl.lineage_id
               AND sl.lineage_name = 2
               AND sl.lineage_id <= 115) v__96,
           (SELECT b.objectid, b.tray_number, b.db_loss, b.first_unit, b.n_units,
                   b.connection_objectid, b.connector_type_name,
                   b.dedicated_status, b.mid_span_distance
              FROM ne.connection_attributes b
             WHERE b.objectid NOT IN (
                      SELECT /*+ HASH_AJ */
                             sde_deletes_row_id
                        FROM ne.d97
                       WHERE deleted_at IN (
                                SELECT l.lineage_id
                                  FROM sde.state_lineages l
                                 WHERE l.lineage_name = 2
                                   AND l.lineage_id <= 115)
                         AND sde_state_id = 0)
            UNION ALL
            SELECT a.objectid, a.tray_number, a.db_loss, a.first_unit, a.n_units,
                   a.connection_objectid, a.connector_type_name,
                   a.dedicated_status, a.mid_span_distance
              FROM ne.a97 a, sde.state_lineages sl
             WHERE (a.objectid, a.sde_state_id) NOT IN (
                      SELECT /*+ HASH_AJ */
                             sde_deletes_row_id, sde_state_id
                        FROM ne.d97
                       WHERE deleted_at IN (
                                SELECT l.lineage_id
                                  FROM sde.state_lineages l
                                 WHERE l.lineage_name = 2
                                   AND l.lineage_id <= 115)
                         AND sde_state_id > 0)
               AND a.sde_state_id = sl.lineage_id
               AND sl.lineage_name = 2
               AND sl.lineage_id <= 115) v__97
    WHERE (    (    (    (    (   (    ne.tmp_trace.equipment_object_id =
                                                                 v__96.to_objectid
                                    AND v__96.to_classid = 9
                                OR (    ne.tmp_trace.transmedia_object_id =
                                                                 v__96.to_objectid
                                    AND v__96.to_classid = 5
                           AND (   (v__96.to_firstunit
                                       BETWEEN ne.tmp_trace.first_unit
                                           AND ne.tmp_trace.last_unit
                                OR (ne.tmp_trace.first_unit
                                       BETWEEN v__96.to_firstunit
                                           AND   v__96.to_firstunit
                                               + v__96.number_of_units
                                               - 1
                      AND v__96.answers = 0
                 AND v__96.objectid = v__97.connection_objectid
            AND (ne.tmp_trace.session_id = -1234)
           );It should return many values from 2 comprehensive views (v__96, v__97) and business table (tmp_trace). 2 comprehensive views ~1,000,000 recs each, business table ~ 10 recs.
    The version of the database is 11.1.0.6.
    These are the parameters relevant to the optimizer:
    SQL> show parameter optimizer
    NAME                                 TYPE                             VALUE
    optimizer_capture_sql_plan_baselines boolean                          FALSE
    optimizer_dynamic_sampling           integer                          2
    optimizer_features_enable            string                           11.1.0.6
    optimizer_index_caching              integer                          0
    optimizer_index_cost_adj             integer                          100
    optimizer_mode                       string                           ALL_ROWS
    optimizer_secure_view_merging        boolean                          TRUE
    optimizer_use_invisible_indexes      boolean                          FALSE
    optimizer_use_pending_statistics     boolean                          FALSE
    optimizer_use_sql_plan_baselines     boolean                          TRUE
    SQL> show parameter db_file_multi
    NAME                                 TYPE                             VALUE
    db_file_multiblock_read_count        integer                          128
    SQL> show parameter db_block_size
    NAME                                 TYPE                             VALUE
    db_block_size                        integer                          8192
    SQL> show parameter cursor_sharing
    NAME                                 TYPE                             VALUE
    cursor_sharing                       string                           FORCE
    SQL> column sname format a20
    SQL> column pname format a20
    SQL> column pval2 format a20
    SQL> select sname, pname, pval1, pval2 from sys.aux_stats$;
    SNAME                PNAME                     PVAL1 PVAL2
    SYSSTATS_INFO        STATUS                          COMPLETED
    SYSSTATS_INFO        DSTART                          07-15-2009 10:27
    SYSSTATS_INFO        DSTOP                           07-15-2009 10:27
    SYSSTATS_INFO        FLAGS                         1
    SYSSTATS_MAIN        CPUSPEEDNW           1812.32129
    SYSSTATS_MAIN        IOSEEKTIM                    10
    SYSSTATS_MAIN        IOTFRSPEED                 4096
    SYSSTATS_MAIN        SREADTIM
    SYSSTATS_MAIN        MREADTIM
    SYSSTATS_MAIN        CPUSPEED
    SYSSTATS_MAIN        MBRC
    SNAME                PNAME                     PVAL1 PVAL2
    SYSSTATS_MAIN        MAXTHR
    SYSSTATS_MAIN        SLAVETHR
    13 rows selected.Here is the output of EXPLAIN PLAN:
    explain plan for -- statement above
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 1005186751
    | Id  | Operation                          | Name                  | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                   |                       |     1 |   282 |   268   (2)| 00:00:04 |
    |   1 |  NESTED LOOPS                      |                       |     1 |   282 |   268   (2)| 00:00:04 |
    |   2 |   MERGE JOIN CARTESIAN             |                       |     1 |   119 |   260   (1)| 00:00:04 |
    |*  3 |    TABLE ACCESS FULL               | TMP_TRACE             |     1 |    65 |     2   (0)| 00:00:01 |
    |   4 |    BUFFER SORT                     |                       |   103K|  5467K|   258   (1)| 00:00:04 |
    |   5 |     VIEW                           |                       |   103K|  5467K|   258   (1)| 00:00:04 |
    |   6 |      UNION-ALL                     |                       |       |       |            |       |
    |   7 |       NESTED LOOPS ANTI            |                       |     1 |    82 |     3   (0)| 00:00:01 |
    |   8 |        TABLE ACCESS FULL           | CONNECTION_ATTRIBUTES |     1 |    78 |     2   (0)| 00:00:01 |
    |   9 |        VIEW PUSHED PREDICATE       | VW_NSO_1              |     1 |     4 |     1   (0)| 00:00:01 |
    |  10 |         NESTED LOOPS               |                       |     1 |    20 |     1   (0)| 00:00:01 |
    |* 11 |          INDEX RANGE SCAN          | LINEAGES_PK           |     5 |    35 |     1   (0)| 00:00:01 |
    |* 12 |          INDEX UNIQUE SCAN         | D97_PK                |     1 |    13 |     0   (0)| 00:00:01 |
    |* 13 |       HASH JOIN RIGHT ANTI         |                       |   103K|  5568K|   255   (1)| 00:00:04 |
    |  14 |        VIEW                        | VW_NSO_2              |     1 |    26 |     2   (0)| 00:00:01 |
    |  15 |         NESTED LOOPS               |                       |     1 |    20 |     2   (0)| 00:00:01 |
    |* 16 |          INDEX FAST FULL SCAN      | D97_PK                |     1 |    13 |     2   (0)| 00:00:01 |
    |* 17 |          INDEX UNIQUE SCAN         | LINEAGES_PK           |     1 |     7 |     0   (0)| 00:00:01 |
    |  18 |        NESTED LOOPS                |                       |       |       |            |       |
    |  19 |         NESTED LOOPS               |                       |   103K|  2936K|   252   (1)| 00:00:04 |
    |* 20 |          INDEX RANGE SCAN          | LINEAGES_PK           |     5 |    35 |     1   (0)| 00:00:01 |
    |* 21 |          INDEX RANGE SCAN          | A97_STATEID_IX1       | 17731 |       |    32   (0)| 00:00:01 |
    |  22 |         TABLE ACCESS BY INDEX ROWID| A97                   | 21491 |   461K|   123   (1)| 00:00:02 |
    |* 23 |   VIEW                             |                       |     1 |   163 |     8  (13)| 00:00:01 |
    |  24 |    UNION ALL PUSHED PREDICATE      |                       |       |       |            |       |
    |  25 |     NESTED LOOPS ANTI              |                       |     1 |   185 |     1   (0)| 00:00:01 |
    |* 26 |      TABLE ACCESS BY INDEX ROWID   | CONNECTION            |     1 |   181 |     0   (0)| 00:00:01 |
    |* 27 |       INDEX UNIQUE SCAN            | R96_SDE_ROWID_UK      |     1 |       |     0   (0)| 00:00:01 |
    |  28 |      VIEW PUSHED PREDICATE         | VW_NSO_3              |     1 |     4 |     1   (0)| 00:00:01 |
    |  29 |       NESTED LOOPS                 |                       |     1 |    20 |     1   (0)| 00:00:01 |
    |* 30 |        INDEX RANGE SCAN            | LINEAGES_PK           |     5 |    35 |     1   (0)| 00:00:01 |
    |* 31 |        INDEX UNIQUE SCAN           | D96_PK                |     1 |    13 |     0   (0)| 00:00:01 |
    |* 32 |     HASH JOIN ANTI                 |                       |     1 |    97 |     7  (15)| 00:00:01 |
    |  33 |      NESTED LOOPS                  |                       |     1 |    71 |     4   (0)| 00:00:01 |
    |* 34 |       TABLE ACCESS BY INDEX ROWID  | A96                   |     1 |    64 |     4   (0)| 00:00:01 |
    |* 35 |        INDEX RANGE SCAN            | A96_PK                |     1 |       |     3   (0)| 00:00:01 |
    |* 36 |       INDEX UNIQUE SCAN            | LINEAGES_PK           |     1 |     7 |     0   (0)| 00:00:01 |
    |  37 |      VIEW                          | VW_NSO_4              |     1 |    26 |     2   (0)| 00:00:01 |
    |  38 |       NESTED LOOPS                 |                       |     1 |    20 |     2   (0)| 00:00:01 |
    |* 39 |        INDEX FAST FULL SCAN        | D96_PK                |     1 |    13 |     2   (0)| 00:00:01 |
    |* 40 |        INDEX UNIQUE SCAN           | LINEAGES_PK           |     1 |     7 |     0   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       3 - filter("TMP_TRACE"."SESSION_ID"=(-1234))
      11 - access("L"."LINEAGE_NAME"=2 AND "L"."LINEAGE_ID"<=115)
      12 - access("DELETED_AT"="L"."LINEAGE_ID" AND "SDE_DELETES_ROW_ID"="B"."OBJECTID" AND
                  "SDE_STATE_ID"=0)
           filter("DELETED_AT"<=115)
      13 - access("A"."OBJECTID"="SDE_DELETES_ROW_ID" AND "A"."SDE_STATE_ID"="SDE_STATE_ID")
      16 - filter("DELETED_AT"<=115 AND "SDE_STATE_ID"<=115 AND "SDE_STATE_ID">0)
      17 - access("L"."LINEAGE_NAME"=2 AND "DELETED_AT"="L"."LINEAGE_ID")
           filter("L"."LINEAGE_ID"<=115)
      20 - access("SL"."LINEAGE_NAME"=2 AND "SL"."LINEAGE_ID"<=115)
      21 - access("A"."SDE_STATE_ID"="SL"."LINEAGE_ID")
           filter("A"."SDE_STATE_ID"<=115)
      23 - filter(("TMP_TRACE"."EQUIPMENT_OBJECT_ID"="V__96"."TO_OBJECTID" AND "V__96"."TO_CLASSID"=9
                  OR "TMP_TRACE"."TRANSMEDIA_OBJECT_ID"="V__96"."TO_OBJECTID" AND "V__96"."TO_CLASSID"=5) AND
                  ("V__96"."TO_FIRSTUNIT">="TMP_TRACE"."FIRST_UNIT" AND
                  "V__96"."TO_FIRSTUNIT"<="TMP_TRACE"."LAST_UNIT" OR "TMP_TRACE"."FIRST_UNIT">="V__96"."TO_FIRSTUNIT"
                  AND "TMP_TRACE"."FIRST_UNIT"<="V__96"."TO_FIRSTUNIT"+"V__96"."NUMBER_OF_UNITS"-1))
      26 - filter("B"."ANSWERS"=0)
      27 - access("B"."OBJECTID"="V__97"."CONNECTION_OBJECTID")
      30 - access("L"."LINEAGE_NAME"=2 AND "L"."LINEAGE_ID"<=115)
      31 - access("DELETED_AT"="L"."LINEAGE_ID" AND "SDE_DELETES_ROW_ID"="B"."OBJECTID" AND
                  "SDE_STATE_ID"=0)
           filter("DELETED_AT"<=115)
      32 - access("A"."OBJECTID"="SDE_DELETES_ROW_ID" AND "A"."SDE_STATE_ID"="SDE_STATE_ID")
      34 - filter("A"."ANSWERS"=0)
      35 - access("A"."OBJECTID"="V__97"."CONNECTION_OBJECTID" AND "A"."SDE_STATE_ID"<=115)
      36 - access("SL"."LINEAGE_NAME"=2 AND "A"."SDE_STATE_ID"="SL"."LINEAGE_ID")
           filter("SL"."LINEAGE_ID"<=115)
      39 - filter("DELETED_AT"<=115 AND "SDE_STATE_ID"<=115 AND
                  "SDE_DELETES_ROW_ID"="V__97"."CONNECTION_OBJECTID" AND "SDE_STATE_ID">0)
      40 - access("L"."LINEAGE_NAME"=2 AND "DELETED_AT"="L"."LINEAGE_ID")
           filter("L"."LINEAGE_ID"<=115)
    Note
       - dynamic sampling used for this statement
    87 rows selected.Here is the output of SQL*Plus AUTOTRACE including the TIMING information:
    SQL> set autotrace traceonly arraysize 100
    Elapsed: 00:00:01.64
    Execution Plan
    Plan hash value: 1198408274
    | Id  | Operation                          | Name                  | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                   |                       |   876K|   238M|  1301   (2)| 00:00:16 |
    |   1 |  CONCATENATION                     |                       |       |       |            |       |
    |*  2 |   HASH JOIN                        |                       |   438K|   119M|   651   (2)| 00:00:08 |
    |*  3 |    HASH JOIN                       |                       |   423 | 98559 |   390   (2)| 00:00:05 |
    |*  4 |     TABLE ACCESS FULL              | TMP_TRACE             |    82 |  5330 |    29   (0)| 00:00:01 |
    |*  5 |     VIEW                           |                       |   103K|    16M|   360   (1)| 00:00:05 |
    |   6 |      UNION-ALL                     |                       |       |       |            |       |
    |   7 |       NESTED LOOPS ANTI            |                       |     1 |   185 |     3   (0)| 00:00:01 |
    |*  8 |        TABLE ACCESS FULL           | CONNECTION            |     1 |   181 |     2   (0)| 00:00:01 |
    |   9 |        VIEW PUSHED PREDICATE       | VW_NSO_3              |     1 |     4 |     1   (0)| 00:00:01 |
    |  10 |         NESTED LOOPS               |                       |     1 |    20 |     1   (0)| 00:00:01 |
    |* 11 |          INDEX RANGE SCAN          | LINEAGES_PK           |     5 |    35 |     1   (0)| 00:00:01 |
    |* 12 |          INDEX UNIQUE SCAN         | D96_PK                |     1 |    13 |     0   (0)| 00:00:01 |
    |* 13 |       HASH JOIN RIGHT ANTI         |                       |   103K|  9820K|   357   (1)| 00:00:05 |
    |  14 |        VIEW                        | VW_NSO_4              |     1 |    26 |     2   (0)| 00:00:01 |
    |  15 |         NESTED LOOPS               |                       |     1 |    20 |     2   (0)| 00:00:01 |
    |* 16 |          INDEX FAST FULL SCAN      | D96_PK                |     1 |    13 |     2   (0)| 00:00:01 |
    |* 17 |          INDEX UNIQUE SCAN         | LINEAGES_PK           |     1 |     7 |     0   (0)| 00:00:01 |
    |  18 |        NESTED LOOPS                |                       |       |       |            |       |
    |  19 |         NESTED LOOPS               |                       |   103K|  7188K|   354   (1)| 00:00:05 |
    |* 20 |          INDEX RANGE SCAN          | LINEAGES_PK           |     5 |    35 |     1   (0)| 00:00:01 |
    |* 21 |          INDEX RANGE SCAN          | A96_STATEID_IX1       | 17731 |       |    32   (0)| 00:00:01 |
    |* 22 |         TABLE ACCESS BY INDEX ROWID| A96                   | 21491 |  1343K|   224   (1)| 00:00:03 |
    |  23 |    VIEW                            |                       |   103K|  5264K|   258   (1)| 00:00:04 |
    |  24 |     UNION-ALL                      |                       |       |       |            |       |
    |  25 |      NESTED LOOPS ANTI             |                       |     1 |    82 |     3   (0)| 00:00:01 |
    |  26 |       TABLE ACCESS FULL            | CONNECTION_ATTRIBUTES |     1 |    78 |     2   (0)| 00:00:01 |
    |  27 |       VIEW PUSHED PREDICATE        | VW_NSO_1              |     1 |     4 |     1   (0)| 00:00:01 |
    |  28 |        NESTED LOOPS                |                       |     1 |    20 |     1   (0)| 00:00:01 |
    |* 29 |         INDEX RANGE SCAN           | LINEAGES_PK           |     5 |    35 |     1   (0)| 00:00:01 |
    |* 30 |         INDEX UNIQUE SCAN          | D97_PK                |     1 |    13 |     0   (0)| 00:00:01 |
    |* 31 |      HASH JOIN RIGHT ANTI          |                       |   103K|  5568K|   255   (1)| 00:00:04 |
    |  32 |       VIEW                         | VW_NSO_2              |     1 |    26 |     2   (0)| 00:00:01 |
    |  33 |        NESTED LOOPS                |                       |     1 |    20 |     2   (0)| 00:00:01 |
    |* 34 |         INDEX FAST FULL SCAN       | D97_PK                |     1 |    13 |     2   (0)| 00:00:01 |
    |* 35 |         INDEX UNIQUE SCAN          | LINEAGES_PK           |     1 |     7 |     0   (0)| 00:00:01 |
    |  36 |       NESTED LOOPS                 |                       |       |       |            |       |
    |  37 |        NESTED LOOPS                |                       |   103K|  2936K|   252   (1)| 00:00:04 |
    |* 38 |         INDEX RANGE SCAN           | LINEAGES_PK           |     5 |    35 |     1   (0)| 00:00:01 |
    |* 39 |         INDEX RANGE SCAN           | A97_STATEID_IX1       | 17731 |       |    32   (0)| 00:00:01 |
    |  40 |        TABLE ACCESS BY INDEX ROWID | A97                   | 21491 |   461K|   123   (1)| 00:00:02 |
    |* 41 |   HASH JOIN                        |                       |   438K|   119M|   651   (2)| 00:00:08 |
    |* 42 |    HASH JOIN                       |                       |   423 | 98559 |   390   (2)| 00:00:05 |
    |* 43 |     TABLE ACCESS FULL              | TMP_TRACE             |    82 |  5330 |    29   (0)| 00:00:01 |
    |* 44 |     VIEW                           |                       |   103K|    16M|   360   (1)| 00:00:05 |
    |  45 |      UNION-ALL                     |                       |       |       |            |       |
    |  46 |       NESTED LOOPS ANTI            |                       |     1 |   185 |     3   (0)| 00:00:01 |
    |* 47 |        TABLE ACCESS FULL           | CONNECTION            |     1 |   181 |     2   (0)| 00:00:01 |
    |  48 |        VIEW PUSHED PREDICATE       | VW_NSO_3              |     1 |     4 |     1   (0)| 00:00:01 |
    |  49 |         NESTED LOOPS               |                       |     1 |    20 |     1   (0)| 00:00:01 |
    |* 50 |          INDEX RANGE SCAN          | LINEAGES_PK           |     5 |    35 |     1   (0)| 00:00:01 |
    |* 51 |          INDEX UNIQUE SCAN         | D96_PK                |     1 |    13 |     0   (0)| 00:00:01 |
    |* 52 |       HASH JOIN RIGHT ANTI         |                       |   103K|  9820K|   357   (1)| 00:00:05 |
    |  53 |        VIEW                        | VW_NSO_4              |     1 |    26 |     2   (0)| 00:00:01 |
    |  54 |         NESTED LOOPS               |                       |     1 |    20 |     2   (0)| 00:00:01 |
    |* 55 |          INDEX FAST FULL SCAN      | D96_PK                |     1 |    13 |     2   (0)| 00:00:01 |
    |* 56 |          INDEX UNIQUE SCAN         | LINEAGES_PK           |     1 |     7 |     0   (0)| 00:00:01 |
    |  57 |        NESTED LOOPS                |                       |       |       |            |       |
    |  58 |         NESTED LOOPS               |                       |   103K|  7188K|   354   (1)| 00:00:05 |
    |* 59 |          INDEX RANGE SCAN          | LINEAGES_PK           |     5 |    35 |     1   (0)| 00:00:01 |
    |* 60 |          INDEX RANGE SCAN          | A96_STATEID_IX1       | 17731 |       |    32   (0)| 00:00:01 |
    |* 61 |         TABLE ACCESS BY INDEX ROWID| A96                   | 21491 |  1343K|   224   (1)| 00:00:03 |
    |  62 |    VIEW                            |                       |   103K|  5264K|   258   (1)| 00:00:04 |
    |  63 |     UNION-ALL                      |                       |       |       |            |       |
    |  64 |      NESTED LOOPS ANTI             |                       |     1 |    82 |     3   (0)| 00:00:01 |
    |  65 |       TABLE ACCESS FULL            | CONNECTION_ATTRIBUTES |     1 |    78 |     2   (0)| 00:00:01 |
    |  66 |       VIEW PUSHED PREDICATE        | VW_NSO_1              |     1 |     4 |     1   (0)| 00:00:01 |
    |  67 |        NESTED LOOPS                |                       |     1 |    20 |     1   (0)| 00:00:01 |
    |* 68 |         INDEX RANGE SCAN           | LINEAGES_PK           |     5 |    35 |     1   (0)| 00:00:01 |
    |* 69 |         INDEX UNIQUE SCAN          | D97_PK                |     1 |    13 |     0   (0)| 00:00:01 |
    |* 70 |      HASH JOIN RIGHT ANTI          |                       |   103K|  5568K|   255   (1)| 00:00:04 |
    |  71 |       VIEW                         | VW_NSO_2              |     1 |    26 |     2   (0)| 00:00:01 |
    |  72 |        NESTED LOOPS                |                       |     1 |    20 |     2   (0)| 00:00:01 |
    |* 73 |         INDEX FAST FULL SCAN       | D97_PK                |     1 |    13 |     2   (0)| 00:00:01 |
    |* 74 |         INDEX UNIQUE SCAN          | LINEAGES_PK           |     1 |     7 |     0   (0)| 00:00:01 |
    |  75 |       NESTED LOOPS                 |                       |       |       |            |       |
    |  76 |        NESTED LOOPS                |                       |   103K|  2936K|   252   (1)| 00:00:04 |
    |* 77 |         INDEX RANGE SCAN           | LINEAGES_PK           |     5 |    35 |     1   (0)| 00:00:01 |
    |* 78 |         INDEX RANGE SCAN           | A97_STATEID_IX1       | 17731 |       |    32   (0)| 00:00:01 |
    |  79 |        TABLE ACCESS BY INDEX ROWID | A97                   | 21491 |   461K|   123   (1)| 00:00:02 |
    Predicate Information (identified by operation id):
       2 - access("V__96"."OBJECTID"="V__97"."CONNECTION_OBJECTID")
       3 - access("TMP_TRACE"."TRANSMEDIA_OBJECT_ID"="V__96"."TO_OBJECTID")
           filter("V__96"."TO_FIRSTUNIT">="TMP_TRACE"."FIRST_UNIT" AND
                  "V__96"."TO_FIRSTUNIT"<="TMP_TRACE"."LAST_UNIT" OR "TMP_TRACE"."FIRST_UNIT">="V__96"."TO_FIRSTUNIT"
                  AND "TMP_TRACE"."FIRST_UNIT"<="V__96"."TO_FIRSTUNIT"+"V__96"."NUMBER_OF_UNITS"-1)
       4 - filter("TMP_TRACE"."SESSION_ID"=(-1234))
       5 - filter("V__96"."TO_CLASSID"=5)
       8 - filter("B"."ANSWERS"=0)
      11 - access("L"."LINEAGE_NAME"=2 AND "L"."LINEAGE_ID"<=115)
      12 - access("DELETED_AT"="L"."LINEAGE_ID" AND "SDE_DELETES_ROW_ID"="B"."OBJECTID" AND
                  "SDE_STATE_ID"=0)
           filter("DELETED_AT"<=115)
      13 - access("A"."OBJECTID"="SDE_DELETES_ROW_ID" AND "A"."SDE_STATE_ID"="SDE_STATE_ID")
      16 - filter("DELETED_AT"<=115 AND "SDE_STATE_ID"<=115 AND "SDE_STATE_ID">0)
      17 - access("L"."LINEAGE_NAME"=2 AND "DELETED_AT"="L"."LINEAGE_ID")
           filter("L"."LINEAGE_ID"<=115)
      20 - access("SL"."LINEAGE_NAME"=2 AND "SL"."LINEAGE_ID"<=115)
      21 - access("A"."SDE_STATE_ID"="SL"."LINEAGE_ID")
           filter("A"."SDE_STATE_ID"<=115)
      22 - filter("A"."ANSWERS"=0)
      29 - access("L"."LINEAGE_NAME"=2 AND "L"."LINEAGE_ID"<=115)
      30 - access("DELETED_AT"="L"."LINEAGE_ID" AND "SDE_DELETES_ROW_ID"="B"."OBJECTID" AND
                  "SDE_STATE_ID"=0)
           filter("DELETED_AT"<=115)
      31 - access("A"."OBJECTID"="SDE_DELETES_ROW_ID" AND "A"."SDE_STATE_ID"="SDE_STATE_ID")
      34 - filter("DELETED_AT"<=115 AND "SDE_STATE_ID"<=115 AND "SDE_STATE_ID">0)
      35 - access("L"."LINEAGE_NAME"=2 AND "DELETED_AT"="L"."LINEAGE_ID")
           filter("L"."LINEAGE_ID"<=115)
      38 - access("SL"."LINEAGE_NAME"=2 AND "SL"."LINEAGE_ID"<=115)
      39 - access("A"."SDE_STATE_ID"="SL"."LINEAGE_ID")
           filter("A"."SDE_STATE_ID"<=115)
      41 - access("V__96"."OBJECTID"="V__97"."CONNECTION_OBJECTID")
      42 - access("TMP_TRACE"."EQUIPMENT_OBJECT_ID"="V__96"."TO_OBJECTID")
           filter((LNNVL("TMP_TRACE"."TRANSMEDIA_OBJECT_ID"="V__96"."TO_OBJECTID") OR
                  LNNVL("V__96"."TO_CLASSID"=5)) AND ("V__96"."TO_FIRSTUNIT">="TMP_TRACE"."FIRST_UNIT" AND
                  "V__96"."TO_FIRSTUNIT"<="TMP_TRACE"."LAST_UNIT" OR "TMP_TRACE"."FIRST_UNIT">="V__96"."TO_FIRSTUNIT"
                  AND "TMP_TRACE"."FIRST_UNIT"<="V__96"."TO_FIRSTUNIT"+"V__96"."NUMBER_OF_UNITS"-1))
      43 - filter("TMP_TRACE"."SESSION_ID"=(-1234))
      44 - filter("V__96"."TO_CLASSID"=9)
      47 - filter("B"."ANSWERS"=0)
      50 - access("L"."LINEAGE_NAME"=2 AND "L"."LINEAGE_ID"<=115)
      51 - access("DELETED_AT"="L"."LINEAGE_ID" AND "SDE_DELETES_ROW_ID"="B"."OBJECTID" AND
                  "SDE_STATE_ID"=0)
           filter("DELETED_AT"<=115)
      52 - access("A"."OBJECTID"="SDE_DELETES_ROW_ID" AND "A"."SDE_STATE_ID"="SDE_STATE_ID")
      55 - filter("DELETED_AT"<=115 AND "SDE_STATE_ID"<=115 AND "SDE_STATE_ID">0)
      56 - access("L"."LINEAGE_NAME"=2 AND "DELETED_AT"="L"."LINEAGE_ID")
           filter("L"."LINEAGE_ID"<=115)
      59 - access("SL"."LINEAGE_NAME"=2 AND "SL"."LINEAGE_ID"<=115)
      60 - access("A"."SDE_STATE_ID"="SL"."LINEAGE_ID")
           filter("A"."SDE_STATE_ID"<=115)
      61 - filter("A"."ANSWERS"=0)
      68 - access("L"."LINEAGE_NAME"=2 AND "L"."LINEAGE_ID"<=115)
      69 - access("DELETED_AT"="L"."LINEAGE_ID" AND "SDE_DELETES_ROW_ID"="B"."OBJECTID" AND
                  "SDE_STATE_ID"=0)
           filter("DELETED_AT"<=115)
      70 - access("A"."OBJECTID"="SDE_DELETES_ROW_ID" AND "A"."SDE_STATE_ID"="SDE_STATE_ID")
      73 - filter("DELETED_AT"<=115 AND "SDE_STATE_ID"<=115 AND "SDE_STATE_ID">0)
      74 - access("L"."LINEAGE_NAME"=2 AND "DELETED_AT"="L"."LINEAGE_ID")
           filter("L"."LINEAGE_ID"<=115)
      77 - access("SL"."LINEAGE_NAME"=2 AND "SL"."LINEAGE_ID"<=115)
      78 - access("A"."SDE_STATE_ID"="SL"."LINEAGE_ID")
           filter("A"."SDE_STATE_ID"<=115)
    Note
       - dynamic sampling used for this statementThe TKPROF output for this statement looks like the following:
    TKPROF: Release 11.1.0.6.0 - Production on Thu Sep 24 09:30:01 2009
    Copyright (c) 1982, 2007, Oracle.  All rights reserved.
    Trace file: pro                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           &

    The TKPROF output for this statement looks like the following:
    TKPROF: Release 11.1.0.6.0 - Production on Thu Sep 24 09:30:01 2009
    Copyright (c) 1982, 2007, Oracle.  All rights reserved.
    Trace file: problem.trc
    Sort options: default
    count    = number of times OCI procedure was executed
    cpu      = cpu time in seconds executing
    elapsed  = elapsed time in seconds executing
    disk     = number of physical reads of buffers from disk
    query    = number of buffers gotten for consistent read
    current  = number of buffers gotten in current mode (usually for update)
    rows     = number of rows processed by the fetch or execute call
    SELECT  V__96.CONNECTOR_OBJECTID,  V__96.CONNECTOR_CLASSID,  V__96.FROM_OBJECTID,  V__96.TO_OBJECTID,  V__96.FROM_CLASSID,  V__96.TO_CLASSID, 
    V__96.FROM_FIRSTUNIT,  V__96.TO_FIRSTUNIT,  V__96.NUMBER_OF_UNITS,  TMP_TRACE.FIRST_UNIT,  TMP_TRACE.LAST_UNIT,  V__96.INV_STATUS_NUMBER, 
    TMP_TRACE.FIRST_UNIT,  TMP_TRACE.LAST_UNIT,  V__96.ANSWERS,  V__96.PRIORITY,  V__97.FIRST_UNIT,  V__97.N_UNITS,  V__97.MID_SPAN_DISTANCE  FROM 
    NE.TMP_TRACE,(SELECT
    b.OBJECTID,b.ANSWERS,b.CONNECTOR_CLASSID,b.CONNECTOR_OBJECTID,b.FROM_CLASSID,b.FROM_OBJECTID,b.TO_CLASSID,b.TO_OBJECTID,b.FROM_FIRSTUNIT,b.TO_FIRSTUNIT,b.NUM
    BER_OF_UNITS,b.INV_STATUS_NUMBER,b.SPLICE_CLOSURE_NAME,b.WORK_ORDER_NAME,b.WORK_ORDER_ITEM_NUMBER,b.INVENTORY_STATUS_CODE,b.PRIORITY  FROM NE.connection b
    WHERE b.OBJECTID NOT IN (SELECT /*+ HASH_AJ */ SDE_DELETES_ROW_ID FROM NE.D96 WHERE DELETED_AT IN (SELECT l.lineage_id FROM SDE.state_lineages l WHERE
    l.lineage_name = :"SYS_B_00" AND l.lineage_id <= :"SYS_B_01") AND SDE_STATE_ID = :"SYS_B_02") UNION ALL SELECT
    a.OBJECTID,a.ANSWERS,a.CONNECTOR_CLASSID,a.CONNECTOR_OBJECTID,a.FROM_CLASSID,a.FROM_OBJECTID,a.TO_CLASSID,a.TO_OBJECTID,a.FROM_FIRSTUNIT,a.TO_FIRSTUNIT,a.NUM
    BER_OF_UNITS,a.INV_STATUS_NUMBER,a.SPLICE_CLOSURE_NAME,a.WORK_ORDER_NAME,a.WORK_ORDER_ITEM_NUMBER,a.INVENTORY_STATUS_CODE,a.PRIORITY  FROM NE.A96
    a,SDE.state_lineages SL WHERE (a.OBJECTID, a.SDE_STATE_ID) NOT IN (SELECT /*+ HASH_AJ */ SDE_DELETES_ROW_ID,SDE_STATE_ID  FROM NE.D96 WHERE DELETED_AT IN
    (SELECT l.lineage_id FROM SDE.state_lineages l WHERE l.lineage_name = :"SYS_B_03" AND l.lineage_id <= :"SYS_B_04") AND SDE_STATE_ID > :"SYS_B_05") AND
    a.SDE_STATE_ID = SL.lineage_id AND SL.lineage_name = :"SYS_B_06" AND SL.lineage_id <= :"SYS_B_07") V__96,(SELECT
    b.OBJECTID,b.TRAY_NUMBER,b.DB_LOSS,b.FIRST_UNIT,b.N_UNITS,b.CONNECTION_OBJECTID,b.CONNECTOR_TYPE_NAME,b.DEDICATED_STATUS,b.MID_SPAN_DISTANCE  FROM
    NE.connection_attributes b WHERE b.OBJECTID NOT IN (SELECT /*+ HASH_AJ */ SDE_DELETES_ROW_ID FROM NE.D97 WHERE DELETED_AT IN (SELECT l.lineage_id FROM
    SDE.state_lineages l WHERE l.lineage_name = :"SYS_B_08" AND l.lineage_id <= :"SYS_B_09") AND SDE_STATE_ID = :"SYS_B_10") UNION ALL SELECT
    a.OBJECTID,a.TRAY_NUMBER,a.DB_LOSS,a.FIRST_UNIT,a.N_UNITS,a.CONNECTION_OBJECTID,a.CONNECTOR_TYPE_NAME,a.DEDICATED_STATUS,a.MID_SPAN_DISTANCE  FROM NE.A97
    a,SDE.state_lineages SL WHERE (a.OBJECTID, a.SDE_STATE_ID) NOT IN (SELECT /*+ HASH_AJ */ SDE_DELETES_ROW_ID,SDE_STATE_ID  FROM NE.D97 WHERE DELETED_AT IN
    (SELECT l.lineage_id FROM SDE.state_lineages l WHERE l.lineage_name = :"SYS_B_11" AND l.lineage_id <= :"SYS_B_12") AND SDE_STATE_ID > :"SYS_B_13") AND
    a.SDE_STATE_ID = SL.lineage_id AND SL.lineage_name = :"SYS_B_14" AND SL.lineage_id <= :"SYS_B_15") V__97  WHERE (((((   (
                                             NE.tmp_trace.equipment_object_id = V__96.to_objectid
                                              AND
                                             V__96.to_classid = :"SYS_B_16"
                                           OR
                                             NE.tmp_trace.transmedia_object_id = V__96.to_objectid
                                               AND
                                             V__96.to_classid = :"SYS_B_17"
                                             )) AND (
                                            (V__96.to_firstunit
                                                BETWEEN NE.tmp_trace.first_unit AND NE.tmp_trace.last_unit)
                                              OR
                                            (NE.tmp_trace.first_unit BETWEEN V__96.to_firstunit
                                                 AND V__96.to_firstunit + V__96.number_of_units - :"SYS_B_18")
                                          )) AND V__96.answers = :"SYS_B_19") AND V__96.objectid = V__97.connection_objectid) AND (NE.tmp_trace.session_id =
    :"SYS_B_20"))
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      5.98       5.99          0      22652          0          10
    total        3      5.98       5.99          0      22652          0          10
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 45 
    Rows     Row Source Operation
         10  NESTED LOOPS  (cr=22652 pr=0 pw=0 time=654515 us cost=67 size=282 card=1)
         10   NESTED LOOPS  (cr=22436 pr=0 pw=0 time=653673 us cost=61 size=235 card=1)
         10    TABLE ACCESS FULL TMP_TRACE (cr=5 pr=0 pw=0 time=7 us cost=2 size=65 card=1)
         10    VIEW  (cr=22431 pr=0 pw=0 time=0 us cost=59 size=170 card=1)
    1773000     UNION-ALL  (cr=22431 pr=0 pw=0 time=93649 us)
          0      NESTED LOOPS ANTI (cr=30 pr=0 pw=0 time=0 us cost=3 size=185 card=1)
          0       TABLE ACCESS FULL CONNECTION (cr=30 pr=0 pw=0 time=0 us cost=2 size=181 card=1)
          0       VIEW PUSHED PREDICATE  VW_NSO_3 (cr=0 pr=0 pw=0 time=0 us cost=1 size=4 card=1)
          0        NESTED LOOPS  (cr=0 pr=0 pw=0 time=0 us cost=1 size=20 card=1)
          0         INDEX RANGE SCAN LINEAGES_PK (cr=0 pr=0 pw=0 time=0 us cost=1 size=7 card=1)(object id 34021)
          0         INDEX UNIQUE SCAN D96_PK (cr=0 pr=0 pw=0 time=0 us cost=0 size=13 card=1)(object id 35121)
    1773000      HASH JOIN RIGHT ANTI (cr=22401 pr=0 pw=0 time=75084 us cost=56 size=46948 card=484)
          0       VIEW  VW_NSO_4 (cr=180 pr=0 pw=0 time=0 us cost=2 size=26 card=1)
          0        FILTER  (cr=180 pr=0 pw=0 time=0 us)
          0         NESTED LOOPS  (cr=180 pr=0 pw=0 time=0 us cost=2 size=20 card=1)
          0          INDEX FAST FULL SCAN D96_PK (cr=180 pr=0 pw=0 time=0 us cost=2 size=13 card=1)(object id 35121)
          0          INDEX UNIQUE SCAN LINEAGES_PK (cr=0 pr=0 pw=0 time=0 us cost=0 size=7 card=1)(object id 34021)
    1773000       NESTED LOOPS  (cr=22221 pr=0 pw=0 time=56155 us)
    1773000        NESTED LOOPS  (cr=3231 pr=0 pw=0 time=15078 us cost=53 size=34364 card=484)
         50         INDEX RANGE SCAN LINEAGES_PK (cr=10 pr=0 pw=0 time=7 us cost=1 size=7 card=1)(object id 34021)
    1773000         INDEX RANGE SCAN A96_STATEID_IX1 (cr=3221 pr=0 pw=0 time=6810 us cost=32 size=0 card=1774)(object id 35116)
    1773000        TABLE ACCESS BY INDEX ROWID A96 (cr=18990 pr=0 pw=0 time=0 us cost=52 size=82560 card=1290)
         10   VIEW  (cr=216 pr=0 pw=0 time=0 us cost=7 size=47 card=1)
         10    UNION ALL PUSHED PREDICATE  (cr=216 pr=0 pw=0 time=0 us)
          0     NESTED LOOPS ANTI (cr=1 pr=0 pw=0 time=0 us cost=2 size=82 card=1)
          0      TABLE ACCESS BY INDEX ROWID CONNECTION_ATTRIBUTES (cr=1 pr=0 pw=0 time=0 us cost=1 size=78 card=1)
          0       INDEX RANGE SCAN GDB_59_CONNECTIO (cr=1 pr=0 pw=0 time=0 us cost=1 size=0 card=1)(object id 34346)
          0      VIEW PUSHED PREDICATE  VW_NSO_1 (cr=0 pr=0 pw=0 time=0 us cost=1 size=4 card=1)
          0       NESTED LOOPS  (cr=0 pr=0 pw=0 time=0 us cost=1 size=20 card=1)
          0        INDEX RANGE SCAN LINEAGES_PK (cr=0 pr=0 pw=0 time=0 us cost=1 size=7 card=1)(object id 34021)
          0        INDEX UNIQUE SCAN D97_PK (cr=0 pr=0 pw=0 time=0 us cost=0 size=13 card=1)(object id 35127)
         10     HASH JOIN ANTI (cr=215 pr=0 pw=0 time=0 us cost=5 size=55 card=1)
         10      NESTED LOOPS  (cr=35 pr=0 pw=0 time=0 us cost=2 size=29 card=1)
         10       TABLE ACCESS BY INDEX ROWID A97 (cr=25 pr=0 pw=0 time=0 us cost=2 size=22 card=1)
         10        INDEX RANGE SCAN GDB_59_CONNECTIO_A (cr=15 pr=0 pw=0 time=0 us cost=1 size=0 card=1)(object id 35122)
         10       INDEX UNIQUE SCAN LINEAGES_PK (cr=10 pr=0 pw=0 time=0 us cost=0 size=7 card=1)(object id 34021)
          0      VIEW  VW_NSO_2 (cr=180 pr=0 pw=0 time=0 us cost=2 size=26 card=1)
          0       FILTER  (cr=180 pr=0 pw=0 time=0 us)
          0        NESTED LOOPS  (cr=180 pr=0 pw=0 time=0 us cost=2 size=20 card=1)
          0         INDEX FAST FULL SCAN D97_PK (cr=180 pr=0 pw=0 time=0 us cost=2 size=13 card=1)(object id 35127)
          0         INDEX UNIQUE SCAN LINEAGES_PK (cr=0 pr=0 pw=0 time=0 us cost=0 size=7 card=1)(object id 34021)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                       2        0.00          0.00
      SQL*Net message from client                     2        0.00          0.00After manually rewrite query in TOAD it produces nested loops on business table and than access v__96, v__97 produce desired quick performance.
    I can use stored outlines but this is the last chance. I am playing with hints right now to produce desired plan with no result yet.
    Does anybody know how to insist Oracle to merge internal views to bigger query block, so Oracle can choose better plan?
    Or any guide what hints to use from ol$hints to get desired result via hints addition to original sql query (thanks God application don't cut hints just pass-through to Oracle)?
    Thanks,
    Sergiy

  • Tuning needed for sql:EXPLAIN PLAN attached

    DB Version:10gR2
    The below sql was running slow, so i took an explain plan
    SQL> explain plan for
      2  SELECT COUNT(1) FROM SHIP_DTL WHERE
      3  SHIP_DTL.PLT_ID = 'AM834'
      4  AND SHIP_DTL.WHSE = '34' AND
      5  SHIP_DTL.STAT_CODE != '845'
      6  ORDER BY SHIP_DTL.LOAD_SEQ ASC;
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id  | Operation                    |  Name             | Rows  | Bytes | Cost (%CPU)|
    |   0 | SELECT STATEMENT             |                   |     1 |    18 |     5  (20)|
    |   1 |  SORT AGGREGATE              |                   |     1 |    18 |            |
    |*  2 |   TABLE ACCESS BY INDEX ROWID| SHIP_DTL        |   200 |  3600 |     5  (20)|
    |*  3 |    INDEX RANGE SCAN          | SHIP_DTL_IND_4  |   203 |       |     3   (0)|
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
       2 - filter("SHIP_DTL"."WHSE"='34' AND "SHIP_DTL"."STAT_CODE"<>845)
       3 - access("SHIP_DTL"."PLT_ID"='AM834')Why is there an INDEX RANGE scan where there is no BETWEEN operator in the query? What are various options(indexes, rewriting query) in tuning this query?

    james_p wrote:
    DB Version:10gR2
    The below sql was running slow, so i took an explain planCheck your plan, the optimizer estimates that the following query:
    select count(*)
    from SHIP_DTL
    where "SHIP_DTL"."PLT_ID"='AM834';only returns 200 records. Is this correct? Please post the result of above query.
    It probably isn't the case, because retrieving 200 records per index range scan and single row random table access shouldn't take long, at maximum a couple of seconds if you need to read each block actually from disk rather than from the cache.
    If the estimate is wrong you need to check the statistics on the table and index that were used by the optimizer to come to that conclusion.
    Are you sure that this plan is the actual plan used at execution time? You can check for the actual plans used to execute by using the DBMS_XPLAN.DISPLAY_CURSOR function in 10g if the SQL is still cached in the Shared Pool. You need to pass the SQL_ID and SQL_CHILD_NUMBER which you can retrieve from V$SESSION while the statement is executing.
    Regards,
    Randolf
    Oracle related stuff blog:
    http://oracle-randolf.blogspot.com/
    SQLTools++ for Oracle (Open source Oracle GUI for Windows):
    http://www.sqltools-plusplus.org:7676/
    http://sourceforge.net/projects/sqlt-pp/

  • Need help for balance calc

    Suppose I have a table which contains code,debit and credit amount. Using decode function balance is calculated. this is my approach any other approach??
    When table size is small the query works fine. But if table size grow query takes time for execution.
    then
    Table compression
    Partitioning
    Is there any way to rewrite query for better result using upper case??
    Any Idea??
    Thanks

    Many other possible approaches. Given that you provided essentially no information, however, that is as much as I can offer as help.
    What does upper case have to do with anything you've written?

  • Issue with a procedure and IN operator...

    Hi,
    Data
    Service_Request_id function_activity_ids
    102092     2     2 -- Query works fine as v_function_activity_ids(i) = 22
    102094 24,25,29 -- Query does not work and returns null as v_function_activity_ids(i) =24,25,29 is passed.
    102152 23,24 -- Query does not work and returns null as v_function_activity_ids(i) =23,22 is passed.
    CURSOR c_service_request_null IS
    SELECT service_request_id,function_activity_ids,service_region_id      
           FROM temp_sop_service_request
           WHERE function_activity_ids IS NOT NULL AND SERVICE_REQUEST_ID IN ( '102092','102094','102152');
    <all the relevant vars. declared here...>
    begin
    OPEN c_service_request_null;
      LOOP
        FETCH c_service_request_null
        BULK COLLECT INTO v_service_req_id,v_platform_type,v_service_country,v_service_state,
                          v_function_activity_ids,v_service_region_id
        LIMIT 500;
        EXIT WHEN v_row_count = c_service_request_null%ROWCOUNT;
        v_row_count := c_service_request_null%ROWCOUNT;
    FOR i IN 1..v_service_req_id.count LOOP
            SELECT  max(decode(upper(trim(region_id)),NULL,'UR',upper(trim(region_id))))
            INTO v_region_id(i)
            FROM SOP_REGION_ACTIVITY_MAP
         WHERE
         (UPPER(TRIM(ACTIVITY_NAME)), UPPER(TRIM(SUB_ACTIVITY_NAME))) IN
                   (SELECT UPPER(TRIM(ACTIVITY_NAME)), UPPER(TRIM(SUB_ACTIVITY_NAME))
                      FROM SOP_FUNCTION_ACTIVITY_MAP
                     WHERE TRIM(FUNCTION_ACTIVITY_ID) IN (TRIM(v_function_activity_ids(i)))); --> Problem Here
    END LOOP;
    END;Now, when variable v_function_activity_ids(i) contains string 24,25,29 the above query does not give anything..i.e. it does not find the match and hence v_region_id(i) is returned as null.
    But when request contains function_activity_ids as single i.e. 25 it works and v_region_id(i) is returned correctly.
    Also, If I hardcode the value as under then it works :
      SELECT  max(decode(upper(trim(region_id)),NULL,'UR',upper(trim(region_id))))
            INTO v_region_id(i)
            FROM SOP_REGION_ACTIVITY_MAP
         WHERE
         (UPPER(TRIM(ACTIVITY_NAME)), UPPER(TRIM(SUB_ACTIVITY_NAME))) IN
                   (SELECT UPPER(TRIM(ACTIVITY_NAME)), UPPER(TRIM(SUB_ACTIVITY_NAME))
                      FROM SOP_FUNCTION_ACTIVITY_MAP
                     WHERE TRIM(FUNCTION_ACTIVITY_ID) IN (TRIM(24,25,29)));Can you pls help me with this..
    Thx..

    Looks like You totally misunderstand the IN() clause.
    In your scenario resulting query looks like
    ... in ( '24,25,29' ) - that's why You will never get result if two or more values comes from function.
    Two solutions:
    1) You can put values in the temporary table or table pl/sql and rewrite query appropriate way:
    ... in (select value from my_temp_table)
    ... in (select value from table(my_plsql_table))
    2) While using 10g, You can format regexp pattern instead of 'val1,val2,val3' and use
    ... regexp_like(FUNCTION_ACTIVITY_ID, PATTERN)
    regexp docs: http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/conditions007.htm#SQLRF00501

  • OBIEE 11.1.1.7 external database authentication fails with hashed passwords.

    Hi .
    I use an external database ( Oracle database 11g  release 11.2.0.1.0) to authenticate user with OBIEE 11.1.1.7.
    I configured  SQL Authentication provider as my provider ,It works OK with :enabled  Plaintext Passwords Enabled option and password  is stored as plain text.
    But It fails when I disable this option and want to authenticate with hashed passwords.It gives Authenticate Denied error.
    In Provider Specific tab there are some parameters which might need changes:
    1-Password Algorithm:??
    2-Password Style:??
    3-SQL Get Users Password:SELECT U_PASSWORD FROM USERS WHERE U_NAME = ?
    How can I find correct values for options 1 and 2 form my external database?
    And Is it need to rewrite query in option 3 ?
    Please find attach files.

    Hi,
    I too faced same issue when I was installing OBIEE 11.1.1.7.0 on windows7 64bit.
    Please refer the below links.
    http://satyaobieesolutions.blogspot.in/2013/05/configuration-action-creating-domain.html
    http://satyaobieesolutions.blogspot.in/2013/05/obiee-111170-simplesoftware-installation.html
    http://satyaobieesolutions.blogspot.in/2012/06/obiee-11.html
    Hope this help's
    Thanks,
    Satya

Maybe you are looking for

  • FCP and Mavericks

    Hi, I have recently upgraded to Mavericks and am now realising that FCP has slowed down considerably. I'm using a mac pro with 10GB RAM and haven't had problems with it before. Any idea on possible solutions? Anything I could do to boost my system a

  • Help!!! XFi-2 loses or hides my music

    I got this player a few months ago. My first music transfer was a complete disaster - most artist files were empty, albums disappeared. Not having time to sit down and figure out the problem, I made do with what i could access. I finally got round to

  • 16 Exobytes of RAM

    I recently bought a 2GB memory kit for a G4 15" 1.67GHz Aluminum Powerbook from Crucial. The kit came with two 1GB sticks of PC-5300 memory. My single 1GB stick of PC-4200 was working fine, but I just figured it would be fun to max out this old lapto

  • Make a Reference Quicktime Movie using QuickTime API for windows?

    Hi all, Does anyone know how to generate or modify a QuickTime Reference file? I try to generate a QuickTime reference file (.mov) that will point to external video clip Avid OpAtom such as \Avid MediaFIles\MXF\V1.mxf, \Avid MediaFIles\MXF\A1.mxf, \A

  • How can we use multiple transactions by using bdc_insert.

    HI How can we use multiple transactions by using bdc_insert.