Help on performance with dynamic query

Hi All,
  We are using SQL Server 2008R2. In our one of report we are using Dynamic query and it is taking more time to retrieve the data. to retrieve 32 records it is taking 13-15 secs. In my observation in a table variable, created more than 60 columns. In
the SP called one more sp with insert statement.
Please let me know how i can improve performance of the SP.
I know that i have to provide the SP  for observation but unfortunately I cannot provide the SP. Please guide me how i can achieve this .
I tried with temp tables by creating indexes on temp tables but i couldn't find improvement in performance. 
Waiting for valuable replies.

First of all a "dynamic query" is not "a query" - it is a multitude of them. Some of them may be fast, others may be slow.
There is of course no way we can give specific suggestions without seeing the code, the table and index definitions etc.
We can only give the generic suggestions. As for the code, make sure that you are using parameterised SQL and you are not building a complete SQL string with parameters and all. If nothing else, this helps to make the code more readable and maintainable.
It also protects you against SQL injection. And it also helps to prevent performance issue due to implicit conversion.
You will need to look at the query plan to see where the bottlenecks may be. You should look at the actual query plan. Note that the thickness of the arrows are more relevant than the percentages you see; the percentages are only estimates, and estimates
are often off. Next step is to see if you can add indexes to alleviate the situation. You should also analyse if there are problems in the query, for instance indexed columns that are entangled in expression. If you are using views, make sure that you don't
have views built on top of views etc. This can often result a table appearing multiple times in a query, when one would be enough.
Erland Sommarskog, SQL Server MVP, [email protected]

