Tuning SQL Query calling multiple views

Dear All,
I have a complex scenario in which I have created views in 3 levels for sales and Service separately so total no of views are 6.
Level 2 calls view in Level 1 and Level 3 calls level 2 in sales as well as services.
Finally Level 4 has the union of sales and Service Level 3 view.
There are 5 tables used in total and all have been indexed for better performance.
The cube processing for the above scenario has processing time of 6 mins.
The goal is to bring it down to 2-3 mins.
The amount of data currently we are looking at is not more than 2-3 GB.
Can anybody help me fine tune this scenario?
Thanks, Franco.

Run the queries the cube is using in SSMS and turn on the Include Actual Execution Plan option. 
https://msdn.microsoft.com/en-us/library/ms189562.aspx?f=255&MSPPError=-2147217396
Straight up it may suggest missing indexes which you can test to see if they improve the query performance.  You can't take these suggestions as gospel - sometimes SQL Server gets it wrong - so you need to test them. 
After that look in the query plan for any table scan operators.  Unless you are actually retrieving every row in a table you shouldn't have any of these and they can probably be removed by placing a properly considered index on the table. 
After that look for any RID Lookups or Key Lookups.  These can generally be resolved fairly easily by adding the columns being looked up as "include" columns in the indexes.  
Here are some links that might get you started.  
Reading Execution Plans: http://www.mssqltips.com/sqlservertip/1873/how-to-read-sql-server-graphical-query-execution-plans/
Resolving Table Scans http://blog.sqlauthority.com/2007/03/30/sql-server-index-seek-vs-index-scan-table-scan/
Resolving Lookups: http://blog.sqlauthority.com/2009/11/09/sql-server-removing-key-lookup-seek-predicate-predicate-an-interesting-observation-related-to-datatypes/
Those are the obvious things - and generally the easiest to achieve.  Performance tuning is a big area.  It may be that the database queries are already performing perfectly well and the time being spent is processing the cube itself so you need
to establish where the time is going.  There is no point trying to tune the database queries if they are already working well.
LucasF

