Tuning query with inline views

Hi!
I have a performance problem with the following query. I try to combine v1 and v2 into one inline view but because of the recursive design of the tables workflow and workflow_node it didn't work.
Does anybody has an idea for tuning this query?
SELECT distinct v1.u_protocol_id
   FROM ( SELECT workflow_node.workflow_id,u_protocol.u_protocol_id
               FROM workflow_node,workflow,U_protocol
               WHERE workflow.workflow_id=workflow_node.workflow_id
                 AND u_protocol.u_protocol_id = workflow_node.parameter_2
              AND workflow_node.workflow_node_type_id=17
              AND workflow.workflow_node_type_id=42
         ) v1,
         ( SELECT workflow_node.workflow_id,test_template.test_template_id
           FROM workflow_node,test_template
           WHERE test_template.test_template_id = workflow_node.template
             AND workflow_node.order_number = 1
             AND workflow_node.workflow_node_type_id=42
         ) v2,
         ( SELECT aliquot.aliquot_id,test_template.test_template_id
           FROM aliquot,test,test_template
           WHERE aliquot.aliquot_id = test.aliquot_id
             AND test.test_template_id = test_template.test_template_id
         ) v3
   WHERE v1.workflow_id = v2.workflow_id
     AND v2.test_template_id= v3.test_template_id

I have found a script (utlxplan.sql) for creating the plan_table so here it is
SQL> @c:\utlxplan.sql;
Table created.
SQL> EXPLAIN PLAN FOR SELECT distinct v1.u_protocol_id
  2     FROM ( SELECT workflow_node.workflow_id,u_protocol.u_protocol_id
  3         FROM lims_sys.workflow_node,lims_sys.workflow,lims_sys.U_protocol
  4         WHERE workflow.workflow_id=workflow_node.workflow_id
  5           AND u_protocol.u_protocol_id = workflow_node.parameter_2
  6        AND workflow_node.workflow_node_type_id=17
  7        AND workflow.workflow_node_type_id=42
  8       ) v1,
  9       ( SELECT workflow_node.workflow_id,test_template.test_template_id
10         FROM lims_sys.aliquot,lims_sys.test,lims_sys.workflow_node,lims_sys.test_template
11         WHERE aliquot.aliquot_id = test.aliquot_id
12           AND test.test_template_id = test_template.test_template_id
13     AND test_template.test_template_id = workflow_node.template
14       ) v2
15     WHERE v1.workflow_id = v2.workflow_id
16  /
Explained.
SQL> SELECT * FROM TABLE(dbms_xplan.display);
PLAN_TABLE_OUTPUT
| Id  | Operation                           |  Name                           |
Rows  | Bytes | Cost  |
|   0 | SELECT STATEMENT                    |                                 |
PLAN_TABLE_OUTPUT
      |       |       |
|   1 |  SORT UNIQUE                        |                                 |
      |       |       |
|   2 |   FILTER                            |                                 |
      |       |       |
|   3 |    NESTED LOOPS                     |                                 |
      |       |       |
PLAN_TABLE_OUTPUT
|   4 |     NESTED LOOPS                    |                                 |
      |       |       |
|   5 |      NESTED LOOPS                   |                                 |
      |       |       |
|   6 |       NESTED LOOPS                  |                                 |
      |       |       |
|   7 |        NESTED LOOPS                 |                                 |
      |       |       |
PLAN_TABLE_OUTPUT
|   8 |         NESTED LOOPS                |                                 |
      |       |       |
|   9 |          TABLE ACCESS BY INDEX ROWID| WORKFLOW                        |
      |       |       |
|* 10 |           INDEX RANGE SCAN          | FK_WORKFLOW_WORKFLOW_NODE_TYPE  |
      |       |       |
|  11 |          TABLE ACCESS BY INDEX ROWID| WORKFLOW_NODE                   |
PLAN_TABLE_OUTPUT
      |       |       |
|  12 |           AND-EQUAL                 |                                 |
      |       |       |
|* 13 |            INDEX RANGE SCAN         | FK_WORKFLOW_NODE_WORKFLOW       |
      |       |       |
|* 14 |            INDEX RANGE SCAN         | FK_WORKFLOW_NODE_NODE_TYPE      |
      |       |       |
PLAN_TABLE_OUTPUT
|  15 |         TABLE ACCESS BY INDEX ROWID | U_PROTOCOL                      |
      |       |       |
|* 16 |          INDEX UNIQUE SCAN          | PK_U_PROTOCOL                   |
      |       |       |
|  17 |        TABLE ACCESS BY INDEX ROWID  | WORKFLOW_NODE                   |
      |       |       |
|* 18 |         INDEX RANGE SCAN            | FK_WORKFLOW_NODE_WORKFLOW       |
      |       |       |
