SQL query slow with call to function

I have a SQL query that will return in less than a second or two with a function in-line selected in the "from" clause of the statement. As soon as I select that returned value in the SQL statement, the statement takes from anywhere from 2 to 5 minutes to return. Here is a simplified sample from the statement:
This statement returns in a second or 2.
select A.pk_id
from stu_schedule A, stu_school B, stu_year C, school_year D,
(select calc_ytd_class_abs2(Z.PK_ID,'U') ytd_unx
from stu_schedule Z) II
where B.pk_id = A.fk_stu_school
and C.pk_id = B.fk_stu_year
and D.pk_id = C.year
and D.school_year = '2011';
if I add this function call in, the statement runs extremely poor.
select A.pk_id,
II.ytd_unx
from stu_schedule A, stu_school B, stu_year C, school_year D,
(select calc_ytd_class_abs2(Z.PK_ID,'U') ytd_unx
from stu_schedule Z) II
where B.pk_id = A.fk_stu_school
and C.pk_id = B.fk_stu_year
and D.pk_id = C.year
and D.school_year = '2011';
Here is the function that is called:
create or replace FUNCTION calc_ytd_class_abs2 (p_fk_stu_schedule in varchar2,
p_legality in varchar2) return number IS
l_days_absent number := 0;
CURSOR get_class_abs IS
select (select nvl(max(D.days_absent),'0')
from cut_code D
where D.pk_id = C.fk_cut_code
and (D.legality = p_legality
or p_legality = '%')) days_absent
from stu_schedule_detail B, stu_class_attendance C
where B.fk_stu_schedule = p_fk_stu_schedule
and C.fk_stu_schedule_detail = B.pk_id;
BEGIN
FOR x in get_class_abs LOOP
l_days_absent := l_days_absent + x.days_absent;
END LOOP;
return (l_days_absent);
END calc_ytd_class_abs2;

Query returns anywhere from 6000 to 32000 rows. For each of those rows a parameter is passed in to 4 different functions to get ytd totals. When I call the functions in the in-line view but do not select from them in the main SQL, the report (oh, this is Application Express 4.0 interactive reports, just an FYI) runs fast. The report comes back in a few seconds. But when I select from the in-line view to display those ytd totals, the report runs extremely slow. I know there are the articles about context switching and how mixing SQL with PL/SQL performs poorly. So I tried a pipeline table function where the function for the ytd totals populate the columns of the pipeline table and I select from the pipeline table in the SQL query in the interactive report. That seemed to perform a little worse from what I can tell.
Thanks for any help you can offer.

