Sql statment tunning

Select * from (SELECT M.MAIL_ID, MAIL_FROM, M.SUBJECT AS S1, CEIL(M.MAIL_SIZE) AS MAIL_SIZE,
TO_CHAR(MAIL_DATE,'dd Mon yyyy hh:mi:ss am') AS MAIL_DATE1, M.ATTACHMENT_FLAG, M.MAIL_TYPE_ID,
M.PRIORITY_NO, M.TEXT, COALESCE(M.MAIL_STATUS_VALUE, M.MAIL_STATUS_VALUE, 0), 0 as email_address,
M.MAIL_DATE AS MAIL_DATE, lower(subject) as subject, read_ipaddress,read_datetime, Folder_Id,
compose_type,interc_count,history_id,pined_flag, rank() over (order by mail_date desc) as rnk
from mail M WHERE M.FOLDER_ID = 1 and M.USER_ID=202990 )
where rnk between 100 and 100;

When your query takes too long ...

Similar Messages

  • Getting a DataReader by stored procedure vs. SQL statment (Performance)

    Hallo DB-Experts,
    I have encountered a performance problem regarding getting a DataReader by stored procedure versus a SQL statment
    and I want to know if this is an known issue and how to tune it.
    Getting a DataReader through a SQL statment is faster than with a stored procedure,
    if the number of data rows are less than about 8000 datarows, although we are using an index.
    The stored procedure ist only faster about 8000 datarows.
    For the first 20 rows the different is between 50 abd 20 percent and between and 20 and 2000 rows it fall down to 10 percent.
    Over 8000 rows the stored procedure is faster!
    The time series table looks like:
    CREATE TABLE TimeSeries
    OBJECT_ID NUMBER(8) NOT NULL,
    UNIVERSAL_TIME NUMBER(10) NOT NULL,
    LOCAL_TIME DATE NOT NULL,
    MOD_TIME NUMBER(10),
    USERID NUMBER(10),
    VALUE NUMBER NOT NULL,
    FLAG NUMBER(2) DEFAULT 0 NOT NULL
    The foreinkey is object_id and another index is for universal_time and mod_time
    The stored procedure looks like:
    PROCEDURE SELECTDATA_UT_MOD (pObjectID IN NUMBER,
    pType IN VARCHAR2,
    pTable IN VARCHAR2,
    pFrom IN NUMBER,
    pTo IN NUMBER,
    IO_CURSOR OUT T_CURSOR)
    IS
    SQLString VARCHAR2(1024);
    BEGIN
    IF pOBJECTID <> 0 THEN
    CASE
    WHEN UPPER(pTYPE)='A' THEN
    SQLString := 'SELECT UNIVERSAL_TIME, VALUE, FLAG, MOD_TIME FROM ' || pTABLE || ' WHERE OBJECT_ID = :t1 AND UNIVERSAL_TIME >= :t2 and UNIVERSAL_TIME < :t3 Order By UNIVERSAL_TIME, MOD_TIME DESC';
    OPEN IO_CURSOR FOR
    SQLString USING pOBJECTID,pFROM,pTO;
    END IF;
    END;
    The SQL statment for the data reader looks like:
    SELECT d.universal_time, d.VALUE, d.flag, 0 AS mod_time
    FROM daten d
    WHERE object_id = 18465
    AND d.universal_time >= 3600
    AND d.universal_time < 28803600
    ORDER BY d.universal_time, mod_time DESC
    Do you have any idea or tip why the sql statment for the first 8000 rows is faster than the stored procedure?
    Many thanks in advance and
    Best regards
    George
    Edited by: hakomdba on 09.01.2009 06:39

    Hallo DB-Experts,
    I have encountered a performance problem regarding getting a DataReader by stored procedure versus a SQL statment
    and I want to know if this is an known issue and how to tune it.
    Getting a DataReader through a SQL statment is faster than with a stored procedure,
    if the number of data rows are less than about 8000 datarows, although we are using an index.
    The stored procedure ist only faster about 8000 datarows.
    For the first 20 rows the different is between 50 abd 20 percent and between and 20 and 2000 rows it fall down to 10 percent.
    Over 8000 rows the stored procedure is faster!
    The time series table looks like:
    CREATE TABLE TimeSeries
    OBJECT_ID NUMBER(8) NOT NULL,
    UNIVERSAL_TIME NUMBER(10) NOT NULL,
    LOCAL_TIME DATE NOT NULL,
    MOD_TIME NUMBER(10),
    USERID NUMBER(10),
    VALUE NUMBER NOT NULL,
    FLAG NUMBER(2) DEFAULT 0 NOT NULL
    The foreinkey is object_id and another index is for universal_time and mod_time
    The stored procedure looks like:
    PROCEDURE SELECTDATA_UT_MOD (pObjectID IN NUMBER,
    pType IN VARCHAR2,
    pTable IN VARCHAR2,
    pFrom IN NUMBER,
    pTo IN NUMBER,
    IO_CURSOR OUT T_CURSOR)
    IS
    SQLString VARCHAR2(1024);
    BEGIN
    IF pOBJECTID <> 0 THEN
    CASE
    WHEN UPPER(pTYPE)='A' THEN
    SQLString := 'SELECT UNIVERSAL_TIME, VALUE, FLAG, MOD_TIME FROM ' || pTABLE || ' WHERE OBJECT_ID = :t1 AND UNIVERSAL_TIME >= :t2 and UNIVERSAL_TIME < :t3 Order By UNIVERSAL_TIME, MOD_TIME DESC';
    OPEN IO_CURSOR FOR
    SQLString USING pOBJECTID,pFROM,pTO;
    END IF;
    END;
    The SQL statment for the data reader looks like:
    SELECT d.universal_time, d.VALUE, d.flag, 0 AS mod_time
    FROM daten d
    WHERE object_id = 18465
    AND d.universal_time >= 3600
    AND d.universal_time < 28803600
    ORDER BY d.universal_time, mod_time DESC
    Do you have any idea or tip why the sql statment for the first 8000 rows is faster than the stored procedure?
    Many thanks in advance and
    Best regards
    George
    Edited by: hakomdba on 09.01.2009 06:39

  • Need help in SQl statment

    this SQL statment work in oracle database :
    SELECT TO_DATE('20080627','YYYYMMDD') - TO_DATE('20080526','YYYYMMDD') FROM dual
    But didn'twork on Timesten Database and this error is appear
    2789: An interval data type must be specified for a datetime arithmetic result
    The command failed.

    SELECT extract (day from TO_DATE('20080627','YYYYMMDD') - TO_DATE('20080626','YYYYMMDD')) FROM dual;
    See
    http://download.oracle.com/otn_hosted_doc/timesten/703/TimesTenDocumentation/wwhelp/wwhimpl/js/html/wwhelp.htm?&accessible=true
    for details.

  • Problem with DBMS_OUTPUT and SQL statment with a function

    I am using SQL Developer version 3.0.04 and I have a function that has a dbms_output statment in it. I am running the following SQL to select the output of that statment.
    select A.A_FUCTION('TEST') from dual;
    The output works fine but the dbms_output line does not show in the dbms_output window. I turned on the output window etc. and i can get the select to print out the output if i wrap it in a declare begin end wrapper... and then change the query to insert the return value into variable.
    just wondering if there is way to get the dbms_output to flush out with just an SQL statment instead of in a begin end wrapper etc.

    just wondering if there is way to get the dbms_output to flush out with just an SQL statment instead of in a begin end wrapper etc.works fine in sql*plus, so I guess it must be a preference or sth. in sql*developer:
    SQL> set serverout on
    SQL> create or replace function f1 (r int)
      2    return int
      3  as
      4  begin
      5    dbms_output.put_line ('Hello World ' || r);
      6    return r;
      7  end f1;
      8  /
    Function created.
    SQL>
    SQL> select f1 (rownum) f1 from dual connect by level <= 3
      2  /
            F1
             1
             2
             3
    3 rows selected.
    Hello World 1
    Hello World 2
    Hello World 3
    SQL>

  • How to improve my pls/sql performance tunning skills

    Hi All , I would like to learn more about pl/sql performance tunning , where or how can i get more knowledge in this area ?
    Is there any tutorials which can help me to understand the Explain plan, Dbms_Profiler, Dbms_Advisor more etc ........Thanks . Bcj

    Explain plan
    http://www.psoug.org/reference/explain_plan.html
    DBMS_PROFILER (10g)
    http://www.psoug.org/reference/dbms_profiler.html
    DBMS_HPROF (11g)
    http://www.psoug.org/reference/dbms_hprof.html
    DBMS_ADVISOR
    http://www.psoug.org/reference/dbms_advisor.html
    DBMS_MONITOR
    http://www.psoug.org/reference/dbms_monitor.html
    DBMS_SUPPORT
    http://www.psoug.org/reference/dbms_support.html
    DBMS_TRACE
    http://www.psoug.org/reference/dbms_trace.html
    DBMS_SQLTUNE
    http://www.psoug.org/reference/dbms_sqltune.html

  • How to find top 10  SQL statments which are consuming more cpu time.

    hi all,
    Is there any command or script to monitor the top 10 sql statments which are consuming more cpu time.
    I know by using AWR REPORT we can find it, i want the command or script to find the top cpu utilization sql statments.
    Regards
    Subhash.

    Subhash,
    A quick and dirty Google search could have get you started with the following:
    Thread: how to get top CPU consuming sql oracle 10g
    Re: how to get top CPU consuming sql oracle 10g
    Oracle SQL top sessions
    http://www.dba-oracle.com/oracle10g_tuning/t_sql_top_sessions.htm
    "How to Find top 10 expensive sql's", version 9.2.0
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:73325450402303
    HTH,
    Thierry

  • Newbee Question to SQL Statment ..

    Hello,
    what does the statment PRODWH refer to in the statment below ....?
    what s the function of {?PRODWH: F_INVOICES.PROD_ID}. Is it an Input Parameter for the user ?
    ist the statment "external Join" replaceble trough Right/left Join ..?
    SQL Statment-------------------
    PRODWH
    SELECT
    "D_PROD_DESC"."PRODUCT_DESC_SHORT",
    "D_PROD"."SKU", "D_PRODUCT"."BU_DEPARTMENT",
    "D_PROD"."PROD_ID"
    FROM
    "D_PROD_DESC" "D_PROD_DESC" INNER JOIN
    "D_PROD" "D_PROD" ON
    "D_PROD_DESC"."PROD_ID"="D_PROD"."PROD_ID"
    EXTERNAL JOIN D_PROD.BU_DEPARTMENT={?PRODWH: Command.BU_DEPARTMENT} AND
    D_PROD.PROD_ID={?PRODWH: F_INVOICES.PROD_ID} AND
    D_PROD.SKU={?PRODWH: D_OLD_CUST.BU_SKU}
    -----END----------------

    The Database is Oracle but the SQL statment is generated by Crystal Reports XI

  • SQL Statment Help

    hiya
    i need help about SQL statment i want get all employee Data if i know the emp_no get specify recored if emp_no = null get all Data
    select * from employe where emp_no=123 if emp_no=null get all records
    thx

    Hi,
    Welcome to the forum!
    Ttushar's solution is what you requested.
    If empno can not be NULL, then you can also modify it like this:
    SELECT  *
    FROM     employee
    WHERE     emp_no = NVL (:v_emp_no, emp_no);

  • Embeded SQL Statment VS Store procedure

    On J2ee tecknology, what is the better method of usind data services.
    raping all sql statment in the store procedure or embeded all sql statment in EJB.
    thanks
    null

    Hi,
    This issue looks similar to the the issue described in:
    Re: Exception in reader for ODP.NET 11.1.0.6.2 same work fine in older version
    Note that Bug 9792727 was filed to track the issue described in the above link.
    Regards,
    -Naveen

  • Help in writing SQl Statment

    Hi all,
    I have a table which contain project details those are the coulmns:
    Project_number (PK)
    Submit Date
    Project_title
    Project_milestones
    I want to retrieve how many number of project in each mounth per year
    Output Example:
    Date Number of projects
    FEB 2008 *6*
    March 2008 *5*
    FEB 2009 *4*
    March 2009 *7*
    And so on, I tryed to write an sql statment to retrieve the desired results but I couldn't.
    If any one has any idea in retrieving such result please assist me how to write this sql statment.

    Hi,
    If submit_date is a DATE, then TRUNC (submit_date, 'MM') is the beginning of the month that countains it.
    So you can say:
    SELECT    TRUNC (submit_date, 'MM')   AS month
    ,         COUNT (*)                   AS cnt
    FROM      project_table
    GROUP BY  TRUNC (submit_date, 'MM');Of course, you can add TO_CHAR to the first line to format the date however you like.

  • How to access currently executing SQL statment?

    Hello -
    I have a C language external procedure that is called from an INSERT / UPDATE / DELETE trigger.
    Is there a way (using OCI, or elsewhere) to get a string containing the SQL statment that fired the trigger?
    Thanks a bunch for your help!
    -js

    http://databasejournal.com/features/oracle/article.php/3373701
    The second page has more details (there is also a part II to this article if you are interested).

  • SQL Statement Tunning Request

    Please help to tune the below query. I have provided following information
    1. Query To be tuned
    2. Parameter Relevant to Optimizer
    3. Explain Plan and AutoTrace Ouput
    4. Query traced at Level 8 and Its Tkprof Ouput
    5. EXPLAIN PLAN output of DBMS_XPLAN.DISPLAY
    INFORMATION 1. SQL QUERY TO BE TUNED
    SELECT DISTINCT C.MAN_WIP_T_IN_TS,
    C.RCP_NO,
    C.WRK_CTR_ID,
    C.WTR_FREE_TST_FLG,
    A.COMPANY_ID,
    A.PROD_ORDER,
    A.PART_NO,
    A.CARRIER_QTY,
    B.PHY_CARID,
    C.WIP_SEQ,
    A.RCP_NO "CARRIER_RCP"
    FROM dbadmintest.PF2_PROD_ORDER_CARRIER A,
    PF2_PHYSICAL_CARRIER B,
    WORK_IN_PROCESS C
    WHERE C.UNIT_TYPE_CD = RTRIM('TL7')
    AND C.UNIT_NM = RTRIM('T41')
    AND C.WIP_TYPE_CD = 'HANDHELD'
    AND C.PHY_CARRIER_SEQ = A.PHY_CARRIER_SEQ
    AND A.PHY_CARRIER_SEQ = B.PHY_CARRIER_SEQ
    AND ((A.CARRIER_LD_TS <= C.MAN_WIP_T_IN_TS
    AND A.CARRIER_UNLD_TS >= C.MAN_WIP_T_IN_TS)
    OR ( A.CARRIER_LD_TS <= C.MAN_WIP_T_IN_TS
    AND A.CARRIER_UNLD_TS IS NULL))
    AND ((A.CARRIER_UNLD_TS >= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
    AND A.CARRIER_UNLD_TS <= TO_DATE('2012-01-12 10:03:00', 'YYYY-MM-DD HH24:MI:SS'))
    OR (A.CARRIER_LD_TS >= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
    AND A.CARRIER_LD_TS <= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS'))
    OR (A.CARRIER_LD_TS <= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
    AND A.CARRIER_UNLD_TS IS NULL)
    OR (A.CARRIER_LD_TS <= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
    AND A.CARRIER_UNLD_TS >= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')))
    ORDER BY 6,5,1
    INFORMATION 2. PARAMETER RELEVANT TO OPTIMIZER
    NAME           TYPE      VALUE
    optimizer_dynamic_sampling      integer      2
    optimizer_features_enable      string      10.2.0.4
    optimizer_index_caching      integer      0
    optimizer_index_cost_adj      integer      100
    optimizer_mode           string      ALL_ROWS
    optimizer_secure_view_merging      boolean      TRUE
    db_file_multiblock_read_count      integer      16
    cursor_sharing           string      EXACT
    SQL> column sname format a20          
    column pname format a20          
    column pval2 format a20          
    select          
    sname          
    , pname          
    , pval1          
    , pval2          
    from sys.aux_stats$;SQL>      
    SNAME      PNAME      PVAL1      PVAL2
    SYSSTATS_INFO      STATUS           COMPLETED
    SYSSTATS_INFO      DSTART           08-25-2009 07:27
    SYSSTATS_INFO      DSTOP           08-25-2009 07:27
    SYSSTATS_INFO      FLAGS      1
    SYSSTATS_MAIN      CPUSPEEDNW      1592.87183
    SYSSTATS_MAIN      IOSEEKTIM      10
    SYSSTATS_MAIN      IOTFRSPEED      4096
    SYSSTATS_MAIN      SREADTIM
    SYSSTATS_MAIN      MREADTIM
    SYSSTATS_MAIN      CPUSPEED
    SYSSTATS_MAIN      MBRC
    SYSSTATS_MAIN      MAXTHR
    SYSSTATS_MAIN      SLAVETHR
    INFORMATION 3. EXPLAIN PLAN AND AUTOTRACE OUTPUT
    Execution Plan
    Plan hash value: 850402268
    | Id | Operation                | Name                | Rows      | Bytes      | Cost (%CPU)     | Time      |
    | 0 | SELECT STATEMENT           |                | 11      | 1100      | 1568      (1)     | 00:00:19      |
    | 1 | SORT UNIQUE                |                | 11      | 1100      | 1567      (1)     | 00:00:19      |
    |* 2 | HASH JOIN                |                | 11      | 1100      | 1566      (1)     | 00:00:19      |
    |* 3 | TABLE ACCESS BY INDEX ROWID      | PF2_PROD_ORDER_CARRIER      | 5      | 270      | 763      (0)     | 00:00:10      |
    | 4 | NESTED LOOPS           |                | 11      | 1001      | 1562      (1)     | 00:00:19      |
    |* 5 | TABLE ACCESS BY INDEX ROWID     | WORK_IN_PROCESS           | 2      | 74      | 35      (0)     | 00:00:01      |
    |* 6 | INDEX RANGE SCAN           | WORK_IN_PROCESS_IX2           | 56      |      | 3      (0)     | 00:00:01      |
    |* 7 | INDEX RANGE SCAN           | PF2_PROD_ORDER_CARRIER_IX3      | 2361      |      | 6      (0)     | 00:00:01      |
    | 8 | TABLE ACCESS FULL           | PF2_PHYSICAL_CARRIER           | 1736      | 15624      | 4      (0)     | 00:00:01 |
    Predicate Information (identified by operation id):
    2 - access("A"."PHY_CARRIER_SEQ"="B"."PHY_CARRIER_SEQ")
    3 - filter(("A"."CARRIER_UNLD_TS" IS NULL AND "A"."CARRIER_LD_TS"<=TO_DATE(' 2012-01-12 08:03:00',
    'syyyy-mm-dd hh24:mi:ss') OR "A"."CARRIER_UNLD_TS">=TO_DATE(' 2012-01-12 08:03:00', 'syyyy-mm-dd
    hh24:mi:ss') AND "A"."CARRIER_LD_TS"<=TO_DATE(' 2012-01-12 08:03:00', 'syyyy-mm-dd hh24:mi:ss') OR
    "A"."CARRIER_UNLD_TS">=TO_DATE(' 2012-01-12 08:03:00', 'syyyy-mm-dd hh24:mi:ss') AND
    "A"."CARRIER_UNLD_TS"<=TO_DATE(' 2012-01-12 10:03:00', 'syyyy-mm-dd hh24:mi:ss') OR
    "A"."CARRIER_LD_TS"=TO_DATE(' 2012-01-12 08:03:00', 'syyyy-mm-dd hh24:mi:ss')) AND
    ("A"."CARRIER_LD_TS"<="C"."MAN_WIP_T_IN_TS" AND "A"."CARRIER_UNLD_TS">="C"."MAN_WIP_T_IN_TS" OR
    "A"."CARRIER_UNLD_TS" IS NULL AND "A"."CARRIER_LD_TS"<="C"."MAN_WIP_T_IN_TS"))
    5 - filter("C"."WIP_TYPE_CD"='HANDHELD' AND "C"."PHY_CARRIER_SEQ" IS NOT NULL)
    6 - access("C"."UNIT_TYPE_CD"='TL7' AND "C"."UNIT_NM"='T41')
    7 - access("C"."PHY_CARRIER_SEQ"="A"."PHY_CARRIER_SEQ")
    filter("A"."PHY_CARRIER_SEQ" IS NOT NULL)
    Statistics
    1           recursive calls
    0           db block gets
    13525998      consistent gets
    7024           physical reads
    0           redo size
    1758           bytes sent via SQL*Net to client
    492           bytes received via SQL*Net from client
    2           SQL*Net roundtrips to/from client
    1           sorts (memory)
    0           sorts (disk)
    14           rows processed
    INFORMATION 4. QUERY TRACES AT LEVEL 8 AND TKPROF OUTPUT
    TKPROF: Release 10.2.0.4.0 - Production on Wed Jan 18 01:48:53 2012
    Copyright (c) 1982, 2007, Oracle. All rights reserved.
    Trace file: ././ppf2_ora_5439924.trc
    Sort options: default
    count = number of times OCI procedure was executed
    cpu = cpu time in seconds executing
    elapsed = elapsed time in seconds executing
    disk = number of physical reads of buffers from disk
    query = number of buffers gotten for consistent read
    current = number of buffers gotten in current mode (usually for update)
    rows = number of rows processed by the fetch or execute call
    SELECT DISTINCT C.MAN_WIP_T_IN_TS,
    C.RCP_NO,
    C.WRK_CTR_ID,
    C.WTR_FREE_TST_FLG,
    A.COMPANY_ID,
    A.PROD_ORDER,
    A.PART_NO,
    A.CARRIER_QTY,
    B.PHY_CARID,
    C.WIP_SEQ,
    A.RCP_NO "CARRIER_RCP"
    FROM PF2_PROD_ORDER_CARRIER A,
    PF2_PHYSICAL_CARRIER B,
    WORK_IN_PROCESS C
    WHERE C.UNIT_TYPE_CD = RTRIM('TL7')
    AND C.UNIT_NM = RTRIM('T41')
    AND C.WIP_TYPE_CD = 'HANDHELD'
    AND C.PHY_CARRIER_SEQ = A.PHY_CARRIER_SEQ
    AND A.PHY_CARRIER_SEQ = B.PHY_CARRIER_SEQ
    AND ((A.CARRIER_LD_TS <= C.MAN_WIP_T_IN_TS
    AND A.CARRIER_UNLD_TS >= C.MAN_WIP_T_IN_TS)
    OR ( A.CARRIER_LD_TS <= C.MAN_WIP_T_IN_TS
    AND A.CARRIER_UNLD_TS IS NULL))
    AND ((A.CARRIER_UNLD_TS >= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
    AND A.CARRIER_UNLD_TS <= TO_DATE('2012-01-12 10:03:00', 'YYYY-MM-DD HH24:MI:SS'))
    OR (A.CARRIER_LD_TS >= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
    AND A.CARRIER_LD_TS <= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS'))
    OR (A.CARRIER_LD_TS <= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
    AND A.CARRIER_UNLD_TS IS NULL)
    OR (A.CARRIER_LD_TS <= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')
    AND A.CARRIER_UNLD_TS >= TO_DATE('2012-01-12 08:03:00', 'YYYY-MM-DD HH24:MI:SS')))
    ORDER BY 6,5,1
    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      2      219.55      294.41      14030      13523455 0      14
    total      4      219.55      294.41      14030      13523455 0      14
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: SYS
    Rows           Row Source Operation
    14           SORT UNIQUE (cr=13523455 pr=14030 pw=0 time=294417731 us)
    14           HASH JOIN (cr=13523455 pr=14030 pw=0 time=294416444 us)
    14           TABLE ACCESS BY INDEX ROWID PF2_PROD_ORDER_CARRIER (cr=13523440 pr=14030 pw=0 time=292675360 us)
    98184018      NESTED LOOPS (cr=270067 pr=9028 pw=0 time=294901120 us)
    12128           TABLE ACCESS BY INDEX ROWID WORK_IN_PROCESS (cr=9842 pr=8788 pw=0 time=20479883 us)
    15241      INDEX RANGE SCAN WORK_IN_PROCESS_IX2 (cr=49 pr=48 pw=0 time=54577 us)(object id 65980)
    98171889      INDEX RANGE SCAN PF2_PROD_ORDER_CARRIER_IX3 (cr=260225 pr=240 pw=0 time=808956 us)(object id 65990)
    1736           TABLE ACCESS FULL PF2_PHYSICAL_CARRIER (cr=15 pr=0 pw=0 time=83 us)
    Elapsed times include waiting on following events:
    Event waited on      Times      Max. Wait      Total Waited
    ----------------------------------------      Waited      ----------           ------------
    SQL*Net message to client          3      0.00           0.00
    SQL*Net message from client      3      0.00           0.00
    db file sequential read      14030      0.47           43.56
    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      0      0.00      0.00      0      0      0      0
    total      2      0.00      0.00      0      0      0      0
    Misses in library cache during parse: 0
    Parsing user id: SYS
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call      count      cpu      elapsed     disk      query      current      rows
    Parse      2      0.00      0.00      0      0      0      0
    Execute 2      0.00      0.00      0      0      0      0
    Fetch      2      219.55      294.41      14030      13523455 0      14
    total      6      219.55      294.41      14030      13523455 0 14
    Misses in library cache during parse: 0
    Elapsed times include waiting on following events:
    Event waited on      Times      Max. Wait      Total Waited
    ----------------------------------------      Waited      ----------           ------------     
    SQL*Net message to client      3      0.00           0.00
    SQL*Net message from client      3      0.00           0.00
    db file sequential read      14030      0.47           43.56
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call      count cpu      elapsed      disk      query      current      rows
    Parse      0      0.00      0.00      0      0      0      0
    Execute 0      0.00      0.00      0      0      0      0
    Fetch      0      0.00      0.00      0      0      0      0
    total      0      0.00      0.00      0      0      0      0
    Misses in library cache during parse: 0
    2 user SQL statements in session.
    0 internal SQL statements in session.
    2 SQL statements in session.
    Trace file: ././ppf2_ora_5439924.trc
    Trace file compatibility: 10.01.00
    Sort options: default
    1      session in tracefile.
    2      user SQL statements in trace file.
    0      internal SQL statements in trace file.
    2      SQL statements in trace file.
    2      unique SQL statements in trace file.
    14137      lines in trace file.
    294      elapsed seconds in trace file.
    INFORMATION 5. EXPLAIN PLAN OUTPUT OF DBMS_XPLAN.DISPLAY
    SQL> select * from table(dbms_xplan.display_cursor(null, null, 'ALLSTATS LAST'));
    PLAN_TABLE_OUTPUT
    SQL_ID 1z1cccq5kxt11, child number 0
    SELECT /*+ gather_plan_statistics */ DISTINCT C.MAN_WIP_T_IN_TS, C.RCP_NO, C.WRK_CTR_ID, C.WTR_FREE_TST_FLG,
    A.COMPANY_ID, A.PROD_ORDER, A.PART_NO, A.CARRIER_QTY, B.PHY_CARID, C.WIP_SEQ, A.RCP_NO "CARRIER_RCP"
    FROM PF2_PROD_ORDER_CARRIER A, PF2_PHYSICAL_CARRIER B, WORK_IN_PROCESS C
    WHERE C.UNIT_TYPE_CD = RTRIM('TL7') AND C.UNIT_NM = RTRIM('T41') AND C.WIP_TYPE_CD ='HANDHELD'
    AND C.PHY_CARRIER_SEQ = A.PHY_CARRIER_SEQ AND A.PHY_CARRIER_SEQ = B.PHY_CARRIER_SEQ
    AND ((A.CARRIER_LD_TS <=C.MAN_WIP_T_IN_TS AND A.CARRIER_UNLD_TS >= C.MAN_WIP_T_IN_TS) OR
    ( A.CARRIER_LD_TS <= C.MAN_WIP_T_IN_TS AND A.CARRIER_UNLD_TS IS NULL)) AND ((A.CARRIER_UNLD_TS >= TO_DATE('2012-01-12
    08:03:00', 'YYYY-MM-DD HH24:MI:SS') AND A.CARRIER_UNLD_TS<= TO
    Plan hash value: 850402268
    | Id | Operation                     | Name                    | Starts      |E-Rows      | A-Rows      |A-Time           | Buffers      | Reads      |OMem      |1Mem      | Used-Mem      |
    | 1 | SORT UNIQUE                     |                | 1      | 11      | 14      |00:05:41.48      | 13M     | 6571      | 2048      | 2048      | 2048 (0)          |
    |* 2 | HASH JOIN                     |                | 1      | 11      | 14      |00:05:41.48      | 13M     | 6571      | 807K     | 807K     | 614K (0)          |
    |* 3 | TABLE ACCESS BY INDEX ROWID           | PF2_PROD_ORDER_CARRIER      | 1      | 5      | 14      |00:05:39.89      | 13M     | 6571      |      |      |           |
    | 4 | NESTED LOOPS                |                | 1      | 11      | 98M     |00:04:55.08      | 270K     | 6569      |      |      |           |
    |* 5 | TABLE ACCESS BY INDEX ROWID          | WORK_IN_PROCESS           | 1      | 2      | 12130      |00:00:13.15      | 9845      | 6569      |      |      |           |
    |* 6 | INDEX RANGE SCAN                | WORK_IN_PROCESS_IX2           | 1      | 56      | 15244      |00:00:00.06      | 49      | 45      |      |      |           |
    |* 7 | INDEX RANGE SCAN                | PF2_PROD_ORDER_CARRIER_IX3      | 12130      | 2361      | 98M     |00:00:00.92      | 260K     | 0      |      |      |           |
    | 8 | TABLE ACCESS FULL                | PF2_PHYSICAL_CARRIER           | 1      | 1736      | 1736      |00:00:00.01      | 15      | 0      |      |      |           |
    Predicate Information (identified by operation id):
    2 - access("A"."PHY_CARRIER_SEQ"="B"."PHY_CARRIER_SEQ")
    3 - filter(((("A"."CARRIER_UNLD_TS" IS NULL AND "A"."CARRIER_LD_TS"<=TO_DATE(' 2012-01-12 08:03:00', 'syyyy-mm-dd hh24:mi:ss')) OR
    ("A"."CARRIER_UNLD_TS">=TO_DATE(' 2012-01-12 08:03:00', 'syyyy-mm-dd hh24:mi:ss') AND "A"."CARRIER_LD_TS"<=TO_DATE(' 2012-01-12 08:03:00',
    'syyyy-mm-dd hh24:mi:ss')) OR ("A"."CARRIER_UNLD_TS">=TO_DATE(' 2012-01-12 08:03:00', 'syyyy-mm-dd hh24:mi:ss') AND
    "A"."CARRIER_UNLD_TS"<=TO_DATE(' 2012-01-12 10:03:00', 'syyyy-mm-dd hh24:mi:ss')) OR "A"."CARRIER_LD_TS"=TO_DATE(' 2012-01-12 08:03:00',
    'syyyy-mm-dd hh24:mi:ss')) AND (("A"."CARRIER_LD_TS"<="C"."MAN_WIP_T_IN_TS" AND "A"."CARRIER_UNLD_TS">="C"."MAN_WIP_T_IN_TS") OR
    ("A"."CARRIER_UNLD_TS" IS NULL AND "A"."CARRIER_LD_TS"<="C"."MAN_WIP_T_IN_TS"))))
    5 - filter(("C"."WIP_TYPE_CD"='HANDHELD' AND "C"."PHY_CARRIER_SEQ" IS NOT NULL))
    6 - access("C"."UNIT_TYPE_CD"='TL7' AND "C"."UNIT_NM"='T41')
    7 - access("C"."PHY_CARRIER_SEQ"="A"."PHY_CARRIER_SEQ")
    filter("A"."PHY_CARRIER_SEQ" IS NOT NULL)
    41 rows selected.
    Regards
    Rahul

    Rahul, post your question on the SQL and PL/SQL forum PL/SQL. This forum is for Oracle Berkeley DB not Oracle Database.
    Thanks,
    Andrei

  • SQL - Need Tunning tips for group by [LATEST EXECUTION PLAN IS ATTACHED]

    Hi All Experts,
    My SQL is taking so much time to execute. If I remove the group by clause it is running within a minute but as soon as I am putting sum() and group by clause it is taking ages to run the sql. Number of records are wihout group by clause is almost 85 Lachs (8 Million). Is hugh dataset is killing this? Is there any way to tune the data on Group by clause. Below is my Select hints and execution plan. Please help.
    SQL
    SELECT /*+ CURSOR_SHARING_EXACT gather_plan_statistics all_rows no_index(atm) no_expand
    leading (src cpty atm)
    index(bk WBKS_PK) index(src WSRC_UK1) index(acct WACC_UK1)
    use_nl(acct src ccy prd cpty grate sb) */
    EXECUTION PLAN
    PLAN_TABLE_OUTPUT
    SQL_ID 1y5pdhnb9tks5, child number 0
    SELECT /*+ CURSOR_SHARING_EXACT gather_plan_statistics all_rows no_index(atm) no_expand leading (src cpty atm) index(bk
    WBKS_PK) index(src WSRC_UK1) index(acct WACC_UK1) use_nl(acct src ccy prd cpty grate sb) */ atm.business_date,
    atm.entity legal_entity, TO_NUMBER (atm.set_of_books) setofbooksid, atm.source_system_id sourcesystemid,
    ccy.ccy_currency_code ccy_currency_code, acct.acct_account_code, 0 gl_bal, SUM (atm.amount)
    atm_bal, 0 gbp_equ, ROUND (SUM (atm.amount * grate.rate), 4) AS
    atm_equ, prd.prd_product_code, glacct.parentreportingclassification parentreportingclassification,
    cpty_counterparty_code FROM wh_sources_d src,
    Plan hash value: 4193892926
    | Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads | OMem | 1Mem | Used-Mem |
    | 1 | HASH GROUP BY | | 1 | 1 | 471 |00:31:38.26 | 904M| 76703 | 649K| 649K| 1149K (0)|
    | 2 | NESTED LOOPS | | 1 | 1 | 8362K|00:47:06.06 | 904M| 76703 | | | |
    | 3 | NESTED LOOPS | | 1 | 1 | 10M|00:28:48.84 | 870M| 17085 | | | |
    | 4 | NESTED LOOPS | | 1 | 1 | 10M|00:27:56.05 | 849M| 17084 | | | |
    | 5 | NESTED LOOPS | | 1 | 8 | 18M|00:14:10.93 | 246M| 17084 | | | |
    | 6 | NESTED LOOPS | | 1 | 22 | 18M|00:11:58.96 | 189M| 17084 | | | |
    | 7 | NESTED LOOPS | | 1 | 22 | 18M|00:10:24.69 | 152M| 17084 | | | |
    | 8 | NESTED LOOPS | | 1 | 1337 | 18M|00:06:00.74 | 95M| 17083 | | | |
    | 9 | NESTED LOOPS | | 1 | 1337 | 18M|00:02:52.20 | 38M| 17073 | | | |
    |* 10 | HASH JOIN | | 1 | 185K| 18M|00:03:46.38 | 1177K| 17073 | 939K| 939K| 575K (0)|
    | 11 | NESTED LOOPS | | 1 | 3 | 3 |00:00:00.01 | 11 | 0 | | | |
    | 12 | TABLE ACCESS BY INDEX ROWID | WH_SOURCES_D | 1 | 3 | 3 |00:00:00.01 | 3 | 0 | | | |
    |* 13 | INDEX RANGE SCAN | WSRC_UK1 | 1 | 3 | 3 |00:00:00.01 | 2 | 0 | | | |
    |* 14 | TABLE ACCESS BY INDEX ROWID | WH_COUNTERPARTIES_D | 3 | 1 | 3 |00:00:00.01 | 8 | 0 | | | |
    |* 15 | INDEX UNIQUE SCAN | WCPY_U1 | 3 | 1 | 3 |00:00:00.01 | 5 | 0 | | | |
    | 16 | PARTITION RANGE SINGLE | | 1 | 91M| 91M|00:00:00.08 | 1177K| 17073 | | | |
    |* 17 | TABLE ACCESS FULL | WH_ATM_BALANCES_F | 1 | 91M| 91M|00:00:00.04 | 1177K| 17073 | | | |
    |* 18 | TABLE ACCESS BY INDEX ROWID | WH_PRODUCTS_D | 18M| 1 | 18M|00:01:43.88 | 37M| 0 | | | |
    |* 19 | INDEX UNIQUE SCAN | WPRD_UK1 | 18M| 1 | 18M|00:00:52.13 | 18M| 0 | | | |
    |* 20 | TABLE ACCESS BY GLOBAL INDEX ROWID| WH_BOOKS_D | 18M| 1 | 18M|00:02:53.01 | 56M| 10 | | | |
    |* 21 | INDEX UNIQUE SCAN | WBKS_PK | 18M| 1 | 18M|00:01:08.32 | 37M| 10 | | | |
    |* 22 | TABLE ACCESS BY INDEX ROWID | T_SDM_SOURCEBOOK | 18M| 1 | 18M|00:03:43.66 | 56M| 1 | | | |
    |* 23 | INDEX RANGE SCAN | TSSB_N5 | 18M| 2 | 23M|00:01:11.50 | 18M| 1 | | | |
    |* 24 | TABLE ACCESS BY INDEX ROWID | WH_CURRENCIES_D | 18M| 1 | 18M|00:01:51.21 | 37M| 0 | | | |
    |* 25 | INDEX UNIQUE SCAN | WCUR_PK | 18M| 1 | 18M|00:00:49.26 | 18M| 0 | | | |
    | 26 | TABLE ACCESS BY INDEX ROWID | WH_GL_DAILY_RATES_F | 18M| 1 | 18M|00:01:55.84 | 56M| 0 | | | |
    |* 27 | INDEX UNIQUE SCAN | WGDR_U2 | 18M| 1 | 18M|00:01:10.89 | 37M| 0 | | | |
    | 28 | INLIST ITERATOR | | 18M| | 10M|00:22:40.03 | 603M| 0 | | | |
    |* 29 | TABLE ACCESS BY INDEX ROWID | WH_ACCOUNTS_D | 150M| 1 | 10M|00:20:19.05 | 603M| 0 | | | |
    |* 30 | INDEX UNIQUE SCAN | WACC_UK1 | 150M| 5 | 150M|00:10:16.81 | 452M| 0 | | | |
    | 31 | TABLE ACCESS BY INDEX ROWID | T_SDM_GLACCOUNT | 10M| 1 | 10M|00:00:50.64 | 21M| 1 | | | |
    |* 32 | INDEX UNIQUE SCAN | TSG_PK | 10M| 1 | 10M|00:00:26.17 | 10M| 0 | | | |
    |* 33 | TABLE ACCESS BY INDEX ROWID | WH_COMMON_TRADES_D | 10M| 1 | 8362K|00:18:52.56 | 33M| 59618 | | | |
    |* 34 | INDEX UNIQUE SCAN | WCTD_PK | 10M| 1 | 10M|00:03:06.56 | 21M| 5391 | | | |
    Edited by: user535789 on Mar 17, 2011 9:45 PM
    Edited by: user535789 on Mar 20, 2011 8:33 PM

    user535789 wrote:
    Hi All Experts,
    My SQL is taking so much time to execute. If I remove the group by clause it is running within a minute but as soon as I am putting sum() and group by clause it is taking ages to run the sql. Number of records are wihout group by clause is almost 85 Lachs (*8 Million*). Is hugh dataset is killing this? Is there any way to tune the data on Group by clause. Below is my Select hints and execution plan. Please help.I doubt that your 8 million records are shown within minutes.
    I guess that the output started after a few minutes. But this does not mean that the full resultset is there. It just means the database is able to return to you the first few records after a few minutes.
    Once you add a group by (or an order by) then this requires that all the rows need to be fetched before the database can start showing them to you.
    But maybe you could run some tests to compare the full output. I find it useful to SET AUTOTRACE TRACEONLY for such a purpose (in sql plus). This avoids to print the selection on the screen.

  • Need help for SQL Queries Tunning

    hi all,
    we have a procedure for search consumers, which using sql queries like:
    SELECT TRIM (NAME) AS NAME, TRIM (accno) AS accno,
    TRIM (connaddress) AS connaddress,
    TRIM (CATEGORY) AS CATEGORY, TRIM (landmark) AS landmark,
    SUBSTR (accno, 1, 3) AS subdivisionname
    FROM consumermaster
    WHERE LOWER (accno) LIKE
    LOWER ('%' || NVL (caccno, '#noval#') || '%')
    OR LOWER (NAME) LIKE LOWER ('%' || NVL (cname, '#noval#') || '%')
    OR LOWER (connaddress) LIKE
    LOWER ('%' || NVL (cadd, '#noval#') || '%')
    OR phone LIKE '%' || NVL (cphone, '#noval#') || '%'
    OR accno = (SELECT accno
    FROM requestregistration
    WHERE requestid = creqid)
    UNION
    SELECT TRIM (NAME) AS NAME, TRIM (accno) AS accno,
    TRIM (connaddress) AS connaddress, TRIM (CATEGORY)
    AS CATEGORY,
    TRIM (landmark) AS landmark,
    SUBSTR (accno, 1, 3) AS subdivisionname
    FROM scodetails
    WHERE LOWER (accno) LIKE
    LOWER ('%' || NVL (caccno, '#noval#') || '%')
    OR LOWER (NAME) LIKE LOWER ('%' || NVL (cname, '#noval#') || '%')
    OR LOWER (connaddress) LIKE
    LOWER ('%' || NVL (cadd, '#noval#') || '%')
    OR phone LIKE '%' || NVL (cphone, '#noval#') || '%'
    OR accno = (SELECT accno
    FROM requestregistration
    WHERE requestid = creqid);
    it's ok for small tables but now data increase .......
    searching method is very slow
    now i want to tune this query for better performance
    please sugg me best method
    Thanks in advance
    Regards
    vij..

    The link given by Asif should get you on the right track for tuning this query.
    I just formatted your SQL:
    SELECT Trim(NAME)        AS NAME,
           Trim(accno)       AS accno,
           Trim(connaddress) AS connaddress,
           Trim(category)    AS category,
           Trim(landmark)    AS landmark,
           Substr(accno,1,3) AS subdivisionname
    FROM   consumermaster
    WHERE  Lower(accno) LIKE Lower('%'
                                   ||Nvl(caccno,'#noval#')
                                   ||'%')
            OR Lower(NAME) LIKE Lower('%'
                                      ||Nvl(cname,'#noval#')
                                      ||'%')
            OR Lower(connaddress) LIKE Lower('%'
                                             ||Nvl(cadd,'#noval#')
                                             ||'%')
            OR phone LIKE '%'
                          ||Nvl(cphone,'#noval#')
                          ||'%'
            OR accno = (SELECT accno
                        FROM   requestregistration
                        WHERE  requestid = creqid)
    UNION
    SELECT Trim(NAME)        AS NAME,
           Trim(accno)       AS accno,
           Trim(connaddress) AS connaddress,
           Trim(category)    AS category,
           Trim(landmark)    AS landmark,
           Substr(accno,1,3) AS subdivisionname
    FROM   scodetails
    WHERE  Lower(accno) LIKE Lower('%'
                                   ||Nvl(caccno,'#noval#')
                                   ||'%')
            OR Lower(NAME) LIKE Lower('%'
                                      ||Nvl(cname,'#noval#')
                                      ||'%')
            OR Lower(connaddress) LIKE Lower('%'
                                             ||Nvl(cadd,'#noval#')
                                             ||'%')
            OR phone LIKE '%'
                          ||Nvl(cphone,'#noval#')
                          ||'%'
            OR accno = (SELECT accno
                        FROM   requestregistration
                        WHERE  requestid = creqid); You are using some function on almost each and every column in the where clause. Try getting rid of them as they are hindering the use of indexes, if any, on any of the columns.
    Also the guidelines in the link provided are the best starting point.

  • SQL Performance tunning on RAC environment

    Hi,
    I am working on oracle 11.2.0.2.0 with 2 node RAC.
    We have a batch process with runs everday and comsumes most of the time in cluster waits. Could someone please suggest what SQL / PL SQL changes / Hints are available to tune this cluster waits..
    Also, if possible please provide link where can find more information on this.
    Thanks

    Is your batch process multi-threaded or single-threaded?
    If multi-threaded, and each thread is doing similar work, running the same code, and if your connections are load balanced across both nodes, it won't take long to end up waiting on cluster interconnect activity. You might try having the connections related to this batch job all go to one node.
    In general, utilizing both nodes at the same time shouldn't be a problem, unless you have code that accesses the same segments on both nodes at the same time. That's when you'll see the worst problems in terms of cluster-related waits.
    -Mark

Maybe you are looking for