PLAN_TABLE_OUTPUT
|  19 |       TABLE ACCESS BY INDEX ROWID   | TEST_TEMPLATE                   |
      |       |       |
|* 20 |        INDEX UNIQUE SCAN            | PK_TEST_TEMPLATE                |
      |       |       |
|  21 |      TABLE ACCESS BY INDEX ROWID    | TEST                            |
      |       |       |
|* 22 |       INDEX RANGE SCAN              | FK_TEST_TEST_TEMPLATE           |
PLAN_TABLE_OUTPUT
      |       |       |
|  23 |     TABLE ACCESS BY INDEX ROWID     | ALIQUOT                         |
      |       |       |
|* 24 |      INDEX UNIQUE SCAN              | PK_ALIQUOT                      |
      |       |       |
|  25 |    INDEX UNIQUE SCAN                | PK_OPERATOR_GROUP               |
      |       |       |
PLAN_TABLE_OUTPUT
|  26 |    INDEX UNIQUE SCAN                | PK_OPERATOR_GROUP               |
      |       |       |
|  27 |    INDEX UNIQUE SCAN                | PK_OPERATOR_GROUP               |
      |       |       |
|  28 |    INDEX UNIQUE SCAN                | PK_OPERATOR_GROUP               |
      |       |       |
|  29 |    INDEX UNIQUE SCAN                | PK_OPERATOR_GROUP               |
      |       |       |
PLAN_TABLE_OUTPUT
Predicate Information (identified by operation id):
  10 - access("SYS_ALIAS_5"."WORKFLOW_NODE_TYPE_ID"=42)
  13 - access("SYS_ALIAS_5"."WORKFLOW_ID"="WORKFLOW_NODE"."WORKFLOW_ID")
  14 - access("WORKFLOW_NODE"."WORKFLOW_NODE_TYPE_ID"=17)
PLAN_TABLE_OUTPUT
  16 - access("SYS_ALIAS_4"."U_PROTOCOL_ID"=TO_NUMBER("WORKFLOW_NODE"."PARAMETER
_2"))
  18 - access("WORKFLOW_NODE"."WORKFLOW_ID"="WORKFLOW_NODE"."WORKFLOW_ID")
  20 - access("SYS_ALIAS_1"."TEST_TEMPLATE_ID"="WORKFLOW_NODE"."TEMPLATE")
  22 - access("SYS_ALIAS_2"."TEST_TEMPLATE_ID"="SYS_ALIAS_1"."TEST_TEMPLATE_ID")
  24 - access("SYS_ALIAS_3"."ALIQUOT_ID"="SYS_ALIAS_2"."ALIQUOT_ID")
Note: rule based optimization

Similar Messages

  • Need help with SQL Query with Inline View + Group by

    Hello Gurus,
    I would really appreciate your time and effort regarding this query. I have the following data set.
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
    1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
    Please Ignore '----', added it for clarity
    I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
    The query should return the following data set
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
    The following is my query. I am kind of lost.
    select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
    from (
    select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
    from INVOICE
    group by sequence_id,check_date, check_number, invoice_number, vendor_number
    ) A, INVOICE B
    where A.sequence_id = B.sequence_id
    Thanks,
    Nick

    It looks like it is a duplicate thread - correct me if i'm wrong in this case ->
    Need help with SQL Query with Inline View + Group by
    Regards.
    Satyaki De.

  • Issue with Inline View Criteria

    Hi,
    I have a VO created on two tables that are joined by a 1:1 association(say Opportunity and Revenue). The query is specified in Expert mode because I need some aggregations performed using analytic functions. Data security predicates are applied on top of this query using a dummy View Criteria. My requirement now is that I need to filter these results using another VC. The issue is that both the tables have attributes with the same name(say Cust ID) and I need to filter based on this using an inline View Criteria. I have done the same declaratively. However, I get an error on hitting the page saying the columns have been ambiguously defined.
    On digging through the log, I discovered the test Query fails to prefix the alias before the attribute. So what I get is something similar to this
    select (o.id, r.amt, sum(), count(), avg(), o.custId) from opty o, revn r where (o.id in DATA SECURITY PREDICATE) and (custId = :bindCustId)
    Is there a way to ensure that the custId can be changed to o.custId???
    Note - The View Criteria was created on an attribute from opty table that was exposed i.e in this case, o.custId. Although the query builder shows it correctly while creating the VC declaratively, the issue persists as seen from the logs.
    Thanks,
    Manoj

    Hi experts...
    Any pointers to this issue???
    Please help!
    Regards,
    Debolina

  • Preparing query through Inline View

    Pls. help to prepare a query by i may extract the following data through inline view (i.e; other than using UNION):
    1. SALESMAN who are working in deptno # 30
    2. MANAGER who are working in deptno # 20
    In department # 30 both SALESMAN and MANAGER are working likewise in department # 20 both SALESMAN and MANAGER are working.
    I want to fetch only MANAGER from department # 20 and only SALESMAN from department 30.
    I can fetch the above sought data through "UNION" but i know whether the above data can be fetched other than "UNION" like using INLINE VIEW.
    INSERT INTO EMP
    VALUES
    (7369,'SMITH','CLERK',7902,'WEDNESDAY, DECEMBER 17, 1980',800,NULL,20)
    INSERT INTO EMP
    VALUES
    (7499,'ALLEN','SALESMAN',7698,'FRIDAY, FEBRUARY 20, 1981',1600,300,30)
    INSERT INTO EMP
    VALUES
    (7521,'WARD','SALESMAN',7698,'SUNDAY, FEBRUARY 22, 1981',1250,500,30)
    INSERT INTO EMP
    VALUES
    (7566,'JONES','MANAGER',7839,'THURSDAY, APRIL 02, 1981',2975,NULL,20)
    INSERT INTO EMP
    VALUES
    (7654,'MARTIN','SALESMAN',7698,'MONDAY, SEPTEMBER 28, 1981',1250,1400,30)
    INSERT INTO EMP
    VALUES
    (7698,'BLAKE','MANAGER',7839,'FRIDAY, MAY 01, 1981',2850,NULL,30)
    INSERT INTO EMP
    VALUES
    (7782,'CLARK','MANAGER',7839,'TUESDAY, JUNE 09, 1981',2450,NULL,10)
    INSERT INTO EMP
    VALUES
    (7788,'SCOTT','ANALYST',7566,'SUNDAY, APRIL 19, 1987',3000,NULL,20)
    INSERT INTO EMP
    VALUES
    (7839,'KING','PRESIDENT',NULL,'TUESDAY, NOVEMBER 17, 1981',5000,NULL,10)
    INSERT INTO EMP
    VALUES
    (7844,'TURNER','SALESMAN',7698,'TUESDAY, SEPTEMBER 08, 1981',1500,0,30)
    INSERT INTO EMP
    VALUES
    (7876,'ADAMS','CLERK',7788,'SATURDAY, MAY 23, 1987',1100,NULL,20)
    INSERT INTO EMP
    VALUES
    (7900,'JAMES','CLERK',7698,'THURSDAY, DECEMBER 03, 1981',950,NULL,30)
    INSERT INTO EMP
    VALUES
    (7902,'FORD','ANALYST',7566,'THURSDAY, DECEMBER 03, 1981',3000,NULL,20)
    INSERT INTO EMP
    VALUES
    (7934,'MILLER','CLERK',7782,'SATURDAY, JANUARY 23, 1982',1300,NULL,10)
    INSERT INTO EMP
    VALUES
    (100,'SALAM','SALESMAN',7698,'FRIDAY, FEBRUARY 20, 1981',1600,300,20)
    INSERT INTO EMP
    VALUES
    (101,'KARIN','SALESMAN',7698,'SATURDAY, FEBRUARY 21, 1981',1250,500,20)
    INSERT INTO EMP
    VALUES
    (102,'RAFIQ','SALESMAN',7698,'SATURDAY, FEBRUARY 20, 1988',1250,1400,20)
    INSERT INTO EMP
    VALUES
    (103,'JABBAR','SALESMAN',7698,'WEDNESDAY, FEBRUARY 20, 1980',1500,0,20)
    INSERT INTO EMP
    VALUES
    (500,'RAHIM','MANAGER',7839,'THURSDAY, DECEMBER 16, 1971',2975,NULL,20)
    /thanks.
    Sharif
    Edited by: user13094274 on May 8, 2010 6:49 AM

    CREATE TABLE emp
        (empno                          NUMBER(4,0) NOT NULL,
        ename                          VARCHAR2(10),
        job                            VARCHAR2(9),
        mgr                            NUMBER(4,0),
        hiredate                       DATE,
        sal                            NUMBER(7,2),
        comm                           NUMBER(7,2),
        deptno                         NUMBER(2,0))

  • Try this one again, outer join with inline views

    Posted this before and got no response from anyone. Can anyone advise ?
    does anyone have an example of inline views combined with outer joins in the same statement ? - am currently converting app from sqlserver to oracle and sqlserver view has many left outer joins in from the same table as well as part of the outer join conditions being a subquery e.g.
    select ...
    from a left outer join b left outer join c
    on a.col = b.col and
    c.col = a.col and
    a.othercol = ((select ..
    from d
    where ...)
    OR (select ...
    from e
    where ...))
    where ....
    sometimes they are just mutliple part left outer joins but as many as 10. I guess I have to convert these to inline views then outer join to that, but not 100% sure. There may be a better way ?
    null

    select ...
    from a,b,(select ...) dummyTable
    where a.col = b.col(+)
    AND a.col = dummyTable (+)
    AND b.col = c.col(+)
    AND ....

  • Help with inline view query

    Hi
    I have written a query that is supposed to return the following result.
    LOCATION                  YOUNGEST                    ELDEST
    york                       Name                        Name
    Luton                      Name                        NameI am having trouble with the INNER JOIN of the outer query. I cannot seem to match up both the YOUNGEST and ELDEST COLUMNS, only one of them. Does anyone know how I match it up to produce the appropriate result
    SELECT
         res.ldes,
         a.first_name||' '||a.last_name YOUNGEST,
         a.first_name||' '||a.last_name ELDEST
    FROM
      SELECT
            l.description ldes,
            MAX(a.birth_date) maxbd,
            MIN(a.birth_date) minbd
      FROM
            locations l
      INNER JOIN
            agents a
      ON
            l.location_id=a.location_id
      GROUP BY
            l.description
    ) res
    INNER JOIN
            agents a
    ON
            a.birth_date = res.maxbd  --PROBLEM IS HERE need to match up a.birth_date with res.minbd also but cannot get it
    ORDER BY
            res.ldesThanks for any response

    metzquar gave your answer.
    try
    with locations as(select 10 location_id,'ABC' description from dual union all
    select 20,'XYZ' from dual union all
    select 30,'RPF' from dual),
    agents as(select 10 location_id,'IM' first_name,'ELDEST' last_name,to_date('08/08/1988','mm/dd/yyyy') birth_date from dual union all
    select 20,'IM','ELDEST', to_date('08/08/1988','mm/dd/yyyy') from dual union all
    select 30,'IM','ELDEST', to_date('08/08/1988','mm/dd/yyyy') from dual union all
    select 10,'IM','MIDAGE', to_date('07/07/1977','mm/dd/yyyy') from dual union all
    select 20,'IM','MIDAGE', to_date('07/07/1977','mm/dd/yyyy') from dual union all
    select 30,'IM','MIDAGE', to_date('07/07/1977','mm/dd/yyyy') from dual union all
    select 10,'IM','YOUNGEST', to_date('06/06/1966','mm/dd/yyyy') from dual union all
    select 20,'IM','YOUNGEST', to_date('06/06/1966','mm/dd/yyyy') from dual union all
    select 30,'IM','YOUNGEST', to_date('06/06/1966','mm/dd/yyyy') from dual)
    SELECT   l.description ldes,
             MIN(a.first_name || ' ' || a.last_name)KEEP (DENSE_RANK FIRST ORDER BY a.birth_date) AS youngest,
             MIN(a.first_name || ' ' || a.last_name)KEEP (DENSE_RANK LAST ORDER BY a.birth_date) AS eldest
        FROM locations l INNER JOIN agents a ON l.location_id = a.location_id
    GROUP BY l.description
    ORDER BY 1;
    O/P:-
    LDES     YOUNGEST      ELDEST
    ABC     IM YOUNGEST     IM ELDEST
    RPF     IM YOUNGEST     IM ELDEST
    XYZ     IM YOUNGEST     IM ELDEST

  • Tuning query with sdo_join in it

    Hello all. I'm new to the forum, but I hope someone can help me tuning a spatial query. I have no DBA experience or education, but I'm writing SQL queries for a few years now, first in Oracle 9i (with Locator), now in Oracle 10g (10.2) and Oracle XE.
    I’ve posted this in the Spatial forum as I suspect it’s mostly a spatial issue.
    I have a table like:
    CREATE TABLE CYCLORAMA (
      DATASETID   VARCHAR2(9 BYTE),
      IMAGEID     VARCHAR2(9 BYTE),
      OPNAMEDATUM CHAR(20 BYTE),
      GEOMETRIE   MDSYS.SDO_GEOMETRY
    )with only a standard spatial index on GEOMETRIE, and containing about 180000 records. IMAGEID is unique, but not defined as such. Geometry is SDO_POINT_TYPE for all records, like: MDSYS.SDO_GEOMETRY(2001,90112,MDSYS.SDO_POINT_TYPE(86039.572,439541.158,'null'),'null','null'). USER_SDO_GEOM_METADATA is filled with values used for all my geometries: SDO_DIM_ARRAY(SDO_DIM_ELEMENT('X',0,300000,,001), SDO_DIM_ELEMENT('Y',300000,600000,,001)) and SRID = 90112.
    What I need to do is to find (and ultimately delete) all records that have another record with a different value for DATASETID, a higher value for OPNAMEDATUM and fall within 3 meters distance. What I came up with so far is:
    select /*+ all_rows */ s.imageid
    , sdo_geom.sdo_distance(s.geometrie,t.geometrie,0.1) dist
    from cyclorama s, cyclorama t
    , table(sdo_join('CYCLORAMA','GEOMETRIE','CYCLORAMA','GEOMETRIE','distance=3')) x
    -- create a crosstable with records that may be within 3 meters distance
    where s.rowid = x.rowid1 and x.rowid2 = t.rowid and not x.rowid1 = x.rowid2
    -- filter 'duplicate matches' sdo_join generates for a self join, and select:
    and s.datasetid != t.datasetid                             -- if in different dataset
    and s.opnamedatum < t.opnamedatum                          -- from a later date
    and sdo_geom.sdo_distance(s.geometrie,t.geometrie,0.1) < 3 -- within 3 meters
    ;This is surprisingly fast (7 seconds for first 50 records), but still takes about 7 minutes (Oracle XE on a 768MB, 2.7GHz VM) for the whole query. This is acceptable, but:
    * Is this solution the best approach?
    * Can this be done faster or more efficient? Clever indexes, hints, smarter query, ...?
    * Is it worth optimizing the SDO_DIM_ARRAY for this table, e.g. narrowing the range of coordinate values)?
    * How to delete the found records most efficiently?
    * Can this be done using an anti-join, to select the records to keep?
    Thank you for reading this, and any answers you may have,
    J-----.
    Jeroen Muris

    Jack,
    Thank you for your response. It helped me to clean up the query. All the changes did not give a much better explain plan - at least not to my inexperienced eyes - but the total execution time for the query is now reduced to under two minutes. The query as it is now:
    select /*+ ordered all_rows */ x.rowid1
    from table(sdo_join('CYCLORAMA','GEOMETRIE','CYCLORAMA','GEOMETRIE','distance=3 mask=ANYINTERACT')) x
    , cyclorama s, cyclorama t
    where not x.rowid1 = x.rowid2
    and s.rowid = x.rowid1 and x.rowid2 = t.rowid
    and s.datasetid != t.datasetid
    and s.opnamedatum < t.opnamedatum;Because the docs state that mask=FILTER is the default, I added an explicit mask=ANYINTERACT to the sdo_join parameters when I removed the sdo_distance from the query. Still, the query returns 205035 records with the sdo_distance, and 205125 without. But this may be the result of the extra 0.001 from sdo_dim. I did not investigate as the 3 meter is not crucial.
    I believe I already had a mechanism in place to reduce the number of self-joins with "not x.rowid1 = x.rowid2" and "s.opnamedatum < t.opnamedatum". I can not guarantee that for all records s.opnamedatum < t.opnamedatum equals x.rowid1 < x.rowid2.
    Based on the [url http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14255/sdo_operat.htm#BGEDJIBF]docs, I finally added an 'ordered' hint and reshuffled the tables in the from clause.
    I'm happy with performance now, and creating a new table with the records to keep should not be a problem. Still I'm curious about the following:
    <li>Is it worth optimizing the SDO_DIM_ARRAY for the original table, e.g. narrowing the range of coordinate values?
    <li>How can sdo_join best be used for an anti-join, to select the records to keep?
    Thank you,
    J-----.

  • Oracle query tuning : query with Order-by clause

    Hi
    I am having a query in my database :
    SELECT * FROM SAPR3.HRP1001 WHERE "MANDT" = 990
    ORDER BY
    "MANDT" , "OTYPE" , "OBJID" , "PLVAR" , "RSIGN" , "RELAT" , "ISTAT" , "PRIOX" , "BEGDA" , "ENDDA" ,"VARYF" , "SEQNR" ;
    Autotrace output is :
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=4649 Card=171895 Byt
    es=22862035)
    1 0 SORT (ORDER BY) (Cost=4649 Card=171895 Bytes=22862035)
    2 1 TABLE ACCESS (FULL) OF 'HRP1001' (Cost=1170 Card=171895
    Bytes=22862035)
    Statistics
    0 recursive calls
    5 db block gets
    12157 consistent gets
    11543 physical reads
    0 redo size
    38253080 bytes sent via SQL*Net to client
    376841 bytes received via SQL*Net from client
    34201 SQL*Net roundtrips to/from client
    0 sorts (memory)
    1 sorts (disk)
    512992 rows processed
    Since it is a issue with order by , it seems a PGA memory issue. there is 12GB PGA available but only 3GB gets allocated. pga_aggregate target is set in the DB. There is a index created for al the columns on order by, but it is not getting used.
    pleas suggest me as I am running into major problems, i can post the output of any query u require from my side. Any help wil be highly apprciated.
    Rishi

    > The query was alwasy spilling over to the One-Parse execution . It can be seen thru ST04N ->resource consumption-> sql work area trace.
    >
    > An undocumented oracle parameter smmmax_size was set which allowed for more usage of physical memory by single process and there was no spillover to the TEMP tablespaces.
    >
    > Also the File read time was analysed from Unix level ( From SAP thru ST04 ->filesystem wait s-> Avg rd (ms) and Ang writes (ms) which showed that reading from the File was not happening well. )
    Hi Rishi,
    the provided execution statistics prove the opposite:
    >Statistics
    >...
    >0 sorts (memory)
    > 1 sorts (disk)
    >512992 rows processed
    This indeed was a single-pass sort, which means it had to use the temp tablespace for one pass of the sorting/grouping.
    Remember that Oracle distinguishes three kinds of sorts: 1. "in memory", 2. "single-pass" and 3. "multi-pass".
    Only the first one won't need to spill out data to the disks. The others do this by definition.
    BTW: the file read times in ST04 are aquired through Oracle V$ views and not directly from the OS - that can make a big difference sometimes.
    regards,
    Lars

  • Tuning query with index

    hello,
    i am trying to avoid full table scan in a query by creating reverse index on the name column in the where clause. but the optimizer still runs full table scan. What can I do?
    Regards,
    Purvi

    Hi,
    Reverse key indexes reverse the bytes of each indexed column with the exception of rowid.
    I am not sure what you mean when you say the reverse index is supposed to index the names in reverse. When you use the reverse key index lexically adjacent keys are not stored next to each other.
    Maybe, reverse index is not right in your situation.

  • Tuning Query with IN-Operator

    Hi all,
    I have to tune the statement below.
    UPDATE TABLE_A A
    SET A.FIELD1 =
    (SELECT B.FIELD1 FROM TABLE_B B WHERE B.IDENTNO IN (A.IDENTNO, A.IDENTNO||'000')
    There are indexes on identno on TABLE_A and TABLE_A
    The subquery returns only one row. The query works, but not fast enough.
    I tried to split the where condition to join it together again with a union like this
    UPDATE TABLE_A A
    SET A.FIELD1 =
    (SELECT B.FIELD1 FROM TABLE_B B WHERE B.IDENTNO = A.IDENTNO
    UNION
    SELECT B.FIELD1 FROM TABLE_B B WHERE B.IDENTNO = A.IDENTNO||'000')
    But the execution plan shows a full table scan for the second part of the union.
    How can I tune this part ? With function based index ?
    Thanks in advance.
    Henning

    Please see this thread
    When your query takes too long ...
    You need to make sure if your statistics are up to date. If not analyze the table.
    It works for me,
    SQL*Plus: Release 9.2.0.6.0 - Production on Tue May 31 17:10:38 2011
    Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
    With the Partitioning, Oracle Label Security, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.8.0 - Production
    SQL> CREATE TABLE TABLE_A AS SELECT 1 field1,'1000' IDENTNO FROM dual;
    Table created.
    SQL> CREATE TABLE TABLE_B AS SELECT 1 field1,'1000000' IDENTNO FROM dual;
    Table created.
    SQL> CREATE INDEX idx13 ON table_B(IDENTNO);
    Index created.
    SQL> CREATE INDEX idx12 ON table_A(IDENTNO);
    Index created.
    SQL> set autotrace on
    SQL> UPDATE TABLE_A A
      2     SET A.FIELD1 =
      3            (SELECT B.FIELD1
      4               FROM TABLE_B B
      5              WHERE B.IDENTNO IN (A.IDENTNO, A.IDENTNO || '000'));
    1 row updated.
    Execution Plan
       0      UPDATE STATEMENT Optimizer=CHOOSE
       1    0   UPDATE OF 'TABLE_A'
       2    1     TABLE ACCESS (FULL) OF 'TABLE_A'
       3    1     CONCATENATION
       4    3       TABLE ACCESS (BY INDEX ROWID) OF 'TABLE_B'
       5    4         INDEX (RANGE SCAN) OF 'IDX13' (NON-UNIQUE)
       6    3       TABLE ACCESS (BY INDEX ROWID) OF 'TABLE_B'
       7    6         INDEX (RANGE SCAN) OF 'IDX13' (NON-UNIQUE)
    Statistics
              2  recursive calls
              2  db block gets
              8  consistent gets
              0  physical reads
            424  redo size
            353  bytes sent via SQL*Net to client
            432  bytes received via SQL*Net from client
              3  SQL*Net roundtrips to/from client
              2  sorts (memory)
              0  sorts (disk)
              1  rows processed
    SQL>

  • UPDATE with inline view - ORA-01779:cannot modify a column which maps to a

    Hello....
    With the following SQL, I get the ORA-01779 mentioned in the Subject Line:
    update
    (select a.old_c1
    ,a.old_c2
    ,a.old_c3
    ,b.old_c1
    ,b.old_c2
    ,b.old_c3
    from table1 a, table2 b
    where a.id = b.id)
    set a.old_c1 = b.old_c1
    ,a.old_c2 = b.old_c2
    ,a.old_c3 = b.old_c3;
    Any help or explanation would be helpful. Thank you.

    This does not work either.Works for me:
    SQL> select * from table1;
                      ID O O O
                     101 a b c
                     102 d e f
    SQL> select * from table2;
                      ID O O O
                     101 x y z
                     103 g h i
    SQL> update table1 a
      2  set   (a.old_c1
      3        ,a.old_c2
      4        ,a.old_c3
      5        ) = (select b.old_c1
      6                   ,b.old_c2
      7                   ,b.old_c3
      8             from   table2 b
      9             where  b.id = a.id
    10            )
    11  where exists
    12            (select 1
    13             from   table2 b
    14             where  b.id = a.id
    15            );
    1 row updated.
    SQL> select * from table1;
                      ID O O O
                     101 x y z
                     102 d e fNeed a little more to go on than "doesn't work".
    Are you still getting duplicates in the subquery?

  • Query works everywhere but Flex: inline views not supported perhaps?

    EDIT2: Actually not. It turns out to be a bug in the way Adobe is treating any integer PK column, no matter how it is defined, INT, or INTEGER, as an alias for the rowid in SQlite.  This is incorrect. rowid does not always equal the PK value.  This causes joins to return the wrong values.
    EDIT: turns out to be the use of the absolute value function in the query.
    See http://forums.adobe.com/thread/516392
    My bread-and-butter query, the one that is the core of my application, uses a UNION query with inline views when doing proximity word-searches. It works beautifully in SQLite returning a resultset  in about one second from an over 300MB database, against several tables equijoined, the two biggest tables having close to 4 million rows and 300,000 rows, respectively.
    It runs fine in Visual Studio using the .NET provider for SQLite, and also in SQLite Manager 0.5.6 by Mrinal Kant and in other front-ends to SQLite. But the verbatim query returns no rows in Flex and zero rows in the SQLite Admin GUI front-end, which is built on the Flex SQL libraries.
    My first thought is that inline views might not be supported in Flex? 
    Does Flex do what in the Microsoft world is called a "pass-through" query, sending the sql intact through to the back end, or does Flex take the query statement apart and apply the WHERE clause conditions client-side, as Microsoft Access does to support so-called "heterogeneous" joins, i.e. queries that might join tables from, say, SQL Server and Oracle in the same query?

    EDIT2: Actually not. It turns out to be a bug in the way Adobe is treating any integer PK column, no matter how it is defined, INT, or INTEGER, as an alias for the rowid in SQlite.  This is incorrect. rowid does not always equal the PK value.  This causes joins to return the wrong values.
    EDIT: turns out to be the use of the absolute value function in the query.
    See http://forums.adobe.com/thread/516392
    My bread-and-butter query, the one that is the core of my application, uses a UNION query with inline views when doing proximity word-searches. It works beautifully in SQLite returning a resultset  in about one second from an over 300MB database, against several tables equijoined, the two biggest tables having close to 4 million rows and 300,000 rows, respectively.
    It runs fine in Visual Studio using the .NET provider for SQLite, and also in SQLite Manager 0.5.6 by Mrinal Kant and in other front-ends to SQLite. But the verbatim query returns no rows in Flex and zero rows in the SQLite Admin GUI front-end, which is built on the Flex SQL libraries.
    My first thought is that inline views might not be supported in Flex? 
    Does Flex do what in the Microsoft world is called a "pass-through" query, sending the sql intact through to the back end, or does Flex take the query statement apart and apply the WHERE clause conditions client-side, as Microsoft Access does to support so-called "heterogeneous" joins, i.e. queries that might join tables from, say, SQL Server and Oracle in the same query?

  • Difference between INLINE view and WITH clause

    Can anyone plz explain me about the performance difference between the below queries?
    Query using INLINE view:
    SELECT e.ename AS employee_name,
    dc.dept_count AS emp_dept_count
    FROM emp e,
    (SELECT deptno, COUNT(*) AS dept_count
    FROM emp
    GROUP BY deptno) dc
    WHERE e.deptno = dc.deptno;
    Query using WITH clause:
    WITH dept_count AS (
    SELECT deptno, COUNT(*) AS dept_count
    FROM emp
    GROUP BY deptno)
    SELECT e.ename AS employee_name,
    dc.dept_count AS emp_dept_count
    FROM emp e,
    dept_count dc
    WHERE e.deptno = dc.deptno;

    Here's another one:
    http://www.oracle-base.com/articles/misc/WithClause.php
    And, here on this forum you will see that the WITH-clause is heavily used by all of us in order to generate some sample data (when OP's don't care to post CREATE TABLE + INSERT INTO statements).
    The WITH clause enables you as well to 'pretend' you have a table and demonstrate a solution very quickly, without doing actual DDL .
    As for the performance difference:
    We would need to know your database version and many other things.
    See:
    HOW TO: Post a SQL statement tuning request - template posting
    for step by step instructions you can (and should) explore yourself.

  • Inline views / view merge slowing the query

    I have a tool generated query. This query uses inline views. The individual view return data under a second but final query is taking 10min +. any suggestion.
    I tried /*+ NO_MERGE(D1,D2,D3,D4)*/ but to no help.
    TIA.
    SELECT /*+ NO_MERGE(D1,D2,D3,D4)*/DISTINCT d4.c5 AS c1, d2.c14 AS c2,
    d3.c8 AS c3, d2.c8 AS c4,
    d2.c9 AS c5, d2.c10 AS c6,
    d2.c11 AS c7, d2.c12 AS c8,
    d2.c13 AS c9
    FROM (vv_d1) d1,
    (vv_d2) d2,
    (vv_d3) d3,
    (vv_d4) d4
    WHERE ( NVL (d1.c1, 'q') =
    NVL (d2.c14, 'q')
    AND NVL (d1.c1, 'z') =
    NVL (d2.c14, 'z')
    AND NVL (d1.c3, 'q') =
    NVL (d2.c12, 'q')
    AND NVL (d1.c3, 'z') =
    NVL (d2.c12, 'z')
    AND NVL (d1.c6, 'q') =
    NVL (d2.c9, 'q')
    AND NVL (d1.c6, 'z') =
    NVL (d2.c9, 'z')
    AND NVL (d1.c4, 'q') =
    NVL (d2.c10, 'q')
    AND NVL (d1.c4, 'z') =
    NVL (d2.c10, 'z')
    AND NVL (d1.c5, 8) =
    NVL (d2.c13, 8)
    AND NVL (d1.c5, 9) =
    NVL (d2.c13, 9)
    AND NVL (d1.c1, 'q') =
    NVL (d4.c6, 'q')
    AND NVL (d1.c1, 'z') =
    NVL (d4.c6, 'z')
    AND NVL (d1.c1, 'q') =
    NVL (d3.c11, 'q')
    AND NVL (d1.c1, 'z') =
    NVL (d3.c11, 'z')
    AND NVL (d1.c2, 88.0) =
    NVL (d3.c9, 88.0)
    AND NVL (d1.c2, 99.0) =
    NVL (d3.c9, 99.0)
    AND NVL (d1.c3, 'q') =
    NVL (d3.c10, 'q')
    AND NVL (d1.c3, 'z') =
    NVL (d3.c10, 'z')
    AND NVL (d1.c7, 'q') =
    NVL (d2.c11, 'q')
    AND NVL (d1.c7, 'z') =
    NVL (d2.c11, 'z')
    )

    And the Oracle version number, to three decimal places is?
    Post EXPLAIN PLAN output created using dbms_xplan
    http://www.psoug.org/reference/explain_plan.html

  • Oracle BUG (CASE + remote tables + inline view)

    Oracle 9.2.0.8
    BUG: Oracle inserts NULL when we use CASE statement in the SELECT query and we join a remote table with inline view.
    Script:
    CREATE TABLE t1 (a number(19,4)OK.
    SELECT (case when b = 1 then c else d end)
    FROM t2@Remote LEFT JOIN
    (SELECT a FROM t3@Remote) q ON (t2.a = q.a)123
    456
    789
    3 rows selected.
    INSERT INTO TABLE t1 (a)
    SELECT (case when b = 1 then c else d end)
    FROM t2@Remote LEFT JOIN
    (SELECT a FROM t3@Remote) q ON (t2.a = q.a)3 rows inserted.
    SELECT * FROM t1<null>
    <null>
    <null>
    3 rows selected
    Oracle inserts the correct values if I:
    * replace the CASE with DECODE
    * join with table not with an inline view
    * join local tables
    Someone with registration in the Metalink can post the bug.
    Best regards, Beroetz

    Oracle 9.2.0.8
    BUG: Oracle inserts NULL when we use CASE statement in the SELECT query and we join a remote table with inline view.
    Script:
    CREATE TABLE t1 (a number(19,4)OK.
    SELECT (case when b = 1 then c else d end)
    FROM t2@Remote LEFT JOIN
    (SELECT a FROM t3@Remote) q ON (t2.a = q.a)123
    456
    789
    3 rows selected.
    INSERT INTO TABLE t1 (a)
    SELECT (case when b = 1 then c else d end)
    FROM t2@Remote LEFT JOIN
    (SELECT a FROM t3@Remote) q ON (t2.a = q.a)3 rows inserted.
    SELECT * FROM t1<null>
    <null>
    <null>
    3 rows selected
    Oracle inserts the correct values if I:
    * replace the CASE with DECODE
    * join with table not with an inline view
    * join local tables
    Someone with registration in the Metalink can post the bug.
    Best regards, Beroetz

Maybe you are looking for