Explain Plan Questions

Hi All,
Q1. Performance wise are the following queries both same.
Which one will yield a better throughput and why?
Approach 1
SELECT
e.desig "Emp Desig",
(select count(1) from emp where empid = e.empid and dt_created between sysdate and sysdate -1) "Emp added since yday",
(select count(1) from emp where empid = e.empid and case_solved_count > 10 ) "Emp with case solved counts > 10",
FROM EMP e
Approach 2
SELECT
e.desig "Emp Desig",
Func1(e.empid ),
Func2(e.empid )
FROM emp e
Q2. If we have three tables T1, T2 and T3 with following record counts - Will their sequence of placement in WHERE clause of the query affect performance? (My understanding is it should not)
Table Record Count
T1 5000
T2 500000
T3 50
Need expert advise....
Regards,
Chinmay
Happy Working

Where did you get these questions from?
Q1. Performance.. is the same. Which one will yield a better throughput and why?
What is the difference between performance and throughput in this context? How in the world throughput could be better when "performance is the same"?
Performance cannot be the same even when Func1 and Func2 contain no more than exactly the same sub-queries as in the 1st SELECT. Functions are called for each row in EMP and each call leads to so called context switch between SQL executor and PL/SQL. This is expensive and may result in substantial increase of elapsed time given the number of rows in EMP is relatively large
On the other hand if the functions contain no more than dummy NULL statement then 2nd query most certainly would perform better
Q2. It depends. With correct statistics and CBO - no, not a chance. With RBO it depends on
1. What is your understanding of "their [tables] sequence of placement in WHERE clause". There are no tables in WHERE clause, there are predicates that mostly deal with table [pseudo]columns
2. Are there any indexes on the tables
3. Which expressions do you use in WHERE clause
4. etc..
Consider following:
DROP TABLE T1;
DROP TABLE T2;
DROP TABLE T3;
CREATE TABLE T1(C1 NUMBER CONSTRAINT T1_PK PRIMARY KEY);
CREATE TABLE T2(C2 NUMBER CONSTRAINT T2_PK PRIMARY KEY);
CREATE TABLE T3(C3 NUMBER CONSTRAINT T3_PK PRIMARY KEY);
INSERT INTO T1 (SELECT OBJECT_ID FROM ALL_OBJECTS);
INSERT INTO T2 (SELECT OBJECT_ID FROM ALL_OBJECTS WHERE ROWNUM <= 1);
INSERT INTO T3 (SELECT OBJECT_ID FROM ALL_OBJECTS WHERE ROWNUM <= 1000);
SET AUTOTRACE TRACEONLY
SELECT --+ RULE
          C1
     FROM T1, T2, T3
     WHERE C3 = C1
          AND C1 = C2
Execution Plan
   0      SELECT STATEMENT Optimizer=HINT: RULE
   1    0   NESTED LOOPS
   2    1     NESTED LOOPS
   3    2       TABLE ACCESS (FULL) OF 'T3'
4 2 INDEX (UNIQUE SCAN) OF 'T1_PK' (UNIQUE)
5 1 INDEX (UNIQUE SCAN) OF 'T2_PK' (UNIQUE)
Statistics
       1008 consistent gets
But
SELECT --+ RULE
          C1
     FROM T1, T2, T3
     WHERE C3 = C2
          AND C1 = C2
Execution Plan
   0      SELECT STATEMENT Optimizer=HINT: RULE
   1    0   NESTED LOOPS
   2    1     NESTED LOOPS
   3    2       TABLE ACCESS (FULL) OF 'T3'
4 2 INDEX (UNIQUE SCAN) OF 'T2_PK' (UNIQUE)
5 1 INDEX (UNIQUE SCAN) OF 'T1_PK' (UNIQUE)
Statistics
       8 consistent getsFortunately RBO is depricated and unsupported in 10g, so the answer should be NO.

