Explain Plan for a SQL

Hi
I have done an explain for one of my sql and i got the result as follows
SELECT STATEMENT Cost = 502
SORT AGGREGATE
HASH JOIN
NESTED LOOPS
HASH JOIN
TABLE ACCESS FULL CMC_NWPE_RELATION
HASH JOIN
TABLE ACCESS FULL CMC_NWST_NET_SET
NESTED LOOPS
TABLE ACCESS FULL CMC_NWPR_RELATION
INDEX UNIQUE SCAN SYS_C006513
INDEX UNIQUE SCAN SYS_C006316
TABLE ACCESS FULL CMC_MEPR_PRIM_PROV
I need to know whether i have gone wrong with any of the joins in the sql. For the matter of fact I need to interpret the result of the explain plan for my sql.
Thanks in advance
Chandra Sekhar

Hi
First of all u haven't send the complete explanation in the plan table. As far i got from your result ur accesing the ful table scan CMC_NWPE_RELATION ,CMC_NWST_NET_SET , CMC_NWPR_RELATION & one more.
check in your auery why these table are accesing full when the data in this table will volumonuous ur system this query will become very slow as it will have to acces nosof rowsin table 1*nosof rowsin table 2*nosof rowsin table 3*nosof rowsin table 4 so u create the index in those tables and index should be made on the columns which r used in ur where clause of the query
Amit