Similar Messages

  • HT1338 I have a macbook Pro i7 mid november 2010. I am wondering if i can exchange my notebook with the latest one. Can anyone help me out with this query please.

    I have a macbook Pro i7 mid november 2010. I am wondering if i can exchange my notebook with the latest one. Can anyone help me out with this query please.

    You can sell your existing computer using eBay, Craigslist or the venue of your choice. You could then use the proceeds to purchase a new computer.

  • Using jquery FullCalendar in APEX with dynamic query

    Hi,
    I am trying to implement jquery FullCalendar in APEX and came across thie following post but I am unable to get the events to work. I would really like to see it working with an Application_Process:
    How we can highlight events in Calendar
    Currently I created an Application Process that simply calls a DB table and convert it into json format.
    DECLARE
    v_sql varchar2(400);
    BEGIN
    v_sql := 'SELECT * FROM CAL_FEED';
    apex_util.json_from_sql(v_sql);
    END;
    But I am unsure how to add the events via an Application_Process.
    I have tried the following in numerious ways (events:function, url feed, etc). It does work if I just do an array but would like it as a dynamic query.
    $('#calendar').fullCalendar({
    events: "http://server:8080/apex/f?p=101:53:4352610578859707:APPLICATION_PROCESS=IAT_TEST_CAL_FEED"
    Thank you in advance,
    Jimmy

    Hi,
    I was able to get the events into Fullcalendar with an Application Process but not sure if this would scale well with alot of events.
    Would someone be able to tell me if there is a better way?
    I am currently using an On Demand Application Process called IAT_TEST_FEED:_
    DECLARE
    lv_cal_list VARCHAR2(16000);
    lv_return_str VARCHAR2(32000);
    BEGIN
    FOR i IN (SELECT "CAL_FEED"."ID" as ID,
    "CAL_FEED"."title" as caltitle,
    "CAL_FEED"."start" as calstart,
    "CAL_FEED"."end" as calend
    FROM "CAL_FEED")
    LOOP
    lv_cal_list := lv_cal_list || '{"id":' || CHR(39) || i.ID || CHR(39) || ',' ||
    ' "title":' || CHR(39) || i.caltitle || CHR(39) || ',' ||
    ' "start":' || CHR(39) || i.calstart || CHR(39) || ',' ||
    ' "end":' || CHR(39) || i.calend || CHR(39) || '},';
    END LOOP;
    lv_return_str := '[' || RTRIM(lv_cal_list,',') || ']';
    htp.prn(lv_return_str);
    EXCEPTION WHEN OTHERS THEN
    htp.prn('error');
    END;
    In a HTML Region on a page within the Region Header:_
    <link rel="stylesheet" type="text/css" href="#WORKSPACE_IMAGES#fullcalendar.css" />
    <script type="text/javascript" src="#WORKSPACE_IMAGES#ui.core.js"></script>
    <script type="text/javascript" src="#WORKSPACE_IMAGES#ui.draggable.js"></script>
    <script type="text/javascript" src="#WORKSPACE_IMAGES#ui.resizable.js"></script>
    <script type="text/javascript" src="#WORKSPACE_IMAGES#jquery.js"></script>
    <script type="text/javascript" src="#WORKSPACE_IMAGES#fullcalendar.js"></script>
    <script type="text/javascript" src="#WORKSPACE_IMAGES#fullcalendar.min.js"></script>
    <script type='text/javascript'>
    $(document).ready(function() {
    $('#calendar').fullCalendar({
    events: function(start, end, callback) {
    $.ajax({
    type: "POST",
    url: "wwv_flow.show",
    dataType: "json",
    data: {
    p_flow_id:$('#pFlowId').val(),
    p_flow_step_id:$('#pFlowStepId').val(),
    p_instance:$('#pInstance').val(),
    p_request:"APPLICATION_PROCESS=IAT_TEST_FEED"
    success:function(calevents){
    $.each(calevents, function(i, calevent){
    $('#calendar').fullCalendar('renderEvent', calevent, true);
    </script>
    The line within the ajax call is basically where my concern would be
    $('#calendar').fullCalendar('renderEvent', calevent, true);
    Thank you,
    Jimmy

  • How to write a perform with dynamic internal table

    Hi to all experts,
    i have to read infotype 2001 2003 2002 with same pernr, begin date, end date im calling hr_read_infotype three times
    can i write a single perform and call it three how to pass different tables (2001, 2002, 2003).

    try the below code...
      DATA: w_subrc TYPE sy-subrc.
      DATA: w_infty(5) TYPE  c.
      data: w_string type string.
      FIELD-SYMBOLS: <f1> TYPE table.
      FIELD-SYMBOLS: <f1_wa> TYPE ANY.
      DATA: ref_tab TYPE REF TO data.
      CONCATENATE 'P' infty INTO w_infty.
      CREATE DATA ref_tab TYPE STANDARD TABLE OF (w_infty).
      ASSIGN ref_tab->* TO <f1>.
    * Create dynamic work area
      CREATE DATA ref_tab TYPE (w_infty).
      ASSIGN ref_tab->* TO <f1_wa>.
      IF begda IS INITIAL.
        begda = '18000101'.
      ENDIF.
      IF endda IS INITIAL.
        endda = '99991231'.
      ENDIF.
      CALL FUNCTION 'HR_READ_INFOTYPE'
        EXPORTING
          pernr           = pernr
          infty           = infty
          begda           = '18000101'
          endda           = '99991231'
        IMPORTING
          subrc           = w_subrc
        TABLES
          infty_tab       = <f1>
        EXCEPTIONS
          infty_not_found = 1
          OTHERS          = 2.
      IF sy-subrc <> 0.
        subrc = w_subrc.
      ELSE.
      ENDIF.

  • Problem with dynamic query in Forms Builder

    Hi,
    I need in forms builder cursor in procedure which parameter is a whole query. But i stuck when i wanna give some text in signs '' to procedure.
    I wanna give like test('select ' ||'test' || ' from dual');
    But this is not good beacuse it is missing ''.
    Query which procedure get is select test from dual.
    The right sql would be select 'test' from dual.
    How could i pass signs '' to procedure.
    Any ideas.
    Thanks in advance.

    test('select ''' ||'test' || ''' from dual');Francois

  • Pipelined Function with dynamic query

    Hello All,
    Orcl Ver: 11g R2.
    I am leveraging the Oracle's pipelined table function.
    It's working fine for static SQL.
    create or replace package test13_pkg as
        type r_disc_req is record(disc_line_id number,
                                 req_id number);
        type t_disc_req is table of r_disc_req;
        function F_GetDiscReq return t_disc_req pipelined;
        procedure P_ProcessDiscReq;
    end;
    CREATE OR REPLACE PACKAGE BODY test13_pkg
    AS
       FUNCTION F_GetDiscReq
          RETURN t_disc_req
          PIPELINED
       IS
          lo_disc_req   r_disc_req;
       BEGIN
          FOR r_row IN (SELECT disc_line_id, req_id
                          FROM edms_disc_lines_stg
                         WHERE ROWNUM < 10)
          LOOP
             lo_disc_req.disc_line_id := r_row.disc_line_id;
             lo_disc_req.req_id := r_row.req_id;
             PIPE ROW (lo_disc_req);
          END LOOP;
       END F_GetDiscReq;
       PROCEDURE P_ProcessDiscReq
       AS
          ln_totalRecords   NUMBER;
       BEGIN
          SELECT COUNT (*)
            INTO ln_totalRecords
            FROM edms_disc_lines_stg t1, TABLE (F_GetDiscReq ()) t2
           WHERE t1.disc_line_id = t2.disc_line_id AND t1.req_id = t2.req_id;
       DBMS_OUTPUT.put_line (ln_totalRecords);
       END;
    END;
    begin
        test13_pkg.P_ProcessDiscReq();
    end;
    How do I leverage it for dynamic sql?
    FUNCTION F_GetDiscReq (p_filter1 IN NUMBER, p_filter2 IN NUMBER, p_filter3 IN NUMBER)
       RETURN t_disc_req
       PIPELINED
    IS
       lo_disc_req   r_disc_req;
       l_sql varchar2(4000) := 'SELECT disc_line_id, req_id
                       FROM edms_disc_lines_stg';
       l_where_clause varchar2(4000) := 'WHERE 1 = 1 ';
    BEGIN
       IF p_filter1 IS NOT NULL THEN
        l_where_clause := l_where_clause||'AND filter1 = '||p_filter1;
       END IF;
       IF p_filter2 IS NOT NULL THEN
        l_where_clause := l_where_clause||'AND filter1 = '||p_filter2;
       END IF;
       IF p_filter3 IS NOT NULL THEN
        l_where_clause := l_where_clause||'AND filter1 = '||p_filter3;
       END IF;
       l_sql := l_sql||l_where_clause;
    --I'm stuck here.   
    FOR r_row IN (l_sql)
       LOOP
          lo_disc_req.disc_line_id := r_row.disc_line_id;
          lo_disc_req.req_id := r_row.req_id;
          PIPE ROW (lo_disc_req);
       END LOOP;
    END F_GetDiscReq;
    Could you please guide me here?
    Thx
    Shank.

    Hi,
    It's very doubtful whether you need or want dynamic SQL for this task.
    If you do, however, here's one way to do it:
    FUNCTION F_GetDiscReq
    (  p_filter1  IN  edms_disc_lines_stg.filter1%TYPE
    ,  p_filter2  IN  edms_disc_lines_stg.filter1%TYPE
    ,  p_filter3  IN  edms_disc_lines_stg.filter1%TYPE
       RETURN t_disc_req
       PIPELINED
    IS
       lo_disc_req   r_disc_req;
       l_sql varchar2(4000) := 'SELECT disc_line_id, req_id
                       FROM edms_disc_lines_stg ';
       l_where_clause varchar2(4000) := 'WHERE 1 = 1 ';
       c     SYS_REFCURSOR;
    BEGIN
       IF p_filter1 IS NOT NULL THEN
        l_where_clause := l_where_clause||'AND filter1 = ''' || p_filter1 || '''';
       END IF;
       IF p_filter2 IS NOT NULL THEN
        l_where_clause := l_where_clause||'AND filter2 = ''' || p_filter2 || '''';
       END IF;
       IF p_filter3 IS NOT NULL THEN
        l_where_clause := l_where_clause||'AND filter3 = ''' || p_filter3 || '''';
       END IF;
       l_sql := l_sql||l_where_clause;
    --   dbms_output.put_line (l_sql || ' = l_sql');   -- For debugging
       OPEN  c  FOR l_sql;
       LOOP
          FETCH  c  INTO  lo_disc_req;
          EXIT WHEN  c%NOTFOUND;
          PIPE ROW (lo_disc_req);
       END LOOP;
    END F_GetDiscReq;
    Static SQL will, in general, be more efficient than dynamic SQL.
    Given that you need dynamic SQL, there are lots of ways the function above could be made more efficient.  If that's an issue, make sure you understand what this is doing before trying to improve it.

  • HT201272 I updated jelly sms and now when I went to use it it says not available in Ireland. Can you help me please with my query? Thanks

    HI
    No idea whats happened to jelly sms, I updated it, went to use it, I uninstalled it and theninstalled again and now it says it's not available in Ireland. I did pay for the app, several ywars back, does anyone know anything? thanks

    I just updated myself to the latest Jelly SMS a few days ago and it stopped working
    I tried uninstalling / reinstalling like yourself, but the App store says it's not available in Ireland anymore. Lucky, I have the old version (4.0.5) synced on my laptop so I restored it. The old version works fine, but I lost all my texts.
    As far as I've been able to find out, the developer (Finbar) is having trouble with Vodafone Ireland who recently introduced a CAPTCHA to their online SMS service, preventing Jelly SMS from working. He said he'd have a new version in the app store (Aug 28th); it appeared briefly but it didn't work so it was withdrawn in Ireland. A new version is on the way.
    I've seen similar happen before, a serious bug is discovered shortly after an update and the app gets withdrawn for a time, then a fix appears later on. Fixes can take a little longer to appear in the app store (compared to Android) as Apple review submitted apps before they're released.
    http://www.jellysms.com/blog/

  • Help! Inaccessible iterator when using dynamic query

    Hi!
    I have a problem retreiving results from a dynamic query into sqlj iterator.
    I consulted the Oracle App Dev Guide and Oracle SQLJ Dev Guide and wrote the following code:
    <PRE>
    package pmServer;
    #sql iterator LocIterator (int id, String name);
    public class pmRISDImpl
    public int GetLocations(...)
    LocIterator locIt;
    String q = "select ID, NAME from PMADM.LOCATIONS";
    #sql
    BEGIN
    open :OUT locIt for :q;
    END;
    </PRE>
    When I try to compile it using tools provided by JDeveloper ver 3.2.2.(Build 915) for JDK 1.2.2 I get error for #sql statement:
    Inaccessible Java type for host item locIt (at position #1): pmServer.LocIterator
    and warning:
    Type pmServer.LocIterator of host item locIt (at position #1) is not permitted in JDBC. This will not be portable.
    Althow the code is identcal to those demonstrated in Oracle document "Oracle8 i
    SQLJ Developers Guide and Reference
    Release 3 (8.1.7)
    July 2000
    Part No. A83723-01" pp 12-67 (PL/SQL in SQLJ for Dynamic SQLDynamicDemo.sqlj). There it looks like
    <PRE>
    private static void dynamicSelectMany(String what_cond)
    throws SQLException {
    System.out.println("dynamic multi-row query on table emp");
    Employees empIter;
    // table/column names cannot be bind args in dynamic PL/SQL, so
    // build up query as Java string
    String query = "select ename, sal from emp " +
    (((what_cond == null) &#0124; &#0124; (what_cond.equals(""))) ? "" :
    (" where " + what_cond)) +
    "order by ename";
    #sql {
    begin
    open :OUT empIter for -- opening ref cursor with dynamic query
    :query;
    -- can have USING clause here if needed
    end;
    while (empIter.next()) {
    System.out.println("Employee " + empIter.ename() +
    " has salary " + empIter.sal() );
    empIter.close();
    </PRE>
    Please guide me what should I do to get it working.
    null

    In the CAST statement the SQLJ runtime must be able to produce an instance of you SQLJ iterator using Java reflection.
    This necessitates that the iterator class must be accessible by public.
    You have two options:
    (1) Declare the iterator public. This requires that you put it in its own file LocIterator.sqlj:
    #sql public iterator LocIterator (int id, String name);
    (2) Declare the iterator as an inner class. In this case you want to make it public static (that is it does not require an instance of the outer class in scope). You might write the following.
    package pmServer;
    public class pmRISDImpl
    #sql public static iterator LocIterator (int id, String name);
    (3) If you are using Oracle 9i you have another option. You can embed dynamic SQL fragments directly in your SQLJ code and do not need to use the CAST:
    public int GetLocations(...)
    LocIterator locIt;
    String q = "PMADM.LOCATIONS";
    #sql locIt = { select ID, NAME from :{q} }; // Note new syntax :{q} for embedding SQL source code
    }

  • Need help with writing a query with dynamic FROM clause

    Hi Folks,
    I need help with an query that should generate the "FROM" clause dynamically.
    My main query is as follows
    select DT_SKEY, count(*)
    from *???*
    where DT_SKEY between 20110601 and 20110719
    group by DT_SKEY
    having count(*) = 0
    order by 1; The "from" clause of the above query should be generated as below
    select 'Schema_Name'||'.'||TABLE_NAME
    from dba_tables
    where OWNER = 'Schema_Name'Simply sticking the later query in the first query does not work.
    Any pointers will be appreciated.
    Thanks
    rogers42

    Hi,
    rogers42 wrote:
    Hi Folks,
    I need help with an query that should generate the "FROM" clause dynamically.
    My main query is as follows
    select DT_SKEY, count(*)
    from *???*
    where DT_SKEY between 20110601 and 20110719
    group by DT_SKEY
    having count(*) = 0
    order by 1; The "from" clause of the above query should be generated as below
    select 'Schema_Name'||'.'||TABLE_NAME
    from dba_tables
    where OWNER = 'Schema_Name'
    Remember that anything inside quotes is case-sensitive. Is the owner really "Schema_Name" with a capital S and a capital N, and 8 lower-case letters?
    Simply sticking the later query in the first query does not work.Right; the table name must be given when you compile the query. It's not an expression that you can generate in the query itself.
    Any pointers will be appreciated.In SQL*Plus, you can do something like the query bleow.
    Say you want to count the rows in scott.emp, but you're not certain that the name is emp; it could be emp_2011 or emp_august, or anything else that starts with e. (And the name could change every day, so you can't just look it up now and hard-code it in a query that you want to run in the future.)
    Typically, how dynamic SQL works is that some code (such as a preliminary query) gets some of the information you need to write the query first, and you use that information in a SQL statement that is compiled and run after that. For example:
    -- Preliminary Query:
    COLUMN     my_table_name_col     NEW_VALUE my_table_name
    SELECT     table_name     AS my_table_name_col
    FROM     all_tables
    WHERE     owner          = 'SCOTT'
    AND     table_name     LIKE 'E%';
    -- Main Query:
    SELECT     COUNT (*)     AS cnt
    FROM     scott.&my_table_name
    ;This assumes that the preliminary query will find exactly one row; that is, it assumes that SCOTT has exactly one table whose name starts with E. Could you have 0 tables in the schema, or more than 1? If so, what results would you want? Give a concrete example, preferably suing commonly available tables (like those in the SCOTT schema) so that the poepl who want to help you can re-create the problem and test their ideas.
    Edited by: Frank Kulash on Aug 11, 2011 2:30 PM

  • Running a SQL Stored Procedure from Power Query with Dynamic Parameters

    Hi,
    I want to execute a stored procedure from Power Query with dynamic parameters.
    In normal process, query will look like below in Power Query. Here the value 'Dileep' is passed as a parameter value to SP.
        Source = Sql.Database("ABC-PC", "SAMPLEDB", [Query="EXEC DBO.spGetData 'Dileep'"]
    Now I want to pass the value dynamically taking from excel sheet. I can get the required excel cell value in a variable but unable to pass it to query.
        Name_Parameter = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
        Name_Value = Name_Parameter{0}[Value],
    I have tried like below but it is not working.
    Source = Sql.Database("ABC-PC", "SAMPLEDB", [Query="EXEC DBO.spGetData Name_Value"]
    Can anyone please help me with this issue.
    Thanks
    Dileep

    Hi,
    I got it. Below is the correct syntax.
    Source = Sql.Database("ABC-PC", "SAMPLEDB", [Query="EXEC DBO.spGetData '" & Name_Value & "'"]
    Thanks
    Dileep

  • Please help me to increase the performance of the query

    Hello
    I am not an oracle expert or developer and i have a problem to resolve.
    Below is the query and explaiation plan and seeking the help to improve the performance of the query.
    Our Analysis,
    The query runs good,takes less one minute and fetches the results but during peak time it takes 8 minutes
    Require anyone suggestion's to improve the query.
    The query is generated from the Microsft dll so we dont have SQL code and require some help on tuning the tables.
    If tuning the query improves then also fine please suggest for that also.
    Enviroment: Solaris 8
    DB : oracle 9i
    (SELECT vw.dispapptobjid, vw.custsiteobjid, vw.emplastname, vw.empfirstname,
    vw.scheduledonsite AS starttime, vw.appttype, vw.latestart,
    vw.endtime, vw.typetitle, vw.empobjid, vw.latitude, vw.longitude,
    vw.workduration AS DURATION, vw.dispatchtype, vw.availability
    FROM ora_appt_disp_view vw
    WHERE ( ( vw.starttime >=
    TO_DATE ('2/12/2007 4:59 PM', 'MM/DD/YYYY HH12:MI AM')
    AND vw.starttime <
    TO_DATE ('2/21/2007 3:59 PM', 'MM/DD/YYYY HH12:MI AM')
    OR vw.endtime >
    TO_DATE ('2/12/2007 4:59 PM', 'MM/DD/YYYY HH12:MI AM')
    AND vw.endtime <=
    TO_DATE ('2/21/2007 3:59 PM', 'MM/DD/YYYY HH12:MI AM')
    OR ( vw.starttime <=
    TO_DATE ('2/12/2007 4:59 PM', 'MM/DD/YYYY HH12:MI AM')
    AND vw.endtime >=
    TO_DATE ('2/21/2007 3:59 PM', 'MM/DD/YYYY HH12:MI AM')
    UNION
    (SELECT 0 AS dispapptobjid, emp.emp_physical_site2site AS custsiteobjid,
    emp.last_name AS emplastname, emp.first_name AS empfirstname,
    TO_DATE ('1/1/3000', 'MM/DD/YYYY') AS starttime, 'E' AS appttype,
    NULL AS latestart, NULL AS endtime, '' AS typetitle,
    emp.objid AS empobjid, 0 AS latitude, 0 AS longitude, 0 AS DURATION,
    '' AS dispatchtype, 0 AS availability
    FROM table_employee emp, table_user usr
    WHERE emp.employee2user = usr.objid AND emp.field_eng = 1 AND usr.status = 1)
    ORDER BY empobjid, starttime, endtime DESC
    Operation     Object Name     Rows     Bytes     Cost     Object Node     In/Out     PStart     PStop
    SELECT STATEMENT Optimizer Mode=HINT: ALL_ROWS          23 K          11312                     
    SORT UNIQUE          23 K     3 M     11140                     
    UNION-ALL                                        
    VIEW     ORA_APPT_DISP_VIEW     17 K     3 M     10485                     
    UNION-ALL                                        
    CONCATENATION                                        
    NESTED LOOPS OUTER          68      24 K     437                     
    NESTED LOOPS          68      23 K     369                     
    NESTED LOOPS OUTER          68      25 K     505                     
    NESTED LOOPS OUTER          68      24 K     505                     
    NESTED LOOPS          68      23 K     369                     
    NESTED LOOPS          68      22 K     369                     
    NESTED LOOPS OUTER          68      22 K     369                     
    NESTED LOOPS          19      6 K     312                     
    NESTED LOOPS          19      5 K     312                     
    HASH JOIN          19      5 K     293                     
    NESTED LOOPS          19      5 K     274                     
    NESTED LOOPS          19      4 K     236                     
    NESTED LOOPS          19      4 K     198                     
    NESTED LOOPS OUTER          19      3 K     160                     
    NESTED LOOPS OUTER          19      3 K     160                     
    NESTED LOOPS OUTER          19      4 K     160                     
    NESTED LOOPS OUTER          19      1 K     103                     
    NESTED LOOPS OUTER          19      2 K     103                     
    NESTED LOOPS OUTER          19      2 K     103                     
    TABLE ACCESS BY INDEX ROWID     TABLE_DISPTCHFE     19      1 K     46                     
    INDEX RANGE SCAN     GSA_SCHED_REPAIR     44           3                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22                          
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22                          
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22      3                     
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28                          
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28                          
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28      3                     
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_CASE     1      30      2                     
    INDEX UNIQUE SCAN     CASE_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_SITE     1      12      2                     
    INDEX UNIQUE SCAN     SITE_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_ADDRESS     1      12      2                     
    INDEX UNIQUE SCAN     ADDRESS_OBJINDEX     1           1                     
    TABLE ACCESS FULL     TABLE_EMPLOYEE     1      34      1                     
    INDEX UNIQUE SCAN     SITE_OBJINDEX     1      6      1                     
    INDEX UNIQUE SCAN     USER_OBJINDEX     1      6                          
    TABLE ACCESS BY INDEX ROWID     TABLE_X_GSA_TIME_STAMPS     4      48      3                     
    INDEX RANGE SCAN     GSAIDX_TS2DISP     1           2                     
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    TABLE ACCESS BY INDEX ROWID     TABLE_MOD_LEVEL     1      12      1                     
    INDEX UNIQUE SCAN     MOD_LEVEL_OBJINDEX     1                               
    INDEX UNIQUE SCAN     PART_NUM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     SUBCASE_OBJINDX     1      6      1                     
    NESTED LOOPS OUTER          68      25 K     505                     
    NESTED LOOPS OUTER          68      24 K     505                     
    NESTED LOOPS OUTER          68      24 K     437                     
    NESTED LOOPS          68      23 K     369                     
    NESTED LOOPS          68      23 K     369                     
    NESTED LOOPS          68      22 K     369                     
    NESTED LOOPS OUTER          68      22 K     369                     
    NESTED LOOPS          19      6 K     312                     
    NESTED LOOPS          19      5 K     312                     
    NESTED LOOPS          19      5 K     293                     
    NESTED LOOPS          19      5 K     274                     
    NESTED LOOPS          19      4 K     236                     
    NESTED LOOPS          19      4 K     198                     
    NESTED LOOPS OUTER          19      4 K     160                     
    NESTED LOOPS OUTER          19      3 K     160                     
    NESTED LOOPS OUTER          19      3 K     160                     
    NESTED LOOPS OUTER          19      2 K     103                     
    NESTED LOOPS OUTER          19      2 K     103                     
    NESTED LOOPS OUTER          19      1 K     103                     
    TABLE ACCESS BY INDEX ROWID     TABLE_DISPTCHFE     19      1 K     46                     
    INDEX RANGE SCAN     GSA_SCHED_REPAIR     44           3                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22      3                     
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22                          
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22                          
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28      3                     
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28                          
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28                          
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_CASE     1      30      2                     
    INDEX UNIQUE SCAN     CASE_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_SITE     1      12      2                     
    INDEX UNIQUE SCAN     SITE_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_ADDRESS     1      12      2                     
    INDEX UNIQUE SCAN     ADDRESS_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_EMPLOYEE     1      34      1                     
    INDEX UNIQUE SCAN     EMPLOYEE_OBJINDEX     1                               
    INDEX UNIQUE SCAN     SITE_OBJINDEX     1      6      1                     
    INDEX UNIQUE SCAN     USER_OBJINDEX     1      6                          
    TABLE ACCESS BY INDEX ROWID     TABLE_X_GSA_TIME_STAMPS     4      48      3                     
    INDEX RANGE SCAN     GSAIDX_TS2DISP     1           2                     
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     SUBCASE_OBJINDX     1      6      1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_MOD_LEVEL     1      12      1                     
    INDEX UNIQUE SCAN     MOD_LEVEL_OBJINDEX     1                               
    INDEX UNIQUE SCAN     PART_NUM_OBJINDEX     1      6                          
    NESTED LOOPS OUTER          68      25 K     505                     
    NESTED LOOPS OUTER          68      24 K     505                     
    NESTED LOOPS OUTER          68      24 K     437                     
    NESTED LOOPS          68      23 K     369                     
    NESTED LOOPS          68      23 K     369                     
    NESTED LOOPS          68      22 K     369                     
    NESTED LOOPS OUTER          68      22 K     369                     
    NESTED LOOPS          19      6 K     312                     
    NESTED LOOPS          19      5 K     312                     
    NESTED LOOPS          19      5 K     293                     
    NESTED LOOPS          19      5 K     274                     
    NESTED LOOPS          19      4 K     236                     
    NESTED LOOPS          19      4 K     198                     
    NESTED LOOPS OUTER          19      4 K     160                     
    NESTED LOOPS OUTER          19      3 K     160                     
    NESTED LOOPS OUTER          19      3 K     160                     
    NESTED LOOPS OUTER          19      2 K     103                     
    NESTED LOOPS OUTER          19      2 K     103                     
    NESTED LOOPS OUTER          19      1 K     103                     
    TABLE ACCESS BY INDEX ROWID     TABLE_DISPTCHFE     19      1 K     46                     
    INDEX RANGE SCAN     GSA_REQ_ETA     44           3                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22      3                     
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22                          
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22                          
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28      3                     
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28                          
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28                          
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_CASE     1      30      2                     
    INDEX UNIQUE SCAN     CASE_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_SITE     1      12      2                     
    INDEX UNIQUE SCAN     SITE_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_ADDRESS     1      12      2                     
    INDEX UNIQUE SCAN     ADDRESS_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_EMPLOYEE     1      34      1                     
    INDEX UNIQUE SCAN     EMPLOYEE_OBJINDEX     1                               
    INDEX UNIQUE SCAN     SITE_OBJINDEX     1      6      1                     
    INDEX UNIQUE SCAN     USER_OBJINDEX     1      6                          
    TABLE ACCESS BY INDEX ROWID     TABLE_X_GSA_TIME_STAMPS     4      48      3                     
    INDEX RANGE SCAN     GSAIDX_TS2DISP     1           2                     
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     SUBCASE_OBJINDX     1      6      1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_MOD_LEVEL     1      12      1                     
    INDEX UNIQUE SCAN     MOD_LEVEL_OBJINDEX     1                               
    INDEX UNIQUE SCAN     PART_NUM_OBJINDEX     1      6                          
    NESTED LOOPS          16 K     2 M     5812                     
    HASH JOIN          16 K     2 M     5812                     
    HASH JOIN          16 K     2 M     5286                     
    TABLE ACCESS FULL     TABLE_EMPLOYEE     13 K     441 K     28                     
    HASH JOIN          16 K     1 M     5243                     
    TABLE ACCESS FULL     TABLE_SCHEDULE     991      11 K     2                     
    HASH JOIN OUTER          16 K     1 M     5240                     
    HASH JOIN OUTER          16 K     1 M     3866                     
    HASH JOIN OUTER          16 K     1 M     450                     
    HASH JOIN          16 K     1 M     44                     
    TABLE ACCESS FULL     TABLE_GBST_ELM     781      14 K     2                     
    TABLE ACCESS FULL     TABLE_APPOINTMENT     16 K     822 K     41                     
    INDEX FAST FULL SCAN     CASE_OBJINDEX     1 M     6 M     201                     
    TABLE ACCESS FULL     TABLE_SITE     967 K     11 M     3157                     
    TABLE ACCESS FULL     TABLE_ADDRESS     961 K     11 M     1081                     
    INDEX FAST FULL SCAN     SITE_OBJINDEX     967 K     5 M     221                     
    INDEX UNIQUE SCAN     USER_OBJINDEX     1      6                          
    HASH JOIN          6 K     272 K     51                     
    TABLE ACCESS FULL     TABLE_USER     6 K     51 K     21                     
    TABLE ACCESS FULL     TABLE_EMPLOYEE     6 K     220 K     28

    Hi,
    First-off, it appear that you are querying a view. I would redo the auery against the base table.
    Next, look at a function-based index for the DATE column. Here are my notes:
    http://www.dba-oracle.com/t_function_based_indexes.htm
    http://www.dba-oracle.com/oracle_tips_index_scan_fbi_sql.htm
    Also, make sure you are analyzed properly with dbms_stats:
    http://www.dba-oracle.com/art_builder_dbms_stats.htm
    And histograms, if appropriate:
    http://www.dba-oracle.com/art_builder_histo.htm
    Lasty, look at increasing hash_area_size or pga_aggregate_tagtet, depending on your table sizes:
    http://www.dba-oracle.com/art_so_undocumented_pga_parameters.htm
    Hope this helps. . . .
    Donald K. Burleson
    Oracle Press Author

  • Need help in optimising the performance of a query

    Need help in optimising the performance of a query. Below is the query that is executed on TABLE_A, TABLE_B and TABLE_C with record counts as 10M, 10m and 42 (only) respectively and it takes around 5-7 minutes to get 40 records:
    SELECT DISTINCT a.T_ID_, a.FIRSTNAME, b.T_CODE, b.PRODUCT,
    CASE WHEN TRUNC(b.DATE) +90 = TRUNC(SYSDATE) THEN -90 WHEN TRUNC(b.DATE) +30 = TRUNC(SYSDATE) THEN -30 ELSE 0 END AS T_DATE FROM TABLE_B b
    INNER JOIN TABLE_A a ON (a.T_ID_ = b.T_ID_) LEFT JOIN TABLE_C c ON b.PRODUCT = c.PRODUCT
    WHERE b.STATUS = 'T' AND (b.TYPE = 'ACTION'
    AND ( TRUNC(b.DATE) + 1 = TRUNC(SYSDATE) ) ) AND b.PRODUCT = 2;
    Note: Indices on the join columns are available in the respective tables
    Please let me know if there is any better way to write it.
    Edited by: 862944 on Aug 18, 2011 9:52 AM

    862944 wrote:
    Need help in optimising the performance of a query. Below is the query that is executed on TABLE_A, TABLE_B and TABLE_C with record counts as 10M, 10m and 42 (only) respectively and it takes around 5-7 minutes to get 40 records:
    SELECT DISTINCT a.T_ID_, a.FIRSTNAME, b.T_CODE, b.PRODUCT,
    CASE WHEN TRUNC(b.DATE) +90 = TRUNC(SYSDATE) THEN -90 WHEN TRUNC(b.DATE) +30 = TRUNC(SYSDATE) THEN -30 ELSE 0 END AS T_DATE FROM TABLE_B b
    INNER JOIN TABLE_A a ON (a.T_ID_ = b.T_ID_) LEFT JOIN TABLE_C c ON b.PRODUCT = c.PRODUCT
    WHERE b.STATUS = 'T' AND (b.TYPE = 'ACTION'
    AND ( TRUNC(b.DATE) + 1 = TRUNC(SYSDATE) ) ) AND b.PRODUCT = 2;
    Note: Indices on the join columns are available in the respective tables
    Please let me know if there is any better way to write it.
    Edited by: 862944 on Aug 18, 2011 9:52 AM[When Your Query Takes Too Long|https://forums.oracle.com/forums/thread.jspa?messageID=1812597]

  • Performance issue with insert query !

    Hi ,
    I am using dbxml-2.4.16, my node-storage container is loaded with a large document ( 54MB xml ).
    My document basically contains around 65k records in the same table ( 65k child nodes for one parent node ). I need to insert more records in to my DB, my insert XQuery is consuming a lot of time ( ~23 sec ) to insert one entry through command-line and around 50sec through code.
    My container is indexed with "node-attribute-equality-string". The insert query I used:
    insert nodes <NS:sampleEntry mySSIAddress='70011' modifier = 'create'><NS:sampleIPZone1Address>AABBCCDD</NS:sampleIPZone1Address><NS:myICMPFlag>1</NS:myICMPFlag><NS:myIngressFilter>1</NS:myIngressFilter><NS:myReadyTimer>4</NS:myReadyTimer><NS:myAPNNetworkID>ggsntest</NS:myAPNNetworkID><NS:myVPLMNFlag>2</NS:myVPLMNFlag><NS:myDAC>100</NS:myDAC><NS:myBcastLLIFlag>2</NS:myBcastLLIFlag><NS:sampleIPZone2Address>00000000</NS:sampleIPZone2Address><NS:sampleIPZone3Address>00000000</NS:sampleIPZone3Address><NS:sampleIPZone4Address>00000000</NS:sampleIPZone4Address><NS:sampleIPZone5Address>00000000</NS:sampleIPZone5Address><NS:sampleIPZone6Address>00000000</NS:sampleIPZone6Address><NS:sampleIPZone7Address>00000000</NS:sampleIPZone7Address></NS:sampleEntry> into doc('dbxml:/n_b_i_f_c_a_z.dbxml/doc_Running-SAMPLE')//NS:NS//NS:sampleTable)
    If I modify my query with
    into doc('dbxml:/n_b_i_f_c_a_z.dbxml/doc_Running-SAMPLE')//NS:sampleTable/NS:sampleEntry[@mySSIAddress='1']
    insted of
    into doc('dbxml:/n_b_i_f_c_a_z.dbxml/doc_Running-SAMPLE')//NS:NS//NS:sampleTable)
    Time taken reduces only by 8 secs.
    I have also tried to use insert "after", "before", "as first", "as last" , but there is no difference in performance.
    Is anything wrong with my query, what should be the expected time to insert one record in a DB of 65k records.
    Has anybody got any idea regarding this performance issue.
    Kindly help me out.
    Thanks,
    Kapil.

    Hi George,
    Thanks for your reply.
    Here is the info you requested,
    dbxml> listIndexes
    Index: unique-node-metadata-equality-string for node {http://www.sleepycat.com/2002/dbxml}:name
    Index: node-attribute-equality-string for node {}:mySSIAddress
    2 indexes found.
    dbxml> info
    Version: Oracle: Berkeley DB XML 2.4.16: (October 21, 2008)
    Berkeley DB 4.6.21: (September 27, 2007)
    Default container name: n_b_i_f_c_a_z.dbxml
    Type of default container: NodeContainer
    Index Nodes: on
    Shell and XmlManager state:
    Not transactional
    Verbose: on
    Query context state: LiveValues,Eager
    The insery query with update takes ~32 sec ( shown below )
    time query "declare namespace foo='MY-SAMPLE';declare namespace NS='NS';insert nodes <NS:sampleEntry mySSIAddress='70000' modifier = 'create' ><NS:sampleIPZone1Address>AABBCCDD</NS:sampleIPZone1Address><NS:myICMPFlag>1</NS:myICMPFlag><NS:myIngressFilter>1</NS:myIngressFilter><NS:myReadyTimer>4</NS:myReadyTimer><NS:myAPNNetworkID>ggsntest</NS:myAPNNetworkID><NS:myVPLMNFlag>2</NS:myVPLMNFlag><NS:myDAC>100</NS:myDAC><NS:myBcastLLIFlag>2</NS:myBcastLLIFlag><NS:sampleIPZone2Address>00000000</NS:sampleIPZone2Address><NS:sampleIPZone3Address>00000000</NS:sampleIPZone3Address><NS:sampleIPZone4Address>00000000</NS:sampleIPZone4Address><NS:sampleIPZone5Address>00000000</NS:sampleIPZone5Address><NS:sampleIPZone6Address>00000000</NS:sampleIPZone6Address><NS:sampleIPZone7Address>00000000</NS:sampleIPZone7Address></NS:sampleEntry> into doc('dbxml:/n_b_i_f_c_a_z.dbxml/doc_Running-SAMPLE')//NS:NS//NS:sampleTable"
    Time in seconds for command 'query': 32.5002
    and the query without the updation part takes ~14 sec ( shown below )
    time query "declare namespace foo='MY-SAMPLE';declare namespace NS='NS'; doc('dbxml:/n_b_i_f_c_a_z.dbxml/doc_Running-SAMPLE')//NS:NS//NS:sampleTable"
    Time in seconds for command 'query': 13.7289
    The query :
    time query "declare namespace foo='MY-SAMPLE';declare namespace NS='NS'; doc('dbxml:/n_b_i_f_c_a_z.dbxml/doc_Running-SAMPLE')//PMB:sampleTable/PMB:sampleEntry[@mySSIAddress='1000']"
    Time in seconds for command 'query': 0.005375
    is very fast.
    The Updation of the document seems to consume much of the time.
    Regards,
    Kapil.

  • Creating Query with dynamic columns to show results

    Hi experts,
    I need to know how to create a query with dynamic columns. Meaning, I don't want to create a query with fixed columns representing the 12 periods of the fiscal year to show me actuals as the fiscal year proceeds.
    For example, if I am currently in the middle of period 3 (March) of a fiscal year, when I execute the query, I need it to automatically only show me the 'Actuals' for periods 1 and 2, without seeing the columns from periods 3 to 12 showing blank.
    Then when I am in the middle period 5 (May) the query should ONLY show me the columns for periods 1 to 4 'Actuals', no results should be shown for periods 5 to 12 yet, and I don't want to even see blank columns for period 6 to 12.
    How do I define my columns, to achieve this.
    Maximum points will be awarded.
    Thanks Everyone.

    Hi Josh,
    I'm having a little difficuluty understanding what should be included in my restricted key figures.
    The time characteristics that I have available to use are:
    0FISCPER3 (posting period)
    0FISCYEAR (fiscal year), currently using SAP EXIT to default current fiscal year.
    0FISCVARNT (fiscal year variant).
    In addition, I have the following characteristics available to be used in the columns:
    Value type (10)
    version (currently I'm using variable for it)
    Currency type (020)
    Currency (USD).
    Can you explain what my restricted key figure should be based on and how it should look.
    I tried to create a restircted key figure using 0AMOUNT, and 0FISCPER3. For 0FISCPER3  I created a range from 1 to previous period (using SAP EXIT that supplied previous period).I also had value type, version, currency type, and currency included in that restricted key figure.Then when I tried to drag 0FISCPER3 under the restricted key figure once again, it wouldn't let me, probably because I've already used 0FISCPER3 in the restricted key figure.
    Please let me know if my explanation is not clear.
    Your step by step help would be great.
    Thanks
    Edited by: Ehab Mansour on Sep 23, 2008 2:40 PM

  • Please help me how to improve the performance of this query further.

    Hi All,
    Please help me how to improve the performance of this query further.
    Thanks.

    Hi,
    this is not your first SQL tuning request in this community -- you really should learn how to obtain performance diagnostics.
    The information you posted is not nearly enough to even start troubleshooting the query -- you haven't specified elapsed time, I/O, or the actual number of rows the query returns.
    The only piece of information we have is saying that your query executes within a second. If we believe this, then your query doesn't need tuning. If we don't, then we throw it away
    and we're left with nothing.
    Start by reading this blog post: Kyle Hailey &amp;raquo; Power of DISPLAY_CURSOR
    and applying this knowledge to your case.
    Best regards,
      Nikolay

Maybe you are looking for

  • OBIEE 11g on Windows 7 64 bit - Error while configuring????

    Hi Experts, I am installing OBIEE 11g on Windows 7 64 bit. And I followed below steps: 1. Installed JDK 64 bit. 2. Installed Weblogic Server with 64 bit JDK. 3. Installed OBIEE 11g - Software only Installation. 4. Ran configuration script. cofig.bat.

  • Show Section/Level 1 Outline Title when Scrolling in iOS Pages

    To make this a bit clear I would like to refer to scrolling in iBooks. When you swipe the scroll bar you will see the title of the chapters (sections) of the book above the tip of your finger. I would like to see same effect/feature of this in Pages.

  • JBO-25013: Too many objects match the primary key oracle.jbo.Key[1661 ].

    Hi , I'm using 11g adf I have a table XX , in which C1 and C2 are bind with composite key.I didn't get any issue while adding records , but when i try to fetch records using QB , i'm getting this error below <Utils><buildFacesMessage> ADF: Adding the

  • Drag and Drop in Procedure Builder :-(

    Drag and Drop works in SQL Worksheet BUT it does not work in procedure builder :'-( It would be nice to have same feature working everywhere. The work around is first drag and drop table in SQL Worksheet to get syntax and then cutting and pasting it

  • Windows desktop VM licensing

    Hi... What's the licensing requirement to build the following test environment -  For 10 users to access 20 Windows 7 or 8 Professional virtual machines. All the virtual machines are based on a server/hypervisor. All the user workstations are using W