Similar Messages

  • Question regarding using of Explain Plan

    Hi. I'm new with Oracle Queries so I have a little obstacles about understanding. I want to learn how to use Explain Plan feature from Oracle
    I am using Oracle 9i as back end .
    Please tell me how can i use feature of Explain Plan Feature for the below query.
    SELECT * FROM emp WHERE empno = 7369
    Thanks in advance.

    [email protected] wrote:
    Hi. I'm new with Oracle Queries so I have a little obstacles about understanding. I want to learn how to use Explain Plan feature from Oracle
    I am using Oracle 9i as back end .
    Please tell me how can i use feature of Explain Plan Feature for the below query.
    SELECT * FROM emp WHERE empno = 7369
    Kiran,
    Firstly , before anything else, I would suggest to change your handle to anything else and remove the email id from it. Its not good to have the id displayed in any public forum.
    About the question, unfortunately, its not that easy to answer. To understand explain plan and how to use it, you need to understand that algorithm/mechanism, whatever you feel like saying, that generates it. Because, explain plan is just the outcome of that mechanism, a final product, its the result of some inputs given by you in the form of your query, predicates, joins and their types and that all bring up the explain plan. Explain plan is basically the constitution of some steps which are used /fixed by optimizer to run the query. I would suggest that you read this page from cover to cover to understand some of the steps and their meanings which are shown to you in the plan. I am giving 10g link as this is a more better version of optimizer than the previous ones and I would suggest you to do experiments on 10g only.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/optimops.htm#i21299
    And I would suggest that you collect these following books and start reading them. I haven't yet found any thing better than these books.
    [Cost Based Oracle Fundamentals (Jonathan Lewis)|http://www.amazon.com/Cost-Based-Oracle-Fundamentals-Experts-Voice/dp/1590596366]
    [Troubleshooting Oracle Performance(Christian Antognini )|http://www.amazon.com/Troubleshooting-Oracle-Performance-Christian-Antognini/dp/1590599179/ref=sr_1_1?ie=UTF8&s=books&qid=1240078634&sr=1-1]
    [Effectuve Oracle By Design(Tom Kyte)|http://www.amazon.com/Effective-Oracle-Design-Osborne-ORACLE/dp/0072230657/ref=sr_1_1?ie=UTF8&s=books&qid=1240078698&sr=1-1]
    It would be real long journey before the mazes of optimizer and explain would be clear so make sure you have patience as well.
    HTH
    Aman....

  • Question about running explain plan

    I tried to run explain plan for a simple query, just to familiarize myself with how to do it. (I have another query that's taking a long time, and I've never run explain plan before). I got an error, googled it, and discovered I had to run the file at @%ORACLE_HOME%\rdbms\admin\utlxplan.sql first, to create the Plan_Table. Well, I tried to run that file and I get the error that I don't have priveleges on the tablespace. This really doesn't surprise me, as my access is read-only. Is there any way around this? I don't know a whole lot about databases, so forgive me if these following questions are dumb, but...
    1) is that file basically trying to create a table (called Plan_Table) within the schema I'm in (the only schema I have access to)?
    2) can my company's DBA run that file for me to create the Plan_Table?

    What version of the database are you on?
    You can get run-time execution plans from V$SQL_PLAN. You will need permission to read the V$ views. First find your query in V$SQL_PLAN (you can do a text search; putting a comment in like '--my_query' can help), then join to V$SQL_PLAN to find the query plan that that query used - join by the ADDRESS and HASH_VALUE columns.
    Otherwise, see if you can get insert/update/delete access on just that one table when your DBA creates it
    Good luck.

  • Explain plans - caching question

    I am trying to get some explain plan information for some queries that we have running poorly. Our application uses some alter session statements to set the optimizer_mode to all_rows. I am trying to determine if we need to include the optimizer_index_cost_adj parameter and possibly the optimizer_index_caching parameter.
    Using SQL Developer I can easily run the different alter session statements needed and then get an explain plan for the query in question. However I am seeing some weird results - for example long query times for queries that have a relatively low cost. On the flip side I am seeing some queries that have a higher cost return quicker.
    I am doing this many times over and am wondering what impact using the same query could have. Is this query being cached in Oracle? To get an accurate explain plan would I need to clear a cache each time?
    Also, in the explain plan is the cost figure the most important? How is it that a query can have a low cost and take longer to complete than the same query with a higher cost and some different parameters?

    There are no fixed road map for what to see in explain plan,but some common observation should be made for explain plan i.e full table scans due to poor use of indexing,inappropriate hints uses for forcing indexing where FTS can be faster.unnecessary sorting,cartesian
    joins, outer joins, and anti-joins.
    At last i would say that every database vary to its different hardware platforms and those hardware have different configuration,these things can effect oracle optimizer.
    So, if my statistics are current, what should I be
    taking out of the explain plan? I always assumed
    cost was the main indicator of the performance of a
    query.As justin already told cost is not something which should be considered for tuning query rather access path, but there is more other then explain plan access path e.g TKPROF tool which will address you plan as well as others stuff which should be considered for tuning query.
    http://download.oracle.com/docs/cd/B10501_01/server.920/a96533/sqltrace.htmKhurram

  • A question about explain plan

    here is my sql statement and running result:
    SQL> @bind_variables_peeking_test.sql
    SQL> SET ECHO OFF
    SQL>
    SQL> REM
    SQL> REM Setup test environment
    SQL> REM
    SQL>
    SQL> ALTER SYSTEM FLUSH SHARED_POOL;
    SQL>
    SQL> DROP TABLE t;
    DROP TABLE t
    ERROR at line 1:
    ORA-00942: table or view does not exist
    SQL>
    SQL> CREATE TABLE t
    2 AS
    3 SELECT rownum AS id
    4 FROM dual
    5 CONNECT BY level <= 1000;
    SQL>
    SQL> execute dbms_stats.gather_table_stats(ownname=>user, tabname=>'t');
    SQL> SELECT count(id), count(DISTINCT id), min(id), max(id) FROM t;
    COUNT(ID) COUNT(DISTINCTID) MIN(ID) MAX(ID)
    1000 1000 1 1000
    SQL>
    SQL> PAUSE
    SQL>
    SQL> REM
    SQL> REM Without bind variables different execution plans are used if the value
    SQL> REM used in the WHERE clause change. This is because the query optimizer
    SQL> REM recognize the different selectivity of the two predicates.
    SQL> REM
    SQL>
    SQL> SELECT count(*) FROM t WHERE id < 990;
    COUNT(*)
    989
    SQL>
    SQL> SELECT * FROM table(dbms_xplan.display_cursor(NULL, NULL, 'typical'));
    PLAN_TABLE_OUTPUT
    SQL_ID bspfffaycy92u, child number 0
    SELECT count(*) FROM t WHERE id < 990
    Plan hash value: 2966233522
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | | | 3 (100)| |
    | 1 | SORT AGGREGATE | | 1 | 3 | | |
    |* 2 | TABLE ACCESS FULL| T | 990 | 2970 | 3 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    2 - filter("ID"<990)
    SQL>
    SQL> PAUSE
    SQL>
    SQL> SELECT count(*) FROM t WHERE id < 10;
    COUNT(*)
    9
    SQL>
    SQL> SELECT * FROM table(dbms_xplan.display_cursor(NULL, NULL, 'typical'));
    PLAN_TABLE_OUTPUT
    SQL_ID 4xfxt0frkj40y, child number 0
    SELECT count(*) FROM t WHERE id < 10
    Plan hash value: 2966233522
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | | | 3 (100)| |
    | 1 | SORT AGGREGATE | | 1 | 3 | | |
    |* 2 | TABLE ACCESS FULL| T | 9 | 27 | 3 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    2 - filter("ID"<10)
    SQL>
    SQL> PAUSE
    SQL>
    SQL> REM
    SQL> REM With bind variables the same execution plan is used. Depending on the
    SQL> REM peeked value (10 or 990), a full table scan or an index range scan is used.
    SQL> REM
    SQL>
    SQL> EXECUTE :id := 10;
    SQL>
    SQL> SELECT count(*) FROM t WHERE id < :id;
    COUNT(*)
    9
    SQL>
    SQL> SELECT * FROM table(dbms_xplan.display_cursor(NULL, NULL, 'typical'));
    PLAN_TABLE_OUTPUT
    SQL_ID dkva59ypaxa6w, child number 0
    SELECT count(*) FROM t WHERE id < :id
    Plan hash value: 2966233522
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | | | 3 (100)| |
    | 1 | SORT AGGREGATE | | 1 | 3 | | |
    |* 2 | TABLE ACCESS FULL| T | 9 | 27 | 3 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    2 - filter("ID"<:ID)
    SQL>
    SQL> PAUSE
    SQL>
    SQL> EXECUTE :id := 10;
    SQL>
    SQL> SELECT count(*) FROM t WHERE id < :id;
    COUNT(*)
    9
    SQL>
    SQL> SELECT * FROM table(dbms_xplan.display_cursor(NULL, NULL, 'typical'));
    PLAN_TABLE_OUTPUT
    SQL_ID dkva59ypaxa6w, child number 0
    SELECT count(*) FROM t WHERE id < :id
    Plan hash value: 2966233522
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | | | 3 (100)| |
    | 1 | SORT AGGREGATE | | 1 | 3 | | |
    |* 2 | TABLE ACCESS FULL| T | 9 | 27 | 3 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    2 - filter("ID"<:ID)
    SQL>
    SQL> PAUSE
    SQL>
    SQL> ALTER SYSTEM FLUSH SHARED_POOL;
    SQL>
    SQL> PAUSE
    SQL>
    SQL> EXECUTE :id := 10;
    SQL> SELECT count(*) FROM t WHERE id < :id;
    COUNT(*)
    9
    SQL> explain plan for SELECT count(*) FROM t WHERE id < :id;
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 2966233522
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 1 | 3 | 3 (0)| 00:00:01 |
    | 1 | SORT AGGREGATE | | 1 | 3 | | |
    |* 2 | TABLE ACCESS FULL| T | 50 | 150 | 3 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    2 - filter("ID"<TO_NUMBER(:ID))
    SQL>
    SQL> ALTER SYSTEM FLUSH SHARED_POOL;
    SQL> PAUSE
    SQL>
    SQL> EXECUTE :id := 10;
    SQL>
    SQL> SELECT count(*) FROM t WHERE id < :id;
    COUNT(*)
    9
    SQL>
    SQL> SELECT * FROM table(dbms_xplan.display_cursor(NULL, NULL, 'typical'));
    PLAN_TABLE_OUTPUT
    SQL_ID dkva59ypaxa6w, child number 0
    SELECT count(*) FROM t WHERE id < :id
    Plan hash value: 2966233522
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | | | 3 (100)| |
    | 1 | SORT AGGREGATE | | 1 | 3 | | |
    |* 2 | TABLE ACCESS FULL| T | 9 | 27 | 3 (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    2 - filter("ID"<:ID)
    SQL>
    SQL>
    SQL> PAUSE
    SQL>
    SQL> REM
    SQL> REM Cleanup
    SQL> REM
    SQL>
    SQL> UNDEFINE sql_id
    SQL>
    SQL> DROP TABLE t;
    SQL> PURGE TABLE t;
    SQL>
    SQL> spool off;
    please noticed the last two explain plan result,one sql statement but have two result,why?

    what do you mean "invalidated the previous plan"?
    i gather the table statistics information once.
    every time before i run the statement and explain plan, i flush share pool to make sure there are not execution plan to reused.
    so i think i do not invalidated the previous plan and the two result should be same.

  • Query tunning in Oracle using Explain Plan

    Adding to my below question: I have now modified the query and the path shownby 'Explain plan' has reduced. The 'Time' column of plan_table is also showing much lesser value. However, some people are suggesting me to consider the time required by the query to execute on Toad. Will it be practical? Please help!!
    Hi, I am using Oracle 11g. I need to optimize a Select query(Need to minimize the execution time). I need to know how 'Explain Plan' would help me. I know how to use Explain Plan command. I refer Plan_table table to see the details of the plan. Please guide me regarding which columns of the Plan_table should be considered while modifying the query for optimization. Some people say, 'Time' column should be considered, some say 'Bytes' etc. Some suggest on minimizing the full table scans, while some people say that I should minimize the total no. operations (less no. of rows should be displayed in Plan_table). As per an experienced friend of mine, full table scans should be reduced (for e.g. if there are 5 full table scans in the plan, then try to reduce them to less than 5. ). However, if I consider any full table scan operation in the plan_table, its shows value of 'time' column as only 1 which is very very less. Does this mean the full scan is actually taking very less time?? If yes, then this means full table scans are very fast in my case and no need to work on them. Some articles suggest that plan shown by 'Explain Plan' command is not necessarily followed while executing the query. So what should I look for then? How should I optimize the query and how will I come to know that it's optimized?? Please help!!...
    Edited by: 885901 on Sep 20, 2011 2:10 AM

    885901 wrote:
    Hi, I am using Oracle 11g. I need to optimize a Select query(Need to minimize the execution time). I need to know how 'Explain Plan' would help me. I know how to use Explain Plan command. I refer Plan_table table to see the details of the plan. Please guide me regarding which columns of the Plan_table should be considered while modifying the query for optimization. Some people say, 'Time' column should be considered, some say 'Bytes' etc. Some suggest on minimizing the full table scans, while some people say that I should minimize the total no. operations (less no. of rows should be displayed in Plan_table). As per an experienced friend of mine, full table scans should be reduced (for e.g. if there are 5 full table scans in the plan, then try to reduce them to less than 5. ). However, if I consider any full table scan operation in the plan_table, its shows value of 'time' column as only 1 which is very very less. Does this mean the full scan is actually taking very less time?? If yes, then this means full table scans are very fast in my case and no need to work on them. Some articles suggest that plan shown by 'Explain Plan' command is not necessarily followed while executing the query. So what should I look for then? How should I optimize the query and how will I come to know that it's optimized?? Please help!!...how fast is fast enough?

  • Performance problem: Query explain plan changes in pl/sql vs. literal args

    I have a complex query with 5+ table joins on large (million+ row) tables. In it's most simplified form, it's essentially
    select * from largeTable large
    join anotherLargeTable anothr on (anothr.id_2 = large.pk_id)
    join...(other aux tables)
    where large.pk_id between 123 and 456;
    Its performance was excellent with literal arguments (1 sec per execution).
    But, when I used pl/sql bind argument variables instead of 123 and 456 as literals, the explain plan changes drastically, and runs 10+ minutes.
    Ex:
    CREATE PROCEDURE runQuery(param1 INTEGER, param2 INTEGER){
    CURSOR LT_CURSOR IS
    select * from largeTable large
    join anotherLargeTable anothr on (anothr.id_2 = large.pk_id)
    join...(other aux tables)
    where large.pk_id between param1 AND param2;
    BEGIN
    FOR aRecord IN LT_CURSOR
    LOOP
    (print timestamp...)
    END LOOP;
    END runQuery;
    Rewriting the query 5 different ways was unfruitful. DB hints were also unfruitful in this particular case. LargeTable.pk_id was an indexed field as were all other join fields.
    Solution:
    Lacking other options, I wrote a literal query that concatenated the variable args. Open a cursor for the literal query.
    Upside: It changed the explain plan to the only really fast option and performed at 1 second instead of 10mins.
    Downside: Query not cached for future use. Perfectly fine for this query's purpose.
    Other suggestions are welcome.

    AmandaSoosai wrote:
    I have a complex query with 5+ table joins on large (million+ row) tables. In it's most simplified form, it's essentially
    select * from largeTable large
    join anotherLargeTable anothr on (anothr.id_2 = large.pk_id)
    join...(other aux tables)
    where large.pk_id between 123 and 456;
    Its performance was excellent with literal arguments (1 sec per execution).
    But, when I used pl/sql bind argument variables instead of 123 and 456 as literals, the explain plan changes drastically, and runs 10+ minutes.
    Ex:
    CREATE PROCEDURE runQuery(param1 INTEGER, param2 INTEGER){
    CURSOR LT_CURSOR IS
    select * from largeTable large
    join anotherLargeTable anothr on (anothr.id_2 = large.pk_id)
    join...(other aux tables)
    where large.pk_id between param1 AND param2;
    BEGIN
    FOR aRecord IN LT_CURSOR
    LOOP
    (print timestamp...)
    END LOOP;
    END runQuery;
    Rewriting the query 5 different ways was unfruitful. DB hints were also unfruitful in this particular case. LargeTable.pk_id was an indexed field as were all other join fields.
    Solution:
    Lacking other options, I wrote a literal query that concatenated the variable args. Open a cursor for the literal query.
    Upside: It changed the explain plan to the only really fast option and performed at 1 second instead of 10mins.
    Downside: Query not cached for future use. Perfectly fine for this query's purpose.
    Other suggestions are welcome.Best wild guess based on what you've posted is a bind variable mismatch (your column is declared as a NUMBER data type and your bind variable is declared as a VARCHAR for example). Unless you have histograms on the columns in question ... which, if you're using bind variables is usually a really bad idea.
    A basic illustration of my guess
    http://blogs.oracle.com/optimizer/entry/how_do_i_get_sql_executed_from_an_application_to_uses_the_same_execution_plan_i_get_from_sqlplus

  • What are the privileges required for explain plan in Oracle 11g database

    I am facing the problem in doing a explain plan for a view in Oracle 11g database. When I select from the view like this:
    select * from zonewisearpu
    It does a select on the view but when I give explain plan like
    explain plan for
    select * from zonewisearpu
    I get the error like insufficient privileges.
    Please let me know if things are getting missed out as I guess system level privileges are required to execute this.
    I hope, my question is clear.
    It’s a humble request to revert urgently if possible as I need to complete a task and do not know the way out.
    Regards

    975148 wrote:
    Thanks for your reply. I have found out that an explain plan is possible on the user's own objects and is not possible on the granted objects from a different schema. For eg, if I do a explain plan on a view querying on tables from a different view, it would not allow the explain plan to proceed. This could mean that explain plan needs different privileges than just a select.
    Requesting for a revert to this.
    Here is a simple test case that I have perfomed
    SQL> create user test1 identified by test1;
    User created.
    SQL> create user test2 identified by test1;
    User created.
    SQL> grant connect, resource to test1,test2;
    Grant succeeded.
    SQL> create table test1.tab1 as select * from v$session;
    Table created.
    SQL> connect test2/test1
    Conencted.
    SQL> show user
    USER is "TEST2"
    SQL>
    SQL> explain plan for
      2  select sid,serial#,status,username from test1.tab1 where username<> '';
    Explained.
    SQL>
    So, as can be seen I am able to do a explain plan from user test2 for tables belong to user test1.
    As far as privileges are concerned, following is the list
    SQL> select * from dba_role_privs where grantee in ('TEST1','TEST2') order by 1;
    GRANTEE                        GRANTED_ROLE                   ADM DEF
    TEST1                          CONNECT                        NO  YES
    TEST1                          RESOURCE                       NO  YES
    TEST2                          CONNECT                        NO  YES
    TEST2                          RESOURCE                       NO  YES
    SQL>
    SQL> select grantee,owner,table_name,privilege from dba_tab_privs where grantee in ('TEST1','TEST2') order by 1;
    GRANTEE    OWNER      TABLE_NAME           PRIVILEGE
    TEST2      TEST1      TAB1                 SELECT
    SQL>
    SQL>  select * from dba_sys_privs where grantee in ('TEST1','TEST2') order by 1;
    GRANTEE    PRIVILEGE                      ADM
    TEST1      UNLIMITED TABLESPACE           NO
    TEST2      UNLIMITED TABLESPACE           NO
    SQL>

  • Explain Plan query

    I just changed the hint to pick different indexes inside the same SQL and they have significant different performance. SQL1 is much faster than SQL2 and the explain plain is very different. I found that there is some values like :Q1003, :Q1004 and :Q1005 under Object Code in the explain plan of SQL1. May I know how to interpret this?
    Thanks.
    Edited by: 843672 on Mar 11, 2011 3:42 AM

    Welcome to the forum.
    Before you even think of posting another 'question', first read:
    http://tkyte.blogspot.com/2005/06/how-to-ask-questions.html
    and secondly, when it comes to tuning requests, read:
    When your query takes too long ...
    HOW TO: Post a SQL statement tuning request - template posting
    and there's also a FAQ and a SQL and PL/SQL FAQ....
    http://forums.oracle.com/forums/ann.jspa?annID=1535

  • Explain Plan in SQL Developer vs. SQLPlus

    Hi everyone,
    I've got a quick question. Why would an explain plan hang in SQL Developer but come back immediately in SQL Plus?
    For example, in SQL developer, I write my statement and use the F6 command to bring up the explain plan and it just hangs and hangs. It looks like it's trying to generate an explain plan, but it's been running for hours now.
    When I log into SQL Plus, I do a
    SQL> explain plan for <query>:
    SQL> select * from table(dbms_xplan.display);That whole process takes less than a minute to get the explain plan.
    Is there something fundamentally different being executed by SQL Developer?
    Thanks!
    -Joe

    Joe,
    F6 in SQL Developer runs an AutoTrace, which actually runs the SQL and also displays timings and the explain plan. If you only want the explain plan, use F10.
    Regards,
    Bob

  • Explain plan for same query in three databases

    Hi,
    We have three databases dev, uat and test, all have same init parameters and almost same data. We are running a query which runs long on dev and on uat and test it runs very fast, the explain plan on uat and test shows a cost of around 4000 but on dev the cost is 20000. Statistics were collected on three instances 2 days ago and the objects are also same.
    My question is what else should I look for this optimizer behaviour? the database version is 10.2.0.3.
    Please help.
    Thanks
    Clin

    user627471 wrote:
    Hi,
    We have three databases dev, uat and test, all have same init parameters and almost same data. We are running a query which runs long on dev and on uat and test it runs very fast, the explain plan on uat and test shows a cost of around 4000 but on dev the cost is 20000. Statistics were collected on three instances 2 days ago and the objects are also same.
    My question is what else should I look for this optimizer behaviour? the database version is 10.2.0.3.
    Please help.
    Thanks
    Clinpost both EXPLAIN PLAN here

  • Hi when i run this in toad for explain plan  its showing an error ORA_22905

    hi when i run this query in toad for explain plan its showing an error ORA_22905 cannot accesss rows from an non nested table item can anyone help me out
    SELECT
    DISTINCT SERVICE_TBL.SERVICE_ID , SERVICE_TBL.CON_TYPE, SERVICE_TBL.S_DESC || '(' || SERVICE_TBL.CON_TYPE || ')' AS SERVICE_DESC ,SERVICE_TBL.CON_STAT
    FROM
    TABLE(:B1 )SERVICE_TBL
    WHERE
    CON_NUM = :B2
    thanks

    Note the name of this forum is SQL Developer *(Not for general SQL/PLSQL questions)* (so for issues with the SQL Developer tool). Please post these questions under the dedicated SQL And PL/SQL forum.
    Regards,
    K.

  • "Explain Plan" in Oracle SQL Developer is greyed out

    Hi all,
    I know this is not the right place to post this, but I have look around and do not know where to post question about Oracle SQL Developer - I presume this tool is also discussed here in this forum.
    My question is very simple (I presume):
    1. I installed Oracle SQL Developer 3.0.04.
    2. I added a new DB connection to a DB hosted in one of my servers in the LAN.
    3. However, when I am writing some SQL queries, I intend to use the "Explain Plan" feature, but it is being greyed out (disabled).
    4. How can I enable it back?

    Hello,
    {forum:id=260}
    Regards
    Marcus

  • Need help in SQL Explain plan

    Hi,
    I was trying to get an explain plan for below query. (Refer - A)
    BILL_DETAIL table have index of ZONECODE,MRNO,AREACODE,WCNO but still it's
    showing 'TABLE ACCESS FULL in BILL_DETAIL'
    If i select only first 4 column, it is going by index. (REFER - B)
    As per my knowledge index will consider only where clause conditions
    but here I couldn't understand why this considering select output columns.
    First time I am trying sql explain plan statement, Please help me to correct
    this query.
    REFER - A
    EXPLAIN PLAN FOR
    SELECT B.ZONECODE ZONECODE, B.MRNO MRNO, B.AREACODE AREACODE, B.WCNO WCNO,
    B.BILLNO BILLNO,B.BILLDT BILLDT,B.FROMDT FROMDT,B.TODT TODT,B.TOBEPAID TOBEPAID,
    B.PREVUNPAID PREVUNPAID,B.DUEDT DUEDT
    FROM BILL_DETAIL B, CONSUMER_MASTER C
    WHERE B.ZONECODE = C.ZONECODE
    AND B.MRNO = C.MRNO
    AND B.AREACODE = C.AREACODE
    AND B.WCNO = C.WCNO
    AND UPPER(B.ZONECODE)=UPPER('SZ-4')
    AND UPPER(B.MRNO)=UPPER('347')
    AND UPPER(B.AREACODE)=UPPER('18')
    AND UPPER(B.WCNO)=UPPER('30910')
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
    | 0 | SELECT STATEMENT | | 1 | 71 | 9 (0)|
    | 1 | NESTED LOOPS | | 1 | 71 | 9 (0)|
    |* 2 | TABLE ACCESS FULL| BILL_DETAIL | 1 | 52 | 9 (0)|
    |* 3 | INDEX UNIQUE SCAN| SYS_C008803 | 1 | 19 | 0 (0)|
    Predicate Information (identified by operation id):
    2 - filter(UPPER("B"."ZONECODE")='SZ-4' AND UPPER("B"."MRNO")='347'
    AND UPPER("B"."AREACODE")='18' AND UPPER("B"."WCNO")='30910')
    3 - access("B"."ZONECODE"="C"."ZONECODE" AND "B"."MRNO"="C"."MRNO"
    AND "B"."AREACODE"="C"."AREACODE" AND "B"."WCNO"="C"."WCNO")
    REFER - B
    EXPLAIN PLAN FOR
    SELECT B.ZONECODE ZONECODE, B.MRNO MRNO, B.AREACODE AREACODE, B.WCNO WCNO
    FROM BILL_DETAIL B, CONSUMER_MASTER C
    WHERE B.ZONECODE = C.ZONECODE
    AND B.MRNO = C.MRNO
    AND B.AREACODE = C.AREACODE
    AND B.WCNO = C.WCNO
    AND UPPER(B.ZONECODE)=UPPER('SZ-4')
    AND UPPER(B.MRNO)=UPPER('347')
    AND UPPER(B.AREACODE)=UPPER('18')
    AND UPPER(B.WCNO)=UPPER('30910')
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)|
    | 0 | SELECT STATEMENT | | 1 | 34 | 4 (0)|
    | 1 | NESTED LOOPS | | 1 | 34 | 4 (0)|
    |* 2 | INDEX FAST FULL SCAN| SYS_C008798 | 1 | 15 | 4 (0)|
    |* 3 | INDEX UNIQUE SCAN | SYS_C008803 | 1 | 19 | 0 (0)|
    Predicate Information (identified by operation id):
    2 - filter(UPPER("B"."ZONECODE")='SZ-4' AND UPPER("B"."MRNO")='347'
    AND UPPER("B"."AREACODE")='18' AND UPPER("B"."WCNO")='30910')
    3 - access("B"."ZONECODE"="C"."ZONECODE" AND "B"."MRNO"="C"."MRNO"
    AND "B"."AREACODE"="C"."AREACODE" AND "B"."WCNO"="C"."WCNO")
    Note
    - 'PLAN_TABLE' is old version

    Welcome to the forums!
    user13295080 wrote:
    I was trying to get an explain plan for below query. (Refer - A)
    BILL_DETAIL table have index of ZONECODE,MRNO,AREACODE,WCNO but still it's
    showing 'TABLE ACCESS FULL in BILL_DETAIL'
    If i select only first 4 column, it is going by index. (REFER - B)
    As per my knowledge index will consider only where clause conditions
    but here I couldn't understand why this considering select output columns.This is because Oracle is smart enough to know that the entire query can be satisfied by using the index without hitting the table. However, once you add a column that doesn't exist in the index Oracle has decided it is more efficient to use the full table scan.
    I also noticed that all the row estimates are 1 in the execution plans. Is this expected? If not, have statistics on the relevant objects been gathered?
    Generally speaking, when you have a query tuning question providing information in these threads is extremely helpful:
    {message:id=1812597}
    {thread:id=863295}
    Additionally, when posting query plans, queries, or any code please use \ tags to preserve formatting.
    Your code here!\                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Exactly how bad is this explain plan?

    Hi,
    I'm on Oracle 9i - 9.2.0.6.0.
    First, please excuse my question, I'm not that good at reading explain plans.
    I have this explain plan:
    | Id  | Operation                                 |  Name                      | Rows  | Bytes |TempSpc| Cost (%CPU)|                                                              
    |   0 | SELECT STATEMENT                          |                            | 70057 |    20M|       |   114K (12)|                                                              
    |*  1 |  FILTER                                   |                            |       |       |       |            |                                                              
    |   2 |   TABLE ACCESS FULL                       | DUAL                       |    82 |       |       |     3  (34)|                                                              
    |*  3 |   INDEX RANGE SCAN                        | CHANGELOG_1                |     1 |    44 |       |  2217   (3)|                                                              
    |   4 |  NESTED LOOPS OUTER                       |                            | 70057 |    20M|       |   114K (12)|                                                              
    |   5 |   NESTED LOOPS OUTER                      |                            | 67062 |    18M|       |   113K (11)|                                                              
    |   6 |    NESTED LOOPS OUTER                     |                            | 64194 |    16M|       |   111K (10)|                                                              
    |   7 |     NESTED LOOPS OUTER                    |                            | 61450 |    14M|       |   110K  (9)|                                                              
    |   8 |      NESTED LOOPS OUTER                   |                            | 58823 |    13M|       |   109K  (8)|                                                              
    |   9 |       NESTED LOOPS OUTER                  |                            | 56308 |    12M|       |   107K  (6)|                                                              
    |  10 |        NESTED LOOPS OUTER                 |                            | 53900 |    11M|       |   106K  (5)|                                                              
    |  11 |         NESTED LOOPS OUTER                |                            | 51596 |    10M|       |   105K  (4)|                                                              
    |  12 |          NESTED LOOPS OUTER               |                            | 49390 |  9212K|       |   104K  (3)|                                                              
    |  13 |           NESTED LOOPS OUTER              |                            | 47278 |  8310K|       |   102K  (2)|                                                              
    |* 14 |            HASH JOIN                      |                            | 31639 |  5067K|  4576K|  7331  (13)|                                                              
    |* 15 |             HASH JOIN                     |                            | 31639 |  4202K|  1936K|  1372   (9)|                                                              
    |  16 |              TABLE ACCESS FULL            | COMPANY                    | 76111 |  1040K|       |   335  (15)|                                                              
    |* 17 |              HASH JOIN                    |                            | 31649 |  3770K|       |   933   (7)|                                                              
    |  18 |               TABLE ACCESS FULL           | AGREEMENT                  |   149 |  3129 |       |     3  (34)|                                                              
    |* 19 |               HASH JOIN                   |                            | 31649 |  3121K|       |   928   (6)|                                                              
    |  20 |                TABLE ACCESS FULL          | CONCRETEAGREEMENT          | 34172 |   333K|       |    55  (24)|                                                              
    |* 21 |                TABLE ACCESS BY INDEX ROWID| SPECIFICATION              | 31649 |  2812K|       |   866   (4)|                                                              
    |* 22 |                 INDEX RANGE SCAN          | SPECIFICATION_DATE         | 37437 |       |       |   143   (5)|                                                              
    |  23 |             TABLE ACCESS FULL             | PERSON                     |  1786K|    47M|       |  4584  (11)|                                                              
    |* 24 |            TABLE ACCESS BY INDEX ROWID    | INFORMATION                |     1 |    16 |       |     4  (25)|                                                              
    |* 25 |             INDEX RANGE SCAN              | INFORMATION_SPECIFICATION  |     2 |       |       |     3  (34)|                                                              
    |* 26 |           TABLE ACCESS BY INDEX ROWID     | INFORMATION                |     1 |    11 |       |            |                                                              
    |* 27 |            INDEX RANGE SCAN               | INFORMATION_SPECIFICATION  |     2 |       |       |     3  (34)|                                                              
    |* 28 |          TABLE ACCESS BY INDEX ROWID      | INFORMATION                |     1 |    14 |       |            |                                                              
    |* 29 |           INDEX RANGE SCAN                | INFORMATION_SPECIFICATION  |     2 |       |       |     3  (34)|                                                              
    |* 30 |         TABLE ACCESS BY INDEX ROWID       | INFORMATION                |     1 |    14 |       |            |                                                              
    |* 31 |          INDEX RANGE SCAN                 | INFORMATION_SPECIFICATION  |     2 |       |       |     3  (34)|                                                              
    |* 32 |        TABLE ACCESS BY INDEX ROWID        | INFORMATION                |     1 |    11 |       |            |                                                              
    |* 33 |         INDEX RANGE SCAN                  | INFORMATION_SPECIFICATION  |     2 |       |       |     3  (34)|                                                              
    |* 34 |       TABLE ACCESS BY INDEX ROWID         | INFORMATION                |     1 |    13 |       |            |                                                              
    |* 35 |        INDEX RANGE SCAN                   | INFORMATION_SPECIFICATION  |     2 |       |       |     3  (34)|                                                              
    |* 36 |      TABLE ACCESS BY INDEX ROWID          | INFORMATION                |     1 |    12 |       |            |                                                              
    |* 37 |       INDEX RANGE SCAN                    | INFORMATION_SPECIFICATION  |     2 |       |       |     3  (34)|                                                              
    |* 38 |     TABLE ACCESS BY INDEX ROWID           | INFORMATION                |     1 |    15 |       |            |                                                              
    |* 39 |      INDEX RANGE SCAN                     | INFORMATION_SPECIFICATION  |     2 |       |       |     3  (34)|                                                              
    |* 40 |    TABLE ACCESS BY INDEX ROWID            | INFORMATION                |     1 |    17 |       |            |                                                              
    |* 41 |     INDEX RANGE SCAN                      | INFORMATION_SPECIFICATION  |     2 |       |       |     3  (34)|                                                              
    |* 42 |   TABLE ACCESS BY INDEX ROWID             | INFORMATION                |     1 |    17 |       |            |                                                              
    |* 43 |    INDEX RANGE SCAN                       | INFORMATION_SPECIFICATION  |     2 |       |       |     3  (34)|                                                              
    ---------------------------------------------------------------------------------------------------------------------                     I can see that there are some FULL TABLE SCAN, but this may be OK. What worries me is the combination with numerous NESTED LOOPS.
    A CTAS for approx 500.000 records out of 14.000.000 runs in about 180 mins. This is too much. My guess is that it should/could be brought down to something like 20 min.
    For completeness, the query in question:
    SELECT *
      FROM stik_spec_inf_v
    WHERE spdate >= to_date('15-03-2008', 'dd-mm-yyyy')
       AND spdate < to_date('15-04-2008', 'dd-mm-yyyy');Wher eview is created as
    CREATE OR REPLACE FORCE VIEW stik_spec_inf_v
    AS
       SELECT CAST(1 AS NUMBER(3)) dataversion
             ,sp.ID AS spid
             ,sp."DATE" AS spdate
             ,sp.valuedate
             ,sp.amount
             ,sp.amountcode
             ,sp.periodstart
             ,sp.periodend
             ,sp.ambcode
             ,sp.state AS spstate
             ,sp."TYPE" AS sptype
             ,sp.respitedate
             ,sp.stopcode
             ,sp.validcode
             ,sp.person
             ,sp.company
             ,sp.concreteagreement
             ,sp.reconciliation
             ,sp.partialscheme
             ,(SELECT 1
                 FROM dual
                WHERE EXISTS(
                         SELECT 1
                           FROM changelog
                          WHERE targetclass = 'com.csc.jpay.voucher.Specification'
                            AND targetid = sp.ID)) spchanged
             ,i1.startdate AS daekgagedato
             ,i1.amount AS daekgage
             ,i2.startdate AS prmgagedato
             ,i2.amount AS prmgage
             ,i3.employerpercent
             ,i3.employeepercent
             ,i3.voluntarypercent
             ,i5.salaryperiod
             ,i6.groupcontractcode
             ,i7.workinghourspercent
             ,i9.startdate AS hiringdate
             ,i10.startdate AS resignationdate
             ,i21.policenumber
             ,ix."TYPE" AS leavecode
             ,ix.startdate AS leavestartdate
             ,ix.enddate AS leaveenddate
             ,pe.cpr
             ,pe.ksdid
             ,co.opkr_number
             ,a.NAME AS agreement_name
         FROM SPECIFICATION sp
             ,information i1
             ,information i2
             ,information i3
             ,information i5
             ,information i6
             ,information i7
             ,information i9
             ,information i10
             ,information i21
             ,information ix
             ,person pe
             ,company co
             ,concreteagreement ca
             ,agreement a
        WHERE 1 = 1
          AND i1.SPECIFICATION(+) = sp.ID
          AND i1."TYPE"(+) = 1
          AND i2.SPECIFICATION(+) = sp.ID
          AND i2."TYPE"(+) = 2
          AND i3.SPECIFICATION(+) = sp.ID
          AND i3."TYPE"(+) = 3
          AND i5.SPECIFICATION(+) = sp.ID
          AND i5."TYPE"(+) = 5
          AND i6.SPECIFICATION(+) = sp.ID
          AND i6."TYPE"(+) = 6
          AND i7.SPECIFICATION(+) = sp.ID
          AND i7."TYPE"(+) = 7
          AND i9.SPECIFICATION(+) = sp.ID
          AND i9."TYPE"(+) = 9
          AND i10.SPECIFICATION(+) = sp.ID
          AND i10."TYPE"(+) = 10
          AND i21.SPECIFICATION(+) = sp.ID
          AND i21."TYPE"(+) = 21
          AND ix.SPECIFICATION(+) = sp.ID
          AND ix."TYPE"(+) > 10
          AND ix."TYPE"(+) < 21
          AND pe.ID = sp.person
          AND co.ID = sp.company
          AND ca.ID = sp.concreteagreement
          AND a.ID = ca.agreement;Please excuse my lengthy post. I still hope for some valuable input.
    Thanks
    Peter

    Hi,
    I have tried with an in-line view as John suggested. This give a FULL TABLE SCAN on information.
    SELECT /*+ RULE */ * FROM (
        SELECT sp.id spid, sp."DATE" spdate
         FROM (SELECT   SPECIFICATION
                       ,max(decode("TYPE", 1, startdate)) daekgagedato
                       ,max(decode("TYPE", 1, amount)) daekgage
                       ,max(decode("TYPE", 2, startdate)) prmgagedato
                       ,max(decode("TYPE", 2, amount)) prmgage
                       ,max(decode("TYPE", 3, employerpercent)) employerpercent
                       ,max(decode("TYPE", 3, employeepercent)) employeepercent
                       ,max(decode("TYPE", 3, voluntarypercent)) voluntarypercent
                       ,max(decode("TYPE", 5, salaryperiod)) salaryperiod
                       ,max(decode("TYPE", 6, groupcontractcode)) groupcontractcode
                       ,max(decode("TYPE", 7, workinghourspercent)) workinghourspercent
                       ,max(decode("TYPE", 9, startdate)) hiringdate
                       ,max(decode("TYPE", 10, startdate)) resignationdate
                       ,max(decode("TYPE", 21, policenumber)) policenumber
                       ,max(decode(sign("TYPE" - 10),1, decode(sign("TYPE" - 21), -1, "TYPE"))) leavecode
                       ,max(decode(sign("TYPE" - 10),1, decode(sign("TYPE" - 21), -1, startdate))) leavestartdate
                       ,max(decode(sign("TYPE" - 10),1, decode(sign("TYPE" - 21), -1, enddate))) leaveenddate
                   FROM information
                  WHERE TYPE BETWEEN 1 AND 21
               GROUP BY SPECIFICATION) i
             ,SPECIFICATION sp
        WHERE 1 = 1
          AND sp.ID = i.SPECIFICATION)
    WHERE spid = 1Any ideas on how to get around that?
    Regards
    Peter

Maybe you are looking for

  • Release retriggering while changing the payment terms

    Dear All, After releasing the purchase order if anybody Changes then payment terms in me22n, release should retrigger how to configure this process Regards, Vijaybhaskar

  • BILLING and PHANTOM CHARGES

    I have had verizon fios for about a year now. Every month I have had to contact them about charges for stuff I did not order. Movies channels and packages I did not order keep showing up. They put the MLB package on my bill and I had to call back 3 m

  • After software Update (2006-07), airport can not connect to the router

    Hi, I installed the software update 2006-07. Afterwards the airport extreme can not connect to the router anymore (NETGEAR). I use a WEP key, but even if I type the WEP Key, the airport does not succeed to the router anymore... I called Apple Care an

  • AME Audio problem

    I have tried to use Adobe Media Encoder CS4 to convert an FLV file to MP4 but the resulting video has no audio. Does any one have an idea what I am doing wrong? MacBook Pro 10.5.7 - 2.64Ghz Intel Core 2 Duo

  • moved to the JSF Forum generating tags IDs dynamically

    << moved to the JSF Forum >> Hello, I have inside a c:foreach loop several JSF tags like h:commandLink .. < I know there are better ways of doing this ! > unfortunately I cannot change that, so no recommendations in that direction, thanks! for this t