Query SQL Tuning

Hi,
What are the reason for "FULL TABLE SCAN"?.
Kindly provide reason.

This is a very abstract question. Ok some of them that came into my mind.
1. If you dont have a index on a column and you are using that column to filter then it goes for a full scan.
2. You have index on the column but still the cost of using the index is heavier than a full scan then oracle goes for a full scan.
So now to know how the cost changes you must spend lot of time reading the behaviour of index. A nice place would be [Richard Foots Blog|http://richardfoote.wordpress.com/]
Thanks,
Karthick.

Similar Messages

  • SQL tuning for a query

    Hello Gurus,
    I have 2 tables. One with a million records and the other with 50,000 records.
    Both have an account id column. The first table contains all the customer accounts and the second table has all the bad debt accounts.
    My problem is I need to update the status column in the first table for all the bad debt records from the second table.
    As I’m still a beginner in SQL tuning, can someone please help me write this query effi ciently considering the table sizes.
    tables description:
    SQL> desc customer
    Name Null? Type
    ACNTNO NUMBER(8)
    STATUS VARCHAR2(6)
    SQL> desc badcustomer
    Name Null? Type
    ACNTNO NUMBER(8)
    The sql I could come up with is:
    update customer outer
    set status='closed'
    where acntno exists (select 'X'
    from badcustomer
    where acntno=outer.acntno);
    Thanks for taking time to read this post.

    To post formatted code, put the {noformat} {noformat}- tag before and after your examples.
    When you post:
    {noformat} select *
    from dual;
    {noformat}
    it will appear as: select *
    from dual;
    on the forum.
    The FAQ will tell you more: http://forums.oracle.com/forums/help.jspa                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Need help to debug SQL Tuning Advisor Error Message

    Hi,
    I am getting an error message while try to get recommendations from the SQL Tuning Advisor.
    Environment:
    Oracle Version:  11.2.0.3.0
    O/S: AIX
    Following is my code:
    declare
    my_task_name  varchar2 (30);
    my_sqltext    clob;
    begin
    my_sqltext := 'SELECT DISTINCT MRKT_AREA AS DIVISION, PROMO_ID,
                    PROMO_CODE,
                    RBR_DTL_TYPE.PERF_DETL_TYP, 
                    RBR_DTL_TYPE.PERF_DETL_DESC,
                    RBR_DTL_TYPE.PERF_DETL_SUB_TYP,
                    RBR_DTL_TYPE.PERF_DETL_SUB_DESC,
                    BU_SYS_ITM_NUM,
                    RBR_CPN_LOC_ITEM_ARCHIVE.CLI_SYS_ITM_DESC,
                    PROMO_START_DATE,
                    PROMO_END_DATE,
                    PROMO_VALUE2,
                    PROMO_VALUE1,
                    EXEC_COMMENTS,
                    PAGE_NUM,
                    BLOCK_NUM,
                    AD_PLACEMENT,
                    BUYER_CODE,
                    RBR_CPN_LOC_ITEM_ARCHIVE.CLI_STAT_TYP,
                    RBR_MASTER_CAL_ARCHIVE.STATUS_FLAG
    FROM  (PROMO_REPT_OWNER.RBR_CPN_LOC_ITEM_ARCHIVE
    INNER JOIN PROMO_REPT_OWNER.RBR_MASTER_CAL_ARCHIVE
    ON (RBR_CPN_LOC_ITEM_ARCHIVE.CLI_PROMO_ID = PROMO_ID)
    AND (RBR_CPN_LOC_ITEM_ARCHIVE.CLI_PERF_DTL_ID = PERF_DETAIL_ID)
    AND (RBR_CPN_LOC_ITEM_ARCHIVE.CLI_STR_NBR = STORE_ZONE)
    AND (RBR_CPN_LOC_ITEM_ARCHIVE.CLI_ITM_ID = ITM_ID))
    INNER JOIN PROMO_REPT_OWNER.RBR_DTL_TYPE
    ON (RBR_MASTER_CAL_ARCHIVE.PERF_DETL_TYP = RBR_DTL_TYPE.PERF_DETL_TYP)
    AND (RBR_MASTER_CAL_ARCHIVE.PERF_DETL_SUB_TYP = RBR_DTL_TYPE.PERF_DETL_SUB_TYP)
    WHERE ( ((MRKT_AREA)=40)
    AND ((RBR_DTL_TYPE.PERF_DETL_TYP)=1)
    AND ((RBR_DTL_TYPE.PERF_DETL_SUB_TYP)=1) )
    AND ((CLI_STAT_TYP)=1 Or (CLI_STAT_TYP)=6)
    AND ((RBR_MASTER_CAL_ARCHIVE.STATUS_FLAG)=''A'')
    AND ( ((PROMO_START_DATE) >= to_date(''2011-10-20'', ''YYYY-MM-DD'')
    And (PROMO_END_DATE) <= to_date(''2011-10-26'', ''YYYY-MM-DD'')) )
    ORDER BY MRKT_AREA';
    my_task_name := dbms_sqltune.create_tuning_task
                                 (sql_text => my_sqltext,
                                  user_name => 'PROMO_REPT_OWNER',
                                  scope     => 'COMPREHENSIVE',
                                  time_limit => 3600,
                                  task_name  => 'Test_Query',
                                  description  => 'Test Query');
    end;
    begin
      dbms_sqltune.execute_tuning_task(task_name => 'Test_Query');
    end;
    set serveroutput on size unlimited;
    set pagesize 5000
    set linesize 130
    set long 50000
    set longchunksize 500000
    SELECT DBMS_SQLTUNE.REPORT_TUNING_TASK('Test_Query') FROM DUAL;
    Output:
    snippet .....
    FINDINGS SECTION (1 finding)
    1- Index Finding (see explain plans section below)
    The execution plan of this statement can be improved by creating one or more
    indices.
    Recommendation (estimated benefit: 71.48%)
    - Consider running the Access Advisor to improve the physical schema design
    or creating the recommended index.
    Error: Cannot fetch actions for recommendation: INDEX
    Error: ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    Rationale
    Creating the recommended indices significantly improves the execution plan
    of this statement. However, it might be preferable to run "Access Advisor"
    using a representative SQL workload as opposed to a single statement. This
    will allow to get comprehensive index recommendations which takes into
    account index maintenance overhead and additional space consumption.
    snippet
    Any ideas why I am getting ORA-06502 error?
    Thanks in advance
    Rogers

    Bug 14407401 - ORA-6502 from index recommendation section of DBMS_SQLTUNE output (Doc ID 14407401.8)
    Fixed:
    The fix for 14407401 is first included in
    12.1.0.1 (Base Release)

  • SQL tuning suggestions.

    Hi
    I am not a sql programmer and developers have given me this sql to have a look. I made the following recommendations after going through the sql. Is there anything else that can be added . I did not add about stats because they are representative and up to date.
    SELECT /*+ PARALLEL(q1,4) */ *
    FROM
    (SELECT /*+ FIRST_ROWS(20) */
    br.resource_id,
    br.resource_code,
    x.resource_seq_num employee_resource_number,
    br.organization_id,
    bd.department_id,
    bd.department_code,
    pf.full_name employee_name,
    (SELECT xxdl_eam_util_pkg.xxdl_eam_get_resource_code(pf.person_id, bd.department_id)
    FROM dual)
    maximum_cost_resource,
    pf.person_id,
    x.wip_entity_id wo_id,
    (SELECT weo1.wip_entity_name
    FROM wip_eam_work_orders_v weo1
    WHERE weo1.wip_entity_id = x.wip_entity_id)
    wo_number,
    CAST(x.start_date AS
    TIMESTAMP) start_date,
    CAST(x.completion_date AS
    TIMESTAMP) completion_date,
    wor.operation_seq_num wo_operation_number,
    wor.resource_seq_num wo_resource_number,
    wor.usage_rate_or_amount HOURS,
    BRE.effective_start_date instance_start_date,
    BRE.effective_end_date instance_end_date,
    BRE.instance_id,
    crc.resource_rate AS
    resource_cost,
    (SELECT xxdl_eam_util_pkg.xxdl_eam_get_all_res_code(pf.person_id, bd.department_id)
    FROM dual)
    all_resources
    FROM per_all_people_f pf,
    wip_eam_work_orders_v weo,
    wip_operations wo,
    wip_operation_resources wor,
    (SELECT instance_id,
    wip_entity_id,
    operation_seq_num,
    resource_seq_num,
    start_date,
    completion_date
    FROM wip_op_resource_instances_v) x,
    bom_dept_res_instances bdri,
    bom_resource_employees BRE,
    bom_department_resources bdr,
    bom_resources br,
    cst_resource_costs crc,
    bom_departments bd
    WHERE br.organization_id = bd.organization_id
    AND bdr.resource_id = br.resource_id
    AND bdr.department_id = bd.department_id
    AND BRE.resource_id = br.resource_id
    AND pf.effective_start_date <=sysdate
    AND pf.effective_end_date >= sysdate
    AND pf.person_id = BRE.person_id
    AND wo.department_id = bd.department_id
    AND wor.operation_seq_num(+) = wo.operation_seq_num
    AND wor.wip_entity_id(+) = wo.wip_entity_id
    AND wor.organization_id(+) = wo.organization_id
    AND weo.wip_entity_id = wo.wip_entity_id
    AND weo.organization_id = wo.organization_id
    -- AND weo.organization_id = 6921
    AND DECODE(bd.disable_date,null, sysdate,bd.disable_date) >= sysdate
    AND DECODE(br.disable_date,null, sysdate,br.disable_date) >= sysdate
    AND DECODE(wo.disable_date,null, sysdate,wo.disable_date) >= sysdate
    AND crc.resource_id(+) = BRE.resource_id
    AND x.wip_entity_id = wor.wip_entity_id
    AND x.operation_seq_num = wor.operation_seq_num
    AND x.resource_seq_num = wor.resource_seq_num
    AND x.instance_id(+) = BRE.instance_id
    AND bdri.department_id = bd.department_id
    AND bdri.resource_id = br.resource_id
    AND weo.organization_id = 6921
    AND bdri.department_id = 5004
    UNION
    SELECT /*+ FIRST_ROWS(20) */ DISTINCT NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    pf.full_name employee_name,
    NULL,
    pf.person_id,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL HOURS,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL
    FROM per_all_people_f pf,
    wip_eam_work_orders_v weo,
    wip_operations wo,
    wip_operation_resources wor,
    bom_dept_res_instances bdri,
    bom_resource_employees BRE,
    bom_department_resources bdr,
    bom_resources br,
    cst_resource_costs crc,
    bom_departments bd
    WHERE br.organization_id = bd.organization_id
    AND bdr.resource_id = br.resource_id
    AND bdr.department_id = bd.department_id
    AND BRE.resource_id = br.resource_id
    AND pf.effective_start_date <=sysdate
    AND pf.effective_end_date >= sysdate
    AND pf.person_id = BRE.person_id
    AND wo.department_id = bd.department_id
    AND wor.operation_seq_num(+) = wo.operation_seq_num
    AND wor.wip_entity_id(+) = wo.wip_entity_id
    AND wor.organization_id(+) = wo.organization_id
    AND weo.wip_entity_id = wo.wip_entity_id
    AND weo.organization_id = wo.organization_id
    AND DECODE(bd.disable_date,null, sysdate,bd.disable_date) >= sysdate
    AND DECODE(br.disable_date,null, sysdate,br.disable_date) >= sysdate
    AND DECODE(wo.disable_date,null, sysdate,wo.disable_date) >= sysdate
    AND crc.resource_id(+) = BRE.resource_id
    AND bdri.department_id = bd.department_id
    AND bdri.resource_id = br.resource_id
    AND weo.organization_id = 6921
    AND bdri.department_id = 5004
    AND NOT EXISTS
    (SELECT instance_id,
    wip_entity_id operation_seq_num,
    resource_seq_num
    FROM wip_op_resource_instances_v)
    ) q1
    ORDER BY department_id,
    resource_code,
    employee_name,
    wo_number
    My suggestions:
    . Try to use UNION ALL instead of UNION. If you can eliminate UNION all together and flatten the query that will be even better.
    2. You are using the function in a select statement xxdl_eam_util_pkg.xxdl_eam_get_resource_code(pf.person_id, bd.department_id)This will slow the performance. Try to get rid of this. Function calls in select are expensive.
    3. Dont use the parallel hint and optimize. It wont get you consistent results.
    4. Use of per_all_people_F is expensive. The UNION again complicates things. per_all_people_f has to be scanned 2x times.
    5. Where does the application get the values for department id? Whether user inputs a value or whether it is hard coded . Most likely user will input value and each time it may be different. If that is the case, then you may be hitting bind peeking. There is not much hope for this. Not much can be done. Whatever you do this can happen. Only way is to pin the plan if you can use literals instead of binds. But that is not possible I think.
    6. AND DECODE(bd.disable_date,null, sysdate,bd.disable_date) >= sysdate
    AND DECODE(br.disable_date,null, sysdate,br.disable_date) >= sysdate
    AND DECODE(wo.disable_date,null, sysdate,wo.disable_date) >= sysdate
    Those statements, if you can rewrite would be good. If there are indexes on any of those columns, they are more than likely not used.
    7. Are the outer joins really required. If not required remove them.
    8. There is a 'WITH' clause in 10g . Try to use that for your subqueries or main query where applicable. It will save some I/O.
    9. Try to tune without any hints. Remove the first rows as well and see the difference.
    I know that the sql is definately bad and can be rewritten but I am not able to exactly write it for them.
    Any inputs or thoughts?
    MSK

    Hi,
    Any suggestions for reading on Sql tuning
    I am looking for a practical book with solutions .
    And books showing the Sql internal workings ?Take a look on Amazon some Jonathan Lewis books.
    I will also recommend you to take a look on the following blogs:
    - http://jonathanlewis.wordpress.com/
    - http://www.juliandyke.com/
    - http://richardfoote.wordpress.com/
    - http://tkyte.blogspot.com/
    And also any good interview based good Oracle DBA books ?You can take a look on my blog for some common DBA interview questions.
    http://oraclenz.com/category/interview-tips/
    Regards,
    Francisco Munoz Alvarez
    www.oraclenz.com

  • SQL tuning

    Hi All,
    I am new to tuning.
    Can somebody help me in tuning this SQL query.
    SELECT pppd.productid, pppd.sequencenumber, pppd.priceareaid, pppd.startdate, pppd.qtyfrom, pppd.enddate, pppd.price,
    pppd.articleid, pppd.customerid, pppd.distributorid, pppd.supplierid, pppd.adviceprice, pppd.customergroupid, pppd.dimensionvalue1, pppd.dimensionvalue2,
    pppd.dimensionvalue3, pppd.dimensionvalue4, pppd.dimensionvalue5, pppd.dimensionvalue6, pppd.discountpercentage,
    pppd.promotionindicator, pppd.vatindicator
    FROM PPM_PRODUCTPRICE pppd WHERE
    pppd.validindicator=1 AND pppd.startdate <= SYSDATE AND NVL(pppd.enddate,SYSDATE +1) >= SYSDATE
    AND NOT EXISTS
    (SELECT 1 FROM PPM_PRODUCTPRICE pppd2 WHERE pppd2.productid = pppd.productid
    AND NOT (pppd2.sequencenumber = pppd.sequencenumber)
    AND pppd2.priceareaid = pppd.priceareaid
    AND (NVL(pppd2.supplierid,9999999999) = NVL(pppd.supplierid,9999999999) )
    AND (NVL(pppd2.distributorid,9999999999) = NVL(pppd.distributorid,9999999999))
    AND (NVL(pppd2.customerid,9999999999) = NVL(pppd.customerid,9999999999) )
    AND (NVL(pppd2.customergroupid,9999999999) = NVL(pppd.customergroupid,9999999999))
    AND (NVL(pppd2.articleid,9999999999) = NVL(pppd.articleid,9999999999))
    AND (NVL(pppd2.dimensionvalue1,9999999999)=NVL(pppd.dimensionvalue1,9999999999))
    AND (NVL(pppd2.dimensionvalue2,9999999999)=NVL(pppd.dimensionvalue2 ,9999999999))
    AND (NVL(pppd2.dimensionvalue3,9999999999)=NVL(pppd.dimensionvalue3 ,9999999999))
    AND (NVL(pppd2.dimensionvalue4,9999999999)=NVL(pppd.dimensionvalue4 ,9999999999))
    AND (NVL(pppd2.dimensionvalue5,9999999999)=NVL(pppd.dimensionvalue5 ,9999999999))
    AND (NVL(pppd2.dimensionvalue6,9999999999)=NVL(pppd.dimensionvalue6 ,9999999999))
    AND pppd2.qtyfrom = pppd.qtyfrom AND pppd2.startdate BETWEEN pppd.startdate AND SYSDATE
    AND NVL(pppd2.enddate,SYSDATE +1) >= SYSDATE )
    AND productid= 30700

    At a minimum I think you should search the forums for SQL Tuning because I know there is some sort of sticked post identifying the GENERAL steps you should follow to tune a query. Us being here trying to help cannot tune a blanket SQL statement for the most part that is given to us. We don't know so many things that it is hard to form a cohesive answer. Some questions that arise are:
    1. What version of Oracle are you using?
    2. What are the table structures?
    3. What is the question you are truly trying to answer?
    4. What is the explain plan saying?
    5. What is your tuning goal (faster execution? lower I/O?)?
    5. etc.....
    At a minimum it appears that you are using the NVL function a lot and I would probably wager a guess that it is preventing you from using indexes on all those ID columns, if there are any.
    Hope this helps!
    Edited by: Centinul on Sep 12, 2008 12:31 PM
    Here is the link to the post I was discussing: When your query takes too long ...

  • SQL Tuning and OPTIMIZER - Execution Time with  " AND col .."

    Hi all,
    I get a question about SQL Tuning and OPTIMIZER.
    There are three samples with EXPLAIN PLAN and execution time.
    This "tw_pkg.getMaxAktion" is a PLSQL Package.
    1.) Execution Time : 0.25 Second
    2.) Execution Time : 0.59 Second
    3.) Execution Time : 1.11 Second
    The only difference is some additional "AND col <> .."
    Why is this execution time growing so strong?
    Many Thanks,
    Thomas
    ----[First example]---
    Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.3.0
    Connected as dbadmin2
    SQL>
    SQL> EXPLAIN PLAN FOR
      2  SELECT * FROM ( SELECT studie_id, tw_pkg.getMaxAktion(studie_id) AS max_aktion_id
      3                    FROM studie
      4                 ) max_aktion
      5  WHERE max_aktion.max_aktion_id < 900 ;
    Explained
    SQL> SELECT * FROM TABLE(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 3201460684
    | Id  | Operation            | Name        | Rows  | Bytes | Cost (%CPU)| Time
    |   0 | SELECT STATEMENT     |             |   220 |   880 |     5  (40)| 00:00:
    |*  1 |  INDEX FAST FULL SCAN| SYS_C005393 |   220 |   880 |     5  (40)| 00:00:
    Predicate Information (identified by operation id):
       1 - filter("TW_PKG"."GETMAXAKTION"("STUDIE_ID")<900)
    13 rows selected
    SQL>
    Execution time (PL/SQL Developer says): 0.25 seconds
    ----[/First]---
    ----[Second example]---
    Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.3.0
    Connected as dbadmin2
    SQL>
    SQL> EXPLAIN PLAN FOR
      2  SELECT * FROM ( SELECT studie_id, tw_pkg.getMaxAktion(studie_id) AS max_aktion_id
      3                    FROM studie
      4                 ) max_aktion
      5  WHERE max_aktion.max_aktion_id < 900
      6    AND max_aktion.max_aktion_id <> 692;
    Explained
    SQL> SELECT * FROM TABLE(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 3201460684
    | Id  | Operation            | Name        | Rows  | Bytes | Cost (%CPU)| Time
    |   0 | SELECT STATEMENT     |             |    11 |    44 |     6  (50)| 00:00:
    |*  1 |  INDEX FAST FULL SCAN| SYS_C005393 |    11 |    44 |     6  (50)| 00:00:
    Predicate Information (identified by operation id):
       1 - filter("TW_PKG"."GETMAXAKTION"("STUDIE_ID")<900 AND
                  "TW_PKG"."GETMAXAKTION"("STUDIE_ID")<>692)
    14 rows selected
    SQL>
    Execution time (PL/SQL Developer says): 0.59 seconds
    ----[/Second]---
    ----[Third example]---
    SQL> EXPLAIN PLAN FOR
      2  SELECT * FROM ( SELECT studie_id, tw_pkg.getMaxAktion(studie_id) AS max_aktion_id
      3                    FROM studie
      4                 ) max_aktion
      5  WHERE max_aktion.max_aktion_id < 900
      6    AND max_aktion.max_aktion_id <> 692
      7    AND max_aktion.max_aktion_id <> 392;
    Explained
    SQL> SELECT * FROM TABLE(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 3201460684
    | Id  | Operation            | Name        | Rows  | Bytes | Cost (%CPU)| Time
    |   0 | SELECT STATEMENT     |             |     1 |     4 |     6  (50)| 00:00:
    |*  1 |  INDEX FAST FULL SCAN| SYS_C005393 |     1 |     4 |     6  (50)| 00:00:
    Predicate Information (identified by operation id):
       1 - filter("TW_PKG"."GETMAXAKTION"("STUDIE_ID")<900 AND
                  "TW_PKG"."GETMAXAKTION"("STUDIE_ID")<>692 AND
                  "TW_PKG"."GETMAXAKTION"("STUDIE_ID")<>392)
    15 rows selected
    SQL>
    Execution time (PL/SQL Developer says): 1.11 seconds
    ----[/Third]---Edited by: thomas_w on Jul 9, 2010 11:35 AM
    Edited by: thomas_w on Jul 12, 2010 8:29 AM

    Hi,
    this is likely because SQL Developer fetches and displays only limited number of rows from query results.
    This number is a parameter called 'sql array fetch size', you can find it in SQL Developer preferences under Tools/Preferences/Database/Advanced tab, and it's default value is 50 rows.
    Query scans a table from the beginning and continue scanning until first 50 rows are selected.
    If query conditions are more selective, then more table rows (or index entries) must be scanned to fetch first 50 results and execution time grows.
    This effect is usually unnoticeable when query uses simple and fast built-in comparison operators (like = <> etc) or oracle built-in functions, but your query uses a PL/SQL function that is much more slower than built-in functions/operators.
    Try to change this parameter to 1000 and most likely you will see that execution time of all 3 queries will be similar.
    Look at this simple test to figure out how it works:
    CREATE TABLE studie AS
    SELECT row_number() OVER (ORDER BY object_id) studie_id,  o.*
    FROM (
      SELECT * FROM all_objects
      CROSS JOIN
      (SELECT 1 FROM dual CONNECT BY LEVEL <= 100)
    ) o;
    CREATE INDEX studie_ix ON studie(object_name, studie_id);
    ANALYZE TABLE studie COMPUTE STATISTICS;
    CREATE OR REPLACE FUNCTION very_slow_function(action IN NUMBER)
    RETURN NUMBER
    IS
    BEGIN
      RETURN action;
    END;
    /'SQL array fetch size' parameter in SQLDeveloper has been set to 50 (default). We will run 3 different queries on test table.
    Query 1:
    SELECT * FROM ( SELECT studie_id, very_slow_function(studie_id) AS max_aktion_id
                         FROM studie
                  ) max_aktion
    WHERE max_aktion.max_aktion_id < 900
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      1.22       1.29          0       1310          0          50
    total        3      1.22       1.29          0       1310          0          50
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 93  (TEST)
    Rows     Row Source Operation
         50  INDEX FAST FULL SCAN STUDIE_IX (cr=1310 pr=0 pw=0 time=355838 us cost=5536 size=827075 card=165415)(object id 79865)
    Rows     Execution Plan
          0  SELECT STATEMENT   MODE: ALL_ROWS
         50   INDEX   MODE: ANALYZED (FAST FULL SCAN) OF 'STUDIE_IX' (INDEX)Query 2:
    SELECT * FROM ( SELECT studie_id, very_slow_function(studie_id) AS max_aktion_id
                         FROM studie
                  ) max_aktion
    WHERE max_aktion.max_aktion_id < 900
          AND max_aktion.max_aktion_id > 800
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.01          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      8.40       8.62          0       9351          0          50
    total        3      8.40       8.64          0       9351          0          50
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 93  (TEST)
    Rows     Row Source Operation
         50  INDEX FAST FULL SCAN STUDIE_IX (cr=9351 pr=0 pw=0 time=16988202 us cost=5552 size=41355 card=8271)(object id 79865)
    Rows     Execution Plan
          0  SELECT STATEMENT   MODE: ALL_ROWS
         50   INDEX   MODE: ANALYZED (FAST FULL SCAN) OF 'STUDIE_IX' (INDEX)Query 3:
    SELECT * FROM ( SELECT studie_id, very_slow_function(studie_id) AS max_aktion_id
                         FROM studie
                  ) max_aktion
    WHERE max_aktion.max_aktion_id = 600
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.01       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1     18.72      19.16          0      19315          0           1
    total        3     18.73      19.16          0      19315          0           1
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 93  (TEST)
    Rows     Row Source Operation
          1  INDEX FAST FULL SCAN STUDIE_IX (cr=19315 pr=0 pw=0 time=0 us cost=5536 size=165415 card=33083)(object id 79865)
    Rows     Execution Plan
          0  SELECT STATEMENT   MODE: ALL_ROWS
          1   INDEX   MODE: ANALYZED (FAST FULL SCAN) OF 'STUDIE_IX' (INDEX)Query 1 - 1,29 sec, 50 rows fetched, 1310 index entries scanned to find these 50 rows.
    Query 2 - 8,64 sec, 50 rows fetched, 9351 index entries scanned to find these 50 rows.
    Query 3 - 19,16 sec, only 1 row fetched, 19315 index entries scanned (full index).
    Now 'SQL array fetch size' parameter in SQLDeveloper has been set to 1000.
    Query 1:
    SELECT * FROM ( SELECT studie_id, very_slow_function(studie_id) AS max_aktion_id
                         FROM studie
                  ) max_aktion
    WHERE max_aktion.max_aktion_id < 900
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1     18.35      18.46          0      19315          0         899
    total        3     18.35      18.46          0      19315          0         899
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 93  (TEST)
    Rows     Row Source Operation
        899  INDEX FAST FULL SCAN STUDIE_IX (cr=19315 pr=0 pw=0 time=20571272 us cost=5536 size=827075 card=165415)(object id 79865)
    Rows     Execution Plan
          0  SELECT STATEMENT   MODE: ALL_ROWS
        899   INDEX   MODE: ANALYZED (FAST FULL SCAN) OF 'STUDIE_IX' (INDEX)Query 2:
    SELECT * FROM ( SELECT studie_id, very_slow_function(studie_id) AS max_aktion_id
                         FROM studie
                  ) max_aktion
    WHERE max_aktion.max_aktion_id < 900
          AND max_aktion.max_aktion_id > 800
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1     18.79      18.86          0      19315          0          99
    total        3     18.79      18.86          0      19315          0          99
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 93  (TEST)
    Rows     Row Source Operation
         99  INDEX FAST FULL SCAN STUDIE_IX (cr=19315 pr=0 pw=0 time=32805696 us cost=5552 size=41355 card=8271)(object id 79865)
    Rows     Execution Plan
          0  SELECT STATEMENT   MODE: ALL_ROWS
         99   INDEX   MODE: ANALYZED (FAST FULL SCAN) OF 'STUDIE_IX' (INDEX)Query 3:
    SELECT * FROM ( SELECT studie_id, very_slow_function(studie_id) AS max_aktion_id
                         FROM studie
                  ) max_aktion
    WHERE max_aktion.max_aktion_id = 600
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1     18.69      18.84          0      19315          0           1
    total        3     18.69      18.84          0      19315          0           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 93  (TEST)
    Rows     Row Source Operation
          1  INDEX FAST FULL SCAN STUDIE_IX (cr=19315 pr=0 pw=0 time=0 us cost=5536 size=165415 card=33083)(object id 79865)
    Rows     Execution Plan
          0  SELECT STATEMENT   MODE: ALL_ROWS
          1   INDEX   MODE: ANALYZED (FAST FULL SCAN) OF 'STUDIE_IX' (INDEX)And now:
    Query 1 - 18.46 sec, 899 rows fetched, 19315 index entries scanned.
    Query 2 - 18.86 sec, 99 rows fetched, 19315 index entries scanned.
    Query 3 - 18.84 sec, 1 row fetched, 19315 index entries scanned.

  • Sql tuning advisor 11g

    Dear all,
    We have installed oracle 11g on solaris. We have configured EM with this DB.. Is there anyway I can check a query using sql tuning advisor in oracle 11g. ? .. I tried, but I couldn't find the exact navigation ?. I need to submit th query and get the advise from sql tuninig advisor ?
    Please guide
    Kai

    OEM db console ?
    Am doing this for educational purpose and not in production
    kai

  • Oracle11g standarad Edititon-Sql tuning Advisor

    Hi,
    Do we have provision to tune the query using sql tuning advisor in oracle 11g r1 Standard Edition SE
    Thanks
    mafaiz

    Mafaiz,
    Tuning & Diagnostic Packs are available in Enterprise Edition only
    Oracle Database - Standard Edition & Diagnosis Pack???
    Thanks,
    Ajay More
    http://www.moreajays.com

  • Stucked between SQL Tuning Advisor and and SQL statement

    Hi,
    There is an important query running on my system which consists
    MEMBER OF function.
    At first place let me explain why i used MEMBER OF,
    I am sending a string( eg : #123#124#125) to query and a function converts this string into a number array.
    After then I use this number array inside my sql.
    The reason I am using this structure, in order to generate a dynamic IN statement inside my sql. (IF you have any other solution that would be great)
    The most important point is; when I put this statement to SQL Tuning Advisor the response is only ORA-00932: inconsistent datatypes: expected UDT got CHAR
    Any answer will be greatly appreciated.
    Thanks

    Solomon Yakobson wrote:
    Object oriented stuff almost never provides better performance over relational. You should stay away from MEMBER OF if performance is a factor. Instead of:
    WHERE expr MEMBER OF nested-tableI'd test:
    WHERE expr IN (SELECT column_value FROM TABLE(nested-table))SY.
    expr IN (SELECT COLUMN_VALUE FROM TABLE (CAST (v_type_number_table AS type_number_table)))worked like a charm. i hope tuning advisor will like it as i do.
    thanks.

  • Oracle 10g SQL Tuning Advisor

    I am working as a junior DBA. I tried to tune a query using SQL Tuning Advisor that is with DBMS_SQLTUNE.I have created the tuning task successfully with DBMS_SQLTUNE.create_tuning_task.But when i execute the tuning task with EXEC DBMS_SQLTUNE.execute_tuning_task() i got an error like
    SQL> EXEC DBMS_SQLTUNE.execute_tuning_task(task_name => 'rep_three');
    BEGIN DBMS_SQLTUNE.execute_tuning_task(task_name => 'rep_three'); END;
    ERROR at line 1:
    ORA-00081: address range [0x60000000000A7D70, 0x60000000000A7D74) is not
    readable
    ORA-00600: internal error code, arguments: [kesatmGetSqlStats:optCost], [], [],
    ORA-06512: at "SYS.PRVT_ADVISOR", line 1624
    ORA-06512: at "SYS.DBMS_ADVISOR", line 186
    ORA-06512: at "SYS.DBMS_SQLTUNE", line 1008
    ORA-06512: at line 1The oracle version is Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bi. The OS is HP-UX. The version is HP-UX B.11.23 U ia64.
    I tried to execute DBMS_SQLTUNE as DWH user.I have granted the advisor,DROP ANY SQL PROFILE,ALTER ANY SQL PROFILE,CREATE ANY SQL PROFILE privileges and DBA roles to the DWH user. The way i ran DBMS_SQLTUNE is, first i logged in as DWH user and i tried to execute the query for getting the SQL_ID for the query. For getting the SQL_ID i selected the SQL_ID column value for the DWH user session from v$session.I kept that query executing and meanwhile i opened another session as DWH user and created the tuning task as follows
    DECLARE
      l_sql_tune_task_id  VARCHAR2(100);
    BEGIN
      l_sql_tune_task_id := DBMS_SQLTUNE.create_tuning_task (
                              sql_id      => 'b65fj39dkkb9v',
                              scope       => DBMS_SQLTUNE.scope_limited,
                              time_limit  => 3600,
                              task_name   => 'rep_three',
                              description => 'Report Tuning');
      DBMS_OUTPUT.put_line('l_sql_tune_task_id: ' || l_sql_tune_task_id);
    END;
    /The creation of tuning task was successful.And i executed the tuning task as follows
    EXEC DBMS_SQLTUNE.execute_tuning_task(task_name => 'rep_three');The above mentioned errors came when i executed the tuning task.
    I am also adding the query which i have tried to tune
    select * from dwh.beneficiary_dim BEN_DIM,
                     (Select adr_dp_id,
                   adr_account_no,
                   ADR_ADDRESS_LINE_1 || ' ' ||
                   ADR_ADDRESS_LINE_2 || ' ' ||
                   ADR_ADDRESS_LINE_3 || ' ' ||
                   ADR_ADDRESS_LINE_4 as ADDRESS,
                   adr_pin_code,adr_phone_no,adr_fax_no
              from dwh.beneficiary_address_dim where adr_type_id = 1) PERMANENT_ADD_DIM,
           (Select adr_dp_id,
                   adr_account_no,
                   ADR_ADDRESS_LINE_1 || ' ' ||
                   ADR_ADDRESS_LINE_2 || ' ' ||
                   ADR_ADDRESS_LINE_3 || ' ' ||
                   ADR_ADDRESS_LINE_4 as ADDRESS,
                   adr_pin_code,adr_phone_no,adr_fax_no
              from dwh.beneficiary_address_dim where adr_type_id = 2) BANK_ADD_DIM,
           (Select adr_dp_id,
                   adr_account_no,
                   ADR_ADDRESS_LINE_1 || ' ' ||
                   ADR_ADDRESS_LINE_2 || ' ' ||
                   ADR_ADDRESS_LINE_3 || ' ' ||
                   ADR_ADDRESS_LINE_4 as ADDRESS,
                   adr_pin_code,adr_phone_no,adr_fax_no
              from dwh.beneficiary_address_dim where adr_type_id = 3) NOM_GUARDIAN_ADD_DIM,
           (Select adr_dp_id,
                   adr_account_no,
                   ADR_ADDRESS_LINE_1 || ' ' ||
                   ADR_ADDRESS_LINE_2 || ' ' ||
                   ADR_ADDRESS_LINE_3 || ' ' ||
                   ADR_ADDRESS_LINE_4 as ADDRESS,
                   adr_pin_code,adr_phone_no,adr_fax_no
              from dwh.beneficiary_address_dim where adr_type_id = 4) CORR_ADD_DIM,
           (Select adr_dp_id,
                   adr_account_no,
                   ADR_ADDRESS_LINE_1 || ' ' ||
                   ADR_ADDRESS_LINE_2 || ' ' ||
                   ADR_ADDRESS_LINE_3 || ' ' ||
                   ADR_ADDRESS_LINE_4 as ADDRESS,
                   adr_pin_code,adr_phone_no,adr_fax_no
              from dwh.beneficiary_address_dim where adr_type_id = 6) MINOR_ADDRESS,
                     (Select rp.requestid as requestid,
    decode(rp.value,'ALL','ALL','','ALL',decode(substr(rp.value,1,instr(rp.value,'|',1,1)-1),'','ALL',substr(rp.value,1,instr(rp.value,'|',1,1)-1))) as Name,
    decode(rp.value,'ALL','ALL','','ALL',decode(substr(rp.value,(instr(rp.value,'|',1,1)+1),((instr(rp.value,'|',1,2))-(instr(rp.value,'|',1,1)+1))),'','ALL',substr(rp.value,(instr(rp.value,'|',1,1)+1),((instr(rp.value,'|',1,2))-(instr(rp.value,'|',1,1)+1))))) as Address,
    decode(rp.value,'ALL','ALL','','ALL',decode(substr(rp.value,(instr(rp.value,'|',1,2)+1)),'','ALL',substr(rp.value,(instr(rp.value,'|',1,2)+1)))) as PAN
                      from disadmin.requestparameters rp, disadmin.requestparameters rps, disadmin.reportrequests rr
                     where rp.parameterid = 'CNAS_PARAM_VALUE'   
                       and rr.status = 'A'
                       and rp.requestid = rr.id
                       and rp.id = rps.id) P_PARAM_VALUE,
                     (Select rp.requestid as requestid, rp.value as Type
                        from disadmin.requestparameters rp, disadmin.reportrequests rr
                       where rp.parameterid = 'CNAS_NAME_TYPE'
                         and rr.status = 'A'
                         and rp.requestid = rr.id)  P_NAME_TYPE,
                     (Select rp.requestid as requestid, rp.value as Addtype
                        from disadmin.requestparameters rp, disadmin.reportrequests rr
                       where rp.parameterid = 'CNAS_ADDRESS_TYPE'
                         and rr.status = 'A'
                         and rp.requestid = rr.id) P_ADDRESS_TYPE    
       where ( 1= case when P_NAME_TYPE.Type = 'F' then
                   case when BEN_DIM.BDM_FIRST_HOLDER_NAME like DECODE(P_PARAM_VALUE.Name,'ALL','%'||BEN_DIM.BDM_FIRST_HOLDER_NAME||'%','%'||P_PARAM_VALUE.Name||'%')
                             or BEN_DIM.BDM_FIRST_HOLDER_SURNAME like DECODE(P_PARAM_VALUE.Name,'ALL','%'||BEN_DIM.BDM_FIRST_HOLDER_SURNAME||'%','%'||P_PARAM_VALUE.Name||'%')
                        then 1
                   else null end
                 else            
                   case when P_NAME_TYPE.Type = 'ALL' then
                     case when (BEN_DIM.BDM_FIRST_HOLDER_NAME like DECODE(P_PARAM_VALUE.Name,'ALL','%'||BEN_DIM.BDM_FIRST_HOLDER_NAME||'%','%'||P_PARAM_VALUE.Name||'%')
                                or BEN_DIM.BDM_FIRST_HOLDER_SURNAME like DECODE(P_PARAM_VALUE.Name,'ALL','%'||BEN_DIM.BDM_FIRST_HOLDER_SURNAME||'%','%'||P_PARAM_VALUE.Name||'%'))
                                and BEN_DIM.BDM_SECOND_HOLDER_NAME like DECODE(P_PARAM_VALUE.Name,'ALL','%'||BEN_DIM.BDM_SECOND_HOLDER_NAME||'%','%'||P_PARAM_VALUE.Name||'%')
                                and BEN_DIM.BDM_THIRD_HOLDER_NAME like DECODE(P_PARAM_VALUE.Name,'ALL','%'||BEN_DIM.BDM_THIRD_HOLDER_NAME||'%','%'||P_PARAM_VALUE.Name||'%')
                          then 1
                     else null end
                   else null end 
                 end )                    
         and BEN_DIM.BDM_IT_PAN like DECODE(P_PARAM_VALUE.PAN,'ALL','%'||BEN_DIM.BDM_IT_PAN||'%','%'||P_PARAM_VALUE.PAN||'%')
         and (1 = case when P_ADDRESS_TYPE.ADDTYPE = 1 then
                         case when instr(PERMANENT_ADD_DIM.ADDRESS, DECODE(P_PARAM_VALUE.ADDRESS,'ALL',PERMANENT_ADD_DIM.ADDRESS, P_PARAM_VALUE.ADDRESS)) <> 0
                              then 1
                         else null end
                       when P_ADDRESS_TYPE.ADDTYPE = 3 then
                         case when instr(NOM_GUARDIAN_ADD_DIM.ADDRESS, DECODE(P_PARAM_VALUE.ADDRESS,'ALL',NOM_GUARDIAN_ADD_DIM.ADDRESS, P_PARAM_VALUE.ADDRESS)) <> 0 
                           then 1
                         else null end 
                       when P_ADDRESS_TYPE.ADDTYPE = 4 then
                         case when instr(CORR_ADD_DIM.ADDRESS, DECODE(P_PARAM_VALUE.ADDRESS,'ALL',CORR_ADD_DIM.ADDRESS, P_PARAM_VALUE.ADDRESS)) <> 0 
                           then 1
                         else null end
                       when P_ADDRESS_TYPE.ADDTYPE = 6 then
                         case when instr(MINOR_ADDRESS.ADDRESS, DECODE(P_PARAM_VALUE.ADDRESS,'ALL',MINOR_ADDRESS.ADDRESS, P_PARAM_VALUE.ADDRESS)) <> 0 
                           then 1
                         else null end 
                  else null end );The above query also tries to access some tables from another user DISADMIN. Could you please help me in solving this problem while using SQL Tuning Advisor ? I am the only DBA here.

    will the rows really be updated just by using the package?Considering DMLs
    SQL> select * from test
      2  /
            NO
             1
             2
    SQL> ed
    Wrote file afiedt.buf
      1  DECLARE
      2   my_task_name VARCHAR2(30);
      3  my_sqltext   CLOB;
      4  BEGIN
      5  my_sqltext := 'insert into test values (3)';
      6  my_task_name := DBMS_SQLTUNE.CREATE_TUNING_TASK(
      7   sql_text    => my_sqltext,
      8  task_name   => 'my_sql_tuning_task');
      9* end;
    SQL> /
    PL/SQL procedure successfully completed.
    SQL> BEGIN
      2  DBMS_SQLTUNE.EXECUTE_TUNING_TASK( task_name => 'my_sql_tuning_task' );
      3  END;
      4  /
    PL/SQL procedure successfully completed.
    SQL> select * from test
      2  /
            NO
             1
             2
    SQL> SELECT DBMS_SQLTUNE.REPORT_TUNING_TASK( 'my_sql_tuning_task')
      2    FROM DUAL;
    DBMS_SQLTUNE.REPORT_TUNING_TASK('MY_SQL_TUNING_TASK')
    GENERAL INFORMATION SECTION
    Tuning Task Name   : my_sql_tuning_task
    Tuning Task Owner  : TEST
    Scope              : COMPREHENSIVE
    Time Limit(seconds): 1800
    Completion Status  : COMPLETED
    Started at         : 03/27/2008 05:16:14
    Completed at       : 03/27/2008 05:16:16
    DBMS_SQLTUNE.REPORT_TUNING_TASK('MY_SQL_TUNING_TASK')
    Schema Name: TEST
    SQL ID     : gwkmgmyj9824t
    SQL Text   : insert into test values (3)
    There are no recommendations to improve the statement.
    -------------------------------------------------------------------------------Adith

  • Noob in SQL Tuning seeking help

    I am trying to learn SQL Tuning and the workings of it. I know the first step is probably explain execution plan of the sql statement? My problem is I do not understand what am I suppose to gather from the execution plan.
    SQL> set autotrace traceonly explain
    SQL> select * from employees A
         where A.last_employed =
         ( SELECT TO_CHAR(MAX(TO_DATE(PAY_DATE,'MMRR')),'MMYY')
           FROM PAYROLL_VW1 B
           WHERE B.SSN = A.SSN AND B.PAY_TYPE_CODE IN ('02','12','22','32')
          AND STATUS = 'ACTIVE' AND A.BRANCH=B.BRANCH
    Execution Plan
       0      SELECT STATEMENT Optimizer=ALL_ROWS (Cost=47427 Card=1 Bytes
              =180)
       1    0   FILTER
       2    1     TABLE ACCESS (FULL) OF 'EMPLOYEES' (TABLE) (Cost=1618 Card
              =297964 Bytes=53633520)
       3    1     SORT (AGGREGATE)
       4    3       VIEW OF 'PAYROLL_VW1' (VIEW) (Cost=2290 Card=2 Bytes=
              46)
       5    4         SORT (UNIQUE) (Cost=2290 Card=2 Bytes=217)
       6    5           UNION-ALL
       7    6             FILTER
       8    7               TABLE ACCESS (FULL) OF 'PAYROLL2012' (TABLE) (C
              ost=2284 Card=1 Bytes=105)
       9    6             FILTER
      10    9               TABLE ACCESS (BY INDEX ROWID) OF 'PAYROLL2011'
              (TABLE) (Cost=4 Card=1 Bytes=112)
      11   10                 INDEX (RANGE SCAN) OF 'PAYROLL2011_IDX1' (IND
              EX) (Cost=3 Card=29)So what do I do with the execution plan? What else do I need to check on it? How do I tune the query?
    Edited by: apex_disco on May 1, 2012 5:57 AM

    I'm not sure how the licensing works. There is a difference between EM and Grid Control. I believe if you just have a single instance, Enterprise Manager is installed and if anything is free I would think that would be. Now, how much of the diagnostic stuff is free? Who knows.
    But it may not matter. If you are just playing around "trying to learn SQL Tuning" say, at home on a Linux box, you can install anything you want and play with it.
    If adding an index sped things up (in your re-written query that now makes sense) then you must have had a fair amount of records in one of those unindexed tables. If you look at the explain plan now it'll probably show the indexes being used, less records searched, less cost, etc. than the other plan.
    But maybe I missed your initial point. Are you trying to learn how to tune queries in general or are you trying to tune this particular query? I assumed the former for my previous replies.
    As to your results, your stats </font>tell at least the high level info. The consistent gets and physical reads went WAY down.
    Initial Statistics
    0 recursive calls
    0 db block gets
    <font color="red"> 1172490142 consistent gets
    4914 physical reads
    191496 redo size</font>
    2340 bytes sent via SQL*Net to client
    329 bytes received via SQL*Net from client
    1 SQL*Net roundtrips to/from client
    <font color="red">115881 sorts (memory) </font>
    0 sorts (disk)
    0 rows processed
    on those tables and below are my stats now. I think it's a major improvement. Time elapsed has greatly been reduced to 00:00:00.65
    Tuned Statistics
    352 recursive calls
    0 db block gets
    <font color="red">31498 consistent gets
    1101 physical reads
    0 redo size
    </font>
    2340 bytes sent via SQL*Net to client
    329 bytes received via SQL*Net from client
    1 SQL*Net roundtrips to/from client
    <font color="red">13 sorts (memory) </font>
    0 sorts (disk)
    0 rows processed
    Edited by: Gaff on May 1, 2012 1:18 PM

  • SQL Tuning Advisor  Recommends New Explain Plan

    Hi:
    I have to believe this has been asked before but didn't see it in a forum search so I'll ask here. I had SQL Tuning Advisor look at a query and it is recommending a new plan for a 50+% improvement (hazah!). The trouble is, I don't want Oracle to re-write the plan to execute the query better, I want to know how I can re-write the query to generate that more optimal plan in the first place because I have similar systems in the field that I would like to also be optimized. What are my options?
    Thanks.

    Sorry Gaff I know where you are talking about but I don't have your answer, but it may be a good start going over the 19g reference guide for these dictionary views -
    SQL> select view_name from dba_views where view_name like 'DBA%ADVISOR%' ;
    VIEW_NAME
    DBA_ADVISOR_DEFINITIONS
    DBA_ADVISOR_COMMANDS
    DBA_ADVISOR_OBJECT_TYPES
    DBA_ADVISOR_USAGE
    DBA_ADVISOR_TASKS
    DBA_ADVISOR_TEMPLATES
    DBA_ADVISOR_LOG
    ...Best regards.

  • SQL tuning or a simple comprise between time and cost?

    Hi,
    What I understand is that SQL tuning is a simple comprise between time and cost. Objectives of SQL tuning include:
    Reduce Cost
    Reduce Time
    Better Results
    Is it right and correct?
    Adith

    NO, WRONG.
    reducing COST is meaningless, because COST is meaningless. It's used internally by the optimizer to weigh the cost/benefits of different execution plans (access methods) for a single query. cost CANNOT be compared across queries. and if you add a hint to a sql, then it becomes a different sql (proven by looking in v$sql) so you cannot compare costs. in fact, when you provide a hint, oracle artificially lowers the cost associated with the hinted action in order to make that action look better to the optimizer, helping it to be choosen.
    reduce time. reduce io. reduce memory usage. that's it.

  • OEM - No ad-hoc SQL tuning?

    Am I correct that there is no way to say to Oracle Enterprise Manager's SQL Tuning Advisor, "here is some SQL - please analyze and tune it". The only way to get it to tune something is to find it running and then say "please run the SQL tuning advisor on it".
    In other words, no way to tune a query without running it first...?
    I've been looking for a way to do this in OEM and can't find it.
    Thanks!

    sb92075 wrote:
    Last I checked, explain plans tell you what will happen, not how you might change things to improve itIf/when an experienced & KNOWLEDGEABLE person see a BAD plan, they may be able to reformulate the SQL to produce a better plan.
    which is what the SQL Tuning Advisor does.Those who live by the GUI, die by the GUI.
    Some/many folks would be incapable of doing anything with or to Oracle RDBMS if OEM did not exist or was broken.Did I ask for opinions on the One True Way to be a DBA, or for a comparison of SQL*Plus vs. OEM, or a survey of the competence level of typical DBAs?
    No.
    I asked a simple, technical question about OEM.

  • Comlex SQL tuning

    dear experts
    i'm facing a bad sql that need to be tuned , but even i'd read Oracle Doc for 2 years , when comes to real problems like this ,
    still i feel a bit of lost and doesn't know what to do next ?
    so , thank you guys first if you can point me in the right direction ...
    here is the SQL
    this is the view definition ,and it querys two tables , rns_p_cgr_cgrdir1_pmc for newer version and P_MSC_CG for old version combined with utp_common_objects for some columns missing on old version table ...
    SELECT
    b.msc_id msc_id,
    b.cgr_id cgr_id,
    b.cgr_name_id cgr_name_id,
    b.cgr_dir_id cgr_dir_id,
    b.period_start_time period_start_time,
    b.period_duration period_duration,
    b.cgrcgroup_nof_circuits cgrcgroup_nof_circuits,
    b.cgrcgroup_nof_woex_crts_in cgrcgroup_nof_woex_crts_in,
    b.cgrcgroup_nof_woex_crts_out cgrcgroup_nof_woex_crts_out,
    b.cgrcgroup_timecong_percentx100 cgrcgroup_timecong_percentx100,
    b.cgrcgroup_call_cong_x_100 cgrcgroup_call_cong_x_100,
    b.cgrcgroup_call_amount_in cgrcgroup_call_amount_in,
    b.cgrcgroup_call_amount_out cgrcgroup_call_amount_out,
    b.cgrcgroup_accepted_in cgrcgroup_accepted_in,
    b.cgrcgroup_accepted_out cgrcgroup_accepted_out,
    b.cgrcgroup_answered_in cgrcgroup_answered_in,
    b.cgrcgroup_answered_out cgrcgroup_answered_out,
    b.cgrcgroup_subs_fail_in cgrcgroup_subs_fail_in,
    b.cgrcgroup_subs_fail_out cgrcgroup_subs_fail_out,
    b.cgrcgroup_int_fail_in cgrcgroup_int_fail_in,
    b.cgrcgroup_int_fail_out cgrcgroup_int_fail_out,
    b.cgrcgroup_ext_fail_in cgrcgroup_ext_fail_in,
    b.cgrcgroup_ext_fail_out cgrcgroup_ext_fail_out,
    b.cgrcgroup_erlangs_in_x_100 cgrcgroup_erlangs_in_x_100,
    b.cgrcgroup_erlangs_out_x_100 cgrcgroup_erlangs_out_x_100,
    b.cgrcgroup_min_free cgrcgroup_min_free,
    b.cgrcgroup_invalid_record cgrcgroup_invalid_record,
    b.cgrcgroup_corrupt_message cgrcgroup_corrupt_message,
    b.cgrcgroup_data_prov_restarted cgrcgroup_data_prov_restarted,
    b.cgrcgroup_ring_in cgrcgroup_ring_in,
    b.cgrcgroup_ring_out cgrcgroup_ring_out FROM
    rns_p_cgr_cgrdir1_pmc b
    UNION ALL SELECT
    c.co_gid,
    to_char(a.circuit_group_nbr),
    a.circuit_group_name,
    to_char(a.circuit_group_direction),
    a.period_start_time,
    a.period_duration,
    a.TOTAL_NBR_CIRCUITS,
    a.AVR_NBR_CARRYING_INC_CIRC,
    a.AVR_NBR_CARRYING_OUT_CIRC,
    a.TIME_CONGESTION_OUT_CIRC,
    a.CALL_CONGESTION_OUT_CIRC,
    a.NBR_CALLS_INC_CIRC,
    a.NBR_CALLS_OUT_CIRC,
    a.SUCC_CALLS_INC_CIRC,
    a.SUCC_CALLS_OUT_CIRC,
    a.INC_ANS_CALLS,
    a.OUT_ANS_CALLS,
    a.SUBSC_ERR_INC_CIRC,
    a.SUBSC_ERR_OUT_CIRC,
    a.INT_ERR_CALLS_INC_CIRC,
    a.INT_ERR_CALLS_OUT_CIRC,
    a.EXT_ERR_CALLS_INC_CIRC,
    a.EXT_ERR_CALLS_OUT_CIRC,
    a.AVR_TRAF_ERLANG_INC_CIRC,
    a.AVR_TRAF_ERLANG_OUT_CIRC,
    a.MIN_FREE_CIRCUITS,
    to_number(NULL),
    to_number(NULL),
    to_number(NULL),
    to_number(NULL),
    to_number(NULL)
    FROM
    P_MSC_CG a,
    utp_common_objects c
    WHERE
    c.co_oc_id IN (107, 108, 581, 1226) AND
    NOT EXISTS (select 1 from rns_p_cgr_cgrdir1_pmc m where m.msc_id=c.co_gid and m.
    period_start_time=a.period_start_time) AND
    a.int_id = c.co_int_id
    The query against base table are fast ,here is the explain plan for those query
    SQL> select count(*) from pm.rns_p_cgr_cgrdir1_pmc;
    COUNT(*)
    123352
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=141 Card=1)
    1 0 SORT (AGGREGATE)
    2 1 INDEX (FAST FULL SCAN) OF 'RNS_PK_MEAS_CGR_O2' (UNIQUE)
    (Cost=141 Card=122700)
    Statistics
    7 recursive calls
    0 db block gets
    985 consistent gets
    0 physical reads
    72 redo size
    520 bytes sent via SQL*Net to client
    655 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    1 rows processed
    SQL>
    SQL> select count(*) from P_MSC_CG;
    COUNT(*)
    120576
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=70 Card=1)
    1 0 SORT (AGGREGATE)
    2 1 INDEX (FAST FULL SCAN) OF 'PI_MSC_CG_X' (NON-UNIQUE) (Co
    st=70 Card=120410)
    Statistics
    18 recursive calls
    0 db block gets
    487 consistent gets
    460 physical reads
    232 redo size
    520 bytes sent via SQL*Net to client
    655 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    1 rows processed
    SQL>
    SQL> select count(*) from UPPER('rns_PJ_cgr_cgrdir1_raw');;
    select count(*) from UPPER('rns_PJ_cgr_cgrdir1_raw');
    ERROR at line 1:
    ORA-00933: SQL command not properly ended
    SQL> select count(*) from pm.rns_PJ_cgr_cgrdir1_raw;
    COUNT(*)
    185186
    Execution Plan
    0 SELECT STATEMENT Optimizer=CHOOSE (Cost=198930 Card=1)
    1 0 SORT (AGGREGATE)
    2 1 VIEW OF 'RNS_PJ_CGR_CGRDIR1_RAW' (Cost=198930 Card=12872
    1)
    3 2 UNION-ALL
    4 3 INDEX (FAST FULL SCAN) OF 'RNS_PK_MEAS_CGR_O2' (UNIQ
    UE) (Cost=141 Card=122700)
    5 3 FILTER
    6 5 HASH JOIN (Cost=96 Card=6021 Bytes=162567)
    7 6 INLIST ITERATOR
    8 7 TABLE ACCESS (BY INDEX ROWID) OF 'UTP_COMMON_O
    BJECTS' (Cost=2 Card=35 Bytes=525)
    9 8 INDEX (RANGE SCAN) OF 'UTP_I_CO_LIC_TARGET_I
    D' (NON-UNIQUE) (Cost=1 Card=1)
    10 6 INDEX (FAST FULL SCAN) OF 'PI_MSC_CG_A' (UNIQUE)
    (Cost=93 Card=120410 Bytes=1444920)
    11 5 INDEX (RANGE SCAN) OF 'RNS_PI_MEAS_CGR_O2' (NON-UN
    IQUE) (Cost=65 Card=19 Bytes=266)
    Statistics
    21 recursive calls
    0 db block gets
    6404250 consistent gets
    0 physical reads
    80 redo size
    520 bytes sent via SQL*Net to client
    655 bytes received via SQL*Net from client
    2 SQL*Net roundtrips to/from client
    0 sorts (memory)
    0 sorts (disk)
    1 rows processed
    6404250 consistent gets is bit of too high , and the query took too long than one can bear ...
    any idea of how to reduce the logical io ?
    thanks a lot
    br/ricky

    hi, pal
    your idea is way better ,only can you or anyone explain it a little ,thanks
      9* pm.rns_p_cgr_cgrdir1_pmc m
    SQL> L
      1   select count(*) from
      2  (
      3  select k.co_gid, k.period_start_time, m.msc_id col
      4  from
      5  (select c.co_gid co_gid, a.period_start_time period_start_time
      6  from P_MSC_CG a, utp_common_objects c
      7  where c.co_oc_id IN (107, 108, 581, 1226) AND a.int_id = c.co_int_id
      8  ) k,
      9  pm.rns_p_cgr_cgrdir1_pmc m
    10  where m.msc_id(+)=k.co_gid and m.period_start_time(+)=k.period_start_time
    11  )
    12* where col is null
    SQL> /
      COUNT(*)
         61440
    Elapsed: 00:00:01.79
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=348 Card=1 Bytes=36)
       1    0   SORT (AGGREGATE)
       2    1     FILTER
       3    2       HASH JOIN (OUTER)
       4    3         VIEW (Cost=96 Card=120410 Bytes=2649020)
       5    4           HASH JOIN (Cost=96 Card=120410 Bytes=3251070)
       6    5             INLIST ITERATOR
       7    6               TABLE ACCESS (BY INDEX ROWID) OF 'UTP_COMMON_O
              BJECTS' (Cost=2 Card=35 Bytes=525)
       8    7                 INDEX (RANGE SCAN) OF 'UTP_I_CO_LIC_TARGET_I
              D' (NON-UNIQUE) (Cost=1 Card=1)
       9    5             INDEX (FAST FULL SCAN) OF 'PI_MSC_CG_A' (UNIQUE)
               (Cost=93 Card=120410 Bytes=1444920)
      10    3         INDEX (FAST FULL SCAN) OF 'RNS_PK_MEAS_CGR_O2' (UNIQ
              UE) (Cost=141 Card=122700 Bytes=1717800)
    Statistics
              7  recursive calls
              0  db block gets
           1705  consistent gets
              1  physical reads
              0  redo size
            520  bytes sent via SQL*Net to client
            655  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processed
    SQL>  select count(*) from (
      2  SELECT
      3  c.co_gid,
      4  to_char(a.circuit_group_nbr),
      5  a.circuit_group_name,
      6  to_char(a.circuit_group_direction),
      7  a.period_start_time,
      8  a.period_duration,
      9  a.TOTAL_NBR_CIRCUITS,
    10  a.AVR_NBR_CARRYING_INC_CIRC,
    11  a.AVR_NBR_CARRYING_OUT_CIRC,
    12  a.TIME_CONGESTION_OUT_CIRC,
    13  a.CALL_CONGESTION_OUT_CIRC,
    14  a.NBR_CALLS_INC_CIRC,
    15  a.NBR_CALLS_OUT_CIRC,
    16  a.SUCC_CALLS_INC_CIRC,
    17  a.SUCC_CALLS_OUT_CIRC,
    18  a.INC_ANS_CALLS,
    19  a.OUT_ANS_CALLS,
    20  a.SUBSC_ERR_INC_CIRC,
    21  a.SUBSC_ERR_OUT_CIRC,
    22  a.INT_ERR_CALLS_INC_CIRC,
    23  a.INT_ERR_CALLS_OUT_CIRC,
    24  a.EXT_ERR_CALLS_INC_CIRC,
    25  a.EXT_ERR_CALLS_OUT_CIRC,
    26  a.AVR_TRAF_ERLANG_INC_CIRC,
    27  a.AVR_TRAF_ERLANG_OUT_CIRC,
    28  a.MIN_FREE_CIRCUITS,
    29  to_number(NULL),
    30  to_number(NULL),
    31  to_number(NULL),
    32  to_number(NULL),
    33  to_number(NULL)
    34  FROM
    35    P_MSC_CG a,
    36     utp_common_objects c
    37  WHERE
    38     c.co_oc_id IN (107, 108, 581, 1226) AND 
    39  NOT EXISTS ( select 1 from pm.rns_p_cgr_cgrdir1_pmc m where m.msc_id=c.co_gid and m.
    40  period_start_time=a.period_start_time) AND
    41     a.int_id = c.co_int_id);
      COUNT(*)
         61440
    Elapsed: 00:05:12.28
    Execution Plan
       0      SELECT STATEMENT Optimizer=CHOOSE (Cost=129 Card=1 Bytes=27)
       1    0   SORT (AGGREGATE)
       2    1     FILTER
       3    2       HASH JOIN (Cost=96 Card=6021 Bytes=162567)
       4    3         INLIST ITERATOR
       5    4           TABLE ACCESS (BY INDEX ROWID) OF 'UTP_COMMON_OBJEC
              TS' (Cost=2 Card=35 Bytes=525)
       6    5             INDEX (RANGE SCAN) OF 'UTP_I_CO_LIC_TARGET_ID' (
              NON-UNIQUE) (Cost=1 Card=1)
       7    3         INDEX (FAST FULL SCAN) OF 'PI_MSC_CG_A' (UNIQUE) (Co
              st=93 Card=120410 Bytes=1444920)
       8    2       INDEX (RANGE SCAN) OF 'RNS_PI_MEAS_CGR_O2' (NON-UNIQUE
              ) (Cost=65 Card=19 Bytes=266)
    Statistics
              7  recursive calls
              0  db block gets
        6372911  consistent gets
              0  physical reads
              0  redo size
            520  bytes sent via SQL*Net to client
            655  bytes received via SQL*Net from client
              2  SQL*Net roundtrips to/from client
              0  sorts (memory)
              0  sorts (disk)
              1  rows processedthanks
    br/ricky
    Edited by: zs_hzh on Oct 7, 2008 4:14 AM

Maybe you are looking for