Similar Messages

  • Explain Plan for Multiple SQL

    Hi ,
    Our db version is Oracle 8i and looking for solution.
    I have multiple select sql statments and need to get the explain plan for all statments.
    Is it possible to take explain plan for all statments one time? If so please provide the steps.
    Thanks.
    Happy Halloween.

    Not sure exactly you are looking. But if you do
    set autotrace on
    from sqlplus and put all the query in a script, you should get all explain plan in one shot. You can spool the output to a file.

  • Why tkprof did not show explain plan for some sql statements

    Hi,
    I did a trace for one of the session, hoping to find the explain plan for its tkprof. However, I only get this:
    INSERT INTO AUDIT_TABLE
    VALUES
    ( :B1 , :B2 , :B3 , :B4 , :B5 , :B6 , :B8 , :B7 )
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute   3698      8.08      59.41       3348        566      19092        3698
    Fetch        0      0.00       0.00          0          0          0           0
    total     3699      8.08      59.42       3348        566      19092        3698
    Misses in library cache during parse: 1
    Misses in library cache during execute: 1
    Optimizer mode: CHOOSE
    Parsing user id: 30     (recursive depth: 2)
    ********************************************************************************Any idea why the explain plan is missing?
    Also looking at the above statistics, what can I conclude?

    Thanks John. What's ur take on this statistics then?
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      0.00       0.00          0          0          0           0
    Execute   1798     12.23      36.75       1758       5404       7418        1798
    Fetch        0      0.00       0.00          0          0          0           0
    total     1798     12.23      36.75       1758       5404       7418        1798
    Misses in library cache during parse: 0
    Optimizer mode: CHOOSE
    Parsing user id: 30     (recursive depth: 1)
    ********************************************************************************

  • Explain plan for a sql statement

    Hi,
    I have a simple sql statement which has a cost of 122, cardinality 59 and CPU cost 1966777.
    Same sql statement written in another way (using a nested select in the 'from' clause), has a cost of 58, cardinality 24 but cpu cost is much higher 29078895.
    What should I look for? For a better cost overall, or for a better cpu cost? Which statement should I consider? What is most important?
    Thanks.

    Roger25 wrote:
    ... Based on this, my question is what statement to choose? which is more important, the cost or the cpu cost?
    Thanks.
    Based on this, sorry, but my reply will remain unchanged:
    Again, you cannot compare explain plan of two different queries.
    Find out more:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:313416745628
    Nicolas.

  • Explain plans for PL/SQL code?

    Hi!
    I am pulling SQL statements (select, insert, update, delete, etc.) from PL/SQL code and producing explain plans. Some of the delete statements have "WHERE CURRENT OF" in them which produces an ORA-3001 error (feature not implemented) error. How can I do an explain plan of these statements? Can I replace "WHERE CURRENT OF" with "=" to get a plan? How far off will the plan be? Any suggestions, ideas, etc. greatfully appreciated!
    This is Oracle 9.2.0.4/5 on AIX if it makes a difference.
    Thanks!
    Dave Venus

    WHERE CURRENT OF shouldn't be a problem. Here above an example on 9.2.0.4 on AIX5.2 :
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.4.0 - 64bit Production
    With the Partitioning option
    JServer Release 9.2.0.4.0 - Production
    SQL> create table TBL_USER_PROFILE_CATEGORY
      2  as
      3  select 654 id_category, 1103 id_user from dual union all
      4  select 654 id_category, 1104 id_user from dual union all
      5  select 18  id_category, 1103 id_user from dual union all
      6  select 629 id_category, 1103 id_user from dual union all
      7  select 110 id_category, 1103 id_user from dual union all
      8  select 110 id_category, 1104 id_user from dual union all
      9  select 18  id_category, 1104 id_user from dual union all
    10  select 37  id_category, 1103 id_user from dual union all
    11  select 24  id_category, 1103 id_user from dual union all
    12  select 7   id_category, 104  id_user from dual union all
    13  select 37  id_category, 1104 id_user from dual union all
    14  select 22  id_category, 1103 id_user from dual union all
    15  select 22  id_category, 1104 id_user from dual union all
    16  select 25  id_category, 1104 id_user from dual union all
    17  select 25  id_category, 1103 id_user from dual ;
    Table created.
    SQL>
    SQL> alter table TBL_USER_PROFILE_CATEGORY add primary key (id_category, id_use
    Table altered.
    SQL>
    SQL> CREATE OR REPLACE
      2  PROCEDURE P$UPDATE_TBL_USER_PROFILE_CAT(p_id_cat_old IN NUMBER) AS
      3    p_id_category number;
      4    p_id_user     number;
      5    cursor mycur is select id_category, id_user
      6                    from TBL_USER_PROFILE_CATEGORY
      7                    where  id_category = p_id_cat_old
      8                    for update of id_category;
      9  BEGIN
    10    open mycur;
    11    LOOP
    12       FETCH mycur INTO p_id_category, p_id_user;
    13       EXIT WHEN mycur%NOTFOUND;
    14       BEGIN
    15 DELETE FROM TBL_USER_PROFILE_CATEGORY
    16 WHERE CURRENT OF mycur;
    17       END;
    18     END LOOP;
    19     CLOSE mycur;
    20     COMMIT;
    21  EXCEPTION WHEN OTHERS THEN rollback;
    22  END;
    23  /
    Procedure created.
    SQL>
    SQL> exec P$UPDATE_TBL_USER_PROFILE_CAT(654)
    PL/SQL procedure successfully completed.
    SQL> select * from TBL_USER_PROFILE_CATEGORY;
    ID_CATEGORY    ID_USER
             18       1103
            629       1103
            110       1103
            110       1104
             18       1104
             37       1103
             24       1103
              7        104
             37       1104
             22       1103
             22       1104
             25       1104
             25       1103
    13 rows selected.
    SQL> Please, paste here what's your code...
    Nicolas.

  • Explain plan for query with variables

    Trying to Explain plan for some sql in sql*plus. The query has a variable in it. How do I do this ?
    I did look into explain plan and dbms_xplan but could not find anything with variables

    use sqlplus bind variables:
    SQL> --define variable
    SQL> var x varchar2
    SQL> -- notice the colon prefixing the variable
    SQL> explain plan for select * from customer where cid = :x;
    Explained.
    SQL> select * from table( dbms_xplan.display );
    PLAN_TABLE_OUTPUT
    Plan hash value: 1709312366
    | Id  | Operation                   | Name     | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |          |     1 |    67 |     2   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| CUSTOMER |     1 |    67 |     2   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | CID      |     1 |       |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("CID"=:X)
    14 rows selected.the variable does not need to be set to explain the query, since explain does not actually execute.
    Edited by: shoblock on Nov 6, 2008 4:51 PM

  • Efficient way to read through big explain plan and genterate html explain plan for sql id's executed in past

    Hi,
    I have a sql which is recently having a performance problems in Production. I have generated a explain plan for it trying to find out what it is doing but plan itself is close to 1000 lines. I want to check if there is any efficient way to go through big plan like this one and quickly find the damaging areas..
    2) I also wanted to know if there is way to generate explain plans in HTML format which executed in past and have entry in dba_hist_sqltext.
    3) I also have two sql_monitor reports which I want to compare. is there any efficient way to do it as well?
    Please share your thoughts!
    Thanks in advance!
    Regards,
    Suman-

    Hi,
    I suggest you can try running sql advisor on the query maybe something fruitful comes up
    http://www.oracle-base.com/articles/11g/sql-access-advisor-11gr1.php
    I am not sure about the explain plan being printed in html format but
    You may also want to try the sqlhistory.sql query from below page
    http://evdbt.com/scripts/
    I have used it many times to check on executions and explain plans which may have changed over the period
    I have faced it many times , the query picks up a bad explain plan and performs poorly

  • Explain Plan in pl/sql

    Dear All.
    DBMS_XPLAN.DISPLAY_CURSOR(
       sql_id        IN  VARCHAR2  DEFAULT  NULL,
       child_number  IN  NUMBER    DEFAULT  NULL,
       format        IN  VARCHAR2  DEFAULT  'TYPICAL');
    SQL> SELECT * FROM table (
      2     DBMS_XPLAN.DISPLAY_CURSOR('b7jn4mf49n569'));
    PLAN_TABLE_OUTPUT
    SQL_ID  b7jn4mf49n569, child number 0
    select o.name, u.name from obj$ o, type$ t, user$ u  where o.oid$ = t.tvoid and
    u.user#=o.owner# and  bitand(t.properties,8388608) = 8388608 and
    (sysdate-o.ctime) > 0.0007
    Plan hash value: 4266358741
    | Id  | Operation                     | Name    | Rows  | Bytes | Cost (%CPU)| T
    |   0 | SELECT STATEMENT              |         |       |       |    94 (100)|
    |   1 |  NESTED LOOPS                 |         |     1 |    72 |    94   (2)| 0
    |   2 |   NESTED LOOPS                |         |     1 |    56 |    93   (2)| 0
    |*  3 |    TABLE ACCESS FULL          | OBJ$    |    71 |  2414 |    37   (3)| 0
    |*  4 |    TABLE ACCESS BY INDEX ROWID| TYPE$   |     1 |    22 |     1   (0)| 0
    |*  5 |     INDEX UNIQUE SCAN         | I_TYPE2 |     1 |       |     0   (0)|
    |   6 |   TABLE ACCESS CLUSTER        | USER$   |     1 |    16 |     1   (0)| 0
    |*  7 |    INDEX UNIQUE SCAN          | I_USER# |     1 |       |     0   (0)|
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
       3 - filter(("O"."OID$" IS NOT NULL AND SYSDATE@!-"O"."CTIME">.0007))
       4 - filter(BITAND("T"."PROPERTIES",8388608)=8388608)
       5 - access("O"."OID$"="T"."TVOID")
       7 - access("U"."USER#"="O"."OWNER#")
    29 rows selected
    SQL> As you can see using DBMS_XPLAN.DISPLAY_CURSOR. I can display the explain plan of any query IN SQL*PLUS.
    But I want to write a PL/SQL function that generating an explain plan for any query and displaying the explain plan in a htlm page
    how can i do same thing in pl/sql? I need yours advice.
    Thanks in advance!

    Generate the plan like so:
    begin
    execute immediate 'explain plan for select * from dual';
    end;Then you can put the dbms_xplan.display bit into a ref cursor and pass that across to the front end.
    Eg:
    SQL> variable rc refcursor
    SQL> begin
      2  execute immediate 'explain plan for select * from dual';
      3  open :rc for select * from table(dbms_xplan.display);
      4* end;
    SQL> /
    PL/SQL procedure successfully completed.
    SQL> print rc;
    PLAN_TABLE_OUTPUT
    Plan hash value: 3543395131
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |     1 |     2 |     5   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS FULL| DUAL |     1 |     2 |     5   (0)| 00:00:01 |
    8 rows selected.

  • Explain plan for MVIEW....

    Hi All,
    please tell me how to invoke EXPLAIN PLAN for CREATE MATERIALIZED VIEW.
    while i am trying to get plan i am getting following error
    ORA-00900: invalid SQL statement
    Thanks in advance.

    Thanks for reply.
    I need it for estimation and solution design. so all
    parameters are necessary. second thing is DDL and
    simple SELECT statements plan are differ. I can get
    explain plan for CREATE TABLE AS SELECT but not for
    CREATE MV.
    Regards,
    Santosh.In case you didn't notice: Create table as select (CTAS) is also DDL.
    There is nothing additionally from point of the execution plan that is added by the CREATE MV command.

  • Explain Plan for Procedure

    Hi,
    For getting the explain plan for a query, we use the statement
    "explain plan for " + Query
    Similarly, to get an explain plan for a procedure, do we have any way like
    "explain plan for " + "Execute " + Procedure
    How do we get an explain plan for a procedure that is executed
    Thanks in Advance.

    teckfreak wrote:
    Hi Robert,
    I am working on an utility application which will execute the procedure and show the explain plan to the user for him to analyze the explain plan and take necessary steps for optimization. I am showing the Procedure inputs to the user, allowing him to enter values and taking them and executing the procedure. I am setting the trace and extracting the explain plan for the procedure using TKPROF utility and showing it to the user.
    While doing so, the trace file is stored in udump folder. I am accessing the trace file from TKPROF utility. I am able to run the TKPROF from the command prompt. But if I try automating the TKPROF command in a .NET application using Process.Start, it says "Not able to access the file.". I tried giving full permissions to Everyone and it still throws the error. Kindly guide me how to proceed.. A different approach that you might want to consider (as indicated by William):
    - Flush the shared pool and use a unique MODULE description for each execution of your procedure (e.g. using DBMS_APPLICATION_INFO.SET_MODULE), e.g. using a logon trigger
    - Query V$SQL for your unique MODULE description and run DBMS_XPLAN.DISPLAY_CURSOR for each corresponding child cursor found (SQL_ID + CHILD_NUMBER) in the shared pool. This plan generation could be automated using a procedure
    The result of this approach corresponds to the tracing using TKPROF since it will provide the actual execution plans used at runtime rather than separate EXPLAIN PLAN results which might differ from the actual plans.
    This assumes that your shared pool is sufficiently large to hold all the child cursor created by your procedure without aging them out while the procedure is running. It's probably also only applicable to an environment where not too much work is being done while running this test and the recommended flushing of the shared pool.
    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/

  • Explain plan for running query

    Hi everyone,
    I come to know how to generate explain plan for a given query by giving
    Explain plan for select * fro emp;
    Consider a query running for 5 hrs in a session and i want to genrate explain plan for that current query in its 4th hour i dont know the sql as well
    all the steps by step would be much apppreciated
    like finding Current SQL then so on
    Thanks
    Shareef

    912856 wrote:
    Hi everyone,
    I come to know how to generate explain plan for a given query by giving
    Explain plan for select * fro emp;
    Consider a query running for 5 hrs in a session and i want to genrate explain plan for that current query in its 4th hour i dont know the sql as well
    all the steps by step would be much apppreciated
    like finding Current SQL then so on
    Thanks
    ShareefYOu can also use dbms_xplain to generate plan used in v$sql. like for example
    SQL>SELECT  SQL_ID,  CHILD_NUMBER FROM  V$SQL WHERE  SQL_TEXT LIKE 'select * from em%';
    SQL_ID        CHILD_NUMBER
    6kd5fkqdjb8fu            0
    SQL>SELECT  * FROM  TABLE(DBMS_XPLAN.DISPLAY_CURSOR('6kd5fkqdjb8fu',0,'ALLSTATS'));If you need the actual tuntime statistics used by sql statement then you need to put hint /*+ gather_plan_statistics */ in sql ststement, something like
    select /*+ gather_plan_statistics */ * from emp;
    and then generate the explain plan for this
    Have a look
    http://hoopercharles.wordpress.com/2010/03/01/dbms_xplan-format-parameters/
    select * from table(dbms_xplan.display_cursor(null,null,'ALLSTATS LAST'));

  • How to run Explain Plan for SP?

    Can we run Explain Plan for SP??

    EXPLAIN PLAN creates an execution plan for SQL statements. PL/SQL is not SQL.
    PL/SQL procedures can contain SQL, yes. These SQLs can be copied and pasted from PL/SQL into something like TOAD and execution plan determined.
    However, if the aim is to see the "execution/performance plan" for PL/SQL code, then you need to profile the PL/SQL code using the DBMS_PROFILER package. This will tell you the execution path and elapsed time to execute a line of PL/SQL.
    Details can be found in the [url http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_profil.htm#sthref5502]Oracle® Database PL/SQL Packages and Types Reference guide.

  • What privileges needed for producing explain plan for other user's object ?

    Hi there,
    What privileges needed for producing explain plan for other user's object (tables) ?
    Cheers
    Soheil

    Experiment: (public plan table exists)
    create user bob identified by bob;
    grant create session to bob;
    connect bob/bob
    start sample_plan
    If will error off on the table being read in the plan
    connect dba_or_privileged_user
    grant select on the referenced_table(s) to bob;
    connect bob/bob
    start sample_plan
    It will now work providing a public plan table exists or you give bob create table and create a bob.plan_table
    I ran the experiment on Oracle version 9.2.0.6 running on AIX 5.3. Select privilege on all referenced tables in the explained SQL must exist
    HTH -- Mark D Powell --

  • How to change the explain plan for currently running query?

    Hi All,
    I am using Oracle enterprise 9i edition. I have a query which frames dynamically and running in the database. I noticed a table with 31147758 rows
    in the query which has no indexes and taking more time to process. I tried to create an INdex on that table. I know the query is already running with a FULL table scan. Is it possible to change the explain plan for the current running query to consider the INDEX?
    [code]
    SELECT /*+ USE_HASH (c,e,b,a) */
    d.att_fcc extrt_prod_dim_id,
    d.att_fcc compr_prod_dim_id,
      a.glbl_uniq_id glbl_uniq_id,
      to_date(c.dit_code,'RRRRMMDD')STRT_DT,
      (to_date(c.dit_code,'RRRRMMDD')+150)END_DT,
      a.pat_nbr pat_id,
      a.rxer_id       rxer_id,
      e.rxer_geog_id  rxer_geog_id,
      a.pharmy_id pharmy_id,
      a.pscr_pack_id pscr_pack_id,
      a.dspnsd_pack_id dspnsd_pack_id,
      DENSE_RANK () OVER (PARTITION BY a.pat_nbr ORDER BY c.dit_code) daterank,
      COUNT( DISTINCT d.att_fcc ) OVER (PARTITION BY a.pat_nbr, c.dit_code) event_cnt
      DENSE_RANK () OVER (PARTITION BY a.pat_nbr,
    d.att_fcc
      ORDER BY c.dit_code) prodrank,
      DENSE_RANK () OVER (PARTITION BY a.pat_nbr,
    d.att_fcc
      ORDER BY c.dit_code DESC) stoprank
      FROM
      pd_dimitems c,
       pd_pack_attribs   d ,
        lrx_tmp_rxer_geog e,
        lrx_tmp_pat_daterank p,
        lrx_tmp_valid_fact_link     a
        WHERE c.dit_id = a.tm_id
        AND   e.rxer_id = a.rxer_id
        AND   a.glbl_uniq_id = p.glbl_uniq_id
        AND   p.daterank > 1
      AND   a.pscr_pack_id = d.att_dit_id
    [/code]
    The table lrx_tmp_pat_daterank is having that 31147758 rows. So I am wondering how to make the query to use the newly created index on the table?

    Why do you think using Indexes will improve the performance of the query? How many rows this query is returning? Optimizer might chose a Full table scan when it finds out that Index plan might not be useful. Why are you using /*+ USE_HASH (c,e,b,a) */ hint? This Hint will force oracle to use Full table scan instead of using the index. Try removing it and see if the plan changes.
    Regards,

  • How to find Explain Plan for a large querry which has multiple sub querries

    Hi All,
    I have a Package which has many procedures and one of the procedure has a cursor which is like 2000 lines. This cursor has a main select statement which again has many select statements in it.
    Now how do I do the explain plan for the main select statement?
    If it can be done easier way in toad(or SQLPLUS), please tell me...

    When your query takes too long ...

Maybe you are looking for

  • Can i fetch images from my remote server to UIImageView or a preview thumbnail in ios app?

    consider i have 1000 images in my hosting, i want all those images in my ios app. It is like ,in one screen around 9 thumbnails of image must be loaded from the webserver .And when i swipe the screen to the right another set of 9 thumbnail images mus

  • I've Got 99 Problems...

    Hey All, I've got so many issues going on with Final Cut Pro and, one project in particular, that I don't even know where to begin. Running the latest versions of everything, including the Apple Pro Application update from yesterday (10.21.05). All r

  • Possible exporting help for a old mac...

    Hi, me again. Trying to find a way to burn my 1 hour 30 movie to disk. I've found out that Final Cut Express cannot burn to disk, and to top it off, my copy (that came with my PowerPC Mac) of IDVD won't work either as i don't have a superdrive. Great

  • Send faxes through F110  and Interest Indicator

    Hello all, we have SAP ECC 6.0. , and it is needed to send faxes through F110 , 1) I would like to know the steps to send a fax through the  f110 transaction 2) Only send faxes for the vendors with interest indicator 3) Do you know some user exit to

  • VAT on iTunes purchase

    Can someone please tell me which VAT % is applicable on my iTunes purchases in Belgium. Is it the normal rate of 21% similar to the rate for other cd's in Belgium? Is it the 15 or 12% rate of Luxembourg (headoffice of iTunes Europe Sarl)? This simple