Sql tuning set explain plan

A hypothetical question came up between dbas in the office.   We regularly take tuning sets before making significant changes on the DB.  Populate from cache.  Great little way of checking to see if anything changed.  Someone asked if a table T1 was accessed during a given day where we had a tuning set being populated from the cache (no reason for auditing to be on at the time).  Well first thing to do is search the sql_statements
select * from DBA_SQLSET_STATEMENTS
where sqlset_name = 'my_sts'
and sql_text like '%select * from t1%'
but no rows returned, so next idea is to query the plan in case a synonym was used
select * from DBA_SQLSET_PLANS
where sqlset_name = 'my_sts'
and object_name = 'T1'
And yes, its there we had a select against the table, the main sql_text in the dba_sqlset_statments view was using a synonym.  great, so now we might be able to use this as a alternative audit method (mmv depending on whether you have the diag pack). 
Heres the question, can we always be guaranteed an object will be in a plan?

Dom Brooks wrote:
Also, the presence of a SQL statement in the shared pool does not indicate it was run today - you'd need to check the relevant column, something like last_active_time.
More importantly, the absence of a SQL statement from the shared pool does not indicate that it was not run today.
Just that it's no longer in the shared pool.
I'm concious of that when running the populate,  even in a busy period our pools last over an hour,  with that in mind when Im populating my tuning set, I set the frequency to 10 minutes to poll the cache where distinct IDs and HASHes are overloaded in the tuning set if theyre already there. 
http://docs.oracle.com/cd/B28359_01/appdev.111/b28419/d_sqltun.htm#CACJHDDC
Note that in production systems the time limit and repeat interval would be set much higher. You should tune the time_limit and repeat_interval parameters based on the workload time and cursor cache turnover properties of your system.