Similar Messages

  • Need help with SQL Query with Inline View + Group by

    Hello Gurus,
    I would really appreciate your time and effort regarding this query. I have the following data set.
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
    1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
    Please Ignore '----', added it for clarity
    I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
    The query should return the following data set
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
    The following is my query. I am kind of lost.
    select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
    from (
    select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
    from INVOICE
    group by sequence_id,check_date, check_number, invoice_number, vendor_number
    ) A, INVOICE B
    where A.sequence_id = B.sequence_id
    Thanks,
    Nick

    It looks like it is a duplicate thread - correct me if i'm wrong in this case ->
    Need help with SQL Query with Inline View + Group by
    Regards.
    Satyaki De.

  • Tuning SQL query

    Please help me in tuning this query. This view has around 2 million of records
    SELECT * FROM employee_v
    WHERE status_id IN (SELECT MAX(v2.status_id)status_id
    FROM employee_v v2
    WHERE UPPER(v2.name) LIKE UPPER(:v_name)||'%'
    GROUP BY v2.emp_id, v2.project_id)
    ORDER BY status_type_id;
    Here:
    employees may work on one or more projects
    employee working on a given project may have one or more status_ids associated.
    for example:
    emp_id     project_id     status_id
    10     100     1
    10     100     2
    20     100     2
    20     200     3
    30     100     4
    30     200     5
    30     200     6
    40     200     6
    If you have any other suggestions , please let me know too. For example, I was thinking that the subquery should use actual tables instead of the view because view is based on 10 tables and the subquery can instead use two tables . Does it make sense?
    Thanks a lot for the help!
    Edited by: user5406804 on Apr 20, 2010 5:42 AM

    If you have any other suggestions , please let me know too. Wild shot in the dark, but maybe using EXISTS instead of IN speeds up your query:
    untested for obvious reasons
    select *
    from  employee_v v
    where  upper(v.name) like upper(:v_name)||'%'
    where not exists ( select null
                       from   employee_v v2
                       and    v2.status_id > v.status_id                  
                       and    v2.emp_id = v.emp_id -- assuming you have some emp_id PK column
                                                   -- if necessary, you need to change the name of this column ofcourse
    order by status_type_id;Do compare the resultsets, not sure this will give you the same/desired result, but it might give you an idea.
    For example, I was thinking that the subquery should use actual tables instead of the view because > view is based on 10 tables and the subquery can instead
    use two tables . Does it make sense?Sounds like worth a try to me, yes. Less data to plough through = faster response.
    As well as using a function based index on UPPER(name) might be worth a try.

  • What is the best way to Optimize a SQL query : call a function or do a join?

    Hi, I want to know what is the best way to optimize a SQL query, call a function inside the SELECT statement or do a simple join?

    Hi,
    If you're even considering a join, then it will probably be faster.  As Justin said, it depends on lots of factors.
    A user-defined function is only necessary when you can't figure out how to do something in pure SQL, using joins and built-in functions.
    You might choose to have a user-defined function even though you could get the same result with a join.  That is, you realize that the function is slow, but you believe that the convenience of using a function is more important than better performance in that particular case.

  • Passing an argument in the SQL Query of a View Object

    Hi,
    It is possible that this question has been asked before, however I have searched for a half an hour in the forums and couldn't find a solution.
    I am also new to using JDeveloper and ADF. Here's the situation:
    I am developing an application that doesn't have to do anything else then displaying data from a database. Pretty straightforward actually.
    Now I have made a vew pages with several collapsible panels (af:showDetailHeader) and have setup the datasources (or so I thought).
    All that remains is:
    - drag & drop a view object, from the application module that I created, onto the collabsible panels, so a child element gets created which displays data from the database.
    - hack the layout so it looks like I want it to.
    The problem that I have is the following:
    I am using a 'User'-class that contains values I need when quering the database.
    That User-object is part of a user-session.
    What I want, for example, is to use the 'getPersonId()' function of that User-object and pass the argument to a SQL-query of a certain view-object.
    The query would become something like:
    'SELECT * FROM people WHERE people.personId = :someNumber'.
    Now I've read some stuff about variable binding, which is complemented by something like (backing bean code):
    getDBTransaction().getRootApplicationModule().getACertainViewObject().setWhereClauseParameter(1, user.getPersonId());
    The examples I have found that might match my wishes are not using business components, but EJB's. I am having difficulty with understanding the 'how'-part of variable binding.
    Also, I do not know enough of ADF to be able to create a situation like:
    'User loads page, collapsible panel 1 is fully shown, the others are undisclosed.'
    (meaning, that for panel1 a query has been executed.)
    'User clicks on collapsible panel 2 which triggers a backingbean that somehow retrieves data from a view object'.
    I would appreciate any help that somebody can give.
    If it is not too much of a problem, please provide code snippets in case you have a solution. I am new to ADF :(.
    -edit
    I am using JDeveloper 10.1.3.3.0 in case that is of any importance.
    Message was edited by:
    Hugo Boog

    Hello Stijn,
    I didn't think about a referenced bean rule in the faces-config.
    I added it right away and I am now able to set parameters of a View-object, not using a page button and before the page loads. You made my day!
    In case anyone ever reads this post again, the summary of how to generate a table based on a View-object using dynamic parameters.:
    1a: Go to faces-config.xml -> Overview tab'
    1b: Go to the menuitem "Referenced Beans"
    1c: Click on 'new' and select the existing bean you want to access data from and input a name. In this example I use name="user"
    2: Create a View-object using the wizard.
    2a: Specify the query you want in the menuitem 'SQL Statement'.
    Add the 'parameters' you want to. You will have something like:
    "SELECT * FROM someTable WHERE table.columnname LIKE :someArgument".
    - hint: if you want the result to become something like:
    "SELECT * FROM someTable WHERE table.columnname LIKE '%someArgument%'" then you have to add the '%'-characters in your code itself (read: someClass.setParameter("%" + someArgument);).
    2b: In the menuitem 'Bind Variables' you have to add the variables you are referring to in the query. If you look at the query in 2a, then you have to add a variable with name "someArgument".
    2c: Add the View-object to a Application Module (create one if nessecairy).
    3a: Open a .jsp(x) file. Drag the View-object created in step 2 from the 'Data Controls'-pane to the page.
    3b: Click on the '+' of the View-object in the 'Data Controls'-pane and open 'Operations' and drag 'ExecuteWithParams' to your page as a button.
    3c: We do not want to use a button, the action has to be executed immediatly. So In the page source remove the lines that were created after dropping 'ExecuteWithParams'.
    3d: Right-click on the page and select "Go to Page Definition".
    3e: Go to the action id that is called 'ExecuteWithParams#', where # is a number.
    Change the id to something useful.
    3f: Change the NDValue so it corresponds with the value you want.
    Example:
    <action id="getAddressData" IterBinding="AddressesView1Iterator"
    InstanceName="MyHRServiceModuleDataControl.AddressView1"
    DataControl="MyHRServiceModuleDataControl" RequiresUpdateModel="true" Action="95">
    <NamedData NDName="someArgument" NDType="java.lang.String"
    NDValue="#{user.personId}"/>
    </action>
    Note: It is possible to use the value of a Backing Bean in NDValue.
    Note 2: user is the bean I referred to in the faces-config.xml!
    3g: Under the executables item, add an 'invokeAction' to pass the parameter to the View-object before your JSP-file loads:
    <executables>
    <invokeAction Binds="getAddressData"
    id="loadAddressDataOfPersonIdInSession"
    Refresh="prepareModel"/>
    Thank Stijn Haus for this :)

  • Using IN keyword in an sql query in a view criteria

    Hi,
    I am using jdev 11.1.1.1.0 and defined an lov query/viewobject as
    select a, b, c from myTable
    I now need to predefine filtering for lov search functionality and need something like the following
    select a, B, c from myTable where B in ('X','Y')
    I could not find a way to do it (i.e. specify the use of IN Keyword) in the Create View Criteria dialog box. I tried to define OR, but is that the best way to redefine IN as i have a long list (the above is just an example)
    (( ( (UPPER(B_FLAG) = UPPER('X') ) ) OR ( (UPPER(DISPLAY_FLAG) = UPPER('Y') ) ) ))

    If you know how many variables are in your "in" You can just write this in the sql query of your VO:
    http://www.oracle.com/technology/obe/obe11jdev/ps1/ria_application/images/t136.gif
    From this tutorial:
    http://www.oracle.com/technology/obe/obe11jdev/ps1/ria_application/developriaapplication_long.htm#ah1

  • Tuning (SQL Query has radically different Buffer GETS in each instance)

    I have been noticing that on Node2 of my 10.2.0.3 RAC cluster CPU has been running 90% for the past couple of days and on Node1 we are at the normal 20-30%. I was comparing AWR for both instances and noticed that the same exact SQL was showing different GETS on each instance.
    Both Instances are configured exactly the same. SGA 3GB, 2 dual core 1.5Ghz CPU on Solaris 10.
    AWR For Node 1
    SQL ordered by Gets
    Resources reported for PL/SQL code includes the resources used by all SQL statements called by the code.
    Total Buffer Gets: 8,199,224
    Captured SQL account for 94.2% of Total
    Buffer Gets  Executions  Gets per Exec  %Total CPU Time (s) Elapsed Time (s) SQL Id SQL Module SQL Text
    4,834,470 16,465 293.62 58.96 442.34 459.42 cs3w0nz7uanhc    BEGIN HRW_EC_QUERY.CHECK_STUDE...
    4,561,082 16,469 276.95 55.63 411.10 430.16 6vbpbvfburc4x    SELECT COUNT(SECURE_PROGRAMS.P... AWR For Node 2
    Buffer Gets  Executions  Gets per Exec  %Total CPU Time (s) Elapsed Time (s) SQL Id SQL Module SQL Text
    219,779,881 9,306 23,617.01 99.26 11791.62 32202.99 cs3w0nz7uanhc    BEGIN HRW_EC_QUERY.CHECK_STUDE...
    219,320,634 9,302 23,577.79 99.05 11760.22 32137.23 6vbpbvfburc4x    SELECT COUNT(SECURE_PROGRAMS.P... Gets on Node 2 are about 45 times what they are on node 1. We are using bind variables in the SQL. The statements are completely identical. Anyone seen this before?
    Thanks,
    Brian

    All parameters are the same between instances. Here is the result of the query.
    PLAN_TABLE_OUTPUT                                                                                                                          
    SQL_ID 6vbpbvfburc4x                                                                                                                       
    SELECT COUNT(SECURE_PROGRAMS.PROG_ID) FROM SECURE_PROGRAMS,HRW_EC_ACTIVE_ITEM, (SELECT ACTIVE_ITEM_ID                                      
    FROM TABLE(CAST(:B1 AS HRW_EC_ACTIVE_ITEM_ID_TABLE_T)) ) T WHERE HRW_EC_ACTIVE_ITEM.ACTIVE_ITEM_ID =                                       
    T.ACTIVE_ITEM_ID AND HRW_EC_ACTIVE_ITEM.SPROG_ID = SECURE_PROGRAMS.PROG_ID AND                                                             
    SECURE_PROGRAMS.STUDENT_RESOURCES_URL = :B2                                                                                                
    Plan hash value: 25280318                                                                                                                  
    | Id  | Operation                           | Name                      | Rows  | Bytes | Cost (%CPU)| Time     |                          
    |   0 | SELECT STATEMENT                    |                           |       |       |   730 (100)|          |                          
    |   1 |  SORT AGGREGATE                     |                           |     1 |    57 |            |          |                          
    |   2 |   HASH JOIN                         |                           |   116 |  6612 |   730   (1)| 00:00:09 |                          
    |   3 |    COLLECTION ITERATOR PICKLER FETCH|                           |       |       |            |          |                          
    |   4 |    NESTED LOOPS                     |                           | 48596 |  2610K|   705   (1)| 00:00:09 |                          
    |   5 |     INDEX RANGE SCAN                | SECURE_PROGRAMS_IDX_04    |     4 |    76 |     2   (0)| 00:00:01 |                          
    |   6 |     INDEX RANGE SCAN                | HRW_EC_ACTIVE_ITEM_IDX_03 | 10984 |   386K|   176   (1)| 00:00:03 |                          
    Query Block Name / Object Alias (identified by operation id):                                                                              
       1 - SEL$62A3881B                                                                                                                        
       5 - SEL$62A3881B / SECURE_PROGRAMS@SEL$1                                                                                                
       6 - SEL$62A3881B / HRW_EC_ACTIVE_ITEM@SEL$1                                                                                             
    SQL_ID 6vbpbvfburc4x                                                                                                                       
    SELECT COUNT(SECURE_PROGRAMS.PROG_ID) FROM SECURE_PROGRAMS,HRW_EC_ACTIVE_ITEM, (SELECT ACTIVE_ITEM_ID                                      
    FROM TABLE(CAST(:B1 AS HRW_EC_ACTIVE_ITEM_ID_TABLE_T)) ) T WHERE HRW_EC_ACTIVE_ITEM.ACTIVE_ITEM_ID =                                       
    T.ACTIVE_ITEM_ID AND HRW_EC_ACTIVE_ITEM.SPROG_ID = SECURE_PROGRAMS.PROG_ID AND                                                             
    SECURE_PROGRAMS.STUDENT_RESOURCES_URL = :B2                                                                                                
    Plan hash value: 219484150                                                                                                                 
    | Id  | Operation                            | Name                      | Rows  | Bytes | Cost (%CPU)| Time     |                         
    |   0 | SELECT STATEMENT                     |                           |       |       |  4845 (100)|          |                         
    |   1 |  SORT AGGREGATE                      |                           |     1 |    57 |            |          |                         
    |   2 |   HASH JOIN                          |                           |  2066 |   115K|  4845   (2)| 00:00:59 |                         
    |   3 |    INDEX RANGE SCAN                  | SECURE_PROGRAMS_IDX_04    |    79 |  1501 |     2   (0)| 00:00:01 |                         
    |   4 |    HASH JOIN                         |                           |  3284 |   121K|  4843   (2)| 00:00:59 |                         
    |   5 |     COLLECTION ITERATOR PICKLER FETCH|                           |       |       |            |          |                         
    |   6 |     INDEX FAST FULL SCAN             | HRW_EC_ACTIVE_ITEM_IDX_03 |  1373K|    47M|  4803   (2)| 00:00:58 |                         
    Query Block Name / Object Alias (identified by operation id):                                                                              
       1 - SEL$62A3881B                                                                                                                        
       3 - SEL$62A3881B / SECURE_PROGRAMS@SEL$1                                                                                                
       6 - SEL$62A3881B / HRW_EC_ACTIVE_ITEM@SEL$1                                                                                             
    Note                                                                                                                                       
       - SQL profile "SYS_SQLPROF_014414387fd00001" used for this statement                                                                    
    SQL_ID 6vbpbvfburc4x                                                                                                                       
    SELECT COUNT(SECURE_PROGRAMS.PROG_ID) FROM SECURE_PROGRAMS,HRW_EC_ACTIVE_ITEM, (SELECT ACTIVE_ITEM_ID                                      
    FROM TABLE(CAST(:B1 AS HRW_EC_ACTIVE_ITEM_ID_TABLE_T)) ) T WHERE HRW_EC_ACTIVE_ITEM.ACTIVE_ITEM_ID =                                       
    T.ACTIVE_ITEM_ID AND HRW_EC_ACTIVE_ITEM.SPROG_ID = SECURE_PROGRAMS.PROG_ID AND                                                             
    SECURE_PROGRAMS.STUDENT_RESOURCES_URL = :B2                                                                                                
    Plan hash value: 740005210                                                                                                                 
    | Id  | Operation                           | Name                      | Rows  | Bytes | Cost (%CPU)| Time     |                          
    |   0 | SELECT STATEMENT                    |                           |       |       |  4845 (100)|          |                          
    |   1 |  SORT AGGREGATE                     |                           |     1 |    57 |            |          |                          
    |   2 |   HASH JOIN                         |                           |     7 |   399 |  4845   (2)| 00:00:59 |                          
    |   3 |    COLLECTION ITERATOR PICKLER FETCH|                           |       |       |            |          |                          
    |   4 |    HASH JOIN                        |                           |  2992 |   160K|  4821   (2)| 00:00:58 |                          
    |   5 |     INDEX RANGE SCAN                | SECURE_PROGRAMS_IDX_04    |    33 |   627 |     2   (0)| 00:00:01 |                          
    |   6 |     INDEX FAST FULL SCAN            | HRW_EC_ACTIVE_ITEM_IDX_03 |  1373K|    47M|  4803   (2)| 00:00:58 |                          
    Query Block Name / Object Alias (identified by operation id):                                                                              
       1 - SEL$62A3881B                                                                                                                        
       5 - SEL$62A3881B / SECURE_PROGRAMS@SEL$1                                                                                                
       6 - SEL$62A3881B / HRW_EC_ACTIVE_ITEM@SEL$1                                                                                             
    Note                                                                                                                                       
       - SQL profile "SYS_SQLPROF_014414387fd00001" used for this statement                                                                    
    SQL_ID 6vbpbvfburc4x                                                                                                                       
    SELECT COUNT(SECURE_PROGRAMS.PROG_ID) FROM SECURE_PROGRAMS,HRW_EC_ACTIVE_ITEM, (SELECT ACTIVE_ITEM_ID                                      
    FROM TABLE(CAST(:B1 AS HRW_EC_ACTIVE_ITEM_ID_TABLE_T)) ) T WHERE HRW_EC_ACTIVE_ITEM.ACTIVE_ITEM_ID =                                       
    T.ACTIVE_ITEM_ID AND HRW_EC_ACTIVE_ITEM.SPROG_ID = SECURE_PROGRAMS.PROG_ID AND                                                             
    SECURE_PROGRAMS.STUDENT_RESOURCES_URL = :B2                                                                                                
    Plan hash value: 1418188916                                                                                                                
    | Id  | Operation                           | Name                      | Rows  | Bytes | Cost (%CPU)| Time     |                          
    |   0 | SELECT STATEMENT                    |                           |       |       |  2136 (100)|          |                          
    |   1 |  SORT AGGREGATE                     |                           |     1 |    57 |            |          |                          
    |   2 |   HASH JOIN                         |                           |     3 |   171 |  2136   (1)| 00:00:26 |                          
    |   3 |    NESTED LOOPS                     |                           |  1103 | 60665 |  2111   (1)| 00:00:26 |                          
    |   4 |     INDEX RANGE SCAN                | SECURE_PROGRAMS_IDX_04    |    12 |   228 |     2   (0)| 00:00:01 |                          
    |   5 |     INDEX RANGE SCAN                | HRW_EC_ACTIVE_ITEM_IDX_03 | 10984 |   386K|   176   (1)| 00:00:03 |                          
    |   6 |    COLLECTION ITERATOR PICKLER FETCH|                           |       |       |            |          |                          
    Query Block Name / Object Alias (identified by operation id):                                                                              
       1 - SEL$62A3881B                                                                                                                        
       4 - SEL$62A3881B / SECURE_PROGRAMS@SEL$1                                                                                                
       5 - SEL$62A3881B / HRW_EC_ACTIVE_ITEM@SEL$1      Thanks,
    Brian

  • BIP SQL Query calling db function....

    Hi ,
    I am using SQL as my data model (Not Data Template).
    Can I modify my SQL query to include a database function .....eg
    select
    col1 ,
    col2,
    mypackage.myfunction(col2)
    from table_1
    Please let me know
    rgds
    s

    yes.
    don't forget to give me the points.
    Ike Wiggins
    http://bipublisher.blogspot.com

  • Sql query across multiple tables ina database

    I have 3 MS Access tables in database that are linked by keyed fields in the table.  Is there a way to fetch only certain records that match a criteria across all three of these tables using the database connectivity toolset VIs?

    Thanks.  I am trying to mechanize/run an SQL query like this 
    SELECT Code_Type.Code_NUM, Code_Type.Code_Word, Word_Type.Parm_Label, Word_Type.Word_Sequence, Word_Type.Num_Words, Parameter_Label.Parm_Label, Parameter_Label.Parm_Name, Parameter_Label.Num_Bits, Parameter_Label.Num_Bits
    FROM (Code_Type INNER JOIN Word_Type ON Code_Type.Code_Word = Word_Type.Code_Word) INNER JOIN Parameter_Label ON Word_Type.Parm_Label = Parameter_Label.Parm_Label;
    while using the VIs in the database connectivity toolset.  How do I code this using these VIs?  I dont see an example of a straight SQL string like this being able to be put into the VIs.

  • Same sql query with multiple database links

    Hi All,
    i want to execute an sql query for a SELECT LIST Item. which should use database links in it's query.
    i'm having a list of database links in the region. say :LOC which is having 10 items each linking to different databases.
    i want to use following query for another item in same page.
    select customer_name from working_lines@:LOC where
    phone_no:phone_no
    can i do this.
    Thank you All.

    What we have done before is to create a report based on a PL/SQL procedure that returns a SQL statement.
    The PL/SQL code grabs the "selected" database link from :LOC and parses the SQL QUERY you want to execute replacing some token (like [LINK]) with '@DBNAME'.
    Lets say your SQL statement is coded like this:
    mySQL := 'SELECT cust_name FROM working_lines[LINK] where phone_no = :Phone;'
    Then all you would have to do to replace '[LINK]' with the proper DB alias would be:
    mySQL := REPLACE(mySQL, '[LINK]', '@'||:LOC);
    and then return the new SQL ...
    if :LOC has something like 'V10GPROD' your SQL would look like :
    SELECT cust_name FROM working_lines@V10GPROD where phone_no = :Phone;
    The beauty of this is that you can also include a "null" option that means the select statement will be executed on THIS database...
    Doug

  • Tuning an SQL query on a view

    Hi
    I have an SQL that has poor performance when querying a 3 table view.
    I have tried to tune the view by adding an additional index but the EXPLAIN plan does not change.  In fact, the plan is ONLY using fields specified in the the views join conditions and not the WHERE clause.
    I have created an index EKET~Z1 with the column for table (T003)
          EINDT   
    and I have also tried another index EKKO~Z2 with the columns for table T001
          BSART
          BSTYP
          EKORG
    The query is as follows:
    SQL Statement                                                                               
    SELECT                                                                    
        "MANDT" , "EBELN" , "EBELP" , "ETENR" , "EKKO_LOEKZ" , "BSTYP" ,        
        "BSART" , "BUKRS" , "EKORG" , "EKGRP" , "STATU" , "AEDAT" , "ERNAM" ,   
        "BEDAT" , "LIFNR" , "ADRNR" , "WAERS" , "EKPO_LOEKZ" , "EKPO_BSTYP" ,   
        "TXZ01" , "MATNR" , "EMATN" , "WERKS" , "MATKL" , "IDNLF" , "MENGE" ,   
        "MEINS" , "NETPR" , "NETWR" , "PSTYP" , "KNTTP" , "WEPOS" , "ANFNR" ,   
        "PRDAT" , "KONNR" , "KTPNR" , "ELIKZ" , "EREKZ" , "EINDT" , "SLFDT" ,   
        "LPEIN" , "EKET_MENGE" , "EKET_WEMNG" , "BANFN" , "BNFPO" , "MBDAT" ,   
        "WADAT" , "WEBRE" , "FRGRL" , "ZZKONNR" , "ZZKTPNR" , "MAHNZ" ,         
        "MAHN1" , "MAHN2" , "MAHN3" , "INFNR"                                   
      FROM                                                                      
        "ZPO_DETAIL"                                                            
      WHERE                                                                     
        "MANDT" = ? AND "EKORG" = ? AND "BSTYP" = ? AND "BSART" = ? AND         
        "WERKS" = ? AND "EINDT" < ? AND "EKPO_LOEKZ" <> ? AND "ELIKZ" <> ?      
      ORDER BY                                                                  
        "EBELN" , "EBELP" , "ETENR"                                             
    VIEW DETAILS
    CREATE VIEW ZPO_DETAIL          
       (MANDT,                      
       EBELN,                       
       EBELP,                       
       ETENR,                       
       EKKO_LOEKZ,                  
       BSTYP,                       
       BSART,                       
       BUKRS,                       
       EKORG,                       
       EKGRP,                       
       STATU,                       
       AEDAT,                       
       ERNAM,                       
       BEDAT,                       
       LIFNR,                       
       ADRNR,                       
       WAERS,                       
       EKPO_LOEKZ,                  
       EKPO_BSTYP,                  
       TXZ01,                       
       MATNR,                       
       EMATN,                       
    WERKS,              
    MATKL,              
    IDNLF,              
    MENGE,              
    MEINS,              
    NETPR,              
    NETWR,              
    PSTYP,              
    KNTTP,              
    WEPOS,              
    ANFNR,              
    PRDAT,              
    KONNR,              
    KTPNR,              
    ELIKZ,              
    EREKZ,              
    EINDT,              
    SLFDT,              
    LPEIN,              
    EKET_MENGE,         
    EKET_WEMNG,         
    BANFN,              
    BNFPO,              
       MBDAT,        
       WADAT,        
       WEBRE,        
       FRGRL,        
       ZZKONNR,      
       ZZKTPNR,      
       MAHNZ,        
       MAHN1,        
       MAHN2,        
       MAHN3 )       
    AS SELECT        
       T0003."MANDT",
        T0003."EBELN",
        T0003."EBELP",
        T0001."ETENR",
        T0002."LOEKZ",
        T0002."BSTYP",
        T0002."BSART",
        T0002."BUKRS",
        T0002."EKORG",
        T0002."EKGRP",
        T0002."STATU",
        T0002."AEDAT",
       T0002."ERNAM",
       T0002."BEDAT",
       T0002."LIFNR",
       T0002."ADRNR",
       T0002."WAERS",
       T0003."LOEKZ",
       T0003."BSTYP",
       T0003."TXZ01",
       T0003."MATNR",
       T0003."EMATN",
       T0003."WERKS",
       T0003."MATKL",
       T0003."IDNLF",
       T0003."MENGE",
       T0003."MEINS",
       T0003."NETPR",
       T0003."NETWR",
       T0003."PSTYP",
       T0003."KNTTP",
       T0003."WEPOS",
       T0003."ANFNR",
       T0003."PRDAT",
       T0003."KONNR",
        T0003."KTPNR",         
        T0003."ELIKZ",         
        T0003."EREKZ",         
        T0001."EINDT",         
        T0001."SLFDT",         
        T0001."LPEIN",         
        T0001."MENGE",         
        T0001."WEMNG",         
        T0001."BANFN",         
        T0001."BNFPO",         
        T0001."MBDAT",         
        T0001."WADAT",         
        T0003."WEBRE",         
        T0002."FRGRL",         
        T0003."ZZKONNR",       
        T0003."ZZKTPNR",       
        T0003."MAHNZ",         
        T0003."MAHN1",         
        T0003."MAHN2",         
        T0003."MAHN3"          
    FROM                       
       SAPCEP."EKET" T0001,    
        SAPCEP."EKKO" T0002,   
        SAPCEP."EKPO" T0003              
    WHERE                                
        T0002."MANDT" = T0003."MANDT" AND
        T0002."EBELN" = T0003."EBELN" AND
        T0003."MANDT" = T0001."MANDT" AND
        T0003."EBELN" = T0001."EBELN" AND
        T0003."EBELP" = T0001."EBELP"    
    EXPLAIN PLAN
    Execution Plan for SQL Optimizer
                                                                                    TABLENAME     COLUMN OR INDEX                STRATEGY                                     PAGECOUNT                                                                               
    T0003                                                             RANGE CONDITION FOR KEY         15758    
                             MANDT                                         (USED KEY COLUMN)   
    T0001                                                             JOIN VIA MULTIPLE KEY COLUMNS  8632    
                             MANDT                                          (USED KEY COLUMN)                                 
                             EBELN                                           (USED KEY COLUMN)    
    T0002                                                             JOIN VIA MULTIPLE KEY COLUMNS   40109    
                             MANDT                                          (USED KEY COLUMN)                                 
                             EBELN                                           (USED KEY COLUMN)                                 
                             EBELP                                           (USED KEY COLUMN)                                                                               
    NO TEMPORARY RESULTS CREATED                   
    SHOW                                                               RESULT IS COPIED   , COSTVALUE IS   31186  
    SHOW                                                          QUERYREWRITE - APPLIED RULES:                          
                       SHOW                                                             MergeFromSelectOrView                          1                                                                               
    The statistics are up-to-date.
    Any tips would be welcome.
    Thanks
    Doug

    > I have created an index EKET~Z1 with the column for table (T003)
    >       EINDT   
    >
    > and I have also tried another index EKKO~Z2 with the columns for table T001
    >       BSART
    >       BSTYP
    >       EKORG
    >
    SQL Statement                                                               
    >                                                                             
    >   SELECT                                                                    
    >     "MANDT" , "EBELN" , "EBELP" , "ETENR" , "EKKO_LOEKZ" , "BSTYP" ,        
    >   FROM                                                                      
    >     "ZPO_DETAIL"                                                            
    >   WHERE                                                                     
    >     "MANDT" = ? AND "EKORG" = ? AND "BSTYP" = ? AND "BSART" = ? AND         
    >     "WERKS" = ? AND "EINDT" < ? AND "EKPO_LOEKZ" <> ? AND "ELIKZ" <> ?      
    >   ORDER BY                                                                  
    >     "EBELN" , "EBELP" , "ETENR"                                             
    >
    > EXPLAIN PLAN
    > -
    >
    > Execution Plan for SQL Optimizer
    >                                                                               
    > TABLENAME     COLUMN OR INDEX                STRATEGY                                     PAGECOUNT     
    >                                                                               
    > T0003                                                             RANGE CONDITION FOR KEY         15758    
    >                          MANDT                                         (USED KEY COLUMN)   
    >                              
    > T0001                                                             JOIN VIA MULTIPLE KEY COLUMNS  8632    
    >                          MANDT                                          (USED KEY COLUMN)                                 
    >                          EBELN                                           (USED KEY COLUMN)    
    >                             
    > T0002                                                             JOIN VIA MULTIPLE KEY COLUMNS   40109    
    >                          MANDT                                          (USED KEY COLUMN)                                 
    >                          EBELN                                           (USED KEY COLUMN)                                 
    >                          EBELP                                           (USED KEY COLUMN)     
    >                            
    >                                                                          NO TEMPORARY RESULTS CREATED                   
    > SHOW                                                               RESULT IS COPIED   , COSTVALUE IS   31186  
    > SHOW                                                          QUERYREWRITE - APPLIED RULES:                          
    >                    SHOW                                                             MergeFromSelectOrView                          1    
    >                                                                               
    >
    > The statistics are up-to-date.
    > Any tips would be welcome.
    Hi Doug,
    here we go...
    What MaxDB version are you using? Did you check whether the DB parameters all comply to the recommendations?
    If so, what are the cardinalities of the columns you indexed (a.k.a. how many different values do each of them contain?)
    If the specification of BSART,  BSTYP and  EKORG does not reduce the number of rows to be retrieved to a large extent, then the indexaccess is likely to produce additional work.
    Anyhow, the join order looks a bit odd here - this might be the problem caused by having set OPTIMIZE_OPERATOR_JOIN_COSTFUNC = YES in a MaxDB version between 7.6.04 and 7.6.06.
    So make sure it's set to NO (see note 814704 MaxDB Version 7.6 parameter settings for OLTP/BW).
    regards,
    Lars

  • Performance tuning of sql query with multiple joins

    My query takes at least half an hour to execute and the number of records returned are approx 1 lakh records.
    Structure of tables are:
    tblSession : ID,option1,option2,option3,option4,option5,option6,option7,option8,option9.
    tblOption : ID, labelID
    tblLabelDetail  : ID, LABELID, text
    optionID 1 to optionID9 are Foreign keys to table tblOption.ID
    My query is as below : 
    select 
    session.ID 
    ,session.tstamp
    ,session.score
    ,session.hid1
    ,session.hID2
    ,session.hID3
    ,session.collectionID
    ,session.consumerID
    ,session.langID
    ,cons_cust.text1 as    customCons_text1, 
    cons_cust.text2 as customCons_text2, 
    cons_cust.text3 as customCons_text3,
    cons_cust.text4 as customCons_text4,
    cons_cust.text5 as customCons_text5,
    cons_cust.text6 as customCons_text6,
    cons_cust.text7 as customCons_text7,
    cons_cust.text8 as customCons_text8,
    cons_cust.text9 as customCons_text9,
    ld_cons1.text as customCons_option1GUID, 
    ld_cons2.text as customCons_option2GUID, 
    ld_cons3.text as customCons_option3GUID, 
    ld_cons4.text as customCons_option4GUID ,
    ld_cons5.text as customCons_option5GUID, 
    ld_cons6.text as customCons_option6GUID, 
    ld_cons7.text as customCons_option7GUID, 
    ld_cons8.text as customCons_option8GUID, 
    ld_cons9.text as customCons_option9GUID,
    --session
    session_cust.text1 as  session_cust_text1, 
    session_cust.text2 as session_cust_text2, 
    session_cust.text3 as session_cust_text3,
    session_cust.text4 as session_cust_text4,
    session_cust.text5 as session_cust_text5,
    session_cust.text6 as session_cust_text6,
    session_cust.text7 as session_cust_text7,
    session_cust.text8 as session_cust_text8,
    session_cust.text9 as session_cust_text9,
    ld_sess1.text as session_cust_option1GUID, 
    ld_sess2.text as session_cust_option2GUID, 
    ld_sess3.text as session_cust_option3GUID, 
    ld_sess4.text as session_cust_option4GUID, 
    ld_sess5.text as session_cust_option5GUID, 
    ld_sess6.text as session_cust_option6GUID, 
    ld_sess7.text as session_cust_option7GUID, 
    ld_sess8.text as session_cust_option8GUID, 
    ld_sess9.text as session_cust_option9GUID, 
    session_cust.tStamp1,
    session_cust.tStamp2
    from mvSession session with (noexpand)
    inner join tblCollection c on c.ID=session.collectionID AND c.templateID = 405
    left join tblConsumer cons on cons.ID=session.consumerID and cons.sessionYM between 601 and 1412 and cons.sID=105
    left join vCustomConsumer cons_cust on cons_cust.sessionYM between 601 and 1412 and cons_cust.sID=105 and cons_cust.ID=cons.ID
    left join tbloption o_cons1 on o_cons1.id = cons_cust.option1 and  o_cons1.sid = 105
    left join tblLabelDetail ld_cons1 on ld_cons1.labelID = o_cons1.labelID and ld_cons1.langId = 1 and ld_cons1.eid = 107 
    left join tbloption o_cons2 on o_cons2.id = cons_cust.option2 and  o_cons2.sid = 105
    left join tblLabelDetail ld_cons2 on ld_cons2.labelID = o_cons2.labelID and ld_cons2.langId = 1 and ld_cons2.eid = 107 
    left join tbloption o_cons3 on o_cons3.id = cons_cust.option3 and  o_cons3.sid = 105
    left join tblLabelDetail ld_cons3 on ld_cons3.labelID = o_cons1.labelID and ld_cons3.langId = 1 and ld_cons3.eid = 107 
    left join tbloption o_cons4 on o_cons4.id = cons_cust.option4 and  o_cons4.sid = 105
    left join tblLabelDetail ld_cons4 on ld_cons4.labelID = o_cons4.labelID and ld_cons4.langId = 1 and ld_cons4.eid = 107 
    left join tbloption o_cons5 on o_cons5.id = cons_cust.option5 and  o_cons5.sid = 105
    left join tblLabelDetail ld_cons5 on ld_cons5.labelID = o_cons5.labelID and ld_cons5.langId = 1 and ld_cons5.eid = 107 
    left join tbloption o_cons6 on o_cons6.id = cons_cust.option6 and  o_cons6.sid = 105
    left join tblLabelDetail ld_cons6 on ld_cons6.labelID = o_cons6.labelID and ld_cons6.langId = 1 and ld_cons6.eid = 107 
    left join tbloption o_cons7 on o_cons7.id = cons_cust.option7 and  o_cons7.sid = 105
    left join tblLabelDetail ld_cons7 on ld_cons7.labelID = o_cons7.labelID and ld_cons7.langId = 1 and ld_cons7.eid = 107 
    left join tbloption o_cons8 on o_cons8.id = cons_cust.option8 and  o_cons8.sid = 105
    left join tblLabelDetail ld_cons8 on ld_cons8.labelID = o_cons8.labelID and ld_cons8.langId = 1 and ld_cons8.eid = 107 
    left join tbloption o_cons9 on o_cons9.id = cons_cust.option9 and  o_cons9.sid = 105
    left join tblLabelDetail ld_cons9 on ld_cons9.labelID = o_cons9.labelID and ld_cons9.langId = 1 and ld_cons9.eid = 107 
    left join vCustomSession session_cust on session_cust.sessionYM between 601 and 1412 and session_cust.sID=105 and session_cust.ID=session.ID
    left join tbloption o_sess1 on o_sess1.id = session_cust.option1 and  o_sess1.sid = 105
    left join tblLabelDetail ld_sess1 on ld_sess1.labelID = o_sess1.labelID and ld_sess1.langId = 1 and ld_sess1.eid = 107 
    left join tbloption o_sess2 on o_sess2.id = session_cust.option2 and  o_sess2.sid = 105
    left join tblLabelDetail ld_sess2 on ld_sess2.labelID = o_sess2.labelID and ld_sess2.langId = 1 and ld_sess2.eid = 107 
    left join tbloption o_sess3 on o_sess2.id = session_cust.option3 and  o_sess3.sid = 105
    left join tblLabelDetail ld_sess3 on ld_sess3.labelID = o_sess2.labelID and ld_sess3.langId = 1 and ld_sess3.eid = 107 
    left join tbloption o_sess4 on o_sess4.id = session_cust.option4 and  o_sess4.sid = 105
    left join tblLabelDetail ld_sess4 on ld_sess4.labelID = o_sess4.labelID and ld_sess4.langId = 1 and ld_sess4.eid = 107 
    left join tbloption o_sess5 on o_sess5.id = session_cust.option5 and  o_sess5.sid = 105
    left join tblLabelDetail ld_sess5 on ld_sess5.labelID = o_sess5.labelID and ld_sess5.langId = 1 and ld_sess5.eid = 107 
    left join tbloption o_sess6 on o_sess6.id = session_cust.option6 and  o_sess6.sid = 105
    left join tblLabelDetail ld_sess6 on ld_sess6.labelID = o_sess6.labelID and ld_sess6.langId = 1 and ld_sess6.eid = 107 
    left join tbloption o_sess7 on o_sess7.id = session_cust.option7 and  o_sess7.sid = 105
    left join tblLabelDetail ld_sess7 on ld_sess7.labelID = o_sess7.labelID and ld_sess7.langId = 1 and ld_sess7.eid = 107 
    left join tbloption o_sess8 on o_sess8.id = session_cust.option8 and  o_sess8.sid = 105
    left join tblLabelDetail ld_sess8 on ld_sess8.labelID = o_sess8.labelID and ld_sess8.langId = 1 and ld_sess8.eid = 107 
    left join tbloption o_sess9 on o_sess9.id = session_cust.option9 and  o_sess9.sid = 105
    left join tblLabelDetail ld_sess9 on ld_sess9.labelID = o_sess9.labelID and ld_sess9.langId = 1 and ld_sess9.eid = 107 
    where session.sID=105  and session.tStamp >= 'Sep  1 2014 12:00AM' and session.tStamp < 'Dec 12 2014 12:00AM'   
    order by session.tStamp, session.ID
    Is there a way , where i can simplify the joins with tbloption and tblLabelDetail and get my o/p in optimal time.
    Regards 

    I have headed towards another approach ie. using unpivot and then pivot.
    First i am converting option1-option9 into column , then doing  PIVOT to get back the same record . But issue is that when i am doing pivoting i am getting NULL values.
    My query is :
    select * into #t1  from
    select ID
    , option1
    , option2
    , option3
    , option4
    , option5
    , option6
    , option7
    , option8
    , option9
    from vCustomConsumer
    where sid=105
    and sessionYM = 1412 
    ) SourceTable
    UNPIVOT
       optionID FOR Col IN
        (option1 
    ,option2
    ,option3 
    ,option4 
    ,option5 
    ,option6 
    ,option7 
    ,option8 
    ,option9 )
    ) AS unpvt
    select t.ID,t.optionID,t.col,cast(ld.text as varchar(max)) as text into #t2
    from #t1 t
    left outer join tbloption o on o.ID =  t.optionID
    left outer join tblLabelDetail ld on ld.labelID = o.labelID and ld.langID=1 
    order by ID,col
    select ID,option1 
    ,option2
    ,[option3]
    ,option4 
    ,option5 
    ,option6 
    ,option7 
    ,option8 
    ,option9
    from
    select ID,optionID,col,text
    from #t2
    )up
    pivot 
    min(text)for col in 
    (option1 
    ,option2
    ,[option3]
    ,option4 
    ,option5 
    ,option6 
    ,option7 
    ,option8 
    ,option9
    )as pvt
    In my last query where i am using pivot, i am getting NULL values. When i check the data in temp table #t2 , it exists perfectly . But when pivoting i dont understand why it is returning most of the NULL values. I am getting data for only one column in single
    row.
    Below are some rows from result set finally obtained after pivoting :
    ID
    option1
    option2
    option3
    option4
    option5
    option6
    option7
    option8
    option9
    62949026
    NULL
    0 to 200 seconds
    NULL
    NULL
    NULL
    NULL
    NULL
    NULL
    NULL
    62966000
    NULL
    NULL
    4
    NULL
    NULL
    NULL
    NULL
    NULL
    NULL
    62966032
    NULL
    NULL
    4
    NULL
    NULL
    NULL
    NULL
    NULL
    NULL
    63090372
    NULL
    NULL
    NULL
    NULL
    EN
    NULL
    NULL
    NULL
    NULL
    63090375
    NULL
    NULL
    NULL
    NULL
    EN
    NULL
    NULL
    NULL
    NULL
    Thanks,

  • Sql query with multiple joins to same table

    I have to write a query for a client to display business officers' names and title along with the business name
    The table looks like this
    AcctNumber
    OfficerTitle
    OfficerName
    RecKey
    90% of the businesses have exactly 4 officer records, although some have less and some have more.
    There is a separate table that has the AcctNumber, BusinessName about 30 other fields that I don’t need
    An individual account can have 30 or 40 records on the other table.
    The client wants to display 1 record per account.
    Initially I wrote a query to join the table to itself:
    Select A.OfficerTtitle, A.OfficerName, B.OfficerTitle, B.OfficerName, C.OfficerTtitle, C.OfficerName, D.OfficerTitle, D.OfficerName where A.AcctNumber = B.AcctNumber and A.AcctNumber = C.AcctNumber and A.AcctNumber = D.AcctNumber
    This returned tons of duplicate rows for each account ( number of records * number of records, I think)
    So added
    And A.RecKey > B.RecKey and B.RecKey > C. RecKey and C.RecKey . D.RecKey
    This works when there are exactly 4 records per account. If there are less than 4 records on the account it skips the account and if there are more than 4 records, it returns multiple rows.
    But when I try to l join this to the other table to get the business name, I get a row for every record on the other table
    I tried select distinct on the other table and the query runs for ever and never returns anything
    I tried outer joins and subqueries, but no luck so far. I was thinking maybe a subquery - if exists - because I don't know how many records there are on an account, but don't know how to structure that
    Any suggestions would be appreciated

    Welcome to the forum!
    user13319842 wrote:
    I have to write a query for a client to display business officers' names and title along with the business name
    The table looks like this
    AcctNumber
    OfficerTitle
    OfficerName
    RecKey
    90% of the businesses have exactly 4 officer records, although some have less and some have more.
    There is a separate table that has the AcctNumber, BusinessName about 30 other fields that I don’t need
    An individual account can have 30 or 40 records on the other table.
    The client wants to display 1 record per account.As someone has already mentioned, you should post CREATE TABLE and INSERT statements for both tables (relevant columns only). You don't have to post a lot of sample data. For example, you need to pick 1 out of 30 or 40 rows (max) for the same account, but it's almost certainly enough if you post only 3 or 4 rows (max) for an account.
    Also, post the results you want from the sample data that you post, and explain how you get those resutls from that data.
    Always say which version of Oracle you're using. This sounds like a PIVOT problem, and a new SELECT .... PIVOT feature was introduced in Oracle 11.1. If you're using Oracle 11, you don't want to have to learn the old way to do pivots. On the other hand, if you have Oracle 10, a solution that uses a new feature that you don't have won't help you.
    Whenever you have a question, please post CREATE TABLE and INSERT statements for some sample data, the results you want from that data, an explanation, and your Oracle version.
    Initially I wrote a query to join the table to itself:
    Select A.OfficerTtitle, A.OfficerName, B.OfficerTitle, B.OfficerName, C.OfficerTtitle, C.OfficerName, D.OfficerTitle, D.OfficerName where A.AcctNumber = B.AcctNumber and A.AcctNumber = C.AcctNumber and A.AcctNumber = D.AcctNumber Be careful, and post the exact code that you're running. The statement above can't be what you ran, because it doesn't have a FROM clause.
    This returned tons of duplicate rows for each account ( number of records * number of records, I think)
    So added
    And A.RecKey > B.RecKey and B.RecKey > C. RecKey and C.RecKey . D.RecKey
    This works when there are exactly 4 records per account. If there are less than 4 records on the account it skips the account and if there are more than 4 records, it returns multiple rows.
    But when I try to l join this to the other table to get the business name, I get a row for every record on the other table
    I tried select distinct on the other table and the query runs for ever and never returns anything
    I tried outer joins and subqueries, but no luck so far. I was thinking maybe a subquery - if exists - because I don't know how many records there are on an account, but don't know how to structure that
    Any suggestions would be appreciatedDisplaying 1 column from n rows as n columns on 1 row is called Pivoting . See the following link fro several ways to do pivots:
    SQL and PL/SQL FAQ
    Pivoting requires that you know exactly how many columns will be in the result set. If that number depends on the data in the table, then you might prefer to use String Aggregation , where the output consists of a huge string column, that contains the concatenation of the data from n rows. This big string can be formatted so that it looks like multiple columns. For different string aggregation techniques, see:
    http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
    The following thread discusses some options for pivoting a variable number of columns:
    Re: Report count and sum from many rows into many columns

  • MS SQL query slow using view column as criteria

    HI,
    I am experiencing a very frustrate problem. I have 2 tables, and create a view
    to union these 2 tables, when do a select on this view using the column of the
    view as criteria is took more 1 minutes, but the query runs fine in Qurey Analyzer.
    Anybody has the same experience? is this the problem with jdbc?

    I searched http://e-docs.bea.com/wls/docs70/index.html, also searched the documentation
    for wls6.1, wls5.1. As you pointed I searched support site, they are all the customer
    case, it's not formal documentation.
    Joe Weinstein <[email protected]> wrote:
    >
    >
    jen wrote:
    Thanks. but I search on the table is fine (the same column). is thereany db setting
    could be tuned? so the view is the problem? No, it's a client decision/issue. If you defined your tables to have
    nvarchar columns
    the jdbc driver's parameter values would be fine as-is.
    I searched "useVarChars" on whole
    site and can't find anything.Which site? This is a property of the weblogic.jdbc.mssqlserver4.Driver.
    I just went to www.bea.com/support and entered useVarChars in the Ask
    BEA
    question panel and got hits...
    Joe
    Joe Weinstein <[email protected]> wrote:
    Jen wrote:
    Sorry it's my bad. I am testing on wls81, but the problems is on wls70,so they
    are using different drivers.
    You are the magic man. It worked on wls81 now. I am sure it will curethe problem
    on wls70. Is there any documentation on this? Why it is not a problemon some
    databse server? ThanksSure. The issue has to do with the MS client-DBMS protocol having evolved
    from
    an 8-bit (7-bit really) character representation. Now it has a newer
    16-bit
    way, to transfer NVARCHAR data. Java characters are all 16-bit, so
    by default
    a JDBC driver will send Java parameters over as NVARCHAR data. This
    is
    crucial
    for Japanese data etc. However, once simple ASCII data is transformed
    to an
    NVARCHAR format, the DBMS can't directly compare it to varchar data,
    or use it
    in index searches. The DBMS has to convert the VARCHAR data to NVARCHAR,
    but it
    can't guarantee that the converted data will retain the same ordering
    as the index,
    so the DBMS has to do a table scan!
    The properties I suggested are each driver's way of allowing you
    to say "I'm
    a simple American ;) I am using simple varchar data so please sendmy
    java
    strings that way.". This allows the DBMS to use your varchar indexes
    in queries.
    Joe Weinstein at BEA
    Joe Weinstein <[email protected]> wrote:
    Jen wrote:
    It doesn't cure the problem. Here is my pool
    <JDBCConnectionPool DriverName="weblogic.jdbc.sqlserver.SQLServerDriver"Name="test_pool"
    Password="{3DES}fKSovViFe5kHzl/vTs0LVQ==" Properties="user=user;PortNumber=1543;useVarChars=true;ServerName=194.20.2.10;DatabaseName=devDB"
    Targets="admin" TestTableName="SQL SELECT COUNT(*) FROM sysobjects"URL="jdbc:bea:sqlserver://194.20.2.10:1543"/>
    Strange is some database is fine.Oh, sorry. I thought it was the older weblogic driver. Change the
    useVarChars=true to sendStringParametersAsUnicode=false
    Let me know... Also, I suggest changing the TestTableName to "SQL
    select
    1".
    For MS, that will be much more efficient than involving a full count
    of sysobjects!
    Joe
    Joe Weinstein <[email protected]> wrote:
    Jen wrote:
    You are right. Tadaa! Am I Kreskin, or what? ;) Here's what I recommend:
    In your pool definition, for this driver add a driver property:
    useVarChars=true
    and let me know if it's all better.
    Joe
    I am using weblogic jdbc driver weblogic.jdbc.mssqlserver4.Driver.
    here is the code:
    getData(Connection connection, String stmt, ArrayList arguments)
         PreparedStatement pStatement=null;>>>>>>>>     ResultSet resultSet=null;>>>>>>>>     try {>>>>>>>>         pStatement = connection.prepareStatement(stmt);>>>>>>>>         for (int i = 1; i <= arguments.size(); i++) {>>>>>>>>          pStatement.setString(i, (String) arguments.get(i-1));>>>>>>>>                    resultSet = pStatement.executeQuery(); //this statement takesmore than 1
    min.
    Joe Weinstein <[email protected]> wrote:
    Jen wrote:
    HI,
    I am experiencing a very frustrate problem. I have 2 tables,
    and
    create
    a view
    to union these 2 tables, when do a select on this view using
    the
    column
    of the
    view as criteria is took more 1 minutes, but the query runs
    fine
    in
    Qurey Analyzer.
    Anybody has the same experience? is this the problem with jdbc?
    I have suspicions... Show me the jdbc code. I'm guessing it's
    a
    PreparedStatement,
    and you send the search criterion column value as a parameter
    you
    set
    with a
    setString().... Let me know... (also let me know which jdbc driveryou're
    using).
    Joe

  • Question on Tuning SQL query

    We are converting from a 9i database to an 11g database.  The query defined works perfectly under 9i (about 1 second) but is taking 60-70 seconds to return in 11g.  The wierd thing is that it has an outer query and a subquery.  If I remove the where clause from the outer query it executes in less than a second.  Here is the query...
    SELECT period, biweek_start, biweek_end, pay_period_complete, worker_count
      FROM (SELECT to_char(en.start_date, 'yyyy/mm/dd') || ' to ' ||
                   to_char(en.start_date + 13, 'yyyy/mm/dd') period,
                   en.start_date biweek_start,
                   en.start_date + 13 biweek_end,
                   decode(sign(sysdate - en.start_date - 13),
                          -1,
                          'In Progress',
                          'Completed') pay_period_complete,
                   ta_mssauth_pkg.actual_endorser(en.start_date, '33811')  worker_count
              FROM (select worker_id,
                           default_endorser resolved_endorser,
                           effective_date,
                           expiration_date
                      from endorse_delegate_history_v
                     where default_endorser = '33811'
                    union
                    select worker_id,
                           temporary_delegate resolved_endorser,
                           effective_date,
                           expiration_date
                      from endorse_delegate_history_v
                     where temporary_delegate = '33811'
                       and temporary_delegate is not null ) de,
                   endorse_activity_v en
             WHERE en.worker_id = de.worker_id
               AND en.endorse_status = 'N'
               AND en.start_date <= de.expiration_date
               AND en.start_date + 13 >= de.effective_date
             GROUP BY en.start_date)
    WHERE worker_count > 0;
    The function that is used as part of the inner query to generate worker_counts is pretty complex.  But it runs subsecond if you run it manually.  And it works great when you run the query without the "where worker_count > 0" portion.
    So the where clause on the outer query seems to be causing the problem - it is based off a function that should have calculated a value FIRST then the outer query should run based on the result of the inner query.  Below are the explain plans for the two different versions:
    BAD QUERY - 60 - 70 Seconds
    Description Object Owner Object Name Cost Cardinality Bytes
    SELECT STATEMENT, GOAL = ALL_ROWS     617 1 41
    HASH GROUP BY     617 1 41
      NESTED LOOPS         
       NESTED LOOPS     616 1 41
        VIEW CA17062   58 186 4464
         SORT UNIQUE     58 186 5392
          UNION-ALL         
           TABLE ACCESS BY INDEX ROWID TAS_AUTH ENDORSE_DELEGATE_HISTORY_TBL 42 139 4170
            INDEX RANGE SCAN TAS_AUTH ENDORSE_DELEGATE_HIST_DEF_IDX 3 139 
           TABLE ACCESS BY INDEX ROWID TAS_AUTH ENDORSE_DELEGATE_HISTORY_TBL 14 47 1222
            INDEX RANGE SCAN TAS_AUTH ENDORSE_DELEGATE_HIST_TEMP_IDX 3 47 
        INDEX RANGE SCAN TAS_AUTH TA_SCLENDORSE_PK 2 1 
           TABLE ACCESS BY INDEX ROWID TAS_AUTH ENDORSE_ACTIVITY_TBL 3 1 17
    GOOD QUERY < 1 second
    Description Object Owner Object Name Cost Cardinality Bytes
    SELECT STATEMENT, GOAL = ALL_ROWS     617 25 1025
    HASH GROUP BY     617 25 1025
      NESTED LOOPS         
       NESTED LOOPS     616 25 1025
        VIEW CA17062   58 186 4464
         SORT UNIQUE     58 186 5392
          UNION-ALL         
           TABLE ACCESS BY INDEX ROWID TAS_AUTH ENDORSE_DELEGATE_HISTORY_TBL 42 139 4170
            INDEX RANGE SCAN TAS_AUTH ENDORSE_DELEGATE_HIST_DEF_IDX 3 139 
           TABLE ACCESS BY INDEX ROWID TAS_AUTH ENDORSE_DELEGATE_HISTORY_TBL 14 47 1222
            INDEX RANGE SCAN TAS_AUTH ENDORSE_DELEGATE_HIST_TEMP_IDX 3 47 
        INDEX RANGE SCAN TAS_AUTH TA_SCLENDORSE_PK 2 1 
       TABLE ACCESS BY INDEX ROWID TAS_AUTH ENDORSE_ACTIVITY_TBL 3 1 17
    So those expleain plans look pretty much identical to me - can anyone tell me why having the where clause on the outer query is causing so much trouble and how I can fix it?  I've tried using NO_MERGE and PUSH_SUBQ hints - but nothing that I have done has made the bad query any better.
    Thanks in advance!
    Cory

    I have traced the queries and attached the trace files here too...
    Here is the bad query...
    SQL ID: 0g07hqvjma217 Plan Hash: 0
    alter session set sql_trace = true
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      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        1      0.00       0.00          0          0          0           0
    Misses in library cache during parse: 0
    Misses in library cache during execute: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 331  (CA17062)
    SQL ID: 9m7787camwh4m Plan Hash: 0
    begin :id := sys.dbms_transaction.local_transaction_id; end;
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        3      0.00       0.00          0          0          0           0
    Execute      3      0.00       0.00          0          0          0           3
    Fetch        0      0.00       0.00          0          0          0           0
    total        6      0.00       0.00          0          0          0           3
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 331  (CA17062)
    SELECT period, biweek_start, biweek_end, pay_period_complete, worker_count
      FROM (SELECT to_char(en.start_date, 'yyyy/mm/dd') || ' to ' ||
                   to_char(en.start_date + 13, 'yyyy/mm/dd') period,
                   en.start_date biweek_start,
                   en.start_date + 13 biweek_end,
                   decode(sign(sysdate - en.start_date - 13),
                          -1,
                          'In Progress',
                          'Completed') pay_period_complete,
                   ta_mssauth_pkg.actual_endorser(en.start_date, '33811')  worker_count
              FROM (select worker_id,
                           default_endorser resolved_endorser,
                           effective_date,
                           expiration_date
                      from endorse_delegate_history_v
                     where default_endorser = '33811'
                    union
                    select worker_id,
                           temporary_delegate resolved_endorser,
                           effective_date,
                           expiration_date
                      from endorse_delegate_history_v
                     where temporary_delegate = '33811'
                       and temporary_delegate is not null ) de,
                   endorse_activity_v en
             WHERE en.worker_id = de.worker_id
               AND en.endorse_status = 'N'
               AND en.start_date <= de.expiration_date
               AND en.start_date + 13 >= de.effective_date
             GROUP BY en.start_date)
    WHERE worker_count > 0
    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      6.11      14.77         38        455          0           6
    total        3      6.11      14.77         38        455          0           6
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 331  (CA17062)
    Number of plan statistics captured: 1
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
             6          6          6  HASH GROUP BY (cr=9330657 pr=826 pw=0 time=86392712 us cost=698 size=41 card=1)
            21         21         21   NESTED LOOPS  (cr=9330657 pr=826 pw=0 time=18442971 us)
            49         49         49    NESTED LOOPS  (cr=9330609 pr=826 pw=0 time=26482026 us cost=697 size=41 card=1)
           213        213        213     VIEW  (cr=32 pr=32 pw=0 time=851827 us cost=58 size=5112 card=213)
           213        213        213      SORT UNIQUE (cr=32 pr=32 pw=0 time=850864 us cost=58 size=5598 card=213)
           213        213        213       UNION-ALL  (cr=32 pr=32 pw=0 time=4390885 us)
            15         15         15        TABLE ACCESS BY INDEX ROWID ENDORSE_DELEGATE_HISTORY_TBL (cr=10 pr=10 pw=0 time=718114 us c)
            15         15         15         INDEX RANGE SCAN ENDORSE_DELEGATE_HIST_DEF_IDX (cr=3 pr=3 pw=0 time=119582 us cost=3 size=)
           198        198        198        TABLE ACCESS BY INDEX ROWID ENDORSE_DELEGATE_HISTORY_TBL (cr=22 pr=22 pw=0 time=7328583 us )
           198        198        198         INDEX RANGE SCAN ENDORSE_DELEGATE_HIST_TEMP_IDX (cr=3 pr=3 pw=0 time=107110 us cost=3 size)
            49         49         49     INDEX RANGE SCAN TA_SCLENDORSE_PK (cr=9330577 pr=794 pw=0 time=157121745 us cost=2 size=0 card)
            21         21         21    TABLE ACCESS BY INDEX ROWID ENDORSE_ACTIVITY_TBL (cr=48 pr=0 pw=0 time=493 us cost=3 size=17 ca)
    Rows     Execution Plan
          0  SELECT STATEMENT   MODE: ALL_ROWS
          6   HASH (GROUP BY)
         21    NESTED LOOPS
         49     NESTED LOOPS
        213      VIEW
        213       SORT (UNIQUE)
        213        UNION-ALL
         15         TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF
                        'ENDORSE_DELEGATE_HISTORY_TBL' (TABLE)
         15          INDEX   MODE: ANALYZED (RANGE SCAN) OF
                         'ENDORSE_DELEGATE_HIST_DEF_IDX' (INDEX)
        198         TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF
                        'ENDORSE_DELEGATE_HISTORY_TBL' (TABLE)
        198          INDEX   MODE: ANALYZED (RANGE SCAN) OF
                         'ENDORSE_DELEGATE_HIST_TEMP_IDX' (INDEX)
         49      INDEX   MODE: ANALYZED (RANGE SCAN) OF 'TA_SCLENDORSE_PK'
                     (INDEX (UNIQUE))
         21     TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF
                    'ENDORSE_ACTIVITY_TBL' (TABLE)
    SQL ID: gwpkaabt9naxy Plan Hash: 2668568437
    SELECT DISTINCT DE.WORKER_ID
    FROM
    ENDORSE_DELEGATE_HISTORY_V DE , ENDORSE_ACTIVITY_V EN ,
      WORKER_ACTIVITY_AUTH_V EA WHERE DE.WORKER_ID = EN.WORKER_ID AND
      EN.WORKER_ID = EA.WORKER_ID AND EN.START_DATE = :B2 AND EN.ENDORSE_STATUS =
      'N' AND EA.ACTIVITY_DATE >= EN.START_DATE AND EA.ACTIVITY_DATE <=
      EN.START_DATE + 13 AND EN.START_DATE <= DE.EXPIRATION_DATE AND
      EN.START_DATE + 13 >= DE.EFFECTIVE_DATE AND (DE.DEFAULT_ENDORSER = :B1 OR
      DE.TEMPORARY_DELEGATE = :B1 ) ORDER BY DE.WORKER_ID
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute  24015      0.97       1.50          0          0          0           0
    Fetch    24015     56.38     132.62        593    9318744          0         285
    total    48031     57.35     134.12        593    9318744          0         285
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 3054  (TAS_AUTH)   (recursive depth: 1)
    Number of plan statistics captured: 1
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
             0          0          0  SORT UNIQUE (cr=407 pr=43 pw=0 time=1057475 us cost=805 size=83 card=1)
             0          0          0   NESTED LOOPS  (cr=407 pr=43 pw=0 time=1057453 us cost=804 size=17347 card=209)
             0          0          0    HASH JOIN RIGHT ANTI (cr=407 pr=43 pw=0 time=1057442 us cost=804 size=16511 card=209)
            19         19         19     INDEX RANGE SCAN INDACC_02X (cr=1 pr=0 pw=0 time=78 us cost=1 size=114 card=19)(object id 5403)
             0          0          0     NESTED LOOPS  (cr=406 pr=43 pw=0 time=1055235 us)
             0          0          0      NESTED LOOPS  (cr=406 pr=43 pw=0 time=1055231 us cost=803 size=19856 card=272)
             0          0          0       NESTED LOOPS  (cr=406 pr=43 pw=0 time=1055226 us cost=431 size=350 card=7)
           186        186        186        TABLE ACCESS BY INDEX ROWID ENDORSE_DELEGATE_HISTORY_TBL (cr=32 pr=0 pw=0 time=4375 us cost)
           213        213        213         BITMAP CONVERSION TO ROWIDS (cr=6 pr=0 pw=0 time=759 us)
             1          1          1          BITMAP OR  (cr=6 pr=0 pw=0 time=533 us)
             1          1          1           BITMAP CONVERSION FROM ROWIDS (cr=3 pr=0 pw=0 time=178 us)
            15         15         15            SORT ORDER BY (cr=3 pr=0 pw=0 time=152 us)
            15         15         15             INDEX RANGE SCAN ENDORSE_DELEGATE_HIST_DEF_IDX (cr=3 pr=0 pw=0 time=62 us cost=3 size=)
             1          1          1           BITMAP CONVERSION FROM ROWIDS (cr=3 pr=0 pw=0 time=328 us)
           198        198        198            SORT ORDER BY (cr=3 pr=0 pw=0 time=319 us)
           198        198        198             INDEX RANGE SCAN ENDORSE_DELEGATE_HIST_TEMP_IDX (cr=3 pr=0 pw=0 time=214 us cost=3 siz)
             0          0          0        TABLE ACCESS BY INDEX ROWID ENDORSE_ACTIVITY_TBL (cr=374 pr=43 pw=0 time=1052137 us cost=2 )
             0          0          0         INDEX UNIQUE SCAN TA_SCLENDORSE_PK (cr=374 pr=43 pw=0 time=1051749 us cost=1 size=0 card=1)
             0          0          0       INDEX RANGE SCAN WORKER_ACTIVITY_WRKR_IX (cr=0 pr=0 pw=0 time=0 us cost=2 size=0 card=90)(ob)
             0          0          0      TABLE ACCESS BY INDEX ROWID WORKER_ACTIVITY_TBL (cr=0 pr=0 pw=0 time=0 us cost=53 size=943 ca)
             0          0          0    INDEX UNIQUE SCAN SCHEDULE_PK (cr=0 pr=0 pw=0 time=0 us cost=0 size=4 card=1)(object id 54342)
    Rows     Execution Plan
          0  SELECT STATEMENT   MODE: ALL_ROWS
          0   SORT (UNIQUE)
          0    CONCATENATION
          0     NESTED LOOPS (ANTI)
         19      NESTED LOOPS
          0       NESTED LOOPS
          0        NESTED LOOPS
          0         TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF
                        'ENDORSE_DELEGATE_HISTORY_TBL' (TABLE)
        186          INDEX   MODE: ANALYZED (RANGE SCAN) OF
                         'ENDORSE_DELEGATE_HIST_TEMP_IDX' (INDEX)
        213         TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF
                        'ENDORSE_ACTIVITY_TBL' (TABLE)
          1          INDEX   MODE: ANALYZED (UNIQUE SCAN) OF
                         'TA_SCLENDORSE_PK' (INDEX (UNIQUE))
          1        TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF
                       'WORKER_ACTIVITY_TBL' (TABLE)
         15         INDEX   MODE: ANALYZED (RANGE SCAN) OF
                        'WORKER_ACTIVITY_WRKR_IX' (INDEX)
         15       INDEX   MODE: ANALYZED (UNIQUE SCAN) OF 'SCHEDULE_PK'
                      (INDEX (UNIQUE))
          1      INDEX   MODE: ANALYZED (RANGE SCAN) OF 'INDACC_02X' (INDEX)
        198     NESTED LOOPS (ANTI)
        198      NESTED LOOPS
          0       NESTED LOOPS
          0        NESTED LOOPS
          0         TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF
                        'ENDORSE_DELEGATE_HISTORY_TBL' (TABLE)
          0          INDEX   MODE: ANALYZED (RANGE SCAN) OF
                         'ENDORSE_DELEGATE_HIST_DEF_IDX' (INDEX)
          0         TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF
                        'ENDORSE_ACTIVITY_TBL' (TABLE)
          0          INDEX   MODE: ANALYZED (UNIQUE SCAN) OF
                         'TA_SCLENDORSE_PK' (INDEX (UNIQUE))
          0        TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF
                       'WORKER_ACTIVITY_TBL' (TABLE)
          0         INDEX   MODE: ANALYZED (RANGE SCAN) OF
                        'WORKER_ACTIVITY_WRKR_IX' (INDEX)
          0       INDEX   MODE: ANALYZED (UNIQUE SCAN) OF 'SCHEDULE_PK'
                      (INDEX (UNIQUE))
          0      INDEX   MODE: ANALYZED (RANGE SCAN) OF 'INDACC_02X' (INDEX)
    SQL ID: 7v8ndut1y3b99 Plan Hash: 2002979989
    SELECT DEFAULT_ENDORSER
    FROM
    ( SELECT DEFAULT_ENDORSER FROM ENDORSE_DELEGATE_HISTORY_V WHERE WORKER_ID =
      :B3 AND TEMPORARY_DELEGATE IS NULL AND :B2 <= EXPIRATION_DATE AND :B1 >=
      EFFECTIVE_DATE ORDER BY EXPIRATION_DATE DESC ) WHERE ROWNUM = 1
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute    285      0.00       0.01          0          0          0           0
    Fetch      285      0.11       3.24        195      13078          0         285
    total      571      0.11       3.26        195      13078          0         285
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 3054  (TAS_AUTH)   (recursive depth: 1)
    Number of plan statistics captured: 1
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
             1          1          1  COUNT STOPKEY (cr=22 pr=20 pw=0 time=576320 us)
             1          1          1   VIEW  (cr=22 pr=20 pw=0 time=576285 us cost=23 size=72 card=12)
             1          1          1    SORT ORDER BY STOPKEY (cr=22 pr=20 pw=0 time=576273 us cost=23 size=396 card=12)
             2          2          2     TABLE ACCESS BY INDEX ROWID ENDORSE_DELEGATE_HISTORY_TBL (cr=22 pr=20 pw=0 time=576205 us cost)
            20         20         20      INDEX RANGE SCAN ENDORSE_DELEGATE_HIST_PK (cr=3 pr=3 pw=0 time=197569 us cost=3 size=0 card=1)
    Rows     Execution Plan
          0  SELECT STATEMENT   MODE: ALL_ROWS
          1   COUNT (STOPKEY)
          1    VIEW
          1     SORT (ORDER BY STOPKEY)
          2      TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF
                     'ENDORSE_DELEGATE_HISTORY_TBL' (TABLE)
         20       INDEX   MODE: ANALYZED (RANGE SCAN) OF
                      'ENDORSE_DELEGATE_HIST_PK' (INDEX (UNIQUE))
    SQL ID: cf06fwacdmgfk Plan Hash: 1546270724
    select 'x'
    from
    dual
    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      0.00       0.00          0          0          0           1
    total        3      0.00       0.00          0          0          0           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 331  (CA17062)
    Number of plan statistics captured: 1
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
             1          1          1  FAST DUAL  (cr=0 pr=0 pw=0 time=6 us cost=2 size=0 card=1)
    Rows     Execution Plan
          0  SELECT STATEMENT   MODE: ALL_ROWS
          1   FAST DUAL
    OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        5      0.00       0.00          0          0          0           0
    Execute      6      0.00       0.00          0          0          0           3
    Fetch        2      6.11      14.77         38        455          0           7
    total       13      6.11      14.77         38        455          0          10
    Misses in library cache during parse: 0
    Misses in library cache during execute: 1
    OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        2      0.00       0.00          0          0          0           0
    Execute  24300      0.97       1.51          0          0          0           0
    Fetch    24300     56.49     135.87        788    9331822          0         570
    total    48602     57.46     137.39        788    9331822          0         570
    Misses in library cache during parse: 0
        6  user  SQL statements in session.
        0  internal SQL statements in session.
        6  SQL statements in session.
        4  statements EXPLAINed in this session.
    Trace file: TAST_ora_26885.trc
    Trace file compatibility: 11.1.0.7
    Sort options: default
           1  session in tracefile.
           6  user  SQL statements in trace file.
           0  internal SQL statements in trace file.
           6  SQL statements in trace file.
           6  unique SQL statements in trace file.
           4  SQL statements EXPLAINed using schema:
               dbo.plan_table
                 Schema was specified.
                 Existing table was used.
       73341  lines in trace file.
         178  elapsed seconds in trace file.
    Here is the good query
    SQL ID: 0g07hqvjma217 Plan Hash: 0
    alter session set sql_trace = true
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        0      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        1      0.00       0.00          0          0          0           0
    Misses in library cache during parse: 0
    Misses in library cache during execute: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 331  (CA17062)
    SQL ID: 9m7787camwh4m Plan Hash: 0
    begin :id := sys.dbms_transaction.local_transaction_id; end;
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        3      0.00       0.00          0          0          0           0
    Execute      3      0.00       0.00          0          0          0           3
    Fetch        0      0.00       0.00          0          0          0           0
    total        6      0.00       0.00          0          0          0           3
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 331  (CA17062)
    SELECT period, biweek_start, biweek_end, pay_period_complete, worker_count
      FROM (SELECT to_char(en.start_date, 'yyyy/mm/dd') || ' to ' ||
                   to_char(en.start_date + 13, 'yyyy/mm/dd') period,
                   en.start_date biweek_start,
                   en.start_date + 13 biweek_end,
                   decode(sign(sysdate - en.start_date - 13),
                          -1,
                          'In Progress',
                          'Completed') pay_period_complete,
                   ta_mssauth_pkg.actual_endorser(en.start_date, '33811')  worker_count
              FROM (select worker_id,
                           default_endorser resolved_endorser,
                           effective_date,
                           expiration_date
                      from endorse_delegate_history_v
                     where default_endorser = '33811'
                    union
                    select worker_id,
                           temporary_delegate resolved_endorser,
                           effective_date,
                           expiration_date
                      from endorse_delegate_history_v
                     where temporary_delegate = '33811'
                       and temporary_delegate is not null ) de,
                   endorse_activity_v en
             WHERE en.worker_id = de.worker_id
               AND en.endorse_status = 'N'
               AND en.start_date <= de.expiration_date
               AND en.start_date + 13 >= de.effective_date
             GROUP BY en.start_date)
    -- WHERE worker_count > 0
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.02       0.03          0          0          0           0
    Execute      1      0.00       0.00          0          0          0           0
    Fetch        1      0.02       0.13          0        841          0           6
    total        3      0.04       0.16          0        841          0           6
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 331  (CA17062)
    Number of plan statistics captured: 1
    Rows (1st) Rows (avg) Rows (max)  Row Source Operation
             6          6          6  HASH GROUP BY (cr=841 pr=0 pw=0 time=79927 us cost=617 size=1025 card=25)
            21         21         21   NESTED LOOPS  (cr=841 pr=0 pw=0 time=15116 us)
           451        451        451    NESTED LOOPS  (cr=409 pr=0 pw=0 time=33039 us cost=616 size=1025 card=25)
           213        213        213     VIEW  (cr=32 pr=0 pw=0 time=12117 us cost=58 size=4464 card=186)
           213        213        213      SORT UNIQUE (cr=32 pr=0 pw=0 time=12005 us cost=58 size=5392 card=186)
           213        213        213       UNION-ALL  (cr=32 pr=0 pw=0 time=1313 us)
            15         15         15        TABLE ACCESS BY INDEX ROWID ENDORSE_DELEGATE_HISTORY_TBL (cr=10 pr=0 pw=0 time=245 us cost=4
    2 size=4170 card=139)
            15         15         15         INDEX RANGE SCAN ENDORSE_DELEGATE_HIST_DEF_IDX (cr=3 pr=0 pw=0 time=122 us cost=3 size=0 ca
    rd=139)(object id 54559)
           198        198        198        TABLE ACCESS BY INDEX ROWID ENDORSE_DELEGATE_HISTORY_TBL (cr=22 pr=0 pw=0 time=427 us cost=1
    4 size=1222 card=47)
           198        198        198         INDEX RANGE SCAN ENDORSE_DELEGATE_HIST_TEMP_IDX (cr=3 pr=0 pw=0 time=222 us cost=3 size=0 c
    ard=47)(object id 54560)
           451        451        451     INDEX RANGE SCAN TA_SCLENDORSE_PK (cr=377 pr=0 pw=0 time=63328 us cost=2 size=0 card=1)(object
    id 54553)
            21         21         21    TABLE ACCESS BY INDEX ROWID ENDORSE_ACTIVITY_TBL (cr=432 pr=0 pw=0 time=2185 us cost=3 size=17 c
    ard=1)
    Rows     Execution Plan
          0  SELECT STATEMENT   MODE: ALL_ROWS
          6   HASH (GROUP BY)
         21    NESTED LOOPS
        451     NESTED LOOPS
        213      VIEW
        213       SORT (UNIQUE)
        213        UNION-ALL
         15         TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF
                        'ENDORSE_DELEGATE_HISTORY_TBL' (TABLE)
         15          INDEX   MODE: ANALYZED (RANGE SCAN) OF
                         'ENDORSE_DELEGATE_HIST_DEF_IDX' (INDEX)
        198         TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF
                        'ENDORSE_DELEGATE_HISTORY_TBL' (TABLE)
        198          INDEX   MODE: ANALYZED (RANGE SCAN) OF
                         'ENDORSE_DELEGATE_HIST_TEMP_IDX' (INDEX)
        451      INDEX   MODE: ANALYZED (RANGE SCAN) OF 'TA_SCLENDORSE_PK'
                     (INDEX (UNIQUE))
         21     TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF
                    'ENDORSE_ACTIVITY_TBL' (TABLE)
    SQL ID: gwpkaabt9naxy Plan Hash: 2668568437
    SELECT DISTINCT DE.WORKER_ID
    FROM
    ENDORSE_DELEGATE_HISTORY_V DE , ENDORSE_ACTIVITY_V EN ,
      WORKER_ACTIVITY_AUTH_V EA WHERE DE.WORKER_ID = EN.WORKER_ID AND
      EN.WORKER_ID = EA.WORKER_ID AND EN.START_DATE = :B2 AND EN.ENDORSE_STATUS =
      'N' AND EA.ACTIVITY_DATE >= EN.START_DATE AND EA.ACTIVITY_DATE <=
      EN.START_DATE + 13 AND EN.START_DATE <= DE.EXPIRATION_DATE AND
      EN.START_DATE + 13 >= DE.EFFECTIVE_DATE AND (DE.DEFAULT_ENDORSER = :B1 OR
      DE.TEMPORARY_DELEGATE = :B1 ) ORDER BY DE.WORKER_ID
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      6      0.01       0.00          0          0          0           0
    Fetch        6      0.01       0.01          0        700      

Maybe you are looking for

  • 9320 Curve not being recognized by Windows Vista - Vista Drivers available?

    Hi I have recently acquired a Blackberry 9320 but when I connect it to my Vista PC, the PC recognises there is new hardware but is unable to locate any drivers for it.  As a result, the Blackberry Desktop Media Application can't connect to it.  The P

  • How do I get iTunes to display updates?

    Ipad says I have 5 updates, but it won't display them in iTunes.  Why?  How do I get this to work so I can do the updates?

  • Performance tuning - Hints

    Hi Experts, I am new to oracle database  developer. currently i am leraning the performance tuning. I have a question that is it a good practice to use hint as having using oracle database version 10g. some where i have read and also some Senior memb

  • Rotation glitch?

    I'm a bit lost on why AE is doing this. I create a null object and make it a 3d layer. I rotate it 90 degrees on the Y axis and then start rotation the X, and Z axis and they do the exact same thing. whats the deal?

  • Nikon dust off plug-in

    Is there a way, either in PS (CS3) or Bridge to read or utilize Nikon Dust Off Reference Photos (*.ndf) to minimize the impact of dust on the camera's sensor (D-200)?