Similar Messages

  • Sql query slowness due to rank and columns with null values:

        
    Sql query slowness due to rank and columns with null values:
    I have the following table in database with around 10 millions records:
    Declaration:
    create table PropertyOwners (
    [Key] int not null primary key,
    PropertyKey int not null,    
    BoughtDate DateTime,    
    OwnerKey int null,    
    GroupKey int null   
    go
    [Key] is primary key and combination of PropertyKey, BoughtDate, OwnerKey and GroupKey is unique.
    With the following index:
    CREATE NONCLUSTERED INDEX [IX_PropertyOwners] ON [dbo].[PropertyOwners]    
    [PropertyKey] ASC,   
    [BoughtDate] DESC,   
    [OwnerKey] DESC,   
    [GroupKey] DESC   
    go
    Description of the case:
    For single BoughtDate one property can belong to multiple owners or single group, for single record there can either be OwnerKey or GroupKey but not both so one of them will be null for each record. I am trying to retrieve the data from the table using
    following query for the OwnerKey. If there are same property rows for owners and group at the same time than the rows having OwnerKey with be preferred, that is why I am using "OwnerKey desc" in Rank function.
    declare @ownerKey int = 40000   
    select PropertyKey, BoughtDate, OwnerKey, GroupKey   
    from (    
    select PropertyKey, BoughtDate, OwnerKey, GroupKey,       
    RANK() over (partition by PropertyKey order by BoughtDate desc, OwnerKey desc, GroupKey desc) as [Rank]   
    from PropertyOwners   
    ) as result   
    where result.[Rank]=1 and result.[OwnerKey]=@ownerKey
    It is taking 2-3 seconds to get the records which is too slow, similar time it is taking as I try to get the records using the GroupKey. But when I tried to get the records for the PropertyKey with the same query, it is executing in 10 milliseconds.
    May be the slowness is due to as OwnerKey/GroupKey in the table  can be null and sql server in unable to index it. I have also tried to use the Indexed view to pre ranked them but I can't use it in my query as Rank function is not supported in indexed
    view.
    Please note this table is updated once a day and using Sql Server 2008 R2. Any help will be greatly appreciated.

    create table #result (PropertyKey int not null, BoughtDate datetime, OwnerKey int null, GroupKey int null, [Rank] int not null)Create index idx ON #result(OwnerKey ,rnk)
    insert into #result(PropertyKey, BoughtDate, OwnerKey, GroupKey, [Rank])
    select PropertyKey, BoughtDate, OwnerKey, GroupKey,
    RANK() over (partition by PropertyKey order by BoughtDate desc, OwnerKey desc, GroupKey desc) as [Rank]
    from PropertyOwners
    go
    declare @ownerKey int = 1
    select PropertyKey, BoughtDate, OwnerKey, GroupKey
    from #result as result
    where result.[Rank]=1
    and result.[OwnerKey]=@ownerKey
    go
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Sql query slow in new redhat enviornment

    We just migrated to a new dev environment in Linux REDHAT5, and now the query is very slow, and I used the TOAD to run the query, it took like 700 msecond to finish, however from any server connection, the sql query takes hours to finish.
    I checked toad monitor, it said need to increase db_buffer_cache and shared pool too small.
    Also three red alert from toad is:
    1. Library Cache get hit ratio: Dynamic or unsharable sql
    2. Chained fetch ratio: PCT free too low for a table
    3. parse to execute ratio: HIgh parse to execute ratio.
    App team said it ran real quick in the old AIX system, however I ran it in old system, and monitored in the toad, it gave me all same 5 red alerts in old system, and it did provide query results a lot quicker though.
    Here is the parameters in the old system (11gr1 on AIX):
    SQL> show parameter target
    NAME TYPE VALUE
    -------------------------------- archive_lag_target integer 0
    db_flashback_retention_target integer 1440
    fast_start_io_target integer 0
    fast_start_mttr_target integer 0
    memory_max_target big integer 0
    memory_target big integer 0
    pga_aggregate_target big integer 278928K
    sga_target big integer 0
    SQL> show parameter shared
    NAME TYPE VALUE
    -------------------------------- hi_shared_memory_address integer 0
    max_shared_servers integer
    shared_memory_address integer 0
    shared_pool_reserved_size big integer 31876710
    shared_pool_size big integer 608M
    shared_server_sessions integer
    shared_servers integer 0
    SQL> show parameter db_buffer
    SQL> show parameter buffer
    NAME TYPE VALUE
    -------------------------------- buffer_pool_keep string
    buffer_pool_recycle string
    db_block_buffers integer 0
    log_buffer integer 2048000
    use_indirect_data_buffers boolean FALSE
    SQL>
    In new 11gr2 Linux REDHAT parameter:
    NAME TYPE VALUE
    ----------- archive_lag_target integer 0
    db_flashback_retention_target integer 1440
    fast_start_io_target integer 0
    fast_start_mttr_target integer 0
    memory_max_target big integer 2512M
    memory_target big integer 2512M
    parallel_servers_target integer 192
    pga_aggregate_target big integer 0
    sga_target big integer 1648M
    SQL> show parameter shared
    NAME TYPE VALUE
    ----------- hi_shared_memory_address integer 0
    max_shared_servers integer
    shared_memory_address integer 0
    shared_pool_reserved_size big integer 28M
    shared_pool_size big integer 0
    shared_server_sessions integer
    shared_servers integer 1
    SQL> show parameter buffer
    NAME TYPE VALUE
    ----------- buffer_pool_keep string
    buffer_pool_recycle string
    db_block_buffers integer 0
    log_buffer integer 18857984
    use_indirect_data_buffers boolean FALSE
    SQL>
    Please help. Thanks in advance.

    846422 wrote:
    why need ddl? we have a sql query slow.The DDL shows the physical structure of the table and physical storage characteristics. All relevant in performance tuning.
    As for the SQL query being slow. It is not.
    You have not provided any evidence that it is slow. And no, comparing performance with a totally different system is not a valid baseline for comparison. (most cars have 4 wheels, a gearbox and a steering wheel - but that does not mean you can compare different cars like a VW Beetle with a VW Porsche)
    What is slow? What are the biggest wait states for the SQL? What does the execution plan say?
    You have not defined a problem - you identified a symptom called "+query is slow+". You need to diagnose the condition by determining exactly what the SQL qeury is doing in the database. (and please, do not use TOAD and similar tools in an attempt to do this - do it properly instead)

  • Passing arrays with Call Library Function does not work after application builder

    Calling a DLL with Call Library Function which requires an array of data works correctly in Labview, but after building an exe with application builder, the call no longer works.  Dereferecing the pointer in the DLL retuns all 0s and not the actual values.
    Solved!
    Go to Solution.
    Attachments:
    TEST.zip ‏28 KB

    I did not run your code because it is a little unclear to me what it does.
    Two things:
    First, is the DLL you are calling the DLL-ified version of PopUpNames.vi? Then the problem is likely that the panel is not being built into the DLL.
    When LabView builds an application / dll, it strips the front panel and block diagram from all VIs that it doesn't think need to show a panel at run time. This reduces file size and increases code security. The App Builder's panel inclusion logic can be overridden by Build Specifications -> Source File Settings -> Remove front panel. A better method is to put a property node on a control in a window you want to show marking it "visible"; this is sufficient to tell the App Builder it should keep the panel.
    Currently Source File Settings shows "no dependencies" (clearly incorrect---another evil side effect of Express VIs I guess) but if you change the settings as shown below to keep ALL panels, one might hope the App Builder can figure it to keep the panel when it deconstructs the Express VI. (Alternatively convert the Express VI into a regular one.)
    A second comment: I am a bit flummoxed at the larger goal here. You are calling LabView DLL from LabView, which doesn't make a lot of sense, so I assume your larger goal is to call LabView from C or vice-versa. In that case be aware that your DLL is x86 (32-bit) but you are passing 64-bit ints as your pointers. In this case it is 32-bit LabView with 32-bit pointers in embedeed in 64-bit containers calling 32-bit LabView with 32-bit pointers in embedeed in 64-bit containers, so it all works, but if your going to call this from C or whatnot you're going to have to follow that same design.
    When calling C code the LabView Call Library Function does have a "unsigned pointer-sized integer" data type that always appears to be 64 bits in the dev env but which actually passes a 64 or 32-bit int to the DLL depending on the environment. The "pointer sized int" has to be 64 bits in the "LabView" part of the code because LabView's strong typing requires the data type to be determined at compile time. Casting all pointers to the largest data type in LabView makes it possible to write platform-independent code, but down at the Call Library level you still have to put the right number of bytes on the stack.

  • How to numberformat when using sql:query alogn with c:forEach JSTL tags

    Is there anyway to format the numeric values returned from the database when using <sql:query> alogn with <c:forEach> tags
    Here is my jsp code
    <sql:query..../>
    <c:forEach var="row" items="${queryResults.rows}">
    <tr>
    <td><c:out value="${row.COL1}" /></td>
    <td><c:out value="${row.COL2}" /></td>
    </tr>
    </c:forEach>
    Col1 values are numeric without any formats Eg: 1000, 10000, 1000000 etc.
    how can i format them to 1,000 , 10,1000 , 100,000 etc

    It is polite to mention what your answer was. These posts are not just here for you to ask questions, but to be used as a resource for other people to find answers. Saying "I solved it" with no details helps noone.
    I presume you discovered the JSTL <fmt:formatNumber> tag?

  • File display extremely slow with call of OLE_FLUSH_CALL standard function

    Hi,
    We are running SAP R/3 Enterprise 640 with Doculink extension.
    When trying to display PDF files stored in an SAP Archive Server, it takes quiet a while to retreive the document, while displaying it through a web browser is very fast.
    I have made a some performances tests in ST05, and the results clearly shows that the ABAP execution time takes most of the process time. When digging deeper into which function takes so many time, I can see that the standard program SAPLOLEA takes a long while on a wait for RFC call. And then when I display the source code responsible for this call, I see that the OLE_FLUSH_CALL call takes the most time.
    I have tried to look around in SAP Notes but didn't find any relevant information regarding this problem. I wondered if I would be able to find more interesting opinions on SDN.
    Thanks in advance for your help,
    Thibault

    Query returns anywhere from 6000 to 32000 rows. For each of those rows a parameter is passed in to 4 different functions to get ytd totals. When I call the functions in the in-line view but do not select from them in the main SQL, the report (oh, this is Application Express 4.0 interactive reports, just an FYI) runs fast. The report comes back in a few seconds. But when I select from the in-line view to display those ytd totals, the report runs extremely slow. I know there are the articles about context switching and how mixing SQL with PL/SQL performs poorly. So I tried a pipeline table function where the function for the ytd totals populate the columns of the pipeline table and I select from the pipeline table in the SQL query in the interactive report. That seemed to perform a little worse from what I can tell.
    Thanks for any help you can offer.

  • SQL query statement  for stored procedure / function listing ...

    Hi everyone,
    Is there a SQL query to list all the stored procedures and functions of an user in an Oracle 8 database?
    I have this idea:
    select * from USER_SOURCE where TYPE = 'PROCEDURE' or TYPE = 'FUNCTION'
    but I am not too sure whether this is correct.
    Thanks in advance,
    Eric

    Yeah
    I agree with you Garcia , my above posting was a correction to the query mentioned in the question only.
    you are correct
    If you only want the name of the object,
    SELECT Object_Name from User_Objects where object_type in ( 'PROCEDURE' ,'FUNCTION');
    is much faster than Selecting (distinct) from User_Source.

  • Sql query slow due to case statement on Joins

    Hi
    The sql query runs very slow for 30 min when the below case statement is added on the joins. Could you please let me know how to tune it. if the case statement is not there then it runs only for 1 min.
    *( CASE*
    WHEN PO_DIST_GL_CODE_COMB.SEGMENT2 <> '1000'
    THEN  PO_DIST_GL_CODE_COMB.SEGMENT1 || PO_DIST_GL_CODE_COMB.SEGMENT2 || '_' || NVL(PO_DIST_GL_CODE_COMB.SEGMENT6,'000')
    WHEN DT_REQ_ALL.EMPMGMTCD IS NOT NULL AND
    PO_DIST_GL_CODE_COMB.SEGMENT2 = '1000'
    THEN DT_REQ_ALL.EMPMGMTCD
    END =DB2.DB2_FDW_MGMT_V.MH_CHILD  )
    SELECT  DISTINCT
      D.DB2_FDW_MGMT_V.RC_PARENT,
      DT_REQ_ALL.FULL_NAME,
      DT_REQ_ALL.EMP_COMPANY_CODE,
      DT_REQ_ALL.EMP_COST_CENTER,
      PO.PO_VENDORS.VENDOR_NAME,
      PO_PO_HEADERS_ALL2.SEGMENT1,
      PO_PO_HEADERS_ALL2.CREATION_DATE,
      PO_DIST_GL_CODE_COMB.SEGMENT1,
      PO_DIST_GL_CODE_COMB.SEGMENT2,
      PO_PO_HEADERS_ALL2.CURRENCY_CODE,
      PO_INV_DIST_ALL.INVOICE_NUM,
      PO_INV_DIST_ALL.INVOICE_DATE,
      (PO_INV_DIST_ALL.INVOICE_AMOUNT* PO_Rates_GL_DR.CONVERSION_RATE),
      (NVL(to_number(PO_DIST_ALL.AMOUNT_BILLED),0) * PO_Rates_GL_DR.CONVERSION_RATE),
      PO_LINES_LOC.LINE_NUM,
      GL.GL_SETS_OF_BOOKS.NAME,
      CASE
            WHEN TRUNC(PO_PO_HEADERS_ALL2.CREATION_DATE) > PO_INV_DIST_ALL.INVOICE_DATE
            THEN 1
            ELSE 0
        END ,
      PO.PO_REQUISITION_LINES_ALL.LINE_LOCATION_ID,
      TRUNC(PO_PO_HEADERS_ALL2.CREATION_DATE,'WW') + 8 WEEK_Ending
    FROM
      DB2.DB2_FDW_MGMT_V,
       PO.PO_VENDORS,
      PO.PO_HEADERS_ALL  PO_PO_HEADERS_ALL2,
      GL.GL_CODE_COMBINATIONS  PO_DIST_GL_CODE_COMB,
      AP.AP_INVOICES_ALL  PO_INV_DIST_ALL,
       PO.PO_DISTRIBUTIONS_ALL  PO_DIST_ALL,
      PO.PO_LINES_ALL  PO_LINES_LOC,
      GL.GL_SETS_OF_BOOKS,
      PO.PO_REQUISITION_LINES_ALL,
      PO.PO_LINE_LOCATIONS_ALL,
      AP.AP_INVOICE_DISTRIBUTIONS_ALL  PO_DIST_INV_DIST_ALL,
      APPS.HR_OPERATING_UNITS,
      PO.PO_REQ_DISTRIBUTIONS_ALL,
       SELECT DISTINCT
                            PO_RDA.DISTRIBUTION_ID,
                            PO_RLA.requisition_line_id,
                            PO_RHA.DESCRIPTION PO_Descr,
                            PO_RHA.NOTE_TO_AUTHORIZER PO_Justification,
                            Req_Emp.FULL_NAME,
                            GL_CC.SEGMENT1         Req_Company_Code,
                            GL_CC.SEGMENT2         Req_Cost_Center,
                            Req_Emp_CC.SEGMENT1    Emp_Company_Code,
                            Req_Emp_CC.SEGMENT2    Emp_Cost_Center,
                            (Case
                            When GL_CC.SEGMENT2 <> 8000
                            Then TRUNC(GL_CC.SEGMENT1) || TRUNC(GL_CC.SEGMENT2) || '_' || NVL(GL_CC.SEGMENT6,'000')
                            Else TRUNC(Req_Emp_CC.SEGMENT1) || TRUNC(Req_Emp_CC.SEGMENT2) || '_' || NVL(Req_Emp_CC.SEGMENT6,'000')
                            End) EmpMgmtCD
                FROM
                            PO.po_requisition_lines_all PO_rla,
                            PO.po_requisition_headers_all PO_rha,
                            PO.PO_REQ_DISTRIBUTIONS_ALL po_RDA,
                            GL.GL_CODE_COMBINATIONS gl_cc,
                            HR.PER_ALL_PEOPLE_F  Req_Emp,
                            HR.PER_ALL_ASSIGNMENTS_F Req_Emp_Assign,
                            HR.hr_all_organization_units Req_Emp_Org,
                            HR.pay_cost_allocation_keyflex Req_Emp_CC
                WHERE
                            PO_RDA.CODE_COMBINATION_ID = GL_CC.CODE_COMBINATION_ID and
                            PO_RLA.REQUISITION_LINE_ID = PO_RDA.REQUISITION_LINE_ID AND
                            PO_RLA.to_person_id = Req_Emp.PERSON_ID AND
                            PO_RLA.REQUISITION_HEADER_ID = PO_RHA.REQUISITION_HEADER_ID AND
                            (trunc(PO_rla.CREATION_DATE) between Req_Emp.effective_start_date and Req_Emp.effective_end_date OR
                            Req_Emp.effective_start_date IS NULL) AND
                            Req_Emp.PERSON_ID = Req_Emp_Assign.PERSON_ID AND
                            Req_Emp_Assign.organization_id = Req_Emp_Org.organization_id AND
                            (trunc(PO_rla.CREATION_DATE) between Req_Emp_Assign.effective_start_date and Req_Emp_Assign.effective_end_date OR
            Req_Emp_Assign.effective_start_date IS NULL) AND
            Req_Emp_Assign.primary_flag = 'Y' AND
            Req_Emp_Assign.assignment_type = 'E' AND
            Req_Emp_Org.cost_allocation_keyflex_id = Req_Emp_CC.cost_allocation_keyflex_id
      )  DT_REQ_ALL,
      SELECT
            FROM_CURRENCY,
            TO_CURRENCY,
            CONVERSION_DATE,
            CONVERSION_RATE
        FROM GL.GL_DAILY_RATES
        UNION
        SELECT Distinct
            'USD',
            'USD',
            CONVERSION_DATE,
            1
        FROM GL.GL_DAILY_RATES
      )  PO_Rates_GL_DR
    WHERE
      ( PO_DIST_GL_CODE_COMB.CODE_COMBINATION_ID=PO_DIST_ALL.CODE_COMBINATION_ID  )
      AND  ( PO_DIST_ALL.LINE_LOCATION_ID=PO.PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID  )
      AND  ( PO_PO_HEADERS_ALL2.VENDOR_ID=PO.PO_VENDORS.VENDOR_ID  )
      AND  ( PO_PO_HEADERS_ALL2.ORG_ID=APPS.HR_OPERATING_UNITS.ORGANIZATION_ID  )
      AND  ( GL.GL_SETS_OF_BOOKS.SET_OF_BOOKS_ID=APPS.HR_OPERATING_UNITS.SET_OF_BOOKS_ID  )
      AND  ( PO_PO_HEADERS_ALL2.CURRENCY_CODE=PO_Rates_GL_DR.FROM_CURRENCY  )
      AND  ( trunc(PO_PO_HEADERS_ALL2.CREATION_DATE)=PO_Rates_GL_DR.CONVERSION_DATE  )
      AND  ( PO_DIST_ALL.REQ_DISTRIBUTION_ID=PO.PO_REQ_DISTRIBUTIONS_ALL.DISTRIBUTION_ID(+)  )
      AND  ( PO.PO_REQ_DISTRIBUTIONS_ALL.REQUISITION_LINE_ID=PO.PO_REQUISITION_LINES_ALL.REQUISITION_LINE_ID(+)  )
      AND  ( PO_LINES_LOC.PO_HEADER_ID=PO_PO_HEADERS_ALL2.PO_HEADER_ID  )
      AND  ( PO.PO_LINE_LOCATIONS_ALL.PO_LINE_ID=PO_LINES_LOC.PO_LINE_ID  )
      AND  ( PO_DIST_ALL.REQ_DISTRIBUTION_ID=DT_REQ_ALL.DISTRIBUTION_ID(+)  )
      AND  ( PO_DIST_ALL.PO_DISTRIBUTION_ID=PO_DIST_INV_DIST_ALL.PO_DISTRIBUTION_ID(+)  )
      AND  ( PO_INV_DIST_ALL.INVOICE_ID(+)=PO_DIST_INV_DIST_ALL.INVOICE_ID  )
      AND  ( PO_INV_DIST_ALL.SOURCE(+) <> 'XML GATEWAY'   )
      AND 
       ( NVL(PO_PO_HEADERS_ALL2.CANCEL_FLAG,'N') <> 'Y'   )
       AND
       ( NVL(PO_PO_HEADERS_ALL2.CLOSED_CODE, 'OPEN') <> 'FINALLY CLOSED'  )
       AND
       ( NVL(PO_PO_HEADERS_ALL2.AUTHORIZATION_STATUS,'IN PROCESS') <> 'REJECTED'  )
       AND
       ( TRUNC(PO_PO_HEADERS_ALL2.CREATION_DATE)  BETWEEN TO_DATE('01-jan-2011') AND TO_DATE('04-jan-2011')  )
       AND
       PO_Rates_GL_DR.TO_CURRENCY  =  'USD'
         AND
       DB2.DB2_FDW_MGMT_V.RC_PARENT  In  ( 'Unavailable','Corp','Commercial'  )
       AND
      ( CASE
            WHEN PO_DIST_GL_CODE_COMB.SEGMENT2 <> '1000'
            THEN  PO_DIST_GL_CODE_COMB.SEGMENT1 || PO_DIST_GL_CODE_COMB.SEGMENT2 || '_' || NVL(PO_DIST_GL_CODE_COMB.SEGMENT6,'000')
            WHEN DT_REQ_ALL.EMPMGMTCD IS NOT NULL AND
                    PO_DIST_GL_CODE_COMB.SEGMENT2 = '1000'
            THEN DT_REQ_ALL.EMPMGMTCD     
        END =DB2.DB2_FDW_MGMT_V.MH_CHILD  )Explain plan. sorry can't get the explain plan from sql. this is from toad.
    Plan
    SELECT STATEMENT  ALL_ROWSCost: 53,932  Bytes: 2,607  Cardinality: 1                                                                                                                               
         79 HASH UNIQUE  Cost: 53,932  Bytes: 2,607  Cardinality: 1                                                                                                                          
              78 NESTED LOOPS OUTER  Cost: 53,931  Bytes: 2,607  Cardinality: 1                                                                                                                     
                   75 NESTED LOOPS OUTER  Cost: 53,928  Bytes: 2,560  Cardinality: 1                                                                                                                
                        72 NESTED LOOPS  Cost: 53,902  Bytes: 2,552  Cardinality: 1                                                                                                           
                             69 NESTED LOOPS OUTER  Cost: 53,900  Bytes: 2,533  Cardinality: 1                                                                                                      
                                  66 NESTED LOOPS OUTER  Cost: 53,898  Bytes: 2,521  Cardinality: 1                                                                                                 
                                       63 HASH JOIN OUTER  Cost: 53,896  Bytes: 2,509  Cardinality: 1                                                                                            
                                            40 TABLE ACCESS BY INDEX ROWID TABLE PO.PO_DISTRIBUTIONS_ALL Cost: 3  Bytes: 26  Cardinality: 1                                                                                       
                                                 39 NESTED LOOPS  Cost: 17,076  Bytes: 2,400  Cardinality: 1                                                                                  
                                                      37 NESTED LOOPS  Cost: 17,073  Bytes: 2,374  Cardinality: 1                                                                             
                                                           34 NESTED LOOPS  Cost: 17,070  Bytes: 2,362  Cardinality: 1                                                                        
                                                                31 NESTED LOOPS  Cost: 17,066  Bytes: 2,347  Cardinality: 1                                                                   
                                                                     29 NESTED LOOPS  Cost: 17,066  Bytes: 2,339  Cardinality: 1                                                              
                                                                          26 NESTED LOOPS  Cost: 17,065  Bytes: 2,312  Cardinality: 1                                                         
                                                                               23 NESTED LOOPS  Cost: 17,064  Bytes: 2,287  Cardinality: 1                                                    
                                                                                    20 NESTED LOOPS  Cost: 17,062  Bytes: 2,261  Cardinality: 1                                               
                                                                                         17 NESTED LOOPS  Cost: 17,056  Bytes: 6,678  Cardinality: 3                                          
                                                                                              15 HASH JOIN  Cost: 17,056  Bytes: 6,663  Cardinality: 3                                     
                                                                                                   13 MERGE JOIN CARTESIAN  Cost: 135  Bytes: 30,352  Cardinality: 14                                
                                                                                                        5 VIEW VIEW DB2.DB2_FDW_MGMT_V Cost: 4  Bytes: 2,128  Cardinality: 1                           
                                                                                                             4 SORT UNIQUE  Cost: 4  Cardinality: 1                      
                                                                                                                  3 UNION-ALL                 
                                                                                                                       1 REMOTE REMOTE SERIAL_FROM_REMOTE PRDFDW.WORLD          
                                                                                                                       2 FAST DUAL  Cost: 3  Cardinality: 1            
                                                                                                        12 BUFFER SORT  Cost: 135  Bytes: 560  Cardinality: 14                           
                                                                                                             11 VIEW DB2. Cost: 131  Bytes: 560  Cardinality: 14                      
                                                                                                                  10 SORT UNIQUE  Cost: 131  Bytes: 310  Cardinality: 14                 
                                                                                                                       9 UNION-ALL            
                                                                                                                            7 TABLE ACCESS BY INDEX ROWID TABLE GL.GL_DAILY_RATES Cost: 65  Bytes: 270  Cardinality: 9       
                                                                                                                                 6 INDEX SKIP SCAN INDEX (UNIQUE) GL.GL_DAILY_RATES_U1 Cost: 64  Cardinality: 1 
                                                                                                                            8 INDEX SKIP SCAN INDEX (UNIQUE) GL.GL_DAILY_RATES_U1 Cost: 64  Bytes: 4,368  Cardinality: 546       
                                                                                                   14 TABLE ACCESS FULL TABLE PO.PO_HEADERS_ALL Cost: 16,920  Bytes: 32,754  Cardinality: 618                                
                                                                                              16 INDEX UNIQUE SCAN INDEX (UNIQUE) HR.HR_ORGANIZATION_UNITS_PK Cost: 0  Bytes: 5  Cardinality: 1                                     
                                                                                         19 TABLE ACCESS BY INDEX ROWID TABLE HR.HR_ORGANIZATION_INFORMATION Cost: 2  Bytes: 35  Cardinality: 1                                          
                                                                                              18 INDEX RANGE SCAN INDEX HR.HR_ORGANIZATION_INFORMATIO_FK2 Cost: 1  Cardinality: 2                                     
                                                                                    22 TABLE ACCESS BY INDEX ROWID TABLE HR.HR_ORGANIZATION_INFORMATION Cost: 2  Bytes: 26  Cardinality: 1                                               
                                                                                         21 INDEX RANGE SCAN INDEX HR.HR_ORGANIZATION_INFORMATIO_FK2 Cost: 1  Cardinality: 1                                          
                                                                               25 TABLE ACCESS BY INDEX ROWID TABLE GL.GL_SETS_OF_BOOKS Cost: 1  Bytes: 25  Cardinality: 1                                                    
                                                                                    24 INDEX UNIQUE SCAN INDEX (UNIQUE) GL.GL_SETS_OF_BOOKS_U2 Cost: 0  Cardinality: 1                                               
                                                                          28 TABLE ACCESS BY INDEX ROWID TABLE PO.PO_VENDORS Cost: 1  Bytes: 27  Cardinality: 1                                                         
                                                                               27 INDEX UNIQUE SCAN INDEX (UNIQUE) PO.PO_VENDORS_U1 Cost: 0  Cardinality: 1                                                    
                                                                     30 INDEX UNIQUE SCAN INDEX (UNIQUE) HR.HR_ALL_ORGANIZATION_UNTS_TL_PK Cost: 0  Bytes: 8  Cardinality: 1                                                              
                                                                33 TABLE ACCESS BY INDEX ROWID TABLE PO.PO_LINES_ALL Cost: 4  Bytes: 60  Cardinality: 4                                                                   
                                                                     32 INDEX RANGE SCAN INDEX (UNIQUE) PO.PO_LINES_U2 Cost: 2  Cardinality: 4                                                              
                                                           36 TABLE ACCESS BY INDEX ROWID TABLE PO.PO_LINE_LOCATIONS_ALL Cost: 3  Bytes: 12  Cardinality: 1                                                                        
                                                                35 INDEX RANGE SCAN INDEX PO.PO_LINE_LOCATIONS_N1 Cost: 2  Cardinality: 1                                                                   
                                                      38 INDEX RANGE SCAN INDEX PO.PO_DISTRIBUTIONS_N1 Cost: 2  Cardinality: 1                                                                             
                                            62 VIEW DB2. Cost: 36,819  Bytes: 1,090  Cardinality: 10                                                                                       
                                                 61 HASH UNIQUE  Cost: 36,819  Bytes: 2,580  Cardinality: 10                                                                                  
                                                      60 NESTED LOOPS  Cost: 36,818  Bytes: 2,580  Cardinality: 10                                                                             
                                                           57 NESTED LOOPS  Cost: 36,798  Bytes: 2,390  Cardinality: 10                                                                        
                                                                54 NESTED LOOPS  Cost: 36,768  Bytes: 2,220  Cardinality: 10                                                                   
                                                                     51 NESTED LOOPS  Cost: 36,758  Bytes: 1,510  Cardinality: 10                                                              
                                                                          48 NESTED LOOPS  Cost: 36,747  Bytes: 1,050  Cardinality: 10                                                         
                                                                               45 HASH JOIN  Cost: 36,737  Bytes: 960  Cardinality: 10                                                    
                                                                                    43 HASH JOIN  Cost: 34,602  Bytes: 230,340  Cardinality: 3,490                                               
                                                                                         41 TABLE ACCESS FULL TABLE HR.PER_ALL_PEOPLE_F Cost: 1,284  Bytes: 1,848,420  Cardinality: 44,010                                          
                                                                                         42 TABLE ACCESS FULL TABLE PO.PO_REQUISITION_LINES_ALL Cost: 31,802  Bytes: 18,340,080  Cardinality: 764,170                                          
                                                                                    44 TABLE ACCESS FULL TABLE HR.PER_ALL_ASSIGNMENTS_F Cost: 2,134  Bytes: 822,540  Cardinality: 27,418                                               
                                                                               47 TABLE ACCESS BY INDEX ROWID TABLE HR.HR_ALL_ORGANIZATION_UNITS Cost: 1  Bytes: 9  Cardinality: 1                                                    
                                                                                    46 INDEX UNIQUE SCAN INDEX (UNIQUE) HR.HR_ORGANIZATION_UNITS_PK Cost: 0  Cardinality: 1                                               
                                                                          50 TABLE ACCESS BY INDEX ROWID TABLE HR.PAY_COST_ALLOCATION_KEYFLEX Cost: 1  Bytes: 46  Cardinality: 1                                                         
                                                                               49 INDEX UNIQUE SCAN INDEX (UNIQUE) HR.PAY_COST_ALLOCATION_KEYFLE_PK Cost: 0  Cardinality: 1                                                    
                                                                     53 TABLE ACCESS BY INDEX ROWID TABLE PO.PO_REQUISITION_HEADERS_ALL Cost: 1  Bytes: 71  Cardinality: 1                                                              
                                                                          52 INDEX UNIQUE SCAN INDEX (UNIQUE) PO.PO_REQUISITION_HEADERS_U1 Cost: 0  Cardinality: 1                                                         
                                                                56 TABLE ACCESS BY INDEX ROWID TABLE PO.PO_REQ_DISTRIBUTIONS_ALL Cost: 3  Bytes: 17  Cardinality: 1                                                                   
                                                                     55 INDEX RANGE SCAN INDEX PO.PO_REQ_DISTRIBUTIONS_N1 Cost: 2  Cardinality: 1                                                              
                                                           59 TABLE ACCESS BY INDEX ROWID TABLE GL.GL_CODE_COMBINATIONS Cost: 2  Bytes: 19  Cardinality: 1                                                                        
                                                                58 INDEX UNIQUE SCAN INDEX (UNIQUE) GL.GL_CODE_COMBINATIONS_U1 Cost: 1  Cardinality: 1                                                                   
                                       65 TABLE ACCESS BY INDEX ROWID TABLE PO.PO_REQ_DISTRIBUTIONS_ALL Cost: 2  Bytes: 12  Cardinality: 1                                                                                            
                                            64 INDEX UNIQUE SCAN INDEX (UNIQUE) PO.PO_REQ_DISTRIBUTIONS_U1 Cost: 1  Cardinality: 1                                                                                       
                                  68 TABLE ACCESS BY INDEX ROWID TABLE PO.PO_REQUISITION_LINES_ALL Cost: 2  Bytes: 12  Cardinality: 1                                                                                                 
                                       67 INDEX UNIQUE SCAN INDEX (UNIQUE) PO.PO_REQUISITION_LINES_U1 Cost: 1  Cardinality: 1                                                                                            
                             71 TABLE ACCESS BY INDEX ROWID TABLE GL.GL_CODE_COMBINATIONS Cost: 2  Bytes: 19  Cardinality: 1                                                                                                      
                                  70 INDEX UNIQUE SCAN INDEX (UNIQUE) GL.GL_CODE_COMBINATIONS_U1 Cost: 1  Cardinality: 1                                                                                                 
                        74 TABLE ACCESS BY INDEX ROWID TABLE AP.AP_INVOICE_DISTRIBUTIONS_ALL Cost: 26  Bytes: 16  Cardinality: 2                                                                                                           
                             73 INDEX RANGE SCAN INDEX AP.AP_INVOICE_DISTRIBUTIONS_N7 Cost: 2  Cardinality: 37                                                                                                      
                   77 TABLE ACCESS BY INDEX ROWID TABLE AP.AP_INVOICES_ALL Cost: 3  Bytes: 47  Cardinality: 1                                                                                                                
                        76 INDEX RANGE SCAN INDEX (UNIQUE) AP.AP_INVOICES_U1 Cost: 2  Cardinality: 1                                                                                                           Thanks

    Forming a new table "new_table" with 3 tables which particiapate in CASE statement logic.
    with  DT_REQ_ALL  as
       SELECT DISTINCT
                            PO_RDA.DISTRIBUTION_ID,
                            PO_RLA.requisition_line_id,
                            PO_RHA.DESCRIPTION PO_Descr,
                            PO_RHA.NOTE_TO_AUTHORIZER PO_Justification,
                            Req_Emp.FULL_NAME,
                            GL_CC.SEGMENT1         Req_Company_Code,
                            GL_CC.SEGMENT2         Req_Cost_Center,
                            Req_Emp_CC.SEGMENT1    Emp_Company_Code,
                            Req_Emp_CC.SEGMENT2    Emp_Cost_Center,
                            (Case
                            When GL_CC.SEGMENT2  8000
                            Then TRUNC(GL_CC.SEGMENT1) || TRUNC(GL_CC.SEGMENT2) || '_' || NVL(GL_CC.SEGMENT6,'000')
                            Else TRUNC(Req_Emp_CC.SEGMENT1) || TRUNC(Req_Emp_CC.SEGMENT2) || '_' || NVL(Req_Emp_CC.SEGMENT6,'000')
                            End) EmpMgmtCD
                FROM
                            PO.po_requisition_lines_all PO_rla,
                            PO.po_requisition_headers_all PO_rha,
                            PO.PO_REQ_DISTRIBUTIONS_ALL po_RDA,
                            GL.GL_CODE_COMBINATIONS gl_cc,
                            HR.PER_ALL_PEOPLE_F  Req_Emp,
                            HR.PER_ALL_ASSIGNMENTS_F Req_Emp_Assign,
                            HR.hr_all_organization_units Req_Emp_Org,
                            HR.pay_cost_allocation_keyflex Req_Emp_CC
                WHERE
                            PO_RDA.CODE_COMBINATION_ID = GL_CC.CODE_COMBINATION_ID and
                            PO_RLA.REQUISITION_LINE_ID = PO_RDA.REQUISITION_LINE_ID AND
                            PO_RLA.to_person_id = Req_Emp.PERSON_ID AND
                            PO_RLA.REQUISITION_HEADER_ID = PO_RHA.REQUISITION_HEADER_ID AND
                            (trunc(PO_rla.CREATION_DATE) between Req_Emp.effective_start_date and Req_Emp.effective_end_date OR
                            Req_Emp.effective_start_date IS NULL) AND
                            Req_Emp.PERSON_ID = Req_Emp_Assign.PERSON_ID AND
                            Req_Emp_Assign.organization_id = Req_Emp_Org.organization_id AND
                            (trunc(PO_rla.CREATION_DATE) between Req_Emp_Assign.effective_start_date and Req_Emp_Assign.effective_end_date OR
            Req_Emp_Assign.effective_start_date IS NULL) AND
            Req_Emp_Assign.primary_flag = 'Y' AND
            Req_Emp_Assign.assignment_type = 'E' AND
            Req_Emp_Org.cost_allocation_keyflex_id = Req_Emp_CC.cost_allocation_keyflex_id
    SELECT  DISTINCT
      D.DB2_FDW_MGMT_V.RC_PARENT,
      DT_REQ_ALL.FULL_NAME,
      DT_REQ_ALL.EMP_COMPANY_CODE,
      DT_REQ_ALL.EMP_COST_CENTER,
      PO.PO_VENDORS.VENDOR_NAME,
      PO_PO_HEADERS_ALL2.SEGMENT1,
      PO_PO_HEADERS_ALL2.CREATION_DATE,
      PO_DIST_GL_CODE_COMB.SEGMENT1,
      PO_DIST_GL_CODE_COMB.SEGMENT2,
      PO_PO_HEADERS_ALL2.CURRENCY_CODE,
      PO_INV_DIST_ALL.INVOICE_NUM,
      PO_INV_DIST_ALL.INVOICE_DATE,
      (PO_INV_DIST_ALL.INVOICE_AMOUNT* PO_Rates_GL_DR.CONVERSION_RATE),
      (NVL(to_number(PO_DIST_ALL.AMOUNT_BILLED),0) * PO_Rates_GL_DR.CONVERSION_RATE),
      PO_LINES_LOC.LINE_NUM,
      GL.GL_SETS_OF_BOOKS.NAME,
      CASE
            WHEN TRUNC(PO_PO_HEADERS_ALL2.CREATION_DATE) > PO_INV_DIST_ALL.INVOICE_DATE
            THEN 1
            ELSE 0
        END ,
      PO.PO_REQUISITION_LINES_ALL.LINE_LOCATION_ID,
      TRUNC(PO_PO_HEADERS_ALL2.CREATION_DATE,'WW') + 8 WEEK_Ending
    FROM
      ( SELECT * FROM
          DB2.DB2_FDW_MGMT_V,
          GL.GL_CODE_COMBINATIONS  PO_DIST_GL_CODE_COMB,
          DT_REQ_ALL
        WHERE
              DB2.DB2_FDW_MGMT_V.RC_PARENT  In  ( 'Unavailable','Corp','Commercial'  )
           AND
            CASE
               WHEN PO_DIST_GL_CODE_COMB.SEGMENT2  <>  '1000'
               THEN  PO_DIST_GL_CODE_COMB.SEGMENT1 || PO_DIST_GL_CODE_COMB.SEGMENT2 || '_' || NVL(PO_DIST_GL_CODE_COMB.SEGMENT6,'000')
               WHEN DT_REQ_ALL.EMPMGMTCD IS NOT NULL AND
                    PO_DIST_GL_CODE_COMB.SEGMENT2 = '1000'
               THEN DT_REQ_ALL.EMPMGMTCD     
            END =DB2.DB2_FDW_MGMT_V.MH_CHILD
       )   new_table,
       PO.PO_VENDORS,
      PO.PO_HEADERS_ALL  PO_PO_HEADERS_ALL2,
      AP.AP_INVOICES_ALL  PO_INV_DIST_ALL,
       PO.PO_DISTRIBUTIONS_ALL  PO_DIST_ALL,
      PO.PO_LINES_ALL  PO_LINES_LOC,
      GL.GL_SETS_OF_BOOKS,
      PO.PO_REQUISITION_LINES_ALL,
      PO.PO_LINE_LOCATIONS_ALL,
      AP.AP_INVOICE_DISTRIBUTIONS_ALL  PO_DIST_INV_DIST_ALL,
      APPS.HR_OPERATING_UNITS,
      PO.PO_REQ_DISTRIBUTIONS_ALL,
      SELECT
            FROM_CURRENCY,
            TO_CURRENCY,
            CONVERSION_DATE,
            CONVERSION_RATE
        FROM GL.GL_DAILY_RATES
        UNION
        SELECT Distinct
            'USD',
            'USD',
            CONVERSION_DATE,
            1
        FROM GL.GL_DAILY_RATES
      )  PO_Rates_GL_DR
    WHERE
      ( PO_DIST_GL_CODE_COMB.CODE_COMBINATION_ID=PO_DIST_ALL.CODE_COMBINATION_ID  )
      AND  ( PO_DIST_ALL.LINE_LOCATION_ID=PO.PO_LINE_LOCATIONS_ALL.LINE_LOCATION_ID  )
      AND  ( PO_PO_HEADERS_ALL2.VENDOR_ID=PO.PO_VENDORS.VENDOR_ID  )
      AND  ( PO_PO_HEADERS_ALL2.ORG_ID=APPS.HR_OPERATING_UNITS.ORGANIZATION_ID  )
      AND  ( GL.GL_SETS_OF_BOOKS.SET_OF_BOOKS_ID=APPS.HR_OPERATING_UNITS.SET_OF_BOOKS_ID  )
      AND  ( PO_PO_HEADERS_ALL2.CURRENCY_CODE=PO_Rates_GL_DR.FROM_CURRENCY  )
      AND  ( trunc(PO_PO_HEADERS_ALL2.CREATION_DATE)=PO_Rates_GL_DR.CONVERSION_DATE  )
      AND  ( PO_DIST_ALL.REQ_DISTRIBUTION_ID=PO.PO_REQ_DISTRIBUTIONS_ALL.DISTRIBUTION_ID(+)  )
      AND  ( PO.PO_REQ_DISTRIBUTIONS_ALL.REQUISITION_LINE_ID=PO.PO_REQUISITION_LINES_ALL.REQUISITION_LINE_ID(+)  )
      AND  ( PO_LINES_LOC.PO_HEADER_ID=PO_PO_HEADERS_ALL2.PO_HEADER_ID  )
      AND  ( PO.PO_LINE_LOCATIONS_ALL.PO_LINE_ID=PO_LINES_LOC.PO_LINE_ID  )
      AND  ( PO_DIST_ALL.REQ_DISTRIBUTION_ID=DT_REQ_ALL.DISTRIBUTION_ID(+)  )
      AND  ( PO_DIST_ALL.PO_DISTRIBUTION_ID=PO_DIST_INV_DIST_ALL.PO_DISTRIBUTION_ID(+)  )
      AND  ( PO_INV_DIST_ALL.INVOICE_ID(+)=PO_DIST_INV_DIST_ALL.INVOICE_ID  )
      AND  ( PO_INV_DIST_ALL.SOURCE(+)  'XML GATEWAY'   )
      AND 
       ( NVL(PO_PO_HEADERS_ALL2.CANCEL_FLAG,'N')  'Y'   )
       AND
       ( NVL(PO_PO_HEADERS_ALL2.CLOSED_CODE, 'OPEN')  'FINALLY CLOSED'  )
       AND
       ( NVL(PO_PO_HEADERS_ALL2.AUTHORIZATION_STATUS,'IN PROCESS')  'REJECTED'  )
       AND
       ( TRUNC(PO_PO_HEADERS_ALL2.CREATION_DATE)  BETWEEN TO_DATE('01-jan-2011') AND TO_DATE('04-jan-2011')  )
       AND
       PO_Rates_GL_DR.TO_CURRENCY  =  'USD'
      

  • SQL Query execution with LISTAGG

    Hello,
    I am trying to get some data using LISTAGG functionality.
    I have below query with works fine with the table, but not with the rowsource which is based on same table.
    SELECT COL1,LISTAGG(COL3, ',') WITHIN GROUP (ORDER BY COL2) AS fieldName FROM IOP_Sample_RS GROUP BY COL1it gives parsing error
    line 1:22: expecting "FROM", found '('col 22 is '(' of LISTAGG function.
    One more Question
    Does UNION, MINUS works with RSQL in IOP?
    Thanks,
    Sumant Chhunchha.
    Edited by: Sumant on Jun 15, 2011 5:04 AM

    LISTAGG, UNION, MINUS is not supported with RSQL, instead you can massage your SQL query to load data into IOP and then use a simple RSQL query.

  • SQL is slow with optimizer_mode=ALL_ROWS

    Hi.
    We have an application layer with htmldb 2.0 running on 10.2 on HP-UX Itanium.
    One of the applications runs a sql joining two tables and using bind variables as in the selection critieria.
    The two tables has the following number of rows;
    SQL> select count(1) from innsyn_kunde.kunde;
    COUNT(1)
    96708
    SQL> select count(1) from innsyn_kunde.regning;
    COUNT(1)
    1867136
    SQL>
    The following intialization parameters are set on instances level:
    SQL> show parameter optimiz
    NAME TYPE VALUE
    optimizer_dynamic_sampling integer 2
    optimizer_features_enable string 10.2.0.1
    optimizer_index_caching integer 80
    optimizer_index_cost_adj integer 10
    optimizer_mode string FIRST_ROWS
    optimizer_secure_view_merging boolean TRUE
    plsql_optimize_level integer 2
    SQL>
    All tables and indexes used by the application has fresh statistics gathered with dbms_stats.
    The following sql is defined in htmldb:
    select
    regn.regningnr
    ,regn.appl_kode
    ,regn.regningtekst1
    ,regn.regningdato
    ,regn.kundenr
    ,kund.kundenavn kunde
    from innsyn_kunde.regning regn
    , innsyn_kunde.kunde kund
    where
    regn.appl_kode=kund.appl_kode
    and regn.kundenr=kund.kundenr(+)
    and regn.appl_kode = :P31_appl_kode
    and regn.kundenr like upper(decode(:P31_kundenr,null,'%',:P31_kundenr||'%'))
    and regn.regningnr like decode(:P31_regningnr,null,'%',:P31_regningnr||'%')
    and kund.kundenavn like upper(decode(:P31_kundenavn,null,'%',:P31_kundenavn||'%'))
    order by regn.regningdato desc
    1) If we substitute the bind variables with actual values in the actual sql in order to fetch one row the query runs very fast:
    select
    regn.regningnr
    ,regn.appl_kode
    ,regn.regningtekst1
    ,regn.regningdato
    ,regn.kundenr
    ,kund.kundenavn kunde
    from innsyn_kunde.regning regn
    , innsyn_kunde.kunde kund
    where
    regn.appl_kode=kund.appl_kode
    and regn.kundenr=kund.kundenr(+)
    and regn.appl_kode = 'SKOL'
    and regn.kundenr like '%'
    and regn.regningnr like '1150456%'
    and kund.kundenavn like '%'
    order by regn.regningdato desc
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 0.00 0.00 0 0 0 0
    Fetch 2 0.00 0.00 5 8 0 1
    total 4 0.00 0.00 5 8 0 1
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 95 (INNSYN_KUNDE)
    Rows Row Source Operation
    1 SORT ORDER BY (cr=8 pr=5 pw=0 time=343 us)
    1 NESTED LOOPS (cr=8 pr=5 pw=0 time=315 us)
    1 TABLE ACCESS BY INDEX ROWID REGNING (cr=4 pr=1 pw=0 time=182 us)
    1 INDEX RANGE SCAN REGNING_IDX_03 (cr=3 pr=1 pw=0 time=165 us)(object id 68870)
    1 TABLE ACCESS BY INDEX ROWID KUNDE (cr=4 pr=4 pw=0 time=129 us)
    1 INDEX UNIQUE SCAN PK_KUNDE (cr=3 pr=3 pw=0 time=99 us)(object id 68356)
    Rows Execution Plan
    0 SELECT STATEMENT MODE: ALL_ROWS
    1 SORT (ORDER BY)
    1 NESTED LOOPS
    1 TABLE ACCESS MODE: ANALYZED (BY INDEX ROWID) OF 'REGNING'
    (TABLE)
    1 INDEX MODE: ANALYZED (RANGE SCAN) OF 'REGNING_IDX_03'
    (INDEX)
    1 TABLE ACCESS MODE: ANALYZED (BY INDEX ROWID) OF 'KUNDE'
    (TABLE)
    1 INDEX MODE: ANALYZED (UNIQUE SCAN) OF 'PK_KUNDE' (INDEX
    (UNIQUE))
    2) If we use bind variables to reproduce the problem in htmldb from sqlplus like this we get the following result;
    select
    regn.regningnr
    ,regn.appl_kode
    ,regn.regningtekst1
    ,regn.regningdato
    ,regn.kundenr
    ,kund.kundenavn kunde
    from innsyn_kunde.regning regn
    , innsyn_kunde.kunde kund
    where
    regn.appl_kode=kund.appl_kode
    and regn.kundenr=kund.kundenr(+)
    and regn.appl_kode = :P31_appl_kode
    and regn.kundenr like upper(decode(:P31_kundenr,null,'%',:P31_kundenr||'%'))
    and regn.regningnr like decode(:P31_regningnr,null,'%',:P31_regningnr||'%')
    and kund.kundenavn like upper(decode(:P31_kundenavn,null,'%',:P31_kundenavn||'%'))
    order by regn.regningdato desc
    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 0
    Fetch 2 30.19 32.64 516728 1406955 0 1
    total 8 30.19 32.64 516728 1406955 0 1
    Misses in library cache during parse: 0
    Parsing user id: 64 (INNSYN_WEB) (recursive depth: 1)
    Rows Row Source Operation
    1 SORT ORDER BY (cr=1406955 pr=516728 pw=75 time=32643407 us)
    1 TABLE ACCESS BY INDEX ROWID REGNING (cr=1406955 pr=516728 pw=75 time=32643357 us)
    1354432 NESTED LOOPS (cr=106950 pr=42778 pw=75 time=17612677 us)
    50191 VIEW index$_join$_002 (cr=661 pr=736 pw=75 time=447634 us)
    50191 HASH JOIN (cr=661 pr=736 pw=75 time=297306 us)
    50191 INDEX RANGE SCAN PK_KUNDE (cr=258 pr=258 pw=0 time=163 us)(object id 68356)
    96705 INDEX RANGE SCAN KUNDE_IDX01 (cr=403 pr=403 pw=0 time=97049 us)(object id 68688)
    1304240 INDEX RANGE SCAN REGNING_IDX_01 (cr=106289 pr=42042 pw=0 time=3401535 us)(object id 68363)
    Rows Execution Plan
    0 SELECT STATEMENT MODE: ALL_ROWS
    1 SORT (ORDER BY)
    1 TABLE ACCESS MODE: ANALYZED (BY INDEX ROWID) OF 'REGNING'
    (TABLE)
    1354432 NESTED LOOPS
    50191 VIEW OF 'index$_join$_002' (VIEW)
    50191 HASH JOIN
    50191 INDEX MODE: ANALYZED (RANGE SCAN) OF 'PK_KUNDE'
    (INDEX (UNIQUE))
    96705 INDEX MODE: ANALYZED (RANGE SCAN) OF 'KUNDE_IDX01'
    (INDEX)
    1304240 INDEX MODE: ANALYZED (RANGE SCAN) OF 'REGNING_IDX_01'
    (INDEX)
    By using bind-variables it uses 30 seconds to fetch one row that is returned in less than a second with standard litherals
    3) And by doing something we probably not should, at least on 10.2 is to hint with RULE based optimization.
    Parsing user id: 95 (INNSYN_KUNDE)
    select /*+ RULE */
    regn.regningnr
    ,regn.appl_kode
    ,regn.regningtekst1
    ,regn.regningdato
    ,regn.kundenr
    ,kund.kundenavn kunde
    from innsyn_kunde.regning regn,
    innsyn_kunde.kunde kund
    where
    regn.appl_kode=kund.appl_kode
    and regn.kundenr=kund.kundenr (+)
    and regn.appl_kode = :P31_appl_kode
    and regn.kundenr like upper(decode(:P31_kundenr,null,'%',:P31_kundenr||'%'))
    and regn.regningnr like decode(:P31_regningnr,null,'%',:P31_regningnr||'%')
    and kund.kundenavn like upper(decode(:P31_kundenavn,null,'%',:P31_kundenavn||'%'))
    order by regn.regningdato desc
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.00 0 0 0 0
    Execute 1 0.00 0.00 0 0 0 0
    Fetch 2 0.13 0.12 1109 1122 0 1
    total 4 0.13 0.12 1109 1122 0 1
    Misses in library cache during parse: 0
    Optimizer mode: RULE
    Parsing user id: 95 (INNSYN_KUNDE)
    Rows Row Source Operation
    1 SORT ORDER BY (cr=1122 pr=1109 pw=0 time=123795 us)
    1 FILTER (cr=1122 pr=1109 pw=0 time=123752 us)
    1 MERGE JOIN OUTER (cr=1122 pr=1109 pw=0 time=123735 us)
    1 SORT JOIN (cr=4 pr=0 pw=0 time=125 us)
    1 TABLE ACCESS BY INDEX ROWID REGNING (cr=4 pr=0 pw=0 time=83 us)
    1 INDEX RANGE SCAN REGNING_IDX_03 (cr=3 pr=0 pw=0 time=64 us)(object id 68870)
    1 SORT JOIN (cr=1118 pr=1109 pw=0 time=123601 us)
    96708 TABLE ACCESS FULL KUNDE (cr=1118 pr=1109 pw=0 time=199 us)
    Rows Execution Plan
    0 SELECT STATEMENT MODE: HINT: RULE
    1 SORT (ORDER BY)
    1 FILTER
    1 MERGE JOIN (OUTER)
    1 SORT (JOIN)
    1 TABLE ACCESS MODE: ANALYZED (BY INDEX ROWID) OF
    'REGNING' (TABLE)
    1 INDEX MODE: ANALYZED (RANGE SCAN) OF
    'REGNING_IDX_03' (INDEX)
    1 SORT (JOIN)
    96708 TABLE ACCESS MODE: ANALYZED (FULL) OF 'KUNDE' (TABLE)
    By using Rule based it uses 0.1 second to fetch one row from the database.
    Anyone seen this problems using Cost based with good statistics and bind variables giving such bad performance .
    Any help would be apreciated.
    rgds
    Kjell

    I have to add that sql that runs with bind variables is defined the following way:
    variable P31_appl_kode varchar2(10);
    variable P31_kundenr varchar2(10);
    variable P31_regningnr varchar2(10);
    variable P31_kundenavn varchar2(10);
    begin
    :p31_appl_kode := 'SKOL';
    :p31_kundenr :=NULL;
    :p31_regningnr :='1150456';
    :p31_kundenavn := null;
    end;
    select /*+ RULE */
    regn.regningnr
    ,regn.appl_kode
    ,regn.regningtekst1
    ,regn.regningdato
    ,regn.kundenr
    ,kund.kundenavn kunde
    from innsyn_kunde.regning regn,
    innsyn_kunde.kunde kund
    where
    regn.appl_kode=kund.appl_kode
    and regn.kundenr=kund.kundenr (+)
    and regn.appl_kode = :P31_appl_kode
    and regn.kundenr like upper(decode(:P31_kundenr,null,'%',:P31_kundenr||'%'))
    and regn.regningnr like decode(:P31_regningnr,null,'%',:P31_regningnr||'%')
    and kund.kundenavn like upper(decode(:P31_kundenavn,null,'%',:P31_kundenavn||'%'))
    order by regn.regningdato desc;
    rgds
    Kjell

  • Problem with Call Library Function. Want to pass a string and return a string, but my compiler does not recognize "CStr" and Labview does not recognize my "char *function()" callout

    Hi, I'm trying to use a .DLL I wrote in Visual C++ .NET. The Call Library Function generates a function prototype of "CStr Parser(CStr arg_raw)"
    but my compiler won't accept this. So I change it to how C normally deals with strings "char *Parser(char *arg_raw). Now the Call Librafy Function does not find "Parser" in my .DLL though it is definitely there!
    Help!
    -Fong

    Hello
    You will need to include extcode.h in your C file. You can find this under ..\LabVIEW\cintools folder.
    The include has all the defines you will need.
    Bilal Durrani
    NI
    Bilal Durrani
    NI

  • Problem in executeQuery(SQL query sentence with a ' );

    for example:
    String strName="";
    //here strName is searching key value.
    String strQueryString="SELECT * FROM Authors WHERE name='" strName "'";
    ResultSet rs=st.executeQuery(strQueryString);
    if strName value is "yijun_lee",that will return all information which the name columns value is "yijun_lee" with SQL Query sentence SELECT * FROM Authors WHERE name='yijun_lee'
    but if strName value is "yijun ' lee",that value contains a '.that will error!
    how to do?
    thanks very much!

    You could parse <strName > and insert another ' for each '
    A concrete example would be SELECT * FROM Authors WHERE name='yijun '' lee'HTH

  • SQL Query Result with Random Sorting

    Hi Experts,
    My Oracle Version : Oracle9i
    I have three tables which are given below,
    Table Name:     check_team
    team_id      team_code
    100          A
    101          B
    102          C
    103          D
    Table Name:     check_product
    product_id     product_code
    1          XXX
    2          XYZ
    Table Name:     check_team_products
    tprod_id     tprod_team_id     tprod_product_id
    1          100          1
    2          100          2
    3          101          1
    4          101          2
    5          102          1
    6          102          2
    7          103          1
    8          103          2
    Required Output First Time:
    team_id   team_code   product_id   product_code
    100       A           1             XXX
    101       B           2             XYZ
    102       A           1             XXX
    103       B           2             XYZ
    Required Output Second Time:
    team_id   team_code   product_id   product_code
    100       B           2             XYZ
    101       A           1             XXX
    102       B           2             XYZ
    103       A           1             XXXI need the result as Required Output specified above and also the result has to be random too.. Can someone help me in writing a SQL Query to get results as that?
    Added Oracle Version

    So, is it something like this you want?
    SQL> ed
    Wrote file afiedt.buf
      1  with check_team as (select 100 as team_id, 'A' as team_code from dual union all
      2                      select 101, 'B' from dual union all
      3                      select 102, 'C' from dual union all
      4                      select 103, 'D' from dual)
      5      ,check_product as (select 1 as product_id, 'XXX' as product_code from dual union all
      6                         select 2, 'XYZ' from dual)
      7      ,check_team_products as (select 1 as tprod_id, 100 as tprod_team_id, 1 as tprod_product_id from dual union all
      8                               select 2, 100, 2 from dual union all
      9                               select 3, 101, 1 from dual union all
    10                               select 4, 101, 2 from dual union all
    11                               select 5, 102, 1 from dual union all
    12                               select 6, 102, 2 from dual union all
    13                               select 7, 103, 1 from dual union all
    14                               select 8, 103, 2 from dual)
    15  --
    16  -- end of test data
    17  --
    18  select team_id, team_code, product_id, product_code
    19  from (
    20        select t.team_id, t.team_code, p.product_id, p.product_code
    21              ,row_number() over (partition by team_id order by dbms_random.random()) as rn
    22        from check_team t join check_team_products tp on (tp.tprod_team_id = t.team_id)
    23                          join check_product p on (p.product_id = tp.tprod_product_id)
    24       )
    25* where rn = 1
    SQL> /
       TEAM_ID T PRODUCT_ID PRO
           100 A          2 XYZ
           101 B          1 XXX
           102 C          2 XYZ
           103 D          1 XXX
    SQL> /
       TEAM_ID T PRODUCT_ID PRO
           100 A          2 XYZ
           101 B          1 XXX
           102 C          2 XYZ
           103 D          1 XXX
    SQL> /
       TEAM_ID T PRODUCT_ID PRO
           100 A          1 XXX
           101 B          2 XYZ
           102 C          1 XXX
           103 D          1 XXX

  • SQL query slow when issued by app, fast when issued mnaually

    Hi there,
    I have a more general question about a specific Oracle behaviour.
    I update a feature from within an application. The application doesn't respond and I finally have to terminate it. I checked Oracle whether a query is running long using the following statement:
    select s.username,s.sid,s.serial#,s.last_call_et/60 mins_running,q.sql_text from v$session s
    join v$sqltext_with_newlines q
    on s.sql_address = q.address
    where status='ACTIVE'
    and type <>'BACKGROUND'
    and last_call_et> 60
    order by sid,serial#,q.piece
    The result of the above query is:
    WITH CONNECTION AS ( SELECT * FROM WW_CONN C WHERE (C.FID_FROM I
    N (SELECT FID FROM WW_LINE WHERE FID_ATTR=:B1 ) AND C.F_CLASS_ID
    FROM =22) OR (C.FIDTO IN (SELECT FID FROM WW_LINE WHERE FID_AT
    TR=:B1 ) AND C.F_CLASS_ID_TO =22) ) SELECT MIN(P.FID_ATTR) AS FI
    D_FROM FROM CONNECTION C, WW_POINT P WHERE (P.FID = C.FID_FROM A
    ND C.F_CLASS_ID_FROM = 32 AND C.FLOW = 1) OR (P.FID = C.FID_TO A
    ND C.F_CLASS_ID_TO = 32 AND C.FLOW = 2)
    I have a different tool which shows me the binding parameter values. So I know that the value for :B1 is 5011 - the id of the feature being updated. This query runs for 20 mins and longer before it eventually stops. The update process involves multiple sql statements - so this one is not doing the update but is part of the process.
    Here is the bit I do not understand: when I run the query in SQL Developer with value 5011 for :B1 it takes 0.5 secs to return a result.
    Why is it, that the sql statement takes so long when issued by the application but takes less than a second when I run it manually?
    I sent a dump of the data to the application vendor who is not able to reproduce the issue in their environment. Could someone explain to me what happens here or give me some keywords for further research?
    We are using 11gR2, 64bit.
    Many thanks,
    Rob

    Hi Rob,
    at least you should see some differences in the statistics for the different child cursor (the one for the execution in the application should show at least a higher value for ELAPSED_TIME). I would use something like the following query to check the information for the child cursors:
    select sql_id
         , PLAN_HASH_VALUE
         , CHILD_NUMBER
         , EXECUTIONS
         , ELAPSED_TIME
         , USER_IO_WAIT_TIME
         , CONCURRENCY_WAIT_TIME
         , DISK_READS
         , BUFFER_GETS
         , ROWS_PROCESSED
      from v$sql
    where sql_id = your_sql_idRegards
    Martin

  • SQL query problem with sorting

    Hi,
    I have question regarding sql query . Right now I am getting the results like this if i use this sql query
    select ID,Name,Desc,Priority from emp order by Priority ;
    Priority is varchar field. I don't want to change the Priority field and cannot add a new column in the table. Because i don't have permission to do that.
    ID Name Desc Priority
    =============================================
    234 paul paul desc Highest
    3452 mike mike desc High
    4342 smith smith desc Low
    6565 kelly kelly desc Low
    9878 nate nate desc Medium
    3223 deb deb desc High
    ============================================
    I need a query to get the results like that.
    ID Name Desc Priority
    =============================================
    234 paul paul desc Highest
    3452 mike mike desc High
    3223 deb deb desc High
    9878 nate nate desc Medium
    4342 smith smith desc Low
    6565 kelly kelly desc Low
    ============================================
    If any one knows about this one, please let me know.
    Thanks,
    Bala

    You are aware that there are differences in the SQL implementation between Sqlserver and Oracle? You could try something like this, if there's a INSTR function:
    ORDER BY INSTR('Highest,High,Medium,Low,', Priority || ',')You may have to change the "Priority || ," to a "Priority + ','), if string concatenation is done differently in sqlserver. Don't know about the ('), maybe you need (").
    C.

Maybe you are looking for

  • Can't get the page to change

    I don't really know much about actionscript, but I want the login page to show up when the movie start, to go away when someone logs in and to come back if someone logs out.  I also want the pages to appear dynamically and not use goToAndStop or .vis

  • Brush size acting up

    Hello guys this is a question I want to ask to you all. when I changed the brush size and paint it looks bigger/smaller but the cursor itself stays the same width other times as the brush got bigger the circle got bigger now its not so its hard to se

  • Zero transducer value

    I am trying to create a vi to zero a differential pressure transducer reading when a button is pushed. I was thinking about acquiring the data with no pressure applied and then using that as a zero offset. Does anyone have any suggestions? I am worki

  • B1i 2007 - I cannot choose Receiver's System in Intercompany Purchasing

    Hi Experts, I have create 2 Landscape called "Head1", "Sub1". Here i went and define "Intercompany Purchasing" scenarion under Business Process. Now i can able to see Sender's System such as "Head1" and "Sub1". *But i cannot able to see anything on m

  • Make Sure Only Black Ink is Used?

    Hello folks, first time posting here so bear with me. Just bought a Laserjet Pro 400 M451nw and am using it on a Mac with Yosemite (even though the driver I installed said it was for Mavericks, it installed ok and is up and running though), my questi