Similar Messages

  • Permissions needed for Applying SQL Tuning Sets/SQL Plans 11g?

    What permission are needed for a user to apply/activate sql tuning sets (sql plans) in 11g? The user can capture and move the the sql tuning sets from a 10g database to an 11g database but is getting "ORA-01031: insufficient privileges" when trying to activate/apply the sqlplans in 11g.
    The user has:
    ADMINISTER SQL MANAGEMENT OBJECT and ADMINISTER SQL TUNING SET and EXECUTE on SYS.DBMS_SPM
    The user is an administrator for our Data Warehouse team but they do not have sysdba priviliges.
    Do you also know of a good white paper that covers the step by step instructions and permissions needed for aquiring and applying/activating sqlplans?
    If more information is needed in order to respond please advise.
    Thank you

    What permission are needed for a user to apply/activate sql tuning sets (sql plans) in 11g? The user can capture and move the the sql tuning sets from a 10g database to an 11g database but is getting "ORA-01031: insufficient privileges" when trying to activate/apply the sqlplans in 11g.
    The user has:
    ADMINISTER SQL MANAGEMENT OBJECT and ADMINISTER SQL TUNING SET and EXECUTE on SYS.DBMS_SPM
    The user is an administrator for our Data Warehouse team but they do not have sysdba priviliges.
    Do you also know of a good white paper that covers the step by step instructions and permissions needed for aquiring and applying/activating sqlplans?
    If more information is needed in order to respond please advise.
    Thank you

  • List Sql Tuning Sets

    I am hoping for a quick easy answer on this. grin
    We have been generating a number of Sql Tuning Sets via Grid Control and now we want to export them. Of course, they all have these awful, non-descriptive names. How do we list them? I was unable to find any help in the "automatic SQL tuning" guide (Chapter 12) of the Performance Guide, and browsing the DBA_* and other fixed views has not revealed anything, yet.

    Does this help?
    BANPROD_SQL > select id,name,owner,description,created from WRI$_SQLSET_DEFINITIONS order by 1 desc;
    ID NAME OWNER DESCRIPTION CREATED
    10 TUNING_SET_1141930799317 ORACLE Automatically generated by ADDM 09-MAR-06
    9 TUNING_SET_1141921159123 ORACLE Automatically generated by ADDM 09-MAR-06
    8 TUNING_SET_1141831053351 ORACLE Automatically generated by ADDM 08-MAR-06
    7 TUNING_SET_1141826801391 ORACLE Automatically generated by ADDM 08-MAR-06
    6 TOP_SQL_1141752418284 ORACLE Automatically generated by Top SQL 07-MAR-06
    5 TOP_SQL_1141749589578 ORACLE Automatically generated by Top SQL 07-MAR-06
    4 TOP_SQL_1141747575814 ORACLE Automatically generated by Top SQL 07-MAR-06
    2 TOP_SQL_1141746930242 ORACLE Automatically generated by Top SQL 07-MAR-06
    1 TUNING_SET_1141660362671 ORACLE Automatically generated by ADDM 06-MAR-06
    9 rows selected.

  • Loading SQL Tuning Sets

    On a 10.2.0.4 database, is it possible to load SQL Tuning sets with SQL from a text file? I can't find anything in the documentation mentioning this but I could have simply missed it and this facility would be very useful to us.
    Our reporting tool is MicroStrategy which operates by building lots of temporary tables: extracting the SQL via Top Activity EM page will put the CTAS statement into the tuning set which (I believe) is ignored by SQL Access Advisor - extracting the sql to a text file, editting to remove the "create table as" and executing in order to load the tuning set is very long winded for a set of queries - at least being able to load the tuning set directly with a set of SQL select statements directly from a text file would help significantly.
    Many thanks for any advice
    Pete

    I did not see a direct way to create the STS from a text file. From the docs:
    "The standard sources for populating an STS are the workload repository, another STS, or the cursor cache"
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/sql_tune.htm#i34915
    But you could try a couple of things:
    1) create one tuning task per statement, using DBMS_SQLTUNE.CREATE_TUNING_TASK, which can use plain text as input: http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/sql_tune.htm#CHDJDHGE
    2) create the STS with queries from cursor cache: http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_sqltun.htm#i1010615
    Both approaches needs some PL/SQL programming, but it can be useful if you can identify your SQL statements some way.
    Regards.

  • ORA-13754: "SQL Tuning Set" "" does not exist for user "SYS"

    While calling dbms_stats.seed_col_usage I got the following error. Can someone help me on how to resolve it
    sqlplus
    SQL*Plus: Release 11.2.0.1.0 Production on Thu Apr 14 14:37:38 2011
    Copyright (c) 1982, 2009, Oracle. All rights reserved.
    Enter user-name: / as sysdba
    Connected to:
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    With the Partitioning, OLAP, Data Mining and Real Application Testing options
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE 11.2.0.1.0 Production
    TNS for IBM/AIX RISC System/6000: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    SQL> show user
    USER is "SYS"
    SQL> begin
    2 dbms_stats.seed_col_usage(null,null,400);
    3 end;
    4 /
    begin
    ERROR at line 1:
    ORA-13754: "SQL Tuning Set" "" does not exist for user "SYS".
    ORA-06512: at "SYS.DBMS_SQLTUNE_INTERNAL", line 17379
    ORA-06512: at "SYS.DBMS_STATS", line 28451
    ORA-06512: at line 2
    Thank You
    Sarayu

    According to the documentation:
    SEED_COL_USAGE ProcedureThis procedure iterates over the SQL statements in the specified SQL tuning set, compiles them and seeds column usage information for the columns that appear in these statements.
    Syntax
    DBMS_STATS.SEED_COL_USAGE (
    sqlset_name IN VARCHAR2,
    owner_name IN VARCHAR2,
    time_limit IN POSITIVE DEFAULT NULL);>
    It looks like you need to provide a SQLSET_NAME and OWNER_NAME to use this procedure correctly, to which you've provided NULLs. I don't see any exceptions in the documentation that indicate special processing when NULLs are provided.

  • Modify sql tuning set

    Hi Experts
    I have created a sql tuning set with all sqls from cursor cache referring table1. Now I have transported this sqlset to nonprod environment, now what I want to do is  make table1 partitioned and test the impact. Instead of altering table1 I want create copy of table1 as partitioned table2. Is there a way I cancl change the sqls in my sqlset to refer to table2 in place of table1. So I basically want to update the sqls with table2 instead of table1. Is this possible and if yes how? If no any other way of doing it, sqlset has ~200 sqls

    Why ever not!
    1. You create a new user with the appropriate privileges
    2. Logon as the new user and create private synonmys (if public ones do not exist) for the objects you need to use
    3. Either import a sql set or create a sqlset.
    4. Create and execute an analysis task - this will be your baseline
    5. Build test1 table as a partitioned table in the new schema - this will override the public synonym
    6. Execute an analysis task - this will be your post change run
    7. Compare results.

  • SQL tuning set for specific SQLID

    Hi,
    Is it possible to create SQL tuning set for specific SQLID's?
    Advance thanks!

    do you have any code or some package to do this?As long as those statements are in AWR or the cursor cache then you can use
    DBMS_SQLTUNE.SELECT_CURSOR_CACHE or
    DBMS_SQLTUNE.SELECT_WORKLOAD_REPOSITORY For example something like this:
    begin
      DBMS_SQLTUNE.CREATE_SQLSET(
        sqlset_name => 'my_tuning_set',
        description  => 'my tuning set');
    end;
    DECLARE
    baseline_cursor DBMS_SQLTUNE.SQLSET_CURSOR;
    BEGIN
    OPEN baseline_cursor FOR
          SELECT VALUE(p)
          FROM   TABLE(DBMS_SQLTUNE.SELECT_CURSOR_CACHE
                 (basic_filter      => 'sql_id in (''1'',''2'',''3'')',
                  attribute_list    => 'ALL'
                  )) p;
        DBMS_SQLTUNE.LOAD_SQLSET(
                 sqlset_name     => 'my_tuning_set',
                 populate_cursor => baseline_cursor);
    END;
    /

  • RAT - SQL Tuning Set from 9i trace in wrong order

    Hi together
    I want to test the impact of some staments on 9.2.0.8 in 11g with Real Application Testing, but the order in the tuning set seems to b wrong (not in the traced order). So i made a small Test Script who is creating a Table, insert Data with a loop and select all.
    Steps :
    * 9i enable trace level 4
    * 9i run the script
    * 9i stop the trace
    * transfer to 11g
    * make an sql tunnig set
    * running in the Performance Analyzer Workflow
    The first run Oracle makes performance datas from the trace files. In the second run I want to execute the statements from the tuning set in the 11g database. The traced Schema from 9i exists.
    In the report after the second run I see the failure that the insert and select statement is not allowed. When i take a look in the SQL Tuning Set i see that the select and insert will be played before the create table ! Also on the view DBA_SQLSET_STATEMENTS.
    Is there a way to get the correct order in the SQL Tuning Set like the statement order (create before insert,select) ? Or can Oracle not handle DDL-Statements in the trace ?
    Regards Martin

    Hi together
    I want to test the impact of some staments on 9.2.0.8 in 11g with Real Application Testing, but the order in the tuning set seems to b wrong (not in the traced order). So i made a small Test Script who is creating a Table, insert Data with a loop and select all.
    Steps :
    * 9i enable trace level 4
    * 9i run the script
    * 9i stop the trace
    * transfer to 11g
    * make an sql tunnig set
    * running in the Performance Analyzer Workflow
    The first run Oracle makes performance datas from the trace files. In the second run I want to execute the statements from the tuning set in the 11g database. The traced Schema from 9i exists.
    In the report after the second run I see the failure that the insert and select statement is not allowed. When i take a look in the SQL Tuning Set i see that the select and insert will be played before the create table ! Also on the view DBA_SQLSET_STATEMENTS.
    Is there a way to get the correct order in the SQL Tuning Set like the statement order (create before insert,select) ? Or can Oracle not handle DDL-Statements in the trace ?
    Regards Martin

  • Ora-01039 - Insuffficient priviliges - Tuning using Explain Plan

    In a TEST instance, i am trying (as the APPS user) on a 9.2.0.5 DB (11.5.10.2) trying to run an explain plan on a query but keep getting the 'ora-01039 - Insuffficient privileges on underlying objects of view' error message.
    I have granted 'select any dictionary' to both the APPS and APPLSYS users - but this does not seem to enable the explain plan to work.
    Could someone please shed some light on this?
    Tks

    You seem to be doin an Explain Plan on a query against a custom view against non-Apps objects.
    Explain Plan needs to be able to "see" the underlying tables (in that other schema).
    See :
    SQL> create view his_cntry_vw as select * from my_cntry;
    View created.
    SQL> grant select on his_cntry_vw to abc;
    Grant succeeded.
    SQL> connect abc/abc
    Connected.
    SQL> create synonym his_cntry_vw for otheruser.his_cntry_vw;
    Synonym created.
    SQL> select * from his_cntry_vw;
    GRP_I CNTRY
    ABC   Z9
    XYZ   UK
    SQL> explain plan for select * from his_cntry_vw;
    explain plan for select * from his_cntry_vw
    ERROR at line 1:
    ORA-01039: insufficient privileges on underlying objects of the view
    SQL> REM  THIS IS THE FIX :
    SQL> connect otheruser/otheruser
    Connected.
    SQL> grant select on my_cntry to abc;
    Grant succeeded.
    SQL> connect abc/abc
    Connected.
    SQL> explain plan for select * from his_cntry_vw;
    Explained.
    SQL>Hemant K Chitale
    http://hemantoracledba.blogspot.com

  • How does SQL Developer run EXPLAIN PLAN?

    Hello,
    I noticed that SQL Developer can do an EXPLAIN PLAN even though I don't have a PLAN_TABLE available for the user that I use to connect in SQL Developer.
    I was always wondering whether there was a way to do an EXPLAIN PLAN without a PLAN_TABLE, apparently this seems to be possible.
    Thomas

    If I try an explain plan when I do not have a plan table available, I get the message "A PLAN_TABLE is required to access the explain plan, but it does not exist. Do you want to create a PLAN_TABLE?". Unfortunately, as that user does not have create table privs, if I say Yes I get the following error "ORA-01031: insufficient privileges".
    Given this, if you are doing an explain plan, you either have access to a plan table or you have create table privs and SQL Developer has created the plan table for you.

  • How to export results of explain plan?

    A colleague tells me that in an older version of SQLDeveloper (1.2.1, perhaps?), he was able to export the results of the explain plan operation (I don't know what export forms were available). In the current version (1.5.1), it generates a tree component with information I can look at, but there's no way to write out these results in any form. Am I missing something?

    HOW TO TRANSPORT A SQL TUNING SET [ID 456019.1]
    Modified 08-SEP-2008 Type HOWTO Status PUBLISHED
    In this Document
    Goal
    Solution
    Applies to:
    Oracle Server - Enterprise Edition - Version: 10.2.0.1 to 11.1.0.6
    Information in this document applies to any platform.
    10.2.X,11.1.X
    Goal
    The Purpose of This Note is to Show the Steps needed to Transport a Sql Tuning Set from
    One Database server to another Database Server.
    Solution
    The Sql Tuning Set name is small_sh_sts_4.It is on 10.2.0.2.0 Database server.
    It has 4 sqls .
    select sql_id, substr(sql_text,1, 15) text
    from dba_sqlset_statements
    where sqlset_name = 'small_sh_sts_4'
    order by sql_id;
    SQL_ID TEXT
    4qdz7j26mdwzb SELECT /*+ my_q
    6y289t15dqj9r SELECT /*+ my_q
    ckm14c67njf0q SELECT /*+ my_q
    g37muqb81wjau SELECT /*+ my_q
    1) Create the Staging Table ON THE SOURCE SYSTEM ( IN this case 10.2.0.2.0 ) .
    execute DBMS_SQLTUNE.CREATE_STGTAB_SQLSET(table_name =>'TEST');
    PL/SQL procedure successfully completed.
    SQL> select count(*) from test;
    COUNT(*)
    0
    2) Popluate the table TEST using DBMS_SQLTUNE.PACK_STGTAB_SQLSET THE SOURCE SYSTEM (IN this case 10.2.0.2.0 )
    execute DBMS_SQLTUNE.PACK_STGTAB_SQLSET(sqlset_name => 'small_sh_sts_4',staging_table_name => 'TEST');
    PL/SQL procedure successfully completed.
    select count(*) from test;
    SQL> select count(*) from test;
    COUNT(*)
    4
    3) Export the table table test on THE SOURCE SYSTEM ( IN this case 10.2.0.2.0 )
    and move the table to the Destination Server
    and Import it . The staging table TEST can also be moved using
    the mechanism of choice such as datapump or database link.
    While exporting the table you will see something like
    About to export specified tables via Conventional Path ...
    Table(T) or Partition(T:P) to be exported: (RETURN to quit) > TEST
    . . exporting table TEST 4 rows exported
    . . exporting table TEST_CBINDS 0 rows exported
    . . exporting table TEST_CPLANS 34 rows exported
    Import on the Destination system ( IN this CASE it was 11.1.0.6.0 )
    While Importing the table you will see something like
    . importing SH's objects into SH
    . importing SH's objects into SH
    . . importing table "TEST" 4 rows imported
    . . importing table "TEST_CBINDS" 0 rows imported
    . . importing table "TEST_CPLANS" 34 rows imported
    Import terminated successfully without warnings.
    SQL> select count(*) from test;
    COUNT(*)
    4
    Verify the contents of DBA_SQLSET or USER_SQLSET on the Destination system
    Select NAME,CREATED,STATEMENT_COUNT FROM DBA_SQLSET;
    4) Unpack the table using DBMS_SQLTUNE.UNPACK_STGTAB_SQLSET on the Destination system ( IN this CASE it was 11.1.0.6.0 )
    execute DBMS_SQLTUNE.UNPACK_STGTAB_SQLSET( sqlset_name => '%',-
    replace => TRUE,-
    staging_table_name => 'TEST');
    Select NAME,OWNER,CREATED,STATEMENT_COUNT FROM DBA_SQLSET;
    NAME CREATED STATEMENT_COUNT
    small_sh_sts_4 24-AUG-07 4
    Related
    Products
    •Oracle Database Products > Oracle Database > Oracle Database > Oracle Server - Enterprise Edition

  • 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

  • Explain plan changed

    Hi All,
    I have a performance issues in one of my database when i checked found that the plan has been changed.
    The previous plan was good and the new plan causing the slowness in query level.
    There is no code level change, No data volume increasing/ Nothing got changed in that query.
    i want to reset the old plan for this query, how can we proceed with that.
    is there any way to reset the old plan for the current query!!!
    please help me
    I dont have the query and plan details with me now, but curious to know how do we set it back with old(good) plan.
    RDBMS version: Version 11.2.0.3
    Edition: Enterprise Edition
    OS: Linux 5.6
    Thanks

    What is the cause of the plan change?
    On 11.2.0.3, it might be cardinality feedback.
    but curious to know how do we set it back with old(good) plan.Assuming you have the old, good plan in either the cursor cache or in AWR, then you have at least two options - one to load the plan into a sql plan baseline or to use a sql profile.
    Assuming that the old plan is not in the cursor cache but is still in AWR, then the steps are along the lines of:
    1. Create a SQL tuning set using DBMS_SQLTUNE.CREATE_SQLSET
    2. Load in your specific plan from AWR into a SQLSET using DBMS_SQLSET.LOAD_SQLSET and DBMS_SQLTUNE.SELECT_WORKLOAD_REPOSITORY
    3. Load plan into a baseline using DBMS_SPM.LOAD_PLANS_FROM_SQLSET.
    Alternatively, to use a sql profile to lock in a specific plan using outline hints, see COE_XFR_SQL_PROFILE script via Oracle Support doc id 215187.1
    The latter is certainly easier but baselines are marketed as sql plan management 2.0.

  • Book advise for explain plan

    Hi guys,
    I have 2 questions. The first one is as you know before, I would like to learn all secrets behind explain plan and how how oracle works behind the scenery. I have researched some books. I found Oracle SQL Tuning: A Close Look at Explain Plans by Dan Hotka. Do you recommend this book? I have just read one page of this books, I thnik the language of this book is simple and it explains the situation from the beginning. I think, it is usefull for beginners like me. Because the things become hard to learn in first time for beginners. As a result I just would like to learn that do you recommend this book?
    My second question is, I want to buy this book but I couldn't find in England (as paperback, not e book). But, appereantly I have to buy it online as ebook. Do you know any trusted web site that I can buy this book's ebook version?
    Thanks a lot for your help.

    944258 wrote:
    Hi guys,
    I have 2 questions. The first one is as you know before, I would like to learn all secrets behind explain plan and how how oracle works behind the scenery. I have researched some books. I found Oracle SQL Tuning: A Close Look at Explain Plans by Dan Hotka. Do you recommend this book? I have just read one page of this books, I thnik the language of this book is simple and it explains the situation from the beginning. I think, it is usefull for beginners like me. Because the things become hard to learn in first time for beginners. As a result I just would like to learn that do you recommend this book?Hi, why not start here first: http://www.orafaq.com/node/1420. There is probably as much information about execution plans found online, as there is in the books. At least the part you would like to know and try to remember will be online available :-)
    >
    My second question is, I want to buy this book but I couldn't find in England (as paperback, not e book). But, appereantly I have to buy it online as ebook. Do you know any trusted web site that I can buy this book's ebook version?
    http://www.amazon.com/Oracle-SQL-Tuning-Close-Explain/dp/1453804196
    Cheers
    FJFranken

  • Sql tuning advisor for concurrent requests

    Dear all,
    I am having one doubt in my mind from very long time.Can we use sql tuning advisor from 10G(EM) to tune concurrent requests and reports?
    Regards

    Hi Helios,
    I am just thinking wiht voice. If you have one code blog which is typed in sql-pl/sql for your concurrent request, its going and run on dbtier. So it has one SQL'ID and also can be check on AWR report. So i belive you can use sqltuning adviser for to can tune related sqlAFAIK, some Instances a single concurrent request may contain multiple SQLID's and in that scenario tuning approach is difficult. Any information how can we consolidate it. If tune one specific sql then the explain plan for other sql become more worst. I came across this situation so many time.
    Any information or inputs on this is really appreciated.
    thanks,
    X A H E E R

Maybe you are looking for