Calling explain plan in ST05

Does anyone know how to?
I am trying to find out if these two tables are hitting the primary or secondary indexes.
/BIC/AZBDITM00
/BI0/ASD_O0600
Any help would be appreciated.

Hi Shawn
Another good possibility apart from an SQL trace is to look for already executed statements in the oracle cursor cache.
ST04 -> Detail analysis menu -> SQL request
Then enter a SQL pattern, e.g. /BIC/AZBDITM00. Now you get all actual statements on this table, you can see the plans by clicking on the statement and then the tool like button. As a bonus you can also jump to the corresponding ABAP coding (will probably not give much in a BI / APO because of the dynamic generated code). You can also see the buffer gets and more there.
Regards
Michael

Similar Messages

  • Passing PL/SQL Procedure call to custom explain plan script

    Hi,
    Oracle have sent me a custom explain plan script and have asked me to pass in my problematic code through it. They use the GET command in their script to retrieve the command which is passed in as a parameter e.g:
    @custom_explain_plan <my sql script>
    The script has a section as follows:
    get &&1 -- my script
    0 explain plan set statement_id = 'APG' into plan_table for
    This works for a standard SQL statement e.g. SELECT SYSDATE FROM DUAL but (and Oracle Support know this) my issue is triggered by a call to an e-Business Suite API that updates the database. This is contained within a PL/SQL block and COMMITs a few sample updates. I've not used explain plan before but I suspect it can only be used on SQL statements? I have no access to the DELETEs and INSERTs that the API triggers, so what am I supposed to do?
    Am I missing something or have Oracel Support sold me a pup?
    I thought I'd post here first before going back to them...
    Many thanks,
    Bagpuss

    Sybrand,
    Many thanks for the swift confirmation. I didn't think I was going mad! Already gave them a standard trace so I guess it's up to them now - my experience with Oracle Support in the last few years has been very deflating - they evidently do not read/understand much of the information they are given in an SR. Added to that, we've had patches from them with basic syntax errors! I've consistently received much more informed responses from the various OTN forums, which are much appreciated.
    I may construct the DELETE and INSERT statements dynamically myself using a typical employee record to at least give them something to ponder over...
    Thanks again,
    Bagpuss.

  • Problems with explain plan and statement

    Hi community,
    I have migrated a j2ee application from DB2 to Oracle.
    First some facts of our application and database instance:
    We are using oracle version 10.2.0.3 and driver version 10.2.0.3. It runs with charset Unicode 3.0 UTF-8.
    Our application is using Tomcat as web container and jboss as application server. We are only using prepared statements. So if I talk about statements I always mean prepared statements. Also our application is setting the defaultNChar property to true because every char and varchar field has been created as an nchar and nvarchar.
    We have some jsp sites that contains lists with search forms. Everytime I enter a value to the form that returns a filled resultset, the lists are performing great. But everytime I enter a value that returns an empty resultset, the lists are 100 times slower. The jsp sites are running in the tomcat environment and submitting their statements directly to the database. The connections are pooled by dbcp. So what can cause this behaviour??
    To anaylze this problem I started logging all statements and filled-in search field values and combinations that are executed by the lists described above. I also developed a standalone helper tool that reads the logged statements, executes them to the database and generates an explain plan for every statement. But now there appears a strange situation. Every statement, that performs really fast within our application, is now executed by the helper tool extremely slow. So I edited some jsp pages within our application to force an explain plan from there (tomcat env). So when I'm executing the same statement I'm getting with the exactly same code two completely different explain plans.
    First the statement itself:
    select LINVIN.BBASE , INVINNUM , INVINNUMALT , LINVIN.LSUPPLIERNUM , LSUPPLIERNUMEXT , LINVIN.COMPANYCODE , ACCOUNT , INVINTXT , INVINSTS , INVINTYP , INVINDAT , RECEIPTDAT , POSTED , POSTINGDATE , CHECKCOSTCENTER , WORKFLOWIDEXT , INVINREFERENCE , RESPONSIBLEPERS , INVINSUM_V , INVINSUMGROSS_V , VOUCHERNUM , HASPOSITIONS , PROCESSINSTANCEID , FCURISO_V , LSUPPLIER.AADDRLINE1 from LINVIN, LSUPPLIER where LINVIN.BBASE = LSUPPLIER.BBASE and LINVIN.LSUPPLIERNUM = LSUPPLIER.LSUPPLIERNUM and LINVIN.BBASE = ? order by LINVIN.BBASE, INVINDAT DESC
    Now the explain plan from our application:
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 101 | 28583 | 55 (0)| 00:00:01 |
    | 1 | NESTED LOOPS | | 101 | 28583 | 55 (0)| 00:00:01 |
    | 2 | TABLE ACCESS BY INDEX ROWID| LINVIN | 93709 | 12M| 25 (0)| 00:00:01 |
    |* 3 | INDEX RANGE SCAN | LINV_INVDAT | 101 | | 1 (0)| 00:00:01 |
    | 4 | TABLE ACCESS BY INDEX ROWID| LSUPPLIER | 1 | 148 | 1 (0)| 00:00:01 |
    |* 5 | INDEX UNIQUE SCAN | PK_177597 | 1 | | 1 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    3 - access("LINVIN"."BBASE"=:1)
    filter("LINVIN"."BBASE"=:1)
    5 - access("LSUPPLIER"."BBASE"=:1 AND "LINVIN"."LSUPPLIERNUM"="LSUPPLIER"."LSUPPLIERNUM")
    Now the one from the standalone tool:
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 93773 | 25M| | 12898 (1)| 00:02:35 |
    | 1 | SORT ORDER BY | | 93773 | 25M| 61M| 12898 (1)| 00:02:35 |
    |* 2 | HASH JOIN | | 93773 | 25M| 2592K| 7185 (1)| 00:01:27 |
    | 3 | TABLE ACCESS BY INDEX ROWID| LSUPPLIER | 16540 | 2390K| | 332 (0)| 00:00:04 |
    |* 4 | INDEX RANGE SCAN | LSUPPLIER_HAS_BASE_FK | 16540 | | | 11 (0)| 00:00:01 |
    | 5 | TABLE ACCESS BY INDEX ROWID| LINVIN | 93709 | 12M| | 6073 (1)| 00:01:13 |
    |* 6 | INDEX RANGE SCAN | LINVOICE_BMDT_FK | 93709 | | | 84 (2)| 00:00:02 |
    Predicate Information (identified by operation id):
    2 - access("LINVIN"."BBASE"="LSUPPLIER"."BBASE" AND "LINVIN"."LSUPPLIERNUM"="LSUPPLIER"."LSUPPLIERNUM")
    4 - access("LSUPPLIER"."BBASE"=:1)
    6 - access("LINVIN"."BBASE"=:1)
    The size of the tables are: LINVIN - 383.692 Rows, LSUPPLIER - 115.782 Rows
    As you can see the one executed from our application is much faster than the one from the helper tool. So why picks oracle a completely different explain plan for the same statement? An why is a hash join much slower than a nested loop? Because If I'm right a nested loop should only be used when the tables are pretty small..
    I also tried to play with some parameters:
    I set optimizer_index_caching to 100 and optimizer_index_cost_adj to 30. I also changed optimizer_mode to FIRST_ROWS_100.
    I would really appreciated, if somebody can help me with this issue, because I'm really getting more and more distressed...
    Thanks in advance,
    Tobias
    Edited by: tobiwan on Sep 3, 2008 11:49 PM
    Edited by: tobiwan on Sep 3, 2008 11:50 PM
    Edited by: tobiwan on Sep 4, 2008 12:01 AM
    Edited by: tobiwan on Sep 4, 2008 12:02 AM
    Edited by: tobiwan on Sep 4, 2008 12:04 AM
    Edited by: tobiwan on Sep 4, 2008 12:06 AM
    Edited by: tobiwan on Sep 4, 2008 12:06 AM
    Edited by: tobiwan on Sep 4, 2008 12:07 AM

    tobiwan wrote:
    Hi again,
    Here ist the answer:
    The problem, because I got two different explain plans, was that the external tool uses the NLS sesssion parameters coming from the OS which are in my case "de/DE".
    Within our application these parameters are changed to "en/US"!! So if I'm calling in my external tool the java function Locale.setDefault(new Locale("en","US")) before connecting to the database the explain plans are finally equal.That might explain why you got two different execution plan, because one plan was obviously able to avoid a SORT ORDER BY operation, whereas the second plan required to run SORT ORDER BY operation, obviously because of the different NLS_SORT settings. An index by default uses the NLS_SORT = 'binary' order whereas ORDER BY obeys the NLS_SORT setting, which probably was set to 'GERMAN' in your "external tool" case. You can check the "NLS_SESSION_PARAMETERS" view to check your current NLS_SORT setting.
    For more information regarding this issue, see my blog note I've written about this some time ago:
    http://oracle-randolf.blogspot.com/2008/09/getting-first-rows-of-large-sorted.html
    Now let me make a guess why you observe the behaviour that it takes so long if your result set is empty:
    The plan avoiding the SORT ORDER BY is able to return the first rows of the result set very quickly, but could take quite a while until all rows are processed, since it requires potentially a lot of iterations of the loop until everything has been processed. Your front end probably by default only display the first n rows of the result set and therefore works fine with this execution plan.
    Now if the result set is empty, depending on your data, indexes and search criteria, Oracle has to work through all the data using the inefficient NESTED LOOP approach only to find out that no data has been found, and since your application attempts to fetch the first n records, but no records will be found, it has to wait until all data has been processed.
    You can try to reproduce this by deliberately fetching all records of a query that returns data and that uses the NESTED LOOP approach... It probably takes as long as in the case when no records are found.
    Note that you seem to use bind variables and 10g, therefore you might be interested that due to the "bind variable peeking" functionality you might potentially end up with "unstable" plans depending on the values "peeked" when the statement is parsed.
    For more information, see this comprehensive description of the issue:
    http://www.pythian.com/blogs/867/stabilize-oracle-10gs-bind-peeking-behaviour-by-cutting-histograms
    Note that this changes in 11g with the introduction of the "Adaptive Cursor Sharing".
    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/

  • Not Understanding the filter in Explain Plan - filter(NULL IS NOT NULL)

    Hi All,
    Request your help in understanding the below scenario. (I am not aware of teh application and table details. Just trying to help my friend)
    SQL> conn
    Enter user-name: [email protected]
    Enter password:
    Connected.
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for Linux: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    --Checking the count in PO_LINES
    SQL> select count(*) from po_lines;
      COUNT(*)
             0
    --PO_LINES is a synonym
    SQL> select object_type,owner from dba_objects where object_name = 'PO_LINES';
    OBJECT_TYPE         OWNER
    SYNONYM             APPS
    --The synonym is pointing to PO.PO_LINES_ALL
    SQL> select * from user_synonyms where synonym_name = 'PO_LINES';
    SYNONYM_NAME                   TABLE_OWNER                    TABLE_NAME                     DB_LINK
    PO_LINES                       PO                             PO_LINES_ALL
    --But when counting PO.PO_LINES_ALL I am getting different result
    SQL> select count(*) c from po.po_lines_all;
             C
          8828
    --Explain plan of teh original query is
    SQL> explain plan for
      2  select
      3  * from po_lines;
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id  | Operation          | Name         | Rows  | Bytes | Cost (%CPU)|
    |   0 | SELECT STATEMENT   |              |     1 |   252 |     0   (0)|
    |*  1 |  FILTER            |              |       |       |            |
    |   2 |   TABLE ACCESS FULL| PO_LINES_ALL |  8796 |  2164K|   106   (4)|
    Predicate Information (identified by operation id):
       1 - filter(NULL IS NOT NULL)
    --Now the object PO.PO_LINES_ALL is TABLE, not an mview.
    SQL> select object_type,owner from dba_objects where object_name = 'PO_LINES_ALL';
    OBJECT_TYPE         OWNER
    TABLE               POSeek your help in understanding what is happening here.
    Thanks in Advance,
    jeneesh

    Next time, prefix with APPS. when you show us the explain plan:
    SQL> explain plan for
      2  select
      3  * from apps.po_lines;  -- added the prefix of owner.Just like you prefixed with PO. when you showed us the query on PO_LINES_ALL. It ensures that you are using the synonym which you showed us.
    Btw. PO_LINES_ALL, could still be a VIEW given your overview of the situation.
    Anyway a filter "NULL IS NOT NULL" is indicative that the optimizer performed something called semantic query optimization (SQO).
    SQO is the process of deducing new predicates based upon a) existing predicates in your query (which there is none), b) added predicates to your query (eg. by a VPD policy function), and c) declared constraints on the tables invovled in your query.
    A typical example of when a "NOT is NOT NULL" predicate will show up is when for instance in the EMP table there is a declared constraint on EMPNO like this:
    check(EMPNO > 0)And your query would hold a predicate that is inconsistent with the constraint, for instance like this:
    select *
    from EMP
    where EMPNO <= 0Oracle will deduce that EMPNO cannot be both greater than zero (constraint) as well as smaller than or equal to zero (your query predicate), and will transform the query into:
    select *
    from EMP
    where EMPNO <= 0
      and NULL is NOT NULLThus preventing accessing the EMP table all together, and immediately returning this query with no data found.
    Edited by: Toon Koppelaars on Mar 15, 2010 7:17 AM

  • Explain plan results are different in SQL Developer than SQL Plus

    My Environment:
    SQL Developer 1.0.0.15.27
    Platform where SQL Developer is running: Windows XP 2002 SP2
    Oracle Database and Client 9.2.0.7
    Optimizer_mode: FIRST_ROWS
    I have the following SQL statement:
    SELECT a1.comp_id
    FROM temp_au_company a0, au_company a1
    WHERE :b2 = a0.temp_emp_code
    AND a0.comp_id = a1.comp_id
    AND a0.sls_terr_code != a1.sls_terr_code
    AND a1.last_mdfy_date > :b1
    When I run an Explain in SQL Developer I get the following access path (which is the one I really want):
    SELECT STATEMENT                          TABLE ACCESS(BY INDEX ROWID) FEDLINK.AU_COMPANY          NESTED LOOPS                                   INDEX(RANGE SCAN)
    FEDLINK.UX2_TEMP_AU_COMPANY
              INDEX(RANGE SCAN) FEDLINK.PX1_COMPANY
    However, when I execute the statement with sql_trace turned on and use tkprof to generate the actual access path, the statement executes as follows (which is WAY more expensive):
    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 3.58 6.68 28136 29232 0 0
    total 3 3.58 6.69 28136 29232 0 0
    Misses in library cache during parse: 1
    Optimizer goal: FIRST_ROWS
    Parsing user id: 979 (FEDLINK) (recursive depth: 1)
    Rows Row Source Operation
    0 NESTED LOOPS
    0 TABLE ACCESS FULL AU_COMPANY
    0 INDEX RANGE SCAN UX2_TEMP_AU_COMPANY (object id 49783)
    Notice the FULL access of au_company.
    I understand that SQL Developer has nothing to do with why the statement executed the way it did, but why is the Explain in SQL Developer different than the actual execution plan?
    Added note....when I run the explain in SQL Plus it is the same as the actual execution. Here is the explain from SQL Plus:
    explain plan for SELECT a1.comp_id
    FROM temp_au_company a0, au_company a1
    WHERE '1' = a0.temp_emp_code
    AND a0.comp_id = a1.comp_id
    AND a0.sls_terr_code != a1.sls_terr_code
    AND a1.last_mdfy_date > '01-MAY-2006';
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 2 | 76 | 2597 |
    | 1 | NESTED LOOPS | | 2 | 76 | 2597 |
    | 2 | TABLE ACCESS FULL | AU_COMPANY | 2 | 42 | 2595 |
    | 3 | INDEX RANGE SCAN | UX2_TEMP_AU_COMPANY | 1 | 17 | 2
    Thanks,
    Brenda

    The explain is different (full scan of au_company in SQL Plus / index access in SQL Developer) even when I use variables in SQL Plus. Here is the output for SQL Plus using variables instead of literals:
    SQL> variable b1 varchar2
    SQL> variable b2 char
    SQL> explain plan for SELECT a1.comp_id
    2 FROM temp_au_company a0, au_company a1
    3 WHERE :b2 = a0.temp_emp_code
    4 AND a0.comp_id = a1.comp_id
    5 AND a0.sls_terr_code != a1.sls_terr_code
    6 AND a1.last_mdfy_date > :b1
    7 /
    Explained.
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes | Cost |
    | 0 | SELECT STATEMENT | | 3184 | 118K| 2995 |
    | 1 | HASH JOIN | | 3184 | 118K| 2995 |
    | 2 | INDEX RANGE SCAN | UX2_TEMP_AU_COMPANY | 3187 | 54179 | 3 |
    | 3 | TABLE ACCESS FULL | AU_COMPANY | 24009 | 492K| 2983 |
    Any other ideas? They should be the same.
    Brenda

  • How to improve the query performance or tune query from Explain Plan

    Hi
    The following is my explain plan for sql query. (The plan is generated by Toad v9.7). How to fix the query?
    SELECT STATEMENT ALL_ROWSCost: 4,160 Bytes: 25,296 Cardinality: 204                                         
         8 NESTED LOOPS Cost: 3 Bytes: 54 Cardinality: 1                                    
              5 NESTED LOOPS Cost: 2 Bytes: 23 Cardinality: 1                               
                   2 TABLE ACCESS BY INDEX ROWID TABLE AR.RA_CUSTOMER_TRX_ALL Cost: 1 Bytes: 13 Cardinality: 1                          
                        1 INDEX UNIQUE SCAN INDEX (UNIQUE) AR.RA_CUSTOMER_TRX_U1 Cost: 1 Cardinality: 1                     
                   4 TABLE ACCESS BY INDEX ROWID TABLE AR.HZ_CUST_ACCOUNTS Cost: 1 Bytes: 10 Cardinality: 1                          
                        3 INDEX UNIQUE SCAN INDEX (UNIQUE) AR.HZ_CUST_ACCOUNTS_U1 Cost: 1 Cardinality: 1                     
              7 TABLE ACCESS BY INDEX ROWID TABLE AR.HZ_PARTIES Cost: 1 Bytes: 31 Cardinality: 1                               
                   6 INDEX UNIQUE SCAN INDEX (UNIQUE) AR.HZ_PARTIES_U1 Cost: 1 Cardinality: 1                          
         10 TABLE ACCESS BY INDEX ROWID TABLE AR.RA_CUSTOMER_TRX_ALL Cost: 1 Bytes: 12 Cardinality: 1                                    
              9 INDEX UNIQUE SCAN INDEX (UNIQUE) AR.RA_CUSTOMER_TRX_U1 Cost: 1 Cardinality: 1                               
         15 NESTED LOOPS Cost: 2 Bytes: 29 Cardinality: 1                                    
              12 TABLE ACCESS BY INDEX ROWID TABLE AR.RA_CUSTOMER_TRX_ALL Cost: 1 Bytes: 12 Cardinality: 1                               
                   11 INDEX UNIQUE SCAN INDEX (UNIQUE) AR.RA_CUSTOMER_TRX_U1 Cost: 1 Cardinality: 1                          
              14 TABLE ACCESS BY INDEX ROWID TABLE ONT.OE_ORDER_HEADERS_ALL Cost: 1 Bytes: 17 Cardinality: 1                               
                   13 INDEX RANGE SCAN INDEX (UNIQUE) ONT.OE_ORDER_HEADERS_U2 Cost: 1 Cardinality: 1                          
         21 FILTER                                    
              16 TABLE ACCESS FULL TABLE ONT.OE_TRANSACTION_TYPES_TL Cost: 2 Bytes: 1,127 Cardinality: 49                               
              20 NESTED LOOPS Cost: 2 Bytes: 21 Cardinality: 1                               
                   18 TABLE ACCESS BY INDEX ROWID TABLE AR.RA_CUSTOMER_TRX_ALL Cost: 1 Bytes: 12 Cardinality: 1                          
                        17 INDEX UNIQUE SCAN INDEX (UNIQUE) AR.RA_CUSTOMER_TRX_U1 Cost: 1 Cardinality: 1                     
                   19 INDEX RANGE SCAN INDEX (UNIQUE) ONT.OE_ORDER_HEADERS_U2 Cost: 1 Bytes: 9 Cardinality: 1                          
         23 TABLE ACCESS BY INDEX ROWID TABLE AR.RA_CUSTOMER_TRX_ALL Cost: 1 Bytes: 12 Cardinality: 1                                    
              22 INDEX UNIQUE SCAN INDEX (UNIQUE) AR.RA_CUSTOMER_TRX_U1 Cost: 1 Cardinality: 1                               
         45 NESTED LOOPS Cost: 4,160 Bytes: 25,296 Cardinality: 204                                    
              42 NESTED LOOPS Cost: 4,150 Bytes: 23,052 Cardinality: 204                               
                   38 NESTED LOOPS Cost: 4,140 Bytes: 19,992 Cardinality: 204                          
                        34 NESTED LOOPS Cost: 4,094 Bytes: 75,850 Cardinality: 925                     
                             30 NESTED LOOPS Cost: 3,909 Bytes: 210,843 Cardinality: 3,699                
                                  26 PARTITION LIST ALL Cost: 2,436 Bytes: 338,491 Cardinality: 14,717 Partition #: 29 Partitions accessed #1 - #18          
                                       25 TABLE ACCESS BY LOCAL INDEX ROWID TABLE XLA.XLA_AE_HEADERS Cost: 2,436 Bytes: 338,491 Cardinality: 14,717 Partition #: 29 Partitions accessed #1 - #18     
                                            24 INDEX SKIP SCAN INDEX XLA.XLA_AE_HEADERS_N1 Cost: 264 Cardinality: 1,398,115 Partition #: 29 Partitions accessed #1 - #18
                                  29 PARTITION LIST ITERATOR Cost: 1 Bytes: 34 Cardinality: 1 Partition #: 32           
                                       28 TABLE ACCESS BY LOCAL INDEX ROWID TABLE XLA.XLA_AE_LINES Cost: 1 Bytes: 34 Cardinality: 1 Partition #: 32      
                                            27 INDEX RANGE SCAN INDEX (UNIQUE) XLA.XLA_AE_LINES_U1 Cost: 1 Cardinality: 1 Partition #: 32
                             33 PARTITION LIST ITERATOR Cost: 1 Bytes: 25 Cardinality: 1 Partition #: 35                
                                  32 TABLE ACCESS BY LOCAL INDEX ROWID TABLE XLA.XLA_DISTRIBUTION_LINKS Cost: 1 Bytes: 25 Cardinality: 1 Partition #: 35           
                                       31 INDEX RANGE SCAN INDEX XLA.XLA_DISTRIBUTION_LINKS_N3 Cost: 1 Cardinality: 1 Partition #: 35      
                        37 PARTITION LIST SINGLE Cost: 1 Bytes: 16 Cardinality: 1 Partition #: 38                     
                             36 TABLE ACCESS BY LOCAL INDEX ROWID TABLE XLA.XLA_EVENTS Cost: 1 Bytes: 16 Cardinality: 1 Partition #: 39 Partitions accessed #2               
                                  35 INDEX UNIQUE SCAN INDEX (UNIQUE) XLA.XLA_EVENTS_U1 Cost: 1 Cardinality: 1 Partition #: 40 Partitions accessed #2          
                   41 PARTITION LIST SINGLE Cost: 1 Bytes: 15 Cardinality: 1 Partition #: 41                          
                        40 TABLE ACCESS BY LOCAL INDEX ROWID TABLE XLA.XLA_TRANSACTION_ENTITIES Cost: 1 Bytes: 15 Cardinality: 1 Partition #: 42 Partitions accessed #2                    
                             39 INDEX UNIQUE SCAN INDEX (UNIQUE) XLA.XLA_TRANSACTION_ENTITIES_U1 Cost: 1 Cardinality: 1 Partition #: 43 Partitions accessed #2               
              44 TABLE ACCESS BY INDEX ROWID TABLE GL.GL_CODE_COMBINATIONS Cost: 1 Bytes: 11 Cardinality: 1                               
                   43 INDEX UNIQUE SCAN INDEX (UNIQUE) GL.GL_CODE_COMBINATIONS_U1 Cost: 1 Cardinality: 1

    damorgan wrote:
    Tuning is NOT about reducing the cost of i/o.
    i/o is only one of many contributors to cost and only one of many contributors to waits.
    Any time you would like to explore this further run this code:
    SELECT 1 FROM dual
    WHERE regexp_like(' ','^*[ ]*a');but not on a production box because you are going to experience an extreme tuning event with zero i/o.
    And when I say "extreme" I mean "EXTREME!"
    You've been warned.I think you just need a faster server.
    SQL> set autotrace traceonly statistics
    SQL> set timing on
    SQL> select 1 from dual
      2  where
      3  regexp_like   (' ','^*[ ]*a');
    no rows selected
    Elapsed: 00:00:00.00
    Statistics
              1  recursive calls
              0  db block gets
              0  consistent gets
              0  physical reads
              0  redo size
            243  bytes sent via SQL*Net to client
            349  bytes received via SQL*Net from client
              1  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              0  rows processedRepeated from an Oracle 10.2.0.x instance:
    SQL> SELECT DISTINCT SID FROM V$MYSTAT;
           SID
           310
    SQL> ALTER SESSION SET EVENTS '10053 TRACE NAME CONTEXT FOREVER, LEVEL 1';
    Session altered.
    SQL> select 1 from dual
      2  where
      3  regexp_like   (' ','^*[ ]*a');The session is hung. Wait a little while and connect to the database using a different session:
    COLUMN STAT_NAME FORMAT A35 TRU
    SET PAGESIZE 200
    SELECT
      STAT_NAME,
      VALUE
    FROM
      V$SESS_TIME_MODEL
    WHERE
      SID=310;
    STAT_NAME                                VALUE
    DB time                                   9247
    DB CPU                                    9247
    background elapsed time                      0
    background cpu time                          0
    sequence load elapsed time                   0
    parse time elapsed                        6374
    hard parse elapsed time                   5997
    sql execute elapsed time                  2939
    connection management call elapsed        1660
    failed parse elapsed time                    0
    failed parse (out of shared memory)          0
    hard parse (sharing criteria) elaps          0
    hard parse (bind mismatch) elapsed           0
    PL/SQL execution elapsed time               95
    inbound PL/SQL rpc elapsed time              0
    PL/SQL compilation elapsed time              0
    Java execution elapsed time                  0
    repeated bind elapsed time                  48
    RMAN cpu time (backup/restore)               0Seems to be using a bit of time for the hard parse (hard parse elapsed time). Wait a little while, then re-execute the query:
    STAT_NAME                                VALUE
    DB time                                   9247
    DB CPU                                    9247
    background elapsed time                      0
    background cpu time                          0
    sequence load elapsed time                   0
    parse time elapsed                        6374
    hard parse elapsed time                   5997
    sql execute elapsed time                  2939
    connection management call elapsed        1660
    failed parse elapsed time                    0
    failed parse (out of shared memory)          0
    hard parse (sharing criteria) elaps          0
    hard parse (bind mismatch) elapsed           0
    PL/SQL execution elapsed time               95
    inbound PL/SQL rpc elapsed time              0
    PL/SQL compilation elapsed time              0
    Java execution elapsed time                  0
    repeated bind elapsed time                  48
    RMAN cpu time (backup/restore)               0The session is not reporting additional CPU usage or parse time.
    Let's check one of the session's statistics:
    SELECT
      SS.VALUE
    FROM
      V$SESSTAT SS,
      V$STATNAME SN
    WHERE
      SN.NAME='consistent gets'
      AND SN.STATISTIC#=SS.STATISTIC#
      AND SS.SID=310;
         VALUE
           163Not many consistent gets after 20+ minutes.
    Let's take a look at the plan:
    SQL> SELECT SQL_ID,CHILD_NUMBER FROM V$SQL WHERE SQL_TEXT LIKE 'select 1 from du
    al%';
    SQL_ID        CHILD_NUMBER
    04mpgrzhsv72w            0
    SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR('04mpgrzhsv72w',0,'TYPICAL'))
    select 1 from dual where regexp_like   (' ','^*[ ]*a')
    NOTE: cannot fetch plan for SQL_ID: 04mpgrzhsv72w, CHILD_NUMBER: 0
          Please verify value of SQL_ID and CHILD_NUMBER;
          It could also be that the plan is no longer in cursor cache (check v$sql_p
    lan)No plan...
    Let's take a look at the 10053 trace file:
    Registered qb: SEL$1 0x19157f38 (PARSER)
      signature (): qb_name=SEL$1 nbfros=1 flg=0
        fro(0): flg=4 objn=258 hint_alias="DUAL"@"SEL$1"
    Predicate Move-Around (PM)
    PM: Considering predicate move-around in SEL$1 (#0).
    PM:   Checking validity of predicate move-around in SEL$1 (#0).
    CBQT: Validity checks failed for 7uqx4guu04x3g.
    CVM: Considering view merge in query block SEL$1 (#0)
    CBQT: Validity checks failed for 7uqx4guu04x3g.
    Subquery Unnest
    SU: Considering subquery unnesting in query block SEL$1 (#0)
    Set-Join Conversion (SJC)
    SJC: Considering set-join conversion in SEL$1 (#0).
    Predicate Move-Around (PM)
    PM: Considering predicate move-around in SEL$1 (#0).
    PM:   Checking validity of predicate move-around in SEL$1 (#0).
    PM:     PM bypassed: Outer query contains no views.
    FPD: Considering simple filter push in SEL$1 (#0)
    FPD:   Current where clause predicates in SEL$1 (#0) :
              REGEXP_LIKE (' ','^*[ ]*a')
    kkogcp: try to generate transitive predicate from check constraints for SEL$1 (#0)
    predicates with check contraints:  REGEXP_LIKE (' ','^*[ ]*a')
    after transitive predicate generation:  REGEXP_LIKE (' ','^*[ ]*a')
    finally:  REGEXP_LIKE (' ','^*[ ]*a')
    apadrv-start: call(in-use=592, alloc=16344), compile(in-use=37448, alloc=42256)
    kkoqbc-start
                : call(in-use=592, alloc=16344), compile(in-use=38336, alloc=42256)
    kkoqbc-subheap (create addr=000000001915C238)Looks like the query never had a chance to start executing - it is still parsing after 20 minutes.
    I am not sure that this is a good example - the query either executes very fast, or never has a chance to start executing. But, it might still make your point physical I/O is not always the problem when performance problems are experienced.
    Charles Hooper
    IT Manager/Oracle DBA
    K&M Machine-Fabricating, Inc.

  • Same query, same dataset, same ddl setup, but wildly different explain plan

    Hello o fountains of oracle knowledge!
    We have a problem that caused us a full stop when rolling out a new version of our system to a customer and a whole Sunday to boot.
    The scenario is as follows:
    1. An previous version database schema
    2. The current version database schema
    3. A migration script to migrate the old schema to the new
    So we perform the following migration:
    1. Export the previous version database schema
    2. Import into a new schema called schema_old
    3. Create a new schema called schema_new
    4. Run migration script which creates objects, copies data, creates indexes etc etc in schema_new
    The migration runs fine in all environments (development, test and production)
    In our development and test environments performance is stellar, on the customer production server the performance is terrible.
    This using the exact same export file (from the production environment) and performing the exact same steps with the exact same migration script.
    Database version is 10.2.0.1.0 EE on all databases. OS is Microsoft Windows Server 2003 EE SP2 on all servers.
    The system is not in any sense under a heavy load (we have tested with no other load than ourselves).
    Looking at the explain plan for a query that is run frequently and does not use bind variables we see wildly different explain plans.
    The explain plan cost on our development and test servers is estimated to *7* for this query and there are no full table scans.
    On the production server the cost is *8433* and there are two full table scans of which one is on the largest table.
    We have tried to run analyse on all objects with very little effect. The plan changed very slightly, but still includes the two full table scans on the problem server and the cost is still the same.
    All tables and indexes are identical (including storage options), created from the same migration script.
    I am currently at loss for where to look? What can be causing this? I assume this could be caused by some parameter that is set on the server, but I don't know what to look for.
    I would be very grateful for any pointers.
    Thanks,
    Håkon

    Thank you for your answer.
    We collected statistics only after we determined that the production server where not behaving according to expectations.
    In this case we used TOAD and the tool within to collect statistics for all objects. We used 'Analyze' and 'Compute Statistics' options.
    I am not an expert, so sorry if this is too naive an approach.
    Here is the query:SELECT count(0)  
    FROM score_result sr, web_scorecard sc, product p
    WHERE sr.score_final_decision like 'VENT%'  
    AND sc.CREDIT_APPLICATION_ID = sr.CREDIT_APPLICATION_ID  
    AND sc.application_complete='Y'   
    AND p.product = sc.web_product   
    AND p.inactive_product = '2' ;I use this as an example, but the problem exists for virtually all queries.
    The output from the 'good' server:
    | Id  | Operation                      | Name                  | Rows  | Bytes | Cost (%CPU)|
    |   0 | SELECT STATEMENT               |                       |     1 |    39 |     7   (0)|
    |   1 |  SORT AGGREGATE                |                       |     1 |    39 |            |
    |   2 |   NESTED LOOPS                 |                       |     1 |    39 |     7   (0)|
    |   3 |    NESTED LOOPS                |                       |     1 |    30 |     6   (0)|
    |   4 |     TABLE ACCESS BY INDEX ROWID| SCORE_RESULT          |     1 |    17 |     4   (0)|
    |   5 |      INDEX RANGE SCAN          | SR_FINAL_DECISION_IDX |     1 |       |     3   (0)|
    |   6 |     TABLE ACCESS BY INDEX ROWID| WEB_SCORECARD         |     1 |    13 |     2   (0)|
    |   7 |      INDEX UNIQUE SCAN         | WEB_SCORECARD_PK      |     1 |       |     1   (0)|
    |   8 |    TABLE ACCESS BY INDEX ROWID | PRODUCT               |     1 |     9 |     1   (0)|
    |   9 |     INDEX UNIQUE SCAN          | PK_PRODUCT            |     1 |       |     0   (0)|
    ---------------------------------------------------------------------------------------------The output from the 'bad' server:
    | Id  | Operation                 | Name                  | Rows  | Bytes | Cost (%CPU)|
    |   0 | SELECT STATEMENT          |                       |     1 |    32 |  8344   (3)|
    |   1 |  SORT AGGREGATE           |                       |     1 |    32 |            |
    |   2 |   HASH JOIN               |                       | 10887 |   340K|  8344   (3)|
    |   3 |    TABLE ACCESS FULL      | PRODUCT               |     6 |    42 |     3   (0)|
    |   4 |    HASH JOIN              |                       | 34381 |   839K|  8340   (3)|
    |   5 |     VIEW                  | index$_join$_001      | 34381 |   503K|  2193   (3)|
    |   6 |      HASH JOIN            |                       |       |       |            |
    |   7 |       INDEX RANGE SCAN    | SR_FINAL_DECISION_IDX | 34381 |   503K|   280   (3)|
    |   8 |       INDEX FAST FULL SCAN| SCORE_RESULT_PK       | 34381 |   503K|  1371   (2)|
    |   9 |     TABLE ACCESS FULL     | WEB_SCORECARD         |   489K|  4782K|  6137   (4)|
    ----------------------------------------------------------------------------------------I hope the formatting makes this readable.
    Stats (from SQL Developer), good table:NUM_ROWS     489716
    BLOCKS     27198
    AVG_ROW_LEN     312
    SAMPLE_SIZE     489716
    LAST_ANALYZED     15.12.2009
    LAST_ANALYZED_SINCE     15.12.2009Stats (from SQL Developer), bad table:
    NUM_ROWS     489716
    BLOCKS     27199
    AVG_ROW_LEN     395
    SAMPLE_SIZE     489716
    LAST_ANALYZED     17.12.2009
    LAST_ANALYZED_SINCE     17.12.2009I'm unsure what would cause the difference in average row length.
    I could obviously try to tune our sql-statements to work on the server not behaving better, but I would rather understand why they are different and make sure that we can expect similar behaviour between environments.
    Thank you again for trying to help me.
    Håkon
    Edited by: ergates on 17.des.2009 05:57
    Edited by: ergates on 17.des.2009 06:02

  • [8i] Can someone help me on using explain plan, tkprof, etc.?

    I am trying to follow the instructions at When your query takes too long ...
    I am trying to figure out why a simple query takes so long.
    The query is:
    SELECT COUNT(*) AS tot_rows FROM my_table;It takes a good 5 minutes or so to run (best case), and the result is around 22 million (total rows).
    My generic username does not (evidently) allow access to PLAN_TABLE, so I had to log on as SYSTEM to run explain plan. In SQL*Plus, I typed in:
    explain plan for (SELECT COUNT(*) AS tot_rows FROM my_table);and the response was "Explained."
    Isn't this supposed to give me some sort of output, or am I missing something?
    Then, the next step in the post I linked is to use tkprof. I see that it says it will output a file to a path specified in a parameter. The only problem is, I don't have access to the db's server. I am working remotely, and do not have any way to remotely (or directly) access the db server. Is there any way to have the file output to my local machine, or am I just S.O.L.?

    SomeoneElse used "create table as" (CTAS), wich automatically gathers the stats. You can see the differende before and after stats clearly in this example.
    This is the script:
    drop table ttemp;
    create table ttemp (object_id number not null, owner varchar2(30), object_name varchar2(200));
    alter table ttemp add constraint ttemp_pk primary key (object_id);
    insert into ttemp
    select object_id, owner, object_name
    from dba_objects
    where object_id is not null;
    set autotrace on
    select count(*) from ttemp;
    exec dbms_stats.gather_table_stats('PROD','TTEMP');
    select count(*) from ttemp;And the result:
    Table dropped.
    Table created.
    Table altered.
    46888 rows created.
      COUNT(*)
         46888
    1 row selected.
    Execution Plan
               SELECT STATEMENT Optimizer Mode=CHOOSE
       1         SORT AGGREGATE
       2    1      TABLE ACCESS FULL PROD.TTEMP
    Statistics
              1  recursive calls
              1  db block gets
            252  consistent gets
              0  physical reads
            120  redo size
              0  PX remote messages sent
              0  PX remote messages recv'd
              0  buffer is pinned count
              0  workarea memory allocated
              4  workarea executions - optimal
              1  rows processed
    PL/SQL procedure successfully completed.
      COUNT(*)
         46888
    1 row selected.
    Execution Plan
               SELECT STATEMENT Optimizer Mode=CHOOSE (Cost=4 Card=1)
       1         SORT AGGREGATE (Card=1)
       2    1      INDEX FAST FULL SCAN PROD.TTEMP_PK (Cost=4 Card=46 K)
    Statistics
              1  recursive calls
              2  db block gets
            328  consistent gets
              0  physical reads
           8856  redo size
              0  PX remote messages sent
              0  PX remote messages recv'd
              0  buffer is pinned count
              0  workarea memory allocated
              4  workarea executions - optimal
              1  rows processed

  • DECODE is changing the explain plan

    I have a statement with a decode function in the where clause like this:
    AND decode(:cropcode,-1,'-1',sdu.u_crop_group) = decode(:cropcode,-1,'-1',:cropcode)When I a pass -1 as parameter for cropgroup the filter would result in "AND '-1' = '-1' and the statement is executed in less than 2 seconds. When I leave out this where clause it takes almost 18 seconds. The result is the same so I don't understand why the explain plan is so much different and why not using index scans in the statement without decode.
    Below the explain plans and tkprofs for 1 (without decode) and 2 (with decode).
    *explain 1*
    {code}
    SQL Statement which produced this data:
    select * from table(dbms_xplan.display)
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)|
    | 0 | SELECT STATEMENT | | 7080 | 2413K| | 43611 (2)|
    | 1 | SORT ORDER BY | | 7080 | 2413K| 5224K| 43611 (2)|
    |* 2 | FILTER | | | | | |
    |* 3 | HASH JOIN | | 7156 | 2438K| | 43075 (2)|
    | 4 | TABLE ACCESS FULL | DWH_ABS_DETERMINATION | 17745 | 363K| | 83 (0)|
    |* 5 | HASH JOIN OUTER | | 7156 | 2292K| | 42991 (2)|
    |* 6 | HASH JOIN | | 7156 | 1355K| | 42907 (2)|
    |* 7 | HASH JOIN | | 6987 | 1187K| | 19170 (2)|
    |* 8 | HASH JOIN | | 6947 | 963K| | 10376 (1)|
    |* 9 | TABLE ACCESS BY INDEX ROWID | ALIQUOT | 3 | 144 | | 3 (0)|
    | 10 | NESTED LOOPS | | 6907 | 897K| | 8577 (1)|
    |* 11 | HASH JOIN | | 2264 | 187K| | 1782 (2)|
    | 12 | TABLE ACCESS BY INDEX ROWID | SAMPLE | 190 | 4370 | | 17 (0)|
    | 13 | NESTED LOOPS | | 2264 | 152K| | 107 (1)|
    | 14 | NESTED LOOPS | | 12 | 552 | | 25 (0)|
    |* 15 | TABLE ACCESS FULL | SDG_USER | 12 | 288 | | 13 (0)|
    | 16 | TABLE ACCESS BY INDEX ROWID| SDG | 1 | 22 | | 1 (0)|
    |* 17 | INDEX UNIQUE SCAN | PK_SDG | 1 | | | 0 (0)|
    |* 18 | INDEX RANGE SCAN | FK_SAMPLE_SDG | 597 | | | 2 (0)|
    | 19 | TABLE ACCESS FULL | SAMPLE_USER | 1078K| 16M| | 1669 (1)|
    |* 20 | INDEX RANGE SCAN | FK_ALIQUOT_SAMPLE | 3 | | | 2 (0)|
    | 21 | TABLE ACCESS FULL | ALIQUOT_USER | 3403K| 29M| | 1781 (3)|
    | 22 | TABLE ACCESS FULL | TEST | 3423K| 104M| | 8775 (2)|
    |* 23 | TABLE ACCESS FULL | RESULT | 3435K| 65M| | 23718 (2)|
    | 24 | VIEW | PLATE | 21787 | 2851K| | 84 (2)|
    |* 25 | FILTER | | | | | |
    | 26 | TABLE ACCESS FULL | PLATE | 21787 | 574K| | 84 (2)|
    |* 27 | INDEX UNIQUE SCAN | PK_OPERATOR_GROUP | 1 | 7 | | 0 (0)|
    |* 28 | INDEX UNIQUE SCAN | PK_OPERATOR_GROUP | 1 | 7 | | 0 (0)|
    |* 29 | INDEX UNIQUE SCAN | PK_OPERATOR_GROUP | 1 | 7 | | 0 (0)|
    |* 30 | INDEX UNIQUE SCAN | PK_OPERATOR_GROUP | 1 | 7 | | 0 (0)|
    |* 31 | INDEX UNIQUE SCAN | PK_OPERATOR_GROUP | 1 | 7 | | 0 (0)|
    Predicate Information (identified by operation id):
    2 - filter(("GROUP_ID" IS NULL OR EXISTS (SELECT /*+ */ 0 FROM "LIMS"."OPERATOR_GROUP"
    "OPERATOR_GROUP" WHERE "OPERATOR_ID"="LIMS$OPERATOR_ID"() AND "GROUP_ID"=:B1)) AND ("GROUP_ID" IS NULL
    OR EXISTS (SELECT /*+ */ 0 FROM "LIMS"."OPERATOR_GROUP" "OPERATOR_GROUP" WHERE
    "OPERATOR_ID"="LIMS$OPERATOR_ID"() AND "GROUP_ID"=:B2)) AND ("GROUP_ID" IS NULL OR EXISTS (SELECT /*+
    */ 0 FROM "LIMS"."OPERATOR_GROUP" "OPERATOR_GROUP" WHERE "OPERATOR_ID"="LIMS$OPERATOR_ID"() AND
    "GROUP_ID"=:B3)) AND ("GROUP_ID" IS NULL OR EXISTS (SELECT /*+ */ 0 FROM "LIMS"."OPERATOR_GROUP"
    "OPERATOR_GROUP" WHERE "OPERATOR_ID"="LIMS$OPERATOR_ID"() AND "GROUP_ID"=:B4)))
    3 - access("U_ABS_DETERMINATION"="DETERMINATION_ASSIGNMENT")
    5 - access("PLT"."PLATE_ID"(+)="PLATE_ID")
    6 - access("TEST_ID"="TEST_ID")
    7 - access("ALIQUOT_ID"="ALIQUOT_ID")
    8 - access("ALIQUOT_ID"="ALIQUOT_ID")
    9 - filter("STATUS"='C' OR "STATUS"='P' OR "STATUS"='V')
    11 - access("SAMPLE_ID"="SAMPLE_ID")
    15 - filter("U_ABS_DETERMINATION" IS NOT NULL AND "U_CLIENT_TYPE"='QC' AND
    "U_WEEK_OF_PROCESSING"=TO_NUMBER(:WEEK) AND "U_YEAR_OF_SAMPLE_DELIVERY"=TO_NUMBER(:YEAR))
    17 - access("SDG_ID"="SDG_ID")
    18 - access("SDG_ID"="SDG_ID")
    20 - access("SAMPLE_ID"="SAMPLE_ID")
    23 - filter("NAME"='End result')
    25 - filter("GROUP_ID" IS NULL OR EXISTS (SELECT /*+ */ 0 FROM "LIMS"."OPERATOR_GROUP"
    "OPERATOR_GROUP" WHERE "OPERATOR_ID"="LIMS$OPERATOR_ID"() AND "GROUP_ID"=:B1))
    27 - access("GROUP_ID"=:B1 AND "OPERATOR_ID"="LIMS$OPERATOR_ID"())
    28 - access("GROUP_ID"=:B1 AND "OPERATOR_ID"="LIMS$OPERATOR_ID"())
    29 - access("GROUP_ID"=:B1 AND "OPERATOR_ID"="LIMS$OPERATOR_ID"())
    30 - access("GROUP_ID"=:B1 AND "OPERATOR_ID"="LIMS$OPERATOR_ID"())
    31 - access("GROUP_ID"=:B1 AND "OPERATOR_ID"="LIMS$OPERATOR_ID"())
    Note
    - 'PLAN_TABLE' is old version
    {code}
    *tkprof 1*
    {code}
    TKPROF: Release 10.2.0.3.0 - Production on Tue Jan 13 13:21:47 2009
    Copyright (c) 1982, 2005, Oracle. All rights reserved.
    Trace file: C:\oracle\product\10.2.0\admin\nautp02\udump\nautp02_ora_880.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 sdu.u_crop_group,
    sd.name as sdg_name,
    ad.variety_name,
    ad.batch_number,
    a.name as aliquot_name,
    sau.u_box_code as box_code,
    sau.u_box_position as box_position,
    t.name as test_name,
    r.original_result,
    plt.name as plate_name,
    concat(chr(a.plate_row + 64),a.plate_column) as plate_position,
    au.u_replicate_number as replicate_number
    FROM lims_sys.sdg sd,
    lims_sys.sdg_user sdu,
    lims_sys.sample sa,
    lims_sys.sample_user sau,
    lims_sys.aliquot a,
    lims_sys.aliquot_user au,
    lims_sys.test t,
    lims_sys.result r,
    lims_sys.plate plt,
    lims_sys.abs_determination ad
    WHERE sd.sdg_id = sdu.sdg_id
    AND sd.sdg_id = sa.sdg_id
    AND sa.sample_id = sau.sample_id
    AND sau.sample_id = a.sample_id
    AND a.aliquot_id = au.aliquot_id
    AND au.aliquot_id = t.aliquot_id
    AND t.test_id = r.test_id
    AND plt.plate_id (+) = a.plate_id
    AND sdu.u_abs_determination = ad.determination_assignment
    AND a.status IN ('V','P','C')
    AND r.name = 'End result'
    AND sdu.u_client_type = 'QC'
    AND sdu.u_year_of_sample_delivery = (:year)
    AND sdu.u_week_of_processing = (:week)
    --AND decode(:cropcode,-1,'-1',sdu.u_crop_group) = decode(:cropcode,-1,'-1',:cropcode)
    ORDER BY box_code, box_position, replicate_number
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 1.15 1.16 0 0 0 0
    Fetch 1 8.53 16.10 227649 241266 0 500
    total 3 9.68 17.27 227649 241266 0 500
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 97
    Rows Row Source Operation
    500 SORT ORDER BY (cr=241266 pr=227649 pw=0 time=16104631 us)
    21311 FILTER (cr=241266 pr=227649 pw=0 time=16246749 us)
    21311 HASH JOIN (cr=241266 pr=227649 pw=0 time=16225434 us)
    17745 TABLE ACCESS FULL DWH_ABS_DETERMINATION (cr=374 pr=0 pw=0 time=69 us)
    21311 HASH JOIN RIGHT OUTER (cr=240892 pr=227649 pw=0 time=16170607 us)
    21895 VIEW PLATE (cr=316 pr=0 pw=0 time=43825 us)
    21895 FILTER (cr=316 pr=0 pw=0 time=43823 us)
    21895 TABLE ACCESS FULL PLATE (cr=316 pr=0 pw=0 time=31 us)
    0 INDEX UNIQUE SCAN PK_OPERATOR_GROUP (cr=0 pr=0 pw=0 time=0 us)(object id 45769)
    21311 HASH JOIN (cr=240576 pr=227649 pw=0 time=16106174 us)
    21311 HASH JOIN (cr=133559 pr=121596 pw=0 time=9594130 us)
    21311 HASH JOIN (cr=94323 pr=83281 pw=0 time=6917067 us)
    21311 HASH JOIN (cr=86383 pr=75547 pw=0 time=5509672 us)
    7776 HASH JOIN (cr=8134 pr=0 pw=0 time=285364 us)
    7776 TABLE ACCESS BY INDEX ROWID SAMPLE (cr=572 pr=0 pw=0 time=27152 us)
    7876 NESTED LOOPS (cr=377 pr=0 pw=0 time=488287 us)
    99 HASH JOIN (cr=160 pr=0 pw=0 time=4168 us)
    99 TABLE ACCESS FULL SDG_USER (cr=53 pr=0 pw=0 time=1209 us)
    5719 TABLE ACCESS FULL SDG (cr=107 pr=0 pw=0 time=17 us)
    7776 INDEX RANGE SCAN FK_SAMPLE_SDG (cr=217 pr=0 pw=0 time=623 us)(object id 45990)
    1079741 TABLE ACCESS FULL SAMPLE_USER (cr=7562 pr=0 pw=0 time=24 us)
    3307948 TABLE ACCESS FULL ALIQUOT (cr=78249 pr=75547 pw=0 time=3331129 us)
    3406836 TABLE ACCESS FULL ALIQUOT_USER (cr=7940 pr=7734 pw=0 time=556 us)
    3406832 TABLE ACCESS FULL TEST (cr=39236 pr=38315 pw=0 time=3413192 us)
    3406832 TABLE ACCESS FULL RESULT (cr=107017 pr=106053 pw=0 time=6848487 us)
    0 INDEX UNIQUE SCAN PK_OPERATOR_GROUP (cr=0 pr=0 pw=0 time=0 us)(object id 45769)
    0 INDEX UNIQUE SCAN PK_OPERATOR_GROUP (cr=0 pr=0 pw=0 time=0 us)(object id 45769)
    0 INDEX UNIQUE SCAN PK_OPERATOR_GROUP (cr=0 pr=0 pw=0 time=0 us)(object id 45769)
    0 INDEX UNIQUE SCAN PK_OPERATOR_GROUP (cr=0 pr=0 pw=0 time=0 us)(object id 45769)
    select 'x'
    from
    dual
    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 0.00 0.00 0 0 0 1
    total 3 0.00 0.00 0 0 0 1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 97
    Rows Row Source Operation
    1 FAST DUAL (cr=0 pr=0 pw=0 time=3 us)
    begin :id := sys.dbms_transaction.local_transaction_id; end;
    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 1
    Fetch 0 0.00 0.00 0 0 0 0
    total 2 0.00 0.00 0 0 0 1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 97
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call count cpu elapsed disk query current rows
    Parse 3 0.00 0.00 0 0 0 0
    Execute 3 1.15 1.16 0 0 0 1
    Fetch 2 8.53 16.10 227649 241266 0 501
    total 8 9.68 17.27 227649 241266 0 502
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call count cpu elapsed disk query current rows
    Parse 30 0.00 0.00 0 0 0 0
    Execute 30 0.00 0.00 0 0 0 0
    Fetch 30 0.00 0.00 0 40 0 10
    total 90 0.00 0.00 0 40 0 10
    Misses in library cache during parse: 0
    3 user SQL statements in session.
    30 internal SQL statements in session.
    33 SQL statements in session.
    Trace file: C:\oracle\product\10.2.0\admin\nautp02\udump\nautp02_ora_880.trc
    Trace file compatibility: 10.01.00
    Sort options: default
    8 sessions in tracefile.
    3 user SQL statements in trace file.
    30 internal SQL statements in trace file.
    33 SQL statements in trace file.
    6 unique SQL statements in trace file.
    633 lines in trace file.
    23 elapsed seconds in trace file.
    {code}

    explain 2
    SQL Statement which produced this data:
      select * from table(dbms_xplan.display)
    PLAN_TABLE_OUTPUT
    | Id  | Operation                               | Name                     | Rows  | Bytes | Cost (%CPU)|
    |   0 | SELECT STATEMENT                        |                          |    71 | 24779 |   857   (1)|
    |   1 |  SORT ORDER BY                          |                          |    71 | 24779 |   857   (1)|
    |*  2 |   FILTER                                |                          |       |       |            |
    |*  3 |    TABLE ACCESS BY INDEX ROWID          | RESULT                   |     1 |    20 |     4   (0)|
    |   4 |     NESTED LOOPS                        |                          |    72 | 25128 |   856   (1)|
    |   5 |      NESTED LOOPS                       |                          |    70 | 23030 |   576   (1)|
    |*  6 |       HASH JOIN OUTER                   |                          |    69 | 20493 |   369   (1)|
    |   7 |        NESTED LOOPS                     |                          |    69 | 11247 |   285   (0)|
    |   8 |         NESTED LOOPS                    |                          |    69 | 10626 |   147   (0)|
    |   9 |          NESTED LOOPS                   |                          |    23 |  2438 |    78   (0)|
    |  10 |           NESTED LOOPS                  |                          |    23 |  2070 |    32   (0)|
    |  11 |            NESTED LOOPS                 |                          |     1 |    67 |    15   (0)|
    |  12 |             NESTED LOOPS                |                          |     1 |    45 |    14   (0)|
    |* 13 |              TABLE ACCESS FULL          | SDG_USER                 |     1 |    24 |    13   (0)|
    |  14 |              TABLE ACCESS BY INDEX ROWID| DWH_ABS_DETERMINATION    |     1 |    21 |     1   (0)|
    |* 15 |               INDEX UNIQUE SCAN         | PK_DWH_ABS_DETERMINATION |     1 |       |     0   (0)|
    |  16 |             TABLE ACCESS BY INDEX ROWID | SDG                      |     1 |    22 |     1   (0)|
    |* 17 |              INDEX UNIQUE SCAN          | PK_SDG                   |     1 |       |     0   (0)|
    |  18 |            TABLE ACCESS BY INDEX ROWID  | SAMPLE                   |   190 |  4370 |    17   (0)|
    |* 19 |             INDEX RANGE SCAN            | FK_SAMPLE_SDG            |   597 |       |     2   (0)|
    |  20 |           TABLE ACCESS BY INDEX ROWID   | SAMPLE_USER              |     1 |    16 |     2   (0)|
    |* 21 |            INDEX UNIQUE SCAN            | PK_SAMPLE_USER           |     1 |       |     1   (0)|
    |* 22 |          TABLE ACCESS BY INDEX ROWID    | ALIQUOT                  |     3 |   144 |     3   (0)|
    |* 23 |           INDEX RANGE SCAN              | FK_ALIQUOT_SAMPLE        |     3 |       |     2   (0)|
    |  24 |         TABLE ACCESS BY INDEX ROWID     | ALIQUOT_USER             |     1 |     9 |     2   (0)|
    |* 25 |          INDEX UNIQUE SCAN              | PK_ALIQUOT_USER          |     1 |       |     1   (0)|
    |  26 |        VIEW                             | PLATE                    | 21787 |  2851K|    84   (2)|
    |* 27 |         FILTER                          |                          |       |       |            |
    |  28 |          TABLE ACCESS FULL              | PLATE                    | 21787 |   574K|    84   (2)|
    |* 29 |          INDEX UNIQUE SCAN              | PK_OPERATOR_GROUP        |     1 |     7 |     0   (0)|
    |  30 |       TABLE ACCESS BY INDEX ROWID       | TEST                     |     1 |    32 |     3   (0)|
    |* 31 |        INDEX RANGE SCAN                 | FK_TEST_ALIQUOT          |     1 |       |     2   (0)|
    |* 32 |      INDEX RANGE SCAN                   | FK_RESULT_TEST           |     2 |       |     2   (0)|
    |* 33 |    INDEX UNIQUE SCAN                    | PK_OPERATOR_GROUP        |     1 |     7 |     0   (0)|
    |* 34 |    INDEX UNIQUE SCAN                    | PK_OPERATOR_GROUP        |     1 |     7 |     0   (0)|
    |* 35 |    INDEX UNIQUE SCAN                    | PK_OPERATOR_GROUP        |     1 |     7 |     0   (0)|
    |* 36 |    INDEX UNIQUE SCAN                    | PK_OPERATOR_GROUP        |     1 |     7 |     0   (0)|
    Predicate Information (identified by operation id):
       2 - filter(("GROUP_ID" IS NULL OR  EXISTS (SELECT /*+ */ 0 FROM "LIMS"."OPERATOR_GROUP"
                  "OPERATOR_GROUP" WHERE "OPERATOR_ID"="LIMS$OPERATOR_ID"() AND "GROUP_ID"=:B1)) AND ("GROUP_ID"
                  IS NULL OR  EXISTS (SELECT /*+ */ 0 FROM "LIMS"."OPERATOR_GROUP" "OPERATOR_GROUP" WHERE
                  "OPERATOR_ID"="LIMS$OPERATOR_ID"() AND "GROUP_ID"=:B2)) AND ("GROUP_ID" IS NULL OR  EXISTS
                  (SELECT /*+ */ 0 FROM "LIMS"."OPERATOR_GROUP" "OPERATOR_GROUP" WHERE
                  "OPERATOR_ID"="LIMS$OPERATOR_ID"() AND "GROUP_ID"=:B3)) AND ("GROUP_ID" IS NULL OR  EXISTS
                  (SELECT /*+ */ 0 FROM "LIMS"."OPERATOR_GROUP" "OPERATOR_GROUP" WHERE
                  "OPERATOR_ID"="LIMS$OPERATOR_ID"() AND "GROUP_ID"=:B4)))
       3 - filter("NAME"='End result')
       6 - access("PLT"."PLATE_ID"(+)="PLATE_ID")
      13 - filter("U_ABS_DETERMINATION" IS NOT NULL AND "U_CLIENT_TYPE"='QC' AND
                  "U_WEEK_OF_PROCESSING"=TO_NUMBER(:WEEK) AND "U_YEAR_OF_SAMPLE_DELIVERY"=TO_NUMBER(:YEAR) AND
                  DECODE(:CROPCODE,(-1),'-1',"U_CROP_GROUP")=DECODE(:CROPCODE,(-1),'-1',:CROPCODE))
      15 - access("U_ABS_DETERMINATION"="DETERMINATION_ASSIGNMENT")
      17 - access("SDG_ID"="SDG_ID")
      19 - access("SDG_ID"="SDG_ID")
      21 - access("SAMPLE_ID"="SAMPLE_ID")
      22 - filter("STATUS"='C' OR "STATUS"='P' OR "STATUS"='V')
      23 - access("SAMPLE_ID"="SAMPLE_ID")
      25 - access("ALIQUOT_ID"="ALIQUOT_ID")
      27 - filter("GROUP_ID" IS NULL OR  EXISTS (SELECT /*+ */ 0 FROM "LIMS"."OPERATOR_GROUP"
                  "OPERATOR_GROUP" WHERE "OPERATOR_ID"="LIMS$OPERATOR_ID"() AND "GROUP_ID"=:B1))
      29 - access("GROUP_ID"=:B1 AND "OPERATOR_ID"="LIMS$OPERATOR_ID"())
      31 - access("ALIQUOT_ID"="ALIQUOT_ID")
      32 - access("TEST_ID"="TEST_ID")
      33 - access("GROUP_ID"=:B1 AND "OPERATOR_ID"="LIMS$OPERATOR_ID"())
      34 - access("GROUP_ID"=:B1 AND "OPERATOR_ID"="LIMS$OPERATOR_ID"())
      35 - access("GROUP_ID"=:B1 AND "OPERATOR_ID"="LIMS$OPERATOR_ID"())
      36 - access("GROUP_ID"=:B1 AND "OPERATOR_ID"="LIMS$OPERATOR_ID"())
    Note
       - 'PLAN_TABLE' is old version
    tkprof 2
    TKPROF: Release 10.2.0.3.0 - Production on Tue Jan 13 13:28:26 2009
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Trace file: C:\oracle\product\10.2.0\admin\nautp02\udump\nautp02_ora_5456.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 sdu.u_crop_group,
           sd.name as sdg_name,
           ad.variety_name,
           ad.batch_number,
           a.name as aliquot_name,
           sau.u_box_code as box_code,
           sau.u_box_position as box_position,
           t.name as test_name,
           r.original_result,
           plt.name as plate_name,
           concat(chr(a.plate_row + 64),a.plate_column) as plate_position,
           au.u_replicate_number as replicate_number
    FROM lims_sys.sdg sd,
         lims_sys.sdg_user sdu,
         lims_sys.sample sa,
         lims_sys.sample_user sau,
         lims_sys.aliquot a,
         lims_sys.aliquot_user au,
         lims_sys.test t,
         lims_sys.result r,
         lims_sys.plate plt,
         lims_sys.abs_determination ad
    WHERE sd.sdg_id = sdu.sdg_id
      AND sd.sdg_id = sa.sdg_id
      AND sa.sample_id = sau.sample_id
      AND sau.sample_id = a.sample_id
      AND a.aliquot_id = au.aliquot_id
      AND au.aliquot_id = t.aliquot_id
      AND t.test_id = r.test_id
      AND plt.plate_id (+) = a.plate_id
      AND sdu.u_abs_determination = ad.determination_assignment
      AND a.status IN ('V','P','C')
      AND r.name = 'End result'
      AND sdu.u_client_type = 'QC'
      AND sdu.u_year_of_sample_delivery = (:year)
      AND sdu.u_week_of_processing = (:week)
      AND decode(:cropcode,-1,'-1',sdu.u_crop_group) = decode(:cropcode,-1,'-1',:cropcode)
    ORDER BY box_code, box_position, replicate_number
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.01       0.00          0          0          0           0
    Execute      1      0.45       0.87          0          0          0           0
    Fetch        1      1.00       0.99          0     221420          0         500
    total        3      1.46       1.86          0     221420          0         500
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 97 
    Rows     Row Source Operation
        500  SORT ORDER BY (cr=221420 pr=0 pw=0 time=992364 us)
      21311   FILTER  (cr=221420 pr=0 pw=0 time=1128970 us)
      21311    TABLE ACCESS BY INDEX ROWID RESULT (cr=221420 pr=0 pw=0 time=1086345 us)
      42623     NESTED LOOPS  (cr=217549 pr=0 pw=0 time=30006317 us)
      21311      NESTED LOOPS  (cr=174880 pr=0 pw=0 time=809278 us)
      21311       NESTED LOOPS  (cr=110117 pr=0 pw=0 time=553538 us)
      21311        HASH JOIN OUTER (cr=46182 pr=0 pw=0 time=319102 us)
      21311         TABLE ACCESS BY INDEX ROWID ALIQUOT (cr=45866 pr=0 pw=0 time=193037 us)
      29088          NESTED LOOPS  (cr=39885 pr=0 pw=0 time=320084 us)
       7776           NESTED LOOPS  (cr=24267 pr=0 pw=0 time=156721 us)
       7776            NESTED LOOPS  (cr=937 pr=0 pw=0 time=78954 us)
         99             NESTED LOOPS  (cr=454 pr=0 pw=0 time=3826 us)
         99              NESTED LOOPS  (cr=253 pr=0 pw=0 time=2833 us)
         99               TABLE ACCESS FULL SDG_USER (cr=53 pr=0 pw=0 time=1531 us)
         99               TABLE ACCESS BY INDEX ROWID DWH_ABS_DETERMINATION (cr=200 pr=0 pw=0 time=956 us)
         99                INDEX UNIQUE SCAN PK_DWH_ABS_DETERMINATION (cr=101 pr=0 pw=0 time=438 us)(object id 46965)
         99              TABLE ACCESS BY INDEX ROWID SDG (cr=201 pr=0 pw=0 time=707 us)
         99               INDEX UNIQUE SCAN PK_SDG (cr=101 pr=0 pw=0 time=330 us)(object id 46071)
       7776             TABLE ACCESS BY INDEX ROWID SAMPLE (cr=483 pr=0 pw=0 time=16261 us)
       7776              INDEX RANGE SCAN FK_SAMPLE_SDG (cr=217 pr=0 pw=0 time=562 us)(object id 45990)
       7776            TABLE ACCESS BY INDEX ROWID SAMPLE_USER (cr=23330 pr=0 pw=0 time=64710 us)
       7776             INDEX UNIQUE SCAN PK_SAMPLE_USER (cr=15554 pr=0 pw=0 time=33728 us)(object id 46012)
      21311           INDEX RANGE SCAN FK_ALIQUOT_SAMPLE (cr=15618 pr=0 pw=0 time=43423 us)(object id 45346)
      21895         VIEW  PLATE (cr=316 pr=0 pw=0 time=43833 us)
      21895          FILTER  (cr=316 pr=0 pw=0 time=21936 us)
      21895           TABLE ACCESS FULL PLATE (cr=316 pr=0 pw=0 time=37 us)
          0           INDEX UNIQUE SCAN PK_OPERATOR_GROUP (cr=0 pr=0 pw=0 time=0 us)(object id 45769)
      21311        TABLE ACCESS BY INDEX ROWID ALIQUOT_USER (cr=63935 pr=0 pw=0 time=182479 us)
      21311         INDEX UNIQUE SCAN PK_ALIQUOT_USER (cr=42624 pr=0 pw=0 time=99160 us)(object id 45386)
      21311       TABLE ACCESS BY INDEX ROWID TEST (cr=64763 pr=0 pw=0 time=219096 us)
      21311        INDEX RANGE SCAN FK_TEST_ALIQUOT (cr=42669 pr=0 pw=0 time=129354 us)(object id 46222)
      21311      INDEX RANGE SCAN FK_RESULT_TEST (cr=42669 pr=0 pw=0 time=125893 us)(object id 45940)
          0    INDEX UNIQUE SCAN PK_OPERATOR_GROUP (cr=0 pr=0 pw=0 time=0 us)(object id 45769)
          0    INDEX UNIQUE SCAN PK_OPERATOR_GROUP (cr=0 pr=0 pw=0 time=0 us)(object id 45769)
          0    INDEX UNIQUE SCAN PK_OPERATOR_GROUP (cr=0 pr=0 pw=0 time=0 us)(object id 45769)
          0    INDEX UNIQUE SCAN PK_OPERATOR_GROUP (cr=0 pr=0 pw=0 time=0 us)(object id 45769)
    select 'x'
    from
    dual
    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      0.00       0.00          0          0          0           1
    total        3      0.00       0.00          0          0          0           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 97 
    Rows     Row Source Operation
          1  FAST DUAL  (cr=0 pr=0 pw=0 time=6 us)
    begin :id := sys.dbms_transaction.local_transaction_id; end;
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          2           0
    Execute      1      0.00       0.00          0          0          0           1
    Fetch        0      0.00       0.00          0          0          0           0
    total        2      0.00       0.00          0          0          2           1
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 97 
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        3      0.01       0.00          0          0          2           0
    Execute      3      0.45       0.87          0          0          0           1
    Fetch        2      1.00       0.99          0     221420          0         501
    total        8      1.46       1.87          0     221420          2         502
    Misses in library cache during parse: 2
    Misses in library cache during execute: 2
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse       43      0.01       0.00          0          0         12           0
    Execute    128      0.00       0.01          0          0          0           0
    Fetch      178      0.00       0.00          0        383          0         465
    total      349      0.01       0.02          0        383         12         465
    Misses in library cache during parse: 5
    Misses in library cache during execute: 5
        3  user  SQL statements in session.
      128  internal SQL statements in session.
      131  SQL statements in session.
    Trace file: C:\oracle\product\10.2.0\admin\nautp02\udump\nautp02_ora_5456.trc
    Trace file compatibility: 10.01.00
    Sort options: default
           1  session in tracefile.
           3  user  SQL statements in trace file.
         128  internal SQL statements in trace file.
         131  SQL statements in trace file.
          19  unique SQL statements in trace file.
        1352  lines in trace file.
         287  elapsed seconds in trace file.

  • Oem explain plan produced doesn't correspond to explain plan with tkprof

    Hello all,
    I am running OEM on a 10.2.0.3 database and I have a very slow query with cognos 8 BI on my data warehouse.
    I went to the dbconsole through OEM and connected to target database I went to look at the query execution and then got an explain plan.
    Then I did a trace file and ran it throught tkprof.
    When I look at both produced explain plan, I can see the tree looks the same exept the corresponding values. In OEM, it says I am going throug 18000 rows and in the tkprof result it says more like millions of records.
    As anybody had these kind of results?
    Shall I have more confidence in TKprof then OEM?
    It is very important to me since I am being chalanged by an external DBA.

    I would recommend you to get Christian Antogini´s book "Troublshooting Oracle Performance", (http://www.antognini.ch/top/) which explains everything you need to know when analyzing Oracle SQL Performance and Explain Plans.
    If you properly trace your SQL Statement, you will get "STAT" lines in the trace file. These stat lines show you the actual number of rows processed per row source operation. Explain plan per default does only show you the "estimated" row counts for the row source operations no matter whether you use "explain=" in the tkprof call or OEM to get the explain plan. Tkprof reads the STAT lines from the trace and outputs a section which is similar to an execution plan but contains the "real" number of rows.
    However, if you want to troubleshoot Oracle Performance, I would recommend you to run the statement with the hint /*+ GATHER_PLAN_STATISTICS */ or set statistics_level=ALL in your session (not database-wide!).
    If you do, you can get an excellent execution plan with DBMS_XPLAN.DISPLAY_CURSOR containing both estimated rows as well as actual rows combined with the "number of starts" for e.g. nested loop joins.
    Get the book, read it, and you will be able to discuss this issue with your external dba in a professional way. ;-)
    Regards,
    Martin
    www.ora-solutions.net

  • Time column of an explain plan

    Hi,
    I'm using Oracle version 10.2.0.3.0. I have 2 tables with 10 million records each. The DDL is as follows.
    create table bigtable(col1 varchar2(20), col2 varchar2(20))
    create table bigtablechild(col1 varchar2(20), col2 varchar(20))
    bigtablechild.col1 is a foreign key to bigtable.col1. Below is the query and explain plan. Over several executions, the query runs for about 20 seconds before returning results. Could anyone please explain what the time column represents? It doesn't match the time it took to return results.
    SQL> set autotrace on
    SQL>
    SQL> select b.col2
      2  from bigtable a, bigtablechild b
      3  where a.col1 = b.col1
      4  and a.col1 = 'ABC6554';
    COL2
    XYZ6554
    XYZ6554
    XYZ6554
    XYZ6554
    XYZ6554
    Execution Plan
    Plan hash value: 4210396901
    | Id  | Operation          | Name          | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |               |     5 |   150 | 21538   (4)| 00:04:19 |
    |*  1 |  HASH JOIN         |               |     5 |   150 | 21538   (4)| 00:04:19 |
    |*  2 |   TABLE ACCESS FULL| BIGTABLE      |     1 |    10 | 13124   (4)| 00:02:38 |
    |*  3 |   TABLE ACCESS FULL| BIGTABLECHILD |     5 |   100 |  8413   (5)| 00:01:41 |
    Predicate Information (identified by operation id):
       1 - access("A"."COL1"="B"."COL1")
       2 - filter("A"."COL1"='ABC6554')
       3 - filter("B"."COL1"='ABC6554')
    Statistics
              0  recursive calls
              0  db block gets
          93672  consistent gets
          91845  physical reads
              0  redo size
            463  bytes sent via SQL*Net to client
            396  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              5  rows processed

    Hi,
    the values in the TIME column are calculated from cost using system I/O statistics. If dbms_stats.gather_system_stats has never been run, then these stats have default values which may be very far from the truth. In your case, the optimizer expects a single-block I/O read to take about 12 ms, while in reality it is closer to 1 ms, thus the discrepancy between the prediction and actual results.
    In general, TIME column is not very helpful not just because of potentially incorrect I/O time estimates, but also because it is hard to predict how much data will be found in cash, so I would recommend not to pay too much attention to it (note, however, that A-time column, on the other hand, is extremely useful, but it's only available if rowsource statistics for the plan have been populated).
    Best regards,
    Nikolay

  • Help in interpreting the output of explain plan

    Hi,
    I have written a query in two different ways and then run an explain plan on both of them. Both these queries give same result. I want to know which one will be more efficient. I am giving the output of explain plan for both the queries:
    The second plan has a lower cost but has much higher consistent gets !!
    Please advise.
    Plan 1:
    Execution Plan
       0      SELECT STATEMENT Optimizer=HINT: FIRST_ROWS (Cost=8637 Card= 1 Bytes=10132)
       1    0   SORT (ORDER BY) (Cost=8637 Card=1 Bytes=10132)
       2    1     WINDOW (SORT) (Cost=8637 Card=1 Bytes=10132)
       3    2       COUNT (STOPKEY)
       4    3         VIEW (Cost=8635 Card=1 Bytes=10132)
       5    4           SORT (ORDER BY) (Cost=8635 Card=1 Bytes=862)
       6    5             WINDOW (SORT) (Cost=8635 Card=1 Bytes=862)
       7    6               MAT_VIEW ACCESS (FULL) OF 'PRD_SEARCH_MVW' (MAT_VIEW) (Cost=8633 Card=1 Bytes=862)
    Statistics
            577  recursive calls
              0  db block gets
          39202  consistent gets
          34798  physical reads
              0  redo size
          72348  bytes sent via SQL*Net to client
           4295  bytes received via SQL*Net from client
              9  SQL*Net roundtrips to/from client
             10  sorts (memory)
              0  sorts (disk)
            100  rows processed
    Plan-2
    Execution Plan
       0      SELECT STATEMENT Optimizer=HINT: FIRST_ROWS (Cost=982 Card=1 Bytes=10145)
       1    0   SORT (ORDER BY) (Cost=982 Card=1 Bytes=10145)
       2    1     WINDOW (SORT) (Cost=982 Card=1 Bytes=10145)
       3    2       COUNT (STOPKEY)
       4    3         VIEW (Cost=980 Card=1 Bytes=10145)
       5    4           SORT (ORDER BY) (Cost=980 Card=1 Bytes=10132)
       6    5             WINDOW (SORT) (Cost=980 Card=1 Bytes=10132)
       7    6               WINDOW (SORT) (Cost=980 Card=1 Bytes=10132)
       8    7                 VIEW (Cost=977 Card=1 Bytes=10132)
       9    8                   WINDOW (SORT PUSHED RANK) (Cost=977 Card=1 Bytes=889)
      10    9                     NESTED LOOPS (Cost=976 Card=1 Bytes=889)
      11   10                       HASH JOIN (Cost=305 Card=670 Bytes=18090)
      12   11                         HASH JOIN (Cost=23 Card=140 Bytes=2240)
      13   12                           INDEX (FAST FULL SCAN) OF 'GLCAT_GRP_TO_CAT_PK' (INDEX (UNIQUE)) (Cost=2 Card=52 Bytes=364)
      14   12                           MAT_VIEW ACCESS (FULL) OF 'GLCAT_CAT_TO_MCAT' (MAT_VIEW) (Cost=20 Card=1039 Bytes=9351)
      15   11                         INDEX (FAST FULL SCAN) OF 'PCITEM2GLCATMCAT_FK_IDS' (INDEX) (Cost=281 Card=16903 Bytes=185933)
      16   10                       MAT_VIEW ACCESS (BY INDEX ROWID) OF 'PRD_SEARCH_MVW' (MAT_VIEW) (Cost=1 Card=1 Bytes=862)
      17   16                         INDEX (UNIQUE SCAN) OF 'PK_PRD_SEARCH_ID' (INDEX (UNIQUE)) (Cost=0 Card=1)
    Statistics
            481    recursive calls
              2      db block gets
         195742  consistent gets
           7516  physical reads
              0  redo size
          71567  bytes sent via SQL*Net to client
           6629  bytes received via SQL*Net from client
              9  SQL*Net roundtrips to/from client
             15  sorts (memory)
              1  sorts (disk)
            100  rows processedRegards
    Madhup
    Message was edited by:
    Madhup

    Thanks a lot for you input. I am posting both the queries below. My requirements are following:
    1) I have a products table
    2) I have Created grouping hierarchy - Groups, Categories and then Micro-categories - and have setup a separate table for each of them in my database
    3) Then I have mapping tables, i.e. a table that stores group to category mapping, another table that stores category to micro-category mapping.
    4) Products are mapped directly to micro-categories and one product could be mapped to multiple micro-categories.
    5) I have created a materialized view on product and store the mappings as comma separated list of IDs - I have three fields there, on to store comma separated group id, second to store comma separated category ids and third to store the comma separated micro category ids to which the product is mapped.
    Now I want to write a query that will return a specified number of matches from this table based on user defined criterion. There are few other filter cirterion apart from Group/Category and Microcategory. These are Company Name, Country, Type of company etc.
    This query when run on production will be accessed very frequently - I expect the access to be in the tune of around 5-10 times per second.
    There are 50 records in the group table
    There are 500 categories
    There are 20000 micro-categories
    Group to category mapping table has around 1000 records
    Category to microcategory table has around 25000 records
    The product table has around 100,000 products.
    Product to microcategory mapping table has 350000 records
    The product mview has the same number of records as that in products table.
    The first query uses the single materialized view to access data, however, it always does a full table scan and does not use any index.
    When I noticed this in the explain plan, then I tried to write the second query which is using JOINs to arrive at the same output.
    The explain plan now says that it is using Index scans.
    I did a sample run of both the queries on my production system and I had to withdraw both of them as both brought my system to grinding halt within few minutes of going live.
    My system at present receives around 3000 requests per hour during peak load and around 600 requests per hour during off-peak hours.
    And I was testing these queries in Off-peak hours !!
    Here are the two sql queries just for reference - there are several variables plugged in where clause which are the key drivers of the query:
    SQL-1
    SELECT DECODE(:OPT,2,A.SC,(MAX(A.SC) OVER (PARTITION BY A.PRD_SEARCH_COMPANY))) AS SO,
         A.SC,                           A.PRD_SEARCH_ID,
         A.PRD_SEARCH_COMPANY_ID,        A.PRD_SEARCH_COMPANY,            A.PRD_SEARCH_COMPANYID_ENCRYPTED,
         A.PRD_SEARCH_PCID,              A.PRD_SEARCH_URL,                A.PRD_SEARCH_PC_CLNT_HOME,
         A.PRD_SEARCH_CLNT_ENABLED,      A.PRD_SEARCH_CODE,               A.PRD_SEARCH_NAME,
         A.PRD_SEARCH_DESC_SMALL,        A.PRD_SEARCH_DESC_DETAILED,      A.PRD_SEARCH_DESC_HTML,
         A.PRD_SEARCH_IMG_SMALL,         A.PRD_SEARCH_IMG_LARGE,          A.PRD_SEARCH_WEIGHT_ITEM,
         A.PRD_SEARCH_MODIFIEDDATE,      A.PRD_SEARCH_SIZE,               A.PRD_SEARCH_LABEL1,
         A.PRD_SEARCH_LABEL1_VALUE,      A.PRD_SEARCH_LABEL2,             A.PRD_SEARCH_LABEL2_VALUE,
         A.PRD_SEARCH_LABEL3,            A.PRD_SEARCH_LABEL3_VALUE,       A.PRD_SEARCH_LABEL4,
         A.PRD_SEARCH_LABEL4_VALUE,      A.PRD_SEARCH_LABEL5,             A.PRD_SEARCH_LABEL5_VALUE,
         A.PRD_SEARCH_LABEL6,            A.PRD_SEARCH_LABEL6_VALUE,       A.PRD_SEARCH_CAT_ID,
         A.PRD_SEARCH_CAT_NAME,          A.PRD_SEARCH_CAT_FLNAME,         A.PRD_SEARCH_NAVIGATION_TREE,
         A.PRD_SEARCH_NAVIGATION_TREE_ID,A.PRD_SEARCH_CITY,               A.PRD_SEARCH_STATE,
         A.PRD_SEARCH_COUNTRY,           A.PRD_SEARCH_PRICE_SALE,         A.PRD_SEARCH_PC_CLNT_TYPE,
         A.PRD_SEARCH_PC_CLNT_TYPE_DESC,
         A.PRD_SEARCH_COMPANY_PHONE,     A.PRD_SEARCH_COMPANY_MOBILE,     A.PRD_SEARCH_COMPANY_FAX,
         A.PRD_SEARCH_COMPANY_EMAIL,     A.PRD_SEARCH_GLCAT_MCAT_ID_LIST, A.PRD_SEARCH_GLCAT_CAT_ID_LIST,
         A.PRD_SEARCH_GLCAT_GRP_ID_LIST, A.PRD_SEARCH_GL_COUNTRY_ISO,     A.PRD_SEARCH_GLUSR_USR_ID,
         A.PRD_SEARCH_TRUSTSEAL_CODE,    A.PRD_SEARCH_CUSTTYPE_ID,        A.PRD_SEARCH_CUSTTYPE_NAME,
         A.PRD_SEARCH_CUSTTYPE_WEIGHT,   A.PRD_SEARCH_CUSTTYPE_WEIGHT_TZ, A.PRD_SEARCH_CUSTTYPE_RANK,
         A.PRD_SEARCH_PC_ITEM_HOTNEW,    A.RK
         FROM
              (SELECT  /*+ FIRST_ROWS (500) */     DECODE(:S_MODE,2,1,3,to_number(to_char(PRD_SEARCH_MODIFIEDDATE,'yyyymmdd')),1) AS SC,
              PRD_SEARCH_ID,
              PRD_SEARCH_COMPANY_ID,        PRD_SEARCH_COMPANY,            PRD_SEARCH_COMPANYID_ENCRYPTED,
              PRD_SEARCH_PCID,              PRD_SEARCH_URL,                PRD_SEARCH_PC_CLNT_HOME,
              PRD_SEARCH_CLNT_ENABLED,      PRD_SEARCH_CODE,               PRD_SEARCH_NAME,
              PRD_SEARCH_DESC_SMALL,        PRD_SEARCH_DESC_DETAILED,      PRD_SEARCH_DESC_HTML,
              PRD_SEARCH_IMG_SMALL,         PRD_SEARCH_IMG_LARGE,          PRD_SEARCH_WEIGHT_ITEM,
              PRD_SEARCH_MODIFIEDDATE,      PRD_SEARCH_SIZE,               PRD_SEARCH_LABEL1,
              PRD_SEARCH_LABEL1_VALUE,      PRD_SEARCH_LABEL2,             PRD_SEARCH_LABEL2_VALUE,
              PRD_SEARCH_LABEL3,            PRD_SEARCH_LABEL3_VALUE,       PRD_SEARCH_LABEL4,
              PRD_SEARCH_LABEL4_VALUE,      PRD_SEARCH_LABEL5,             PRD_SEARCH_LABEL5_VALUE,
              PRD_SEARCH_LABEL6,            PRD_SEARCH_LABEL6_VALUE,       PRD_SEARCH_CAT_ID,
              PRD_SEARCH_CAT_NAME,          PRD_SEARCH_CAT_FLNAME,         PRD_SEARCH_NAVIGATION_TREE,
              PRD_SEARCH_NAVIGATION_TREE_ID,PRD_SEARCH_CITY,               PRD_SEARCH_STATE,
              PRD_SEARCH_COUNTRY,           PRD_SEARCH_PRICE_SALE,         PRD_SEARCH_PC_CLNT_TYPE,
              PRD_SEARCH_PC_CLNT_TYPE_DESC,
              PRD_SEARCH_COMPANY_PHONE,     PRD_SEARCH_COMPANY_MOBILE,     PRD_SEARCH_COMPANY_FAX,
              PRD_SEARCH_COMPANY_EMAIL,     PRD_SEARCH_GLCAT_MCAT_ID_LIST, PRD_SEARCH_GLCAT_CAT_ID_LIST,
              PRD_SEARCH_GLCAT_GRP_ID_LIST, PRD_SEARCH_GL_COUNTRY_ISO,     PRD_SEARCH_GLUSR_USR_ID,
              PRD_SEARCH_TRUSTSEAL_CODE,    PRD_SEARCH_CUSTTYPE_ID,        PRD_SEARCH_CUSTTYPE_NAME,
              PRD_SEARCH_CUSTTYPE_WEIGHT,   PRD_SEARCH_CUSTTYPE_WEIGHT_TZ, PRD_SEARCH_CUSTTYPE_RANK,
              PRD_SEARCH_PC_ITEM_HOTNEW,
              ROW_NUMBER() OVER (PARTITION BY PRD_SEARCH_COMPANY_ID
                                  ORDER BY DECODE(:S_MODE,2,1,3,to_number(to_char(PRD_SEARCH_MODIFIEDDATE,'yyyymmdd')),1) DESC) AS RK
              FROM      PRD_SEARCH
              WHERE     DECODE(:GRP_ID_STR,NULL,1,REGEXP_INSTR(','||REPLACE(PRD_SEARCH_GLCAT_GRP_ID_LIST,' ','')||',',:MYGRP_ID_STR)) > 0
              AND       DECODE(:CAT_ID_STR,NULL,1,REGEXP_INSTR(','||REPLACE(PRD_SEARCH_GLCAT_CAT_ID_LIST,' ','')||',',:MYCAT_ID_STR)) > 0
              AND       DECODE(:MCAT_ID_STR,NULL,1,REGEXP_INSTR(','||REPLACE(PRD_SEARCH_GLCAT_MCAT_ID_LIST,' ','')||',',:MYMCAT_ID_STR)) > 0
              AND       DECODE(:ITEM_ID_STR,NULL,1,REGEXP_INSTR(','||PRD_SEARCH_ID||',',:MYITEM_ID_STR)) > 0
              AND       DECODE(:COUNTRY_ISO,NULL,1,REGEXP_INSTR(','||PRD_SEARCH_GL_COUNTRY_ISO||',',:COUNTRY_ISO)) > 0
              AND       DECODE(nvl(NULL,0),0,1,PRD_SEARCH_COMPANY_ID) = DECODE(nvl(NULL,0),0,1,NULL)
              AND       DECODE(nvl(NULL,0),0,1,PRD_SEARCH_GLUSR_USR_ID) = DECODE(nvl(NULL,0),0,1,NULL)
              AND       PRD_SEARCH_CLNT_ENABLED >= nvl(:LIST_TYPE,0)
              AND       NVL(Length(PRD_SEARCH_TRUSTSEAL_CODE),0) >= :TSONLY
              ORDER BY SC DESC, PRD_SEARCH_CUSTTYPE_WEIGHT ASC, DBMS_RANDOM.RANDOM
              )  A
    WHERE A.RK <= :MY_PRD_PER_COMP
    AND   ROWNUM <= :MYMAXREC
    ORDER BY SO DESC, DECODE(:OPT,2,'1',A.PRD_SEARCH_COMPANY), A.RK ASC, DBMS_RANDOM.RANDOM
    SQL-2
         SELECT
              DECODE(:OPT,2,SC,(MAX(SC) OVER (PARTITION BY PRD_SEARCH_COMPANY))) AS SO,
              SC,                           PRD_SEARCH_ID,
              PRD_SEARCH_COMPANY_ID,        PRD_SEARCH_COMPANY,            PRD_SEARCH_COMPANYID_ENCRYPTED,
              PRD_SEARCH_PCID,              PRD_SEARCH_URL,                PRD_SEARCH_PC_CLNT_HOME,
              PRD_SEARCH_CLNT_ENABLED,      PRD_SEARCH_CODE,               PRD_SEARCH_NAME,
              PRD_SEARCH_DESC_SMALL,        PRD_SEARCH_DESC_DETAILED,      PRD_SEARCH_DESC_HTML,
              PRD_SEARCH_IMG_SMALL,         PRD_SEARCH_IMG_LARGE,          PRD_SEARCH_WEIGHT_ITEM,
              PRD_SEARCH_MODIFIEDDATE,      PRD_SEARCH_SIZE,               PRD_SEARCH_LABEL1,
              PRD_SEARCH_LABEL1_VALUE,      PRD_SEARCH_LABEL2,             PRD_SEARCH_LABEL2_VALUE,
              PRD_SEARCH_LABEL3,            PRD_SEARCH_LABEL3_VALUE,       PRD_SEARCH_LABEL4,
              PRD_SEARCH_LABEL4_VALUE,      PRD_SEARCH_LABEL5,             PRD_SEARCH_LABEL5_VALUE,
              PRD_SEARCH_LABEL6,            PRD_SEARCH_LABEL6_VALUE,       PRD_SEARCH_CAT_ID,
              PRD_SEARCH_CAT_NAME,          PRD_SEARCH_CAT_FLNAME,         PRD_SEARCH_NAVIGATION_TREE,
              PRD_SEARCH_NAVIGATION_TREE_ID,PRD_SEARCH_CITY,               PRD_SEARCH_STATE,
              PRD_SEARCH_COUNTRY,           PRD_SEARCH_PRICE_SALE,         PRD_SEARCH_PC_CLNT_TYPE,
              PRD_SEARCH_PC_CLNT_TYPE_DESC,
              PRD_SEARCH_COMPANY_PHONE,     PRD_SEARCH_COMPANY_MOBILE,     PRD_SEARCH_COMPANY_FAX,
              PRD_SEARCH_COMPANY_EMAIL,     PRD_SEARCH_GLCAT_MCAT_ID_LIST, PRD_SEARCH_GLCAT_CAT_ID_LIST,
              PRD_SEARCH_GLCAT_GRP_ID_LIST, PRD_SEARCH_GL_COUNTRY_ISO,     PRD_SEARCH_GLUSR_USR_ID,
              PRD_SEARCH_TRUSTSEAL_CODE,    PRD_SEARCH_CUSTTYPE_ID,        PRD_SEARCH_CUSTTYPE_NAME,
              PRD_SEARCH_CUSTTYPE_WEIGHT,   PRD_SEARCH_CUSTTYPE_WEIGHT_TZ, PRD_SEARCH_CUSTTYPE_RANK,
              PRD_SEARCH_PC_ITEM_HOTNEW,    RK
         FROM
                   SELECT
                        /*+ FIRST_ROWS (500) */ DECODE(:OPT,2,SC,(MAX(SC) OVER (PARTITION BY PRD_SEARCH_COMPANY))) AS SO,
                        SC,PRD_SEARCH_ID,
                        PRD_SEARCH_COMPANY_ID,        PRD_SEARCH_COMPANY,            PRD_SEARCH_COMPANYID_ENCRYPTED,
                        PRD_SEARCH_PCID,              PRD_SEARCH_URL,                PRD_SEARCH_PC_CLNT_HOME,
                        PRD_SEARCH_CLNT_ENABLED,      PRD_SEARCH_CODE,               PRD_SEARCH_NAME,
                        PRD_SEARCH_DESC_SMALL,        PRD_SEARCH_DESC_DETAILED,      PRD_SEARCH_DESC_HTML,
                        PRD_SEARCH_IMG_SMALL,         PRD_SEARCH_IMG_LARGE,          PRD_SEARCH_WEIGHT_ITEM,
                        PRD_SEARCH_MODIFIEDDATE,      PRD_SEARCH_SIZE,               PRD_SEARCH_LABEL1,
                        PRD_SEARCH_LABEL1_VALUE,      PRD_SEARCH_LABEL2,             PRD_SEARCH_LABEL2_VALUE,
                        PRD_SEARCH_LABEL3,            PRD_SEARCH_LABEL3_VALUE,       PRD_SEARCH_LABEL4,
                        PRD_SEARCH_LABEL4_VALUE,      PRD_SEARCH_LABEL5,             PRD_SEARCH_LABEL5_VALUE,
                        PRD_SEARCH_LABEL6,            PRD_SEARCH_LABEL6_VALUE,       PRD_SEARCH_CAT_ID,
                        PRD_SEARCH_CAT_NAME,          PRD_SEARCH_CAT_FLNAME,         PRD_SEARCH_NAVIGATION_TREE,
                        PRD_SEARCH_NAVIGATION_TREE_ID,PRD_SEARCH_CITY,               PRD_SEARCH_STATE,
                        PRD_SEARCH_COUNTRY,           PRD_SEARCH_PRICE_SALE,         PRD_SEARCH_PC_CLNT_TYPE,
                        PRD_SEARCH_PC_CLNT_TYPE_DESC,
                        PRD_SEARCH_COMPANY_PHONE,     PRD_SEARCH_COMPANY_MOBILE,     PRD_SEARCH_COMPANY_FAX,
                        PRD_SEARCH_COMPANY_EMAIL,     PRD_SEARCH_GLCAT_MCAT_ID_LIST, PRD_SEARCH_GLCAT_CAT_ID_LIST,
                        PRD_SEARCH_GLCAT_GRP_ID_LIST, PRD_SEARCH_GL_COUNTRY_ISO,     PRD_SEARCH_GLUSR_USR_ID,
                        PRD_SEARCH_TRUSTSEAL_CODE,    PRD_SEARCH_CUSTTYPE_ID,        PRD_SEARCH_CUSTTYPE_NAME,
                        PRD_SEARCH_CUSTTYPE_WEIGHT,   PRD_SEARCH_CUSTTYPE_WEIGHT_TZ, PRD_SEARCH_CUSTTYPE_RANK,
                        PRD_SEARCH_PC_ITEM_HOTNEW,
                        ROW_NUMBER() OVER (PARTITION BY PRD_SEARCH_COMPANY_ID
                                  ORDER BY DECODE(:S_MODE,2,1,3,TO_NUMBER(TO_CHAR(PRD_SEARCH_MODIFIEDDATE,'YYYYMMDD')),1) DESC) AS RK
                   FROM
                             SELECT
                                  DECODE(:S_MODE,2,1,3,TO_NUMBER(TO_CHAR(PRD_SEARCH_MODIFIEDDATE,'YYYYMMDD')),1) AS SC,
                                  PRD_SEARCH_ID,
                                  PRD_SEARCH_COMPANY_ID,        PRD_SEARCH_COMPANY,            PRD_SEARCH_COMPANYID_ENCRYPTED,
                                  PRD_SEARCH_PCID,              PRD_SEARCH_URL,                PRD_SEARCH_PC_CLNT_HOME,
                                  PRD_SEARCH_CLNT_ENABLED,      PRD_SEARCH_CODE,               PRD_SEARCH_NAME,
                                  PRD_SEARCH_DESC_SMALL,        PRD_SEARCH_DESC_DETAILED,      PRD_SEARCH_DESC_HTML,
                                  PRD_SEARCH_IMG_SMALL,         PRD_SEARCH_IMG_LARGE,          PRD_SEARCH_WEIGHT_ITEM,
                                  PRD_SEARCH_MODIFIEDDATE,      PRD_SEARCH_SIZE,               PRD_SEARCH_LABEL1,
                                  PRD_SEARCH_LABEL1_VALUE,      PRD_SEARCH_LABEL2,             PRD_SEARCH_LABEL2_VALUE,
                                  PRD_SEARCH_LABEL3,            PRD_SEARCH_LABEL3_VALUE,       PRD_SEARCH_LABEL4,
                                  PRD_SEARCH_LABEL4_VALUE,      PRD_SEARCH_LABEL5,             PRD_SEARCH_LABEL5_VALUE,
                                  PRD_SEARCH_LABEL6,            PRD_SEARCH_LABEL6_VALUE,       PRD_SEARCH_CAT_ID,
                                  PRD_SEARCH_CAT_NAME,          PRD_SEARCH_CAT_FLNAME,         PRD_SEARCH_NAVIGATION_TREE,
                                  PRD_SEARCH_NAVIGATION_TREE_ID,PRD_SEARCH_CITY,               PRD_SEARCH_STATE,
                                  PRD_SEARCH_COUNTRY,           PRD_SEARCH_PRICE_SALE,         PRD_SEARCH_PC_CLNT_TYPE,
                                  PRD_SEARCH_PC_CLNT_TYPE_DESC,
                                  PRD_SEARCH_COMPANY_PHONE,     PRD_SEARCH_COMPANY_MOBILE,     PRD_SEARCH_COMPANY_FAX,
                                  PRD_SEARCH_COMPANY_EMAIL,     PRD_SEARCH_GLCAT_MCAT_ID_LIST, PRD_SEARCH_GLCAT_CAT_ID_LIST,
                                  PRD_SEARCH_GLCAT_GRP_ID_LIST, PRD_SEARCH_GL_COUNTRY_ISO,     PRD_SEARCH_GLUSR_USR_ID,
                                  PRD_SEARCH_TRUSTSEAL_CODE,    PRD_SEARCH_CUSTTYPE_ID,        PRD_SEARCH_CUSTTYPE_NAME,
                                  PRD_SEARCH_CUSTTYPE_WEIGHT,   PRD_SEARCH_CUSTTYPE_WEIGHT_TZ, PRD_SEARCH_CUSTTYPE_RANK,
                                  PRD_SEARCH_PC_ITEM_HOTNEW,
                                  ROW_NUMBER() OVER (PARTITION BY P.PRD_SEARCH_ID ORDER BY P.PRD_SEARCH_ID) RK1
                             FROM
                                  GLCAT_GRP_TO_CAT G2C, GLCAT_CAT_TO_MCAT C2M, PC_ITEM_TO_GLCAT_MCAT M, PRD_SEARCH P
                             WHERE
                                  G2C.FK_GLCAT_CAT_ID = C2M.FK_GLCAT_CAT_ID
                                  AND C2M.FK_GLCAT_MCAT_ID = M.FK_GLCAT_MCAT_ID
                                  AND M.FK_PC_ITEM_ID = P.PRD_SEARCH_ID
                                  AND DECODE(:MCAT_ID_STR, NULL, 1, INSTR(','||:MCAT_ID_STR||',',','||M.FK_GLCAT_MCAT_ID||',',1))> 0
                                  AND DECODE(:CAT_ID_STR, NULL, 1, INSTR(','||:CAT_ID_STR||',',','||C2M.FK_GLCAT_CAT_ID||',',1)) > 0
                                  AND DECODE(:GRP_ID_STR, NULL, 1, INSTR(','||:GRP_ID_STR||',',','||G2C.FK_GLCAT_GRP_ID||',',1)) > 0
                                  AND DECODE(:ITEM_ID_STR,NULL,1,INSTR(','||:ITEM_ID_STR||',' , ','||P.PRD_SEARCH_ID||',')) > 0
                                  AND DECODE(:COUNTRY_ISO,NULL,1,INSTR(','||:COUNTRY_ISO||',', ','||P.PRD_SEARCH_GL_COUNTRY_ISO||',')) > 0
                                  AND DECODE(NVL(:COMPANY_ID,0),0,1,P.PRD_SEARCH_COMPANY_ID) = DECODE(NVL(:COMPANY_ID,0),0,1,:COMPANY_ID)
                                  AND DECODE(NVL(:GLUSR_ID,0),0,1,P.PRD_SEARCH_GLUSR_USR_ID) = DECODE(NVL(:GLUSR_ID,0),0,1,:GLUSR_ID)
                                  AND P.PRD_SEARCH_CLNT_ENABLED >= NVL(:LIST_TYPE,0)
                                  AND NVL(LENGTH(P.PRD_SEARCH_TRUSTSEAL_CODE),0) >= :TSONLY
                   WHERE RK1=1
                   ORDER BY SC DESC, PRD_SEARCH_CUSTTYPE_WEIGHT ASC, DBMS_RANDOM.RANDOM
              ) A
         WHERE A.RK <= :MY_PRD_PER_COMP
         AND   ROWNUM <= :MYMAXREC
         ORDER BY A.SO DESC, DECODE(:OPT,2,'1', A.PRD_SEARCH_COMPANY), A.RK ASC, DBMS_RANDOM.RANDOMRegards
    Madhup

  • Explain plan shows 300T of TempSpc and 999 hours - tuning request

    Hi,
    I have a query which obtains summary statistics. There is an items table which contains the dictionary of items which can be recorded. There is an events table which contains the item ID, timestamp and a value. The query summarizes the data for each item. e.g. Mean, stddev, sample values, length. I have trimmed the query down as simply as possible and am having a problem with large temp space and runtime estimates in the explain plan. Here is the query:
    WITH ChartItems AS (
        SELECT
          ci.itemid,
          ci.label,
          ci.category,
          ci.description,
          COUNT(*),
          COUNT(distinct subject_id)
        FROM mimic2v26.d_chartitems ci
        JOIN mimic2v26.chartevents ce ON ce.itemid = ci.itemid
        --WHERE ci.itemid = 51
        GROUP BY ci.itemid,
                 ci.label,
                 ci.category,
                 ci.description
    --select * from ChartItems;
    , RawData AS (
        SELECT DISTINCT
          ci.itemid,
          ci.label,
          ci.category,
          ci.description,
          last_value(ce.value1) ignore nulls over (partition BY ci.itemid order by
          ce.charttime ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS
          value1_last
        FROM ChartItems ci
        JOIN mimic2v26.chartevents ce ON ce.itemid = ci.itemid
    select * from RawData;Which gives this explain plan:
    Plan hash value: 642453121
    | Id  | Operation                    | Name           | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT             |                |  4811G|  1238T|       |  3686M (13)|999:59:59 |
    |   1 |  VIEW                        |                |  4811G|  1238T|       |  3686M (13)|999:59:59 |
    |   2 |   HASH UNIQUE                |                |  4811G|   258T|       |  3686M (13)|999:59:59 |
    |   3 |    WINDOW BUFFER             |                |  4811G|   258T|       |  3686M (13)|999:59:59 |
    |   4 |     SORT GROUP BY            |                |  4811G|   258T|   317T|  3686M (13)|999:59:59 |
    |*  5 |      HASH JOIN               |                |  4811G|   258T|  4943M|    25M (90)| 85:14:28 |
    |   6 |       VIEW                   | VW_DAG_0       |   152M|  3199M|       |  1366K  (1)| 04:33:18 |
    |   7 |        HASH GROUP BY         |                |   152M|  4216M|  5839M|  1366K  (1)| 04:33:18 |
    |*  8 |         HASH JOIN            |                |   152M|  4216M|       |   147K  (2)| 00:29:36 |
    |   9 |          TABLE ACCESS FULL   | D_CHARTITEMS   |  4832 | 96640 |       |     7   (0)| 00:00:01 |
    |  10 |          INDEX FAST FULL SCAN| CHARTEVENTS_O2 |   196M|  1683M|       |   147K  (1)| 00:29:25 |
    |  11 |       TABLE ACCESS FULL      | CHARTEVENTS    |   196M|  6922M|       |   616K  (1)| 02:03:19 |
    Predicate Information (identified by operation id):
       5 - access("CE"."ITEMID"="ITEM_2")300T of temp space! Ouch.
    TKPROF output (I let the query run for a short while. I let it run for ages earlier, but wasn't tracing the session. Should I let it run for longer?):
    TKPROF: Release 11.2.0.3.0 - Development on Tue Jul 10 16:54:27 2012
    Copyright (c) 1982, 2011, Oracle and/or its affiliates.  All rights reserved.
    Trace file: /oracle/11gr2/app/oracle/diag/rdbms/mimic2/mimic2/trace/mimic2_ora_6507.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
    WITH ChartItems AS (
        SELECT
          ci.itemid,
          ci.label,
          ci.category,
          ci.description,
          COUNT(*),
          COUNT(distinct subject_id)
        FROM mimic2v26.d_chartitems ci
        JOIN mimic2v26.chartevents ce ON ce.itemid = ci.itemid
        GROUP BY ci.itemid,
                 ci.label,
                 ci.category,
                 ci.description
    , RawData AS (
        SELECT DISTINCT
          ci.itemid,                                                                                                                                                                                           
          ci.label,                                                                                                                                                                                            
          ci.category,                                                                                                                                                                                         
          ci.description,                                                                                                                                                                                      
          last_value(ce.value1) ignore nulls over (partition BY ci.itemid order by                                                                                                                             
          ce.charttime ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS                                                                                                                            
          value1_last                                                                                                                                                                                          
        FROM ChartItems ci                                                                                                                                                                                     
        JOIN mimic2v26.chartevents ce ON ce.itemid = ci.itemid                                                                                                                                                 
    select * from RawData                                                                                                                                                                                      
    call     count       cpu    elapsed       disk      query    current        rows                                                                                                                           
    Parse        1      0.02       0.02          0          0          0           0                                                                                                                           
    Execute      1      0.00       0.00          0          0          0           0                                                                                                                           
    Fetch        1    582.40     712.23     705238     737351          0           0                                                                                                                           
    total        3    582.43     712.25     705238     737351          0           0                                                                                                                           
    Misses in library cache during parse: 1                                                                                                                                                                    
    Optimizer mode: ALL_ROWS                                                                                                                                                                                   
    Parsing user id: 85 
    Number of plan statistics captured: 1
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
             0          0          0  VIEW  (cr=0 pr=0 pw=0 time=184 us cost=3686387254 size=1361581801333882 card=4811243114254)
             0          0          0   HASH UNIQUE (cr=0 pr=0 pw=0 time=180 us cost=3686387254 size=283863343740986 card=4811243114254)
             0          0          0    WINDOW BUFFER (cr=0 pr=0 pw=0 time=74 us cost=3686387254 size=283863343740986 card=4811243114254)
             0          0          0     SORT GROUP BY (cr=0 pr=0 pw=0 time=59 us cost=3686387254 size=283863343740986 card=4811243114254)
    178073889  178073889  178073889      HASH JOIN  (cr=737351 pr=705238 pw=124635 time=476372451 us cost=25572251 size=283863343740986 card=4811243114254)
       6211631    6211631    6211631       VIEW  VW_DAG_0 (cr=613768 pr=581413 pw=35805 time=286546567 us cost=1366486 size=3354399576 card=152472708)
       6211631    6211631    6211631        HASH GROUP BY (cr=613768 pr=581413 pw=35805 time=281271878 us cost=1366486 size=4421708532 card=152472708)
    196182740  196182740  196182740         HASH JOIN  (cr=613768 pr=545608 pw=0 time=557485047 us cost=147987 size=4421708532 card=152472708)
          4832       4832       4832          TABLE ACCESS FULL D_CHARTITEMS (cr=18 pr=16 pw=0 time=13666 us cost=7 size=96640 card=4832)
    196182740  196182740  196182740          INDEX FAST FULL SCAN CHARTEVENTS_O2 (cr=613750 pr=545592 pw=0 time=148428499 us cost=147046 size=1765644660 card=196182740)(object id 96501)
      10683044   10683044   10683044       TABLE ACCESS FULL CHARTEVENTS (cr=123583 pr=123825 pw=0 time=25175510 us cost=616507 size=7258761380 card=196182740)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                       1        0.00          0.00
      db file sequential read                         2        0.01          0.01
      db file scattered read                          3        0.02          0.03
      direct path read                             5265        0.75         77.13
      asynch descriptor resize                        1        0.00          0.00
      direct path write temp                      15077        0.71         45.54
      direct path read temp                        2387        0.29         13.54
      SQL*Net break/reset to client                   1        0.66          0.66
      SQL*Net message from client                     1        0.00          0.00
    SQL ID: 7jby2dxrpkkm9 Plan Hash: 1388734953
    select SYS_CONTEXT('USERENV','SESSIONID')
    from
    dual
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.01          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.00       0.00          0          0          0           1
    total        3      0.00       0.01          0          0          0           1
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 85 
    Number of plan statistics captured: 1
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
             1          1          1  FAST DUAL  (cr=0 pr=0 pw=0 time=4 us cost=2 size=0 card=1)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                       1        0.00          0.00
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        2      0.02       0.04          0          0          0           0
    Execute      2      0.00       0.00          0          0          0           0
    Fetch        2    582.40     712.23     705238     737351          0           1
    total        6    582.43     712.27     705238     737351          0           1
    Misses in library cache during parse: 2
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                       4        0.00          0.00
      db file sequential read                         2        0.01          0.01
      db file scattered read                          3        0.02          0.03
      direct path read                             5265        0.75         77.13
      asynch descriptor resize                        1        0.00          0.00
      direct path write temp                      15077        0.71         45.54
      direct path read temp                        2387        0.29         13.54
      SQL*Net break/reset to client                   1        0.66          0.66
      SQL*Net message from client                     3       14.99         15.01
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute      0      0.00       0.00          0          0          0           0
    Fetch        0      0.00       0.00          0          0          0           0
    total        0      0.00       0.00          0          0          0           0
    Misses in library cache during parse: 0
        2  user  SQL statements in session.
        0  internal SQL statements in session.
        2  SQL statements in session.
    Trace file: /oracle/11gr2/app/oracle/diag/rdbms/mimic2/mimic2/trace/mimic2_ora_6507.trc
    Trace file compatibility: 11.1.0.7
    Sort options: default
           1  session in tracefile.
           2  user  SQL statements in trace file.
           0  internal SQL statements in trace file.
           2  SQL statements in trace file.
           2  unique SQL statements in trace file.
       24245  lines in trace file.
         728  elapsed seconds in trace file.Optimizer parameters:
    NAME                                               TYPE        VALUE                                                                                               
    optimizer_capture_sql_plan_baselines               boolean     FALSE                                                                                               
    optimizer_dynamic_sampling                         integer     2                                                                                                   
    optimizer_features_enable                          string      11.2.0.3                                                                                            
    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                                                                                                 Can anyone help me figure out what's wrong?
    This is a data warehouse, with up to date statistics. The DB is version 11.2.0.3.0
    Thanks,
    Dan

    rp0428 wrote:
    >
    I trimmed the query down to the simplest that I could which still exhibited the problem
    >
    The DISTINCT isn't the issue. The issue is that the query you posted isn't necessary and doesn't appear to be represented in the plan that you posted.
    That makes it hard to tell where the cardinality misestimates are coming from. How many records does the actual first query (the one with the group by) return? You have a SELECT * commented out - how many rows?No, it's not necessary, but then it isn't the full query. The estimates are still wrong when I pass the count columns through to the second query. The full query contains many more analytic functions in the second query, and some additions to the first. It could probably be cleaned up a little, but the current structure makes logical sense. Should I change the aggregates to analytics and move them into the second query? In any case, there definitely seems to be something wrong with the plan.
    I don't know what you mean when you say "doesn't appear to be represented in the plan that you posted".
    I just checked the first query and while the temp space has dropped to a reasonable amount, the number of rows in the hash join is still way off (I didn't notice before because I was looking at the temp space). The rows for d_chartitems and the index on chartevents are correct:
    Plan hash value: 1249235674
    | Id  | Operation               | Name           | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT        |                |   152M|    35G|       |  1366K  (1)| 04:33:18 |
    |   1 |  VIEW                   |                |   152M|    35G|       |  1366K  (1)| 04:33:18 |
    |   2 |   WINDOW SORT           |                |   152M|  4216M|  5839M|  1366K  (1)| 04:33:18 |
    |*  3 |    HASH JOIN            |                |   152M|  4216M|       |   147K  (2)| 00:29:36 |
    |   4 |     TABLE ACCESS FULL   | D_CHARTITEMS   |  4832 | 96640 |       |     7   (0)| 00:00:01 |
    |   5 |     INDEX FAST FULL SCAN| CHARTEVENTS_O2 |   196M|  1683M|       |   147K  (1)| 00:29:25 |
    Predicate Information (identified by operation id):
       3 - access("CE"."ITEMID"="CI"."ITEMID")Edited by: danscott on Jul 10, 2012 5:43 PM
    Edited by: danscott on Jul 11, 2012 6:28 AM

  • Explain Plan

    Just Question about Explain Plan.
    Q- 1. Is it Possible to trace a current session query from other session without altering that session. If How can i do it. I can not do it with v$session becuase it will be different sessionid. Also i ndon't want to alter session.
    Q-2 I have SQl statement gives different EXECUTION PLAN on 9R2 and 10g. Is it possible.
    Can any one explain this please

    thank you smoradi and william for your response.
    Sorry for Long Post
    I tried to post it before also. i did not get the conculsion. This are the final results i got. So can any one Help me.
    Following are the information
    I have TKPROF result. can any one expalin me this what it means. Where are wait time.
    I got the explain plan as unnder can any one explain me please i am still having problem solving this
    can any one explain me how to improve the perfomance.
    1.SS_SKU_STORE_WEEk is the biggest table around 12 million rows.
    2. SS_SKU_STORE 50 thosand rows
    3. ITEM 44 thousand
    4.Rest all tables are small.
    SQL>  SELECT   /*+ index( ss_sku_store SS_SKU_ST_PK ) */
      2              TO_NUMBER( ss_sku_store.sku || ss_sku_store.store_num) rowkey,
      3              ss_sku_store.sku psku,
      4              ' ' || INITCAP( item.descrip ) description,
      5              dept_id,
      6              TO_CHAR( dept_id ) || '.' || TO_CHAR( sub_dept_id ) subdepartment,
      7              TO_CHAR( dept_id ) || '.' || TO_CHAR( sub_dept_id ) ||'.'|| TO_CHAR( class_id ) class,
      8              NVL( vendor_id, -1 ),
      9              NVL( buyer_num, -1),
    10              NVL( TRIM(pattern_cd), -1),
    11              DECODE(Color_Cd, 0, -1, NVL( Color_Cd, -1)) Color_Cd,
    12              NVL( size_cd, -1),
    13              -1 list_id,
    14              ss_sku.sku skuattribute,
    15              ss_sku_store.store_num pstore,
    16              INITCAP( store.name ) location,
    17              store.state,
    18              NVL( INITCAP( regional_vp), :cUNASSIGNED) regional_vp,
    19              NVL( INITCAP( regional_merch_mgr), :cUNASSIGNED) regional_merch_mgr,
    20              NVL( INITCAP( district_mgr), :cUNASSIGNED) district_mgr,
    21              NVL( INITCAP( area_mgr), :cUNASSIGNED) area_mgr,
    22              NVL( sq_footage, -1),
    23              SUBSTR( '000' || fashion_attribute.seq, -3, 3 ) || NVL( store.fashion_att_cd, '' ) fashion_att_cd,
    24              SUBSTR( '000' || cust_profile.seq, -3, 3 ) || NVL( store.cust_type_cd, '' ) cust_type_cd,
    25              NVL( section_count, -1) section_count,
    26              '000' corp_vol_grp_cd,
    27              0 storegroup,
    28              store.store_num storeattribute,
    29              0 storesort,
    30              submit_status,
    31              DECODE( current_user, :pUserID, shipment_schedules.check_staged_sku(ss_sku_store.sku,-1), 1) lockedflag,
    32              '' aggregatedrowkey,
    33              '' AttributeDescription,
    34              starting_on_hand     onhand
    35     FROM     cust_profile,
    36              fashion_attribute,
    37              ( SELECT   vendor_id,
    38                         sku
    39                FROM     item_vendor
    40                WHERE    sku IN ( SELECT  sku
    41                                  FROM    ss_session_sku
    42                                  WHERE   user_key = :pUserKey)
    43                AND      primary_flag = :cTRUE ) primaryvendor,
    44              ( SELECT   SKU,
    45                         DECODE( status, 0, 0, DECODE( status, 1 ,0 ,1) ) AS submit_status
    46                FROM     ( SELECT   /*+ full(ss_session_sku) use_nl(ss_session_sku,ss_sku_store_week) index(ss_sku_store_week SS_SKU_STR_WK_SKU )*/
    47                                    SS_SKU_Store_Week.SKU,
    48                                    MAX( NVL( ssk_week_status, 0 ) ) AS status
    49                           FROM     ss_session_sku,
    50                                    ss_sku_store_week
    51                           WHERE    user_key              = :pUserKey
    52                           AND      ss_sku_store_week.sku = ss_session_sku.sku
    53                           GROUP BY ss_sku_store_week.sku )
    54               ) sku_status,
    55              ss_sku,
    56              store,
    57              ss_sku_store,
    58              item
    59     WHERE    sku_status.sku           =  item.sku
    60     AND      sku_status.sku           =  ss_sku.sku
    61     AND      sku_status.sku           =  ss_sku_store.sku
    62     AND      sku_status.sku           =  primaryvendor.sku
    63     AND      sku_status.sku           =  sku_status.sku
    64     AND      ss_sku_store.store_num   =  store.store_num
    65     AND      store.cust_type_cd       =  cust_profile.cust_type_cd(+)
    66     AND      store.fashion_att_cd     =  fashion_attribute.fashion_att_cd(+)
    67     ORDER BY ss_sku_store.sku,
    68              ss_sku_store.store_num;
    Execution Plan
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=531 Card=3203 Bytes=948088)                                                            
       1    0  SORT (GROUP BY) (Cost=531 Card=3203 Bytes=948088)                  
       2    1    HASH JOIN (RIGHT OUTER) (Cost=323 Card=3203 Bytes=948088)                                                                    
       3    2      TABLE ACCESS (FULL) OF 'CUST_PROFILE' (TABLE) (Cost=2 Card=16 Bytes=304)                                                   
       4    2      HASH JOIN (RIGHT OUTER) (Cost=321 Card=3203 Bytes=887231)                                                                  
       5    4        TABLE ACCESS (FULL) OF 'FASHION_ATTRIBUTE' (TABLE) (Cost=2 Card=9 Bytes=162)                                             
       6    4        HASH JOIN (Cost=318 Card=3203 Bytes=829577)                  
       7    6          TABLE ACCESS (FULL) OF 'STORE' (TABLE) (Cost=15 Card=1289 Bytes=105698)                                                
       8    6          TABLE ACCESS (BY LOCAL INDEX ROWID) OF 'SS_SKU_STORE' (TABLE) (Cost=3 Card=707 Bytes=17675)                            
       9    8           NESTED LOOPS (Cost=302 Card=3203 Bytes=566931)           
      10    9             HASH JOIN (Cost=287 Card=5 Bytes=760)                  
      11   10               NESTED LOOPS (Cost=284 Card=5 Bytes=655)             
      12   11                 NESTED LOOPS (Cost=273 Card=5 Bytes=270)           
      13   12                   NESTED LOOPS (Cost=252 Card=86 Bytes=3784)                                                                   
      14   13                     NESTED LOOPS (Cost=17 Card=13 Bytes=468)                                                                   
      15   14                       SORT (UNIQUE) (Cost=1 Card=13 Bytes=130)                                                                 
      16   15                         INDEX (RANGE SCAN) OF 'SS_SESS_SKU_PK' (INDEX (UNIQUE)) (Cost=1 Card=13 Bytes=130)                     
      17   14                       TABLE ACCESS (BY INDEX ROWID) OF 'ITEM_VENDOR' (TABLE) (Cost=3 Card=1 Bytes=26)                          
      18   17                         INDEX (RANGE SCAN) OF 'ITEM_VENDOR_ITEM_FK_IDX' (INDEX) (Cost=2 Card=1)                                
      19   13                     PARTITION HASH (ITERATOR) (Cost=65 Card=7 Bytes=56)                                                        
      20   19                       TABLE ACCESS (BY LOCAL INDEX ROWID)OF 'SS_SKU_STORE_WEEK' (TABLE) (Cost=65 Card=7 Bytes=56)             
      21   20                         INDEX (RANGE SCAN) OF 'SS_SKU_STR_WK_SKU' (INDEX) (Cost=14 Card=6427)                                  
      22   12                   TABLE ACCESS (FULL) OF 'SS_SESSION_SKU'(TABLE) (Cost=0 Card=1 Bytes=10)                                     
      23   11                 TABLE ACCESS (BY INDEX ROWID) OF 'ITEM' (TABLE) (Cost=2 Card=1 Bytes=77)                                       
      24   23                   INDEX (UNIQUE SCAN) OF 'ITEM_PK' (INDEX (UNIQUE)) (Cost=1 Card=1)                                            
      25   10               TABLE ACCESS (FULL) OF 'SS_SKU' (TABLE) (Cost=3 Card=343 Bytes=7203)                                             
      26    9             PARTITION HASH (ITERATOR) (Cost=1 Card=211)
      27   26               INDEX (RANGE SCAN) OF 'SS_SKU_ST_PK' (INDEX(UNIQUE)) (Cost=1 Card=211)                                          
    EXPLIAN PLAN AND DATA FROM TKPROF
    all     count       cpu    elapsed       disk      query    current        rows
    Parse        2      0.00       0.01          0          0          0           0
    Execute      2      1.35       1.30          0          0          0           0
    Fetch        5      0.14       0.16          5       2497          0         111
    total        9      1.49       1.49          5       2497          0         111
    Misses in library cache during parse: 2
    Misses in library cache during execute: 2
    Optimizer mode: ALL_ROWS
    Parsing user id: 30  (MDSEADMIN)
    Rows     Row Source Operation
          0  PX COORDINATOR FORCED SERIAL (cr=797 pr=2 pw=0 time=42745 us)
          0   PX SEND QC (ORDER) :TQ10005 (cr=797 pr=2 pw=0 time=42711 us)
          0    SORT ORDER BY (cr=797 pr=2 pw=0 time=42701 us)
          0     PX RECEIVE  (cr=797 pr=2 pw=0 time=42627 us)
          0      PX SEND RANGE :TQ10004 (cr=797 pr=2 pw=0 time=42617 us)
          0       BUFFER SORT (cr=797 pr=2 pw=0 time=42609 us)
          0        NESTED LOOPS OUTER (cr=797 pr=2 pw=0 time=42532 us)
          0         NESTED LOOPS OUTER (cr=797 pr=2 pw=0 time=42520 us)
          0          NESTED LOOPS  (cr=797 pr=2 pw=0 time=42510 us)
          0           NESTED LOOPS  (cr=797 pr=2 pw=0 time=42502 us)
          0            NESTED LOOPS  (cr=797 pr=2 pw=0 time=42495 us)
          0             NESTED LOOPS  (cr=797 pr=2 pw=0 time=42488 us)
          0              HASH JOIN  (cr=797 pr=2 pw=0 time=42480 us)
          1               BUFFER SORT (cr=5 pr=1 pw=0 time=13357 us)
          1                PX RECEIVE  (cr=5 pr=1 pw=0 time=13300 us)
          1                 PX SEND HASH :TQ10001 (cr=5 pr=1 pw=0 time=13291 us)
          1                  TABLE ACCESS BY INDEX ROWID ITEM_VENDOR (cr=5 pr=1 pw=0 time=13280 us)
          3                   NESTED LOOPS  (cr=4 pr=0 pw=0 time=423 us)
          1                    SORT UNIQUE (cr=1 pr=0 pw=0 time=189 us)
          1                     INDEX RANGE SCAN SS_SESS_SKU_PK (cr=1 pr=0 pw=0 time=86 us)(object id 25279)
          1                    INDEX RANGE SCAN ITEM_VENDOR_ITEM_FK_IDX (cr=3 pr=0 pw=0 time=53 us)(object id 24079)
          0               PX RECEIVE  (cr=792 pr=1 pw=0 time=28530 us)
          0                PX SEND HASH :TQ10003 (cr=792 pr=1 pw=0 time=28524 us)
          0                 VIEW  (cr=792 pr=1 pw=0 time=28517 us)
          0                  HASH GROUP BY (cr=792 pr=1 pw=0 time=28509 us)
          0                   PX RECEIVE  (cr=792 pr=1 pw=0 time=28295 us)
          0                    PX SEND HASH :TQ10002 (cr=792 pr=1 pw=0 time=28290 us)
          0                     NESTED LOOPS  (cr=792 pr=1 pw=0 time=28284 us)
          1                      BUFFER SORT (cr=1 pr=0 pw=0 time=139 us)
          1                       PX RECEIVE  (cr=1 pr=0 pw=0 time=45 us)
          1                        PX SEND BROADCAST :TQ10000 (cr=1 pr=0 pw=0 time=40 us)
          1                         INDEX RANGE SCAN SS_SESS_SKU_PK (cr=1 pr=0 pw=0 time=34 us)(object id 25279)
          0                      PX BLOCK ITERATOR PARTITION: KEY KEY (cr=791 pr=1 pw=0 time=28136 us)
          0                       TABLE ACCESS FULL SS_SKU_STORE_WEEK PARTITION: KEY KEY (cr=791 pr=1 pw=0 time=28084 us)
          0              TABLE ACCESS BY INDEX ROWID ITEM (cr=0 pr=0 pw=0 time=0 us)
          0               INDEX UNIQUE SCAN ITEM_PK (cr=0 pr=0 pw=0 time=0 us)(object id 24055)
          0             TABLE ACCESS BY INDEX ROWID SS_SKU (cr=0 pr=0 pw=0 time=0 us)
          0              INDEX UNIQUE SCAN SS_SKU_PK (cr=0 pr=0 pw=0 time=0 us)(object id 25300)
          0            PARTITION HASH ITERATOR PARTITION: KEY KEY (cr=0 pr=0 pw=0 time=0 us)
          0             TABLE ACCESS BY LOCAL INDEX ROWID SS_SKU_STORE PARTITION: KEY KEY (cr=0 pr=0 pw=0 time=0 us)
          0              INDEX RANGE SCAN SS_SKU_ST_PK PARTITION: KEY KEY (cr=0 pr=0 pw=0 time=0 us)(object id 25547)
          0           TABLE ACCESS BY INDEX ROWID STORE (cr=0 pr=0 pw=0 time=0 us)
          0            INDEX UNIQUE SCAN STORE_PK (cr=0 pr=0 pw=0 time=0 us)(object id 25586)
          0          TABLE ACCESS BY INDEX ROWID FASHION_ATTRIBUTE (cr=0 pr=0 pw=0 time=0 us)
          0           INDEX UNIQUE SCAN FASHION_ATTRIBUTE_PK (cr=0 pr=0 pw=0 time=0 us)(object id 24035)
          0         TABLE ACCESS BY INDEX ROWID CUST_PROFILE (cr=0 pr=0 pw=0 time=0 us)
          0          INDEX UNIQUE SCAN CUST_PROFILE_PK (cr=0 pr=0 pw=0 time=0 us)(object id 24036)
    ALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse       43      0.10       0.11          0          1          0           0
    Execute    861      0.38       0.45        357        622         46         621
    Fetch      845      0.21       0.21        128       2626          2         892
    total     1749      0.69       0.78        485       3249         48        1513
    Misses in library cache during parse: 21
    Misses in library cache during execute: 16
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      SQL*Net message to client                      60        0.00          0.00
      SQL*Net message from client                    39        0.00          0.16
      db file scattered read                         82        0.01          0.05
      db file sequential read                       185        0.01          0.05
      log file sync                                   1        0.00          0.00
      191  user  SQL statements in session.
       23  internal SQL statements in session.
      214  SQL statements in session.
       37  statements EXPLAINed in this session.Thank you for your help in advance
    Message was edited by:
    devmiral

  • Explain Plan and Execution Plan in 10gR2.

    Hi,
    Version 10.2.0.1.0.
    I have two questions:
    1) If the explain plan differs from the execution path in this version, then, is it safe to assume that the statistics are stale (or not gathered at all) on the underlying tables?
    2) Can you in any way make a query use RBO instead of CBO? (I know it doesn't make any sense since CBO is lot smarter, but, for purely academic reasons).
    Thank you,
    Rahul.

    The rule based optimizer is most definitely present in 10gR2. It might not be in the documentation, but it is still there.
    C:\sql>sqlplus test/test
    SQL*Plus: Release 10.2.0.2.0 - Production on Tue Oct 10 15:43:34 2006
    Copyright (c) 1982, 2005, Oracle. All Rights Reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Production
    With the Partitioning, OLAP and Data Mining options
    test@SVTEST> set autotrace traceonly
    test@SVTEST> alter session set optimizer_mode=rule;
    Session altered.
    Elapsed: 00:00:00.01
    test@SVTEST> select * from dual;
    Elapsed: 00:00:00.03
    Execution Plan
    Plan hash value: 272002086
    | Id | Operation | Name |
    | 0 | SELECT STATEMENT | |
    | 1 | TABLE ACCESS FULL| DUAL |
    Note
    - rule based optimizer used (consider using cbo)
    Statistics
    1 recursive calls
    0 db block gets
    3 consistent gets
    2 physical reads
    0 redo size
    407 bytes sent via SQL*Net to client
    381 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    1 rows processed
    test@SVTEST>

Maybe you are looking for