Hi in my sql query i applied like condition (like '%TEST') but it is taking long time

Hi in my sql query i applied like condition (like '%TEST') but it is taking long time. I applied indexes also,but still i'm facing the same problem. In my databse nearly 2,00,000 records their.

Hi Manikandan
Is there a difference in performance between running the query in BEx and WebI?
have you aggregates in place on the BEx side of things?
When you say its taking too long to open the report, have you a variable screen coming up for the report and is that what is taking the time or is it the report execution.
With regards
Gill

Similar Messages

  • SQL Query (updateable report) Region - Conditionally Hide and Set Values

    SQL Query (updateable report) Region - Conditionally Hide and Set Values
    Outline of requirement :-
    Master / Detail page with Detail updated on same page using SQL Query (updateable report).
    The detail region has the following source
    SELECT item_id,
           contract_id,
           CASE WHEN hardware_id IS NOT NULL THEN
                   'HA'
                WHEN backup_dev_id IS NOT NULL THEN
                   'BD'
                WHEN hardware_os_id IS NOT NULL THEN
                   'HS'
           END item_type,
           hardware_id,
           backup_dev_id,
           hardware_os_id
    FROM   "#OWNER#".support_items
    WHERE  contract_id = :P26_CONTRACT_IDThe table support_items implements arced relationships and has the following columns
    CREATE TABLE SUPPORT_ITEMS
      ITEM_ID         NUMBER                        NOT NULL,
      CONTRACT_ID     NUMBER                        NOT NULL,
      HARDWARE_ID     NUMBER,
      BACKUP_DEV_ID   NUMBER,
      HARDWARE_OS_ID  NUMBER
    )A check type constaint on support_items ensures that only one of the fk's is present.
          (    hardware_id    IS NOT NULL
           AND backup_dev_id  IS NULL
           AND hardware_os_id IS NULL
    OR    (    hardware_id    IS NULL
           AND backup_dev_id  IS NOT NULL
           AND hardware_os_id IS NULL
    OR    (    hardware_id    IS NULL
           AND backup_dev_id  IS NULL
           AND hardware_os_id IS NOT NULL
          )    Hardware_Id is a FK to Hardware_Assets
    Backup_dev_id is a FK to Backup_Devices
    Hardware_os_id is a FK to Hardware_op_systems
    The Tabular Form Element based on item_type column of SQL query is Displayed As Select List (based on LOV) referencing a named list of values which have the following properties
    Display Value     Return Value
    Hardware Asset    HA
    Backup Device     BD
    Computer System   HSThe Tabular Form Elements for the report attributes for hardware_id, backup_dev_id and hardware_os_id are all Displayed As Select List (Based on LOV).
    What I want to do is only display the Select List for the FK depending on the value of the Select List on Item Type, e.g.
    Item_Type is 'HA' then display Select List for hardware_id, do not display and set to NULL the Select Lists for backup_dev_id and hardware_os_id.
    Item_Type is 'BB' then display Select List for backup_dev_id, do not display and set to NULL the Select Lists for hardware_id and hardware_os_id.
    Item_Type is 'HS' then display Select List for hardware_os_id, do not display and set to NULL the Select Lists backup_dev_id and hardware_id.
    There are properties on elements to conditionally display it but how do we reference the values of the SQL query Updateable region? they are not given a page item name?
    Also on the Tabular For Elements there is an Edit tick against a report item - however when you go to the Column Attributes there is not a property with which you can control the Edit setting.
    What's the best way of implementing this requirement in APEX 3.1?
    Thanks.

    >
    Welcome to the forum: please read the FAQ and forum sticky threads (if you haven't done so already), and update your profile with a real handle instead of "user13515136".
    When you have a problem you'll get a faster, more effective response by including as much relevant information as possible upfront. This should include:
    <li>Full APEX version
    <li>Full DB/version/edition/host OS
    <li>Web server architecture (EPG, OHS or APEX listener/host OS)
    <li>Browser(s) and version(s) used
    <li>Theme
    <li>Template(s)
    <li>Region/item type(s) (making particular distinction as to whether a "report" is a standard report, an interactive report, or in fact an "updateable report" (i.e. a tabular form)
    With APEX we're also fortunate to have a great resource in apex.oracle.com where we can reproduce and share problems. Reproducing things there is the best way to troubleshoot most issues, especially those relating to layout and visual formatting. If you expect a detailed answer then it's appropriate for you to take on a significant part of the effort by getting as far as possible with an example of the problem on apex.oracle.com before asking for assistance with specific issues, which we can then see at first hand.
    I have a multi-row region that displays values and allows entries in a number of fields.Provide exact details of how this has been implemented. (An example on apex.oracle.com is always a good way to do this.)
    I should like the fields to be conditional in that they do not permit entry, but still display, if certain conditions apply (e.g. older rows greyed out). Can this be done? Almost anything can be done, often in multiple ways. Which are appropriate may be dependent on a particular implementation, the skills available to implement it, and the effort you're willing to expend on it. Hence it's necessary to provide full details of what you've done so far...

  • OTL I am trying to wright a SQL query that will return the date the timesheet was submitted and date/time it was approved, can anyone guide me on this?

    Hi
    I am trying to wright a SQL query that will return the date the timesheet was submitted and date/time it was approved, can anyone guide me on this?
    I basically need person name who submitted, date - time it was submitted for approval, then the person who approved it and the date - time that it was approved
    Thanks
    Ruby

    Ruby,
    you can start with HXC_TIMECARD_SUMMARY table for submitter detail. But for approver details, i think you need WF tables to get the data for item type HXCEMP.

  • This part of query is taking long time to run, its about 40 minutes. Can anyone help wit it.

    ------Load Dataset into Temp table---------------
    SELECT
    z.SYSTEMNAME
    --,Case when ZXC.[Subsystem Name] <> 'NULL' Then zxc.[SubSystem Name]
    --else NULL
    --End AS SubSystemName
    , CASE
    WHEN z.PROV_TAX_ID IN
    (SELECT DISTINCT zxc.TIN
    FROM dbo.SQS_Provider_Tracking zxc
    WHERE zxc.[SubSystem Name] <> 'NULL'
    THEN
    (SELECT DISTINCT [Subsystem Name]
    FROM dbo.SQS_Provider_Tracking zxc
    WHERE z.PROV_TAX_ID = zxc.TIN)
    End As SubSYSTEMNAME
    ,z.PROVIDERNAME
    ,z.STATECODE
    ,z.PROV_TAX_ID
    ,z.SRC_PAR_CD
    ,SUM(z.SEQUEST_AMT) Actual_Sequestered_Amt
    , CASE
    WHEN z.SRC_PAR_CD IN ('E','O','S','W')
    THEN 'Nonpar Waiver'
    --**Amendment Mailed**
    --WHEN z.PROV_TAX_ID IN
    When EXISTS
    (SELECT DISTINCT b.PROV_TIN
    FROM dbo.SQS_Mailed_TINs_010614 b WITH (NOLOCK )
    where not exists (select * from dbo.sqs_objector_TINs t where b.PROV_TIN = t.prov_tin))
    THEN
    (SELECT DISTINCT b.Mailing
    FROM dbo.SQS_Mailed_TINs_010614 b WITH (NOLOCK )
    WHERE z.PROV_TAX_ID = b.PROV_TIN
    -- --**Amendment Mailed Wave 3 and 4**
    --WHEN z.PROV_TAX_ID In
    When EXISTS
    (SELECT
    qz.PROV_TIN
    FROM
    [SQS_Mailed_TINs] qz WITH (NOLOCK )
    where qz.Mailing = 'Amendment Mailed (3rd Wave)'
    and not exists (select * from dbo.sqs_objector_TINs t WITH (NOLOCK ) where qz.PROV_TIN = t.prov_tin))
    THEN 'Amendment Mailed (3rd Wave)'
    WHEN EXISTS
    (SELECT
    qz.PROV_TIN
    FROM
    [SQS_Mailed_TINs] qz WITH (NOLOCK )
    where qz.Mailing = 'Amendment Mailed (4th Wave)'
    and not exists (select * from dbo.sqs_objector_TINs t WITH (NOLOCK ) where qz.PROV_TIN = t.prov_tin))
    THEN 'Amendment Mailed (4th Wave)'
    -- --Is Puerto Rico of Lifesynch
    WHEN EXISTS
    (SELECT DISTINCT a.PROV_TAX_ID
    FROM PACT.dbo.SQS_NonPar_PR_LS_TINs a WITH (NOLOCK )
    WHERE a.Bucket <> 'Nonpar'
    THEN
    (SELECT DISTINCT a.Bucket
    FROM PACT.dbo.SQS_NonPar_PR_LS_TINs a WITH (NOLOCK )
    WHERE a.PROV_TAX_ID = z.PROV_TAX_ID)
    -- --**Top Objecting Systems**
    WHEN z.SYSTEMNAME IN
    ('ADVENTIST HEALTH SYSTEM','ASCENSION HEALTH ALLIANCE','AULTMAN HEALTH FOUNDATION','BANNER HEALTH SYSTEM','BERT FISH MEDICAL CENTER','BETHESDA MEMORIAL HOSPITAL','BJC HEALTHCARE','BLOUNT MEMORIAL HOSPITAL','BOCA RATON REGIONAL HOSPITAL','CAROMONT HEALTH SYSTEM','CATHOLIC HEALTH INITIATIVES','CATHOLIC HEALTHCARE PARTNERS','CHRISTUS HEALTH',/*'CLEVELAND CLINIC HEALTH SYSTEM',*/'COLUMBUS REGIONAL HEALTHCARE SYSTEM','COMMUNITY HEALTH SYSTEMS, INC','COXHEALTH','HCA','HEALTH MANAGEMENT ASSOCIATES','HUNTSVILLE HOSPITAL HEALTH SYSTEM','INTEGRIS HEALTH','JUPITER MEDICAL CENTER','LEE MEMORIAL HEALTH SYSTEM','MARTIN MEMORIAL HEALTH SYSTEM','MERCY','MT SINAI MEDICAL CENTER (MIAMI)','MUNROE REGIONAL MEDICAL CENTER','NORMAN REGIONAL HEALTH SYSTEM','NORTHSIDE HEALTH SYSTEM','SHANDS HEALTHCARE','SISTERS OF MERCY - SPRINGFIELD, MO','SSM HEALTH CARE','ST LUKES HEALTH SYSTEM','SUMMA HEALTH SYSTEM','SUSQUEHANNA HEALTH SYSTEM','TBD -- TRINITY HEALTH - CATHOLIC HEALTH EAST','UNIVERSITY OF MISSOURI HEALTH SYSTEM','UNIVERSITY OF NEW MEXICO HOSPITALS','UNIVERSITY OF UTAH HEALTH CARE')
    THEN 'Top Objecting Systems'
    WHEN EXISTS
    (SELECT
    h.PROV_TAX_ID
    FROM
    #HIHO_Records h
    INNER JOIN SQS_Provider_Tracking obj WITH (NOLOCK )
    ON h.PROV_TAX_ID = obj.TIN
    AND obj.[Objector?] = 'Top Objector'
    WHERE z.PROV_TAX_ID = h.PROV_TAX_ID
    OR h.SMG_ID IS NOT NULL
    )and z.LCLM_RSTMT_TREND_CAT_CD IN ('HO','HI')
    THEN 'Top Objecting Systems'
    -- --**Other Objecting Hospitals**
    WHEN EXISTS
    (SELECT
    h.PROV_TAX_ID
    FROM
    #HIHO_Records h
    INNER JOIN SQS_Provider_Tracking obj WITH (NOLOCK )
    ON h.PROV_TAX_ID = obj.TIN
    AND obj.[Objector?] = 'Objector'
    WHERE z.PROV_TAX_ID = h.PROV_TAX_ID
    OR h.SMG_ID IS NOT NULL
    )and z.LCLM_RSTMT_TREND_CAT_CD IN ('HO','HI')
    THEN 'Other Objecting Hospitals'
    -- --**Objecting Physicians**
    WHEN EXISTS
    (SELECT z.PROV_TAX_ID
    FROM SQS_EDW_Source z WITH (NOLOCK)
    WHERE EXISTS
    (SELECT DISTINCT
    obj.TIN
    FROM SQS_Provider_Tracking obj WITH (NOLOCK )
    WHERE obj.[Objector?] in ('Objector','Top Objector')
    and z.PROV_TAX_ID = obj.TIN
    and z.LCLM_RSTMT_TREND_CAT_CD not IN ('HO','HI')
    THEN 'Objecting Physicians'
    --****Rejecting Hospitals****
    WHEN EXISTS
    (SELECT
    h.PROV_TAX_ID
    FROM
    #HIHO_Records h
    INNER JOIN SQS_Provider_Tracking obj WITH (NOLOCK )
    ON h.PROV_TAX_ID = obj.TIN
    AND obj.[Objector?] = 'Rejector'
    WHERE z.PROV_TAX_ID = h.PROV_TAX_ID
    OR h.SMG_ID IS NOT NULL
    )and z.LCLM_RSTMT_TREND_CAT_CD IN ('HO','HI')
    THEN 'Rejecting Hospitals'
    --****Rejecting Physciains****
    WHEN EXISTS
    (SELECT obj.TIN
    FROM SQS_Provider_Tracking obj WITH (NOLOCK )
    WHERE z.PROV_TAX_ID = obj.TIN
    AND obj.[Objector?] = 'Rejector')
    and z.LCLM_RSTMT_TREND_CAT_CD NOT IN ('HO','HI')
    THEN 'REjecting Physicians'
    ----**********ALL OBJECTORS SHOULD HAVE BEEN BUCKETED AT THIS POINT IN THE QUERY**********
    -- --**Non-Objecting Hospitals**
    WHEN EXISTS
    (SELECT DISTINCT
    h.PROV_TAX_ID
    FROM
    #HIHO_Records h WITH (NOLOCK )
    WHERE
    (z.PROV_TAX_ID = h.PROV_TAX_ID)
    OR h.SMG_ID IS NOT NULL
    )and z.LCLM_RSTMT_TREND_CAT_CD IN ('HO','HI')
    THEN 'Non-Objecting Hospitals'
    -- **Outstanding Contracts for Review**
    WHEN EXISTS
    (SELECT qz.PROV_TIN
    FROM
    [PACT].[HUMAD\ARS3766].[SQS_Mailed_TINs] qz WITH (NOLOCK )
    where qz.Mailing = 'Non-Objecting Bilateral Physicians'
    AND z.PROV_TAX_ID = qz.PROV_TIN)
    Then 'Non-Objecting Bilateral Physicians'
    When EXISTS
    (select
    p.prov_tax_id
    from dbo.SQS_CoC_Potential_Mail_List p WITH (NOLOCK )
    where p.amendmentrights <> 'Unilateral'
    AND z.prov_tax_id = p.prov_tax_id)
    THEN 'Non-Objecting Bilateral Physicians'
    WHEN EXISTS
    (SELECT
    qz.PROV_TIN
    FROM
    [SQS_Mailed_TINs] qz WITH (NOLOCK )
    where qz.Mailing = 'More Research Needed'
    AND qz.PROV_TIN = z.PROV_TAX_ID)
    THEN 'More Research Needed'
    WHEN EXISTS (SELECT qz.PROV_TIN FROM [SQS_Mailed_TINs] qz WITH (NOLOCK ) where qz.Mailing = 'Objector' AND qz.PROV_TIN = z.PROV_TAX_ID)
    THEN 'ERROR'
    else 'Market Review/Preparing to Mail'
    END AS [Updated Bucket]
    ,COALESCE(q.INDdesc, f.IND_desc) AS INDdesc
    ,f.Time_Period_for_Dispute
    ,f.Renew_Term_Ind
    ,f.Renewal_Date
    ,z.SMG_ID
    ,'' AS OrderedRank
    INTO SQS_Bucketed_Details_SMG_on_SMGXXX
    From #SQS_EDW_SOURCE_WithSMG z
    left join #F f ON f.PROV_TAX_ID = z.PROV_TAX_ID
    AND z.SYSTEMNAME = f.SYSTEM_NAME
    AND z.PROVIDERNAME = f.Provider
    Left join #Q q ON z.PROV_TAX_ID = q.TIN
    GROUP BY z.SYSTEMNAME
    --,Z.[SubsystemName]
    ,z.PROVIDERNAME
    ,z.STATECODE
    ,z.PROV_TAX_ID
    ,z.SRC_PAR_CD
    ,q.INDdesc
    ,f.IND_Desc
    ,f.Time_Period_for_Dispute
    ,f.Renew_Term_Ind
    ,f.Renewal_Date
    ,z.SMG_ID
    ,z.LCLM_RSTMT_TREND_CAT_CD
    As I am a developer I do not have the access to Sql profiler or tuning agent to optimize my query, I have used some joins over the temp table #HIHO which indeed pulling the records from table EDW_Source which has 5 million records, I also added Non clustered
    indexes on prov_ID, SMG_ID and Incurred month for this table, but still it is taking longer time. Need help

    Hi, It needs some more tweaks but pls try this one
    USE
    Go
    --****Create sqs_objector_TINs (Objections and Rejections)****
    --Drop table .dbo.sqs_objector_TINs
    select distinct a.TIN as Prov_TIN
    Into #sqs_objector_TINs
    from .dbo.sqs_provider_tracking as a with (nolock)
    where a.[Objector?] in ('Top Objector','Objector','Rejector')
    /*********** Query for SQS_TINtoSyst***********/
    --DROP TABLE .dbo.SQS_TINtoSystem
    select distinct
    b.SRC_PROV_ID
    --,case
    -- when a.SYSTEM_NAME is null
    -- then
    -- case
    -- when a.CTRCT_GRP_NAME is null
    -- then a.PROV_SMG_NAME
    -- else a.CTRCT_GRP_NAME
    -- end
    -- else a.SYSTEM_NAME
    --end as SYSTEM_NAME
    ,COALESCE(a.SYSTEM_NAME, a.CTRCT_GRP_NAME, a.PROV_SMG_NAME) AS SYSTEM_NAME
    INTO #SQS_TINtoSystem
    from
    PARE.dbo.EDW_PROD_HOSPITAL_MASTER a with (nolock)
    Inner Join PARE.dbo.EDW_PROD_HOSPITAL_ID_XREF b with (nolock)
    on a.SMG_ID = b.SMG_ID
    -- Inner Join .dbo.SQS_EDW_Source q
    --on b.SRC_PROV_ID = q.PROV_TAX_ID
    where b.SRC_PLATFORM_CD = 'TX'
    and exists
    select
    SMG_ID
    from PARE.dbo.EDW_PROD_HOSPITAL_ID_XREF as t1 with (nolock)
    where SRC_PLATFORM_CD = 'TX'
    and exists (select q.PROV_TAX_ID from .dbo.SQS_EDW_Source q with (nolock) where q.PROV_TAX_ID = b.SRC_PROV_ID)
    and a.SMG_ID = t1.SMG_ID
    /************** Query for SQS_Bucketed_Details_SMG*****************/
    DROP TABLE .dbo.SQS_Bucketed_Details_SMG
    --Create temp table
    SELECT z.SYSTEMNAME
    ,Z.PROV_TAX_ID
    ,z.PROVIDERNAME
    ,z.STATECODE
    ,z.SRC_PAR_CD
    ,z.SEQUEST_AMT
    ,case when Z.LCLM_RSTMT_TREND_CAT_CD IN ('HI','HO') Then 'H' else 'P' end as Hosp_Ind
    ,Z.SMG_ID
    INTO #SQS_EDW_SOURCE_WithSMG
    FROM dbo.SQS_EDW_SOURCE_WithSMG z with (nolock)
    WHERE (Z.Incurred_Mth >= convert(datetime,'01/01/2013')) and (Z.Incurred_Mth < convert(datetime, '1/1/2014'))
    --between convert(datetime,'01/01/2013') and convert(datetime, '12/31/2013 23:59:59.996')
    --YEAR(Z.Incurred_Mth)=2013
    -- Create Temp table Q
    select
    x.TIN,
    case when max(x.IND) = 'NYN'
    then 'Standard'
    when max(x.IND) = 'YNN'
    then 'Express'
    when max(x.IND) = 'NNY'
    then 'Non_Standard' else 'Mixed'
    end as INDdesc
    Into #Q
    FROM
    (SELECT
    a.tin,
    MAX(a.express) + MAX(a.StandardInd) + MAX(NonstandardIND) as IND
    from
    (select r.TIN,
    case when MAX(r.Express) like 'Y%' then 'Y' else 'N' end As Express,
    case when MAX(r.Standard) = 'Y' then 'Y' else 'N' end As StandardInd,
    case when MAX(r.[Non-Standard]) = 'Y' then 'Y' else 'N' end AS NonstandardIND
    FROM DBO.SQS_Objectors_01032014 r with (nolock)
    GROUP BY r.TIN) a
    group by a.TIN) x
    group by x.TIN
    --Create Temp table F
    Select *
    INTO #F
    FROM(
    SELECT distinct g.prov_tax_id
    ,g.system_name
    ,g.provider
    ,case when g.reimburse_mixed = 'Y' then 'Mixed'
    when g.reimburse_express = 'Y' then 'Express'
    when g.reimburse_standard = 'Y' then 'Standard'
    when g.reimburse_NonStandard = 'Y' then 'NonStandard'
    end as IND_Desc
    ,g.Time_Period_for_Dispute
    ,case when g.Renewal_Date = 'N' and g.Expiration_Date = 'N'
    then 'Unclear'
    when g.Renewal_Date = 'N' and g.Expiration_Date <> 'N'
    then 'Termination'
    when g.Renewal_Date <> 'N' and g.Expiration_Date = 'N'
    then 'Evergreen'
    when g.Renewal_Date <> 'N' and g.Expiration_Date <> 'N'
    then 'Termination'
    else 'Unknown'
    end as 'Renew_Term_Ind'
    ,g.Renewal_Date
    FROM
    (select distinct
    bb.PROV_TAX_ID1 as prov_tax_id
    ,aa.*
    from
    [dbo].[Top_600_Hospitals3] aa with (nolock)
    left join pare.dbo.EDW_PROD_HOSPITAL_MASTER bb with (nolock)
    on --a.CTRCT_GRP_NAME = b.CTRCT_GRP_NAME
    aa.Provider = bb.PROV_SMG_NAME
    -- and (a.SYSTEM_NAME = b.SMG_SYS_NAME or a.SYSTEM_NAME = b.SYSTEM_NAME)
    --and a.ADDR_LINE1 = b.ADDR_LINE1
    and aa.STATE_CD = bb.STATE_CD
    --and a.ZIP_CD = b.ZIP_CD
    and aa.City1 = bb.CITY_NAME
    where aa.SYSTEM_NAME <> 'SEE ABOVE') g
    where g.system_name <> 'SEE ABOVE') h
    where h.ind_Desc is not null
    SELECT DISTINCT z.PROV_TAX_ID
    , z.SMG_ID
    INTO #HIHO_Records
    FROM SQS_EDW_SOURCE_WithSMG z with (nolock)
    WHERE z.LCLM_RSTMT_TREND_CAT_CD IN ('HO', 'HI')
    AND Z.Incurred_Mth >=convert(datetime, '1/1/2013') and Z.Incurred_Mth <convert(datetime, '1/1/2014')
    --YEAR(Z.Incurred_Mth)=2013
    ---------------------------------Load Dataset into Temp table---------------
    SELECT
    z.SYSTEMNAME
    --,Case when ZXC.[Subsystem Name] <> 'NULL' Then zxc.[SubSystem Name]
    --else NULL
    --End AS SubSystemName
    , CASE
    WHEN z.PROV_TAX_ID IN
    (SELECT zxc.TIN
    FROM dbo.SQS_Provider_Tracking zxc with (nolock)
    WHERE zxc.[SubSystem Name] <> 'NULL'
    THEN
    (SELECT top 1 [Subsystem Name]
    FROM dbo.SQS_Provider_Tracking zxc with (nolock)
    WHERE z.PROV_TAX_ID = zxc.TIN)
    End As SubSYSTEMNAME
    ,z.PROVIDERNAME
    ,z.STATECODE
    ,z.PROV_TAX_ID
    ,z.SRC_PAR_CD
    ,SUM(z.SEQUEST_AMT) Actual_Sequestered_Amt
    , CASE
    WHEN z.SRC_PAR_CD IN ('E','O','S','W')
    THEN 'Nonpar Waiver'
    -- --Is Puerto Rico of Lifesynch
    WHEN z.PROV_TAX_ID IN
    (SELECT a.PROV_TAX_ID
    FROM .dbo.SQS_NonPar_PR_LS_TINs a with (nolock)
    WHERE a.Bucket <> 'Nonpar'
    THEN
    (SELECT top 1 a.Bucket
    FROM .dbo.SQS_NonPar_PR_LS_TINs a with (nolock)
    WHERE a.PROV_TAX_ID = z.PROV_TAX_ID)
    --**Amendment Mailed**
    WHEN z.PROV_TAX_ID IN
    (SELECT b.PROV_TIN
    FROM dbo.SQS_Mailed_TINs_010614 b WITH (NOLOCK )
    where not exists (select * from dbo.sqs_objector_TINs t with (nolock) where b.PROV_TIN = t.prov_tin))
    and z.Hosp_Ind = 'P'
    THEN
    (SELECT top 1 b.Mailing
    FROM dbo.SQS_Mailed_TINs_010614 b with (nolock)
    WHERE z.PROV_TAX_ID = b.PROV_TIN
    -- --**Amendment Mailed Wave 3-5**
    WHEN z.PROV_TAX_ID In
    (SELECT
    qz.PROV_TIN
    FROM
    [SQS_Mailed_TINs] qz
    where qz.Mailing = 'Amendment Mailed (3rd Wave)'
    and not exists (select * from dbo.sqs_objector_TINs t with (nolock) where qz.PROV_TIN = t.prov_tin))
    and z.Hosp_Ind = 'P'
    THEN 'Amendment Mailed (3rd Wave)'
    WHEN z.PROV_TAX_ID IN
    (SELECT
    qz.PROV_TIN
    FROM
    [SQS_Mailed_TINs] qz
    where qz.Mailing = 'Amendment Mailed (4th Wave)'
    and not exists (select * from dbo.sqs_objector_TINs t with (nolock) where qz.PROV_TIN = t.prov_tin))
    and z.Hosp_Ind = 'P'
    THEN 'Amendment Mailed (4th Wave)'
    WHEN z.PROV_TAX_ID IN
    (SELECT
    qz.PROV_TIN
    FROM
    [SQS_Mailed_TINs] qz
    where qz.Mailing = 'Amendment Mailed (5th Wave)'
    and not exists (select * from dbo.sqs_objector_TINs t with (nolock) where qz.PROV_TIN = t.prov_tin))
    and z.Hosp_Ind = 'P'
    THEN 'Amendment Mailed (5th Wave)'
    -- --**Top Objecting Systems**
    WHEN z.SYSTEMNAME IN
    ('ADVENTIST HEALTH SYSTEM','ASCENSION HEALTH ALLIANCE','AULTMAN HEALTH FOUNDATION')
    THEN 'Top Objecting Systems'
    WHEN z.PROV_TAX_ID IN
    (SELECT
    h.PROV_TAX_ID
    FROM
    #HIHO_Records h
    INNER JOIN .dbo.SQS_Provider_Tracking obj with (nolock)
    ON h.PROV_TAX_ID = obj.TIN
    AND obj.[Objector?] = 'Top Objector'
    WHERE z.PROV_TAX_ID = h.PROV_TAX_ID
    OR h.SMG_ID IS NOT NULL
    )and z.Hosp_Ind = 'H'
    THEN 'Top Objecting Systems'
    -- --**Other Objecting Hospitals**
    WHEN (z.PROV_TAX_ID IN
    (SELECT
    h.PROV_TAX_ID
    FROM
    #HIHO_Records h
    INNER JOIN .dbo.SQS_Provider_Tracking obj with (nolock)
    ON h.PROV_TAX_ID = obj.TIN
    AND obj.[Objector?] = 'Objector'
    WHERE z.PROV_TAX_ID = h.PROV_TAX_ID
    OR h.SMG_ID IS NOT NULL
    )and z.Hosp_Ind = 'H')
    THEN 'Other Objecting Hospitals'
    -- --**Objecting Physicians**
    WHEN (z.PROV_TAX_ID IN
    (SELECT
    obj.TIN
    FROM .dbo.SQS_Provider_Tracking obj with (nolock)
    WHERE obj.[Objector?] in ('Objector','Top Objector')
    and z.PROV_TAX_ID = obj.TIN
    and z.Hosp_Ind = 'P')
    THEN 'Objecting Physicians'
    --****Rejecting Hospitals****
    WHEN (z.PROV_TAX_ID IN
    (SELECT
    h.PROV_TAX_ID
    FROM
    #HIHO_Records h
    INNER JOIN .dbo.SQS_Provider_Tracking obj with (nolock)
    ON h.PROV_TAX_ID = obj.TIN
    AND obj.[Objector?] = 'Rejector'
    WHERE z.PROV_TAX_ID = h.PROV_TAX_ID
    OR h.SMG_ID IS NOT NULL
    )and z.Hosp_Ind = 'H')
    THEN 'Rejecting Hospitals'
    --****Rejecting Physciains****
    WHEN
    (z.PROV_TAX_ID IN
    (SELECT
    obj.TIN
    FROM .dbo.SQS_Provider_Tracking obj with (nolock)
    WHERE z.PROV_TAX_ID = obj.TIN
    AND obj.[Objector?] = 'Rejector')
    and z.Hosp_Ind = 'P')
    THEN 'REjecting Physicians'
    ----**********ALL OBJECTORS SHOULD HAVE BEEN BUCKETED AT THIS POINT IN THE QUERY**********
    -- --**Non-Objecting Hospitals**
    WHEN z.PROV_TAX_ID IN
    (SELECT
    h.PROV_TAX_ID
    FROM
    #HIHO_Records h
    WHERE
    (z.PROV_TAX_ID = h.PROV_TAX_ID)
    OR h.SMG_ID IS NOT NULL)
    and z.Hosp_Ind = 'H'
    THEN 'Non-Objecting Hospitals'
    -- **Outstanding Contracts for Review**
    WHEN z.PROV_TAX_ID IN
    (SELECT
    qz.PROV_TIN
    FROM
    [SQS_Mailed_TINs] qz with (nolock)
    where qz.Mailing = 'Non-Objecting Bilateral Physicians'
    AND z.PROV_TAX_ID = qz.PROV_TIN)
    Then 'Non-Objecting Bilateral Physicians'
    When z.prov_tax_id in
    (select
    p.prov_tax_id
    from dbo.SQS_CoC_Potential_Mail_List p with (nolock)
    where p.amendmentrights <> 'Unilateral'
    AND z.prov_tax_id = p.prov_tax_id)
    THEN 'Non-Objecting Bilateral Physicians'
    WHEN z.PROV_TAX_ID IN
    (SELECT
    qz.PROV_TIN
    FROM
    [SQS_Mailed_TINs] qz
    where qz.Mailing = 'More Research Needed'
    AND qz.PROV_TIN = z.PROV_TAX_ID)
    THEN 'More Research Needed'
    WHEN z.PROV_TAX_ID IN (SELECT qz.PROV_TIN FROM [SQS_Mailed_TINs] qz with (nolock) where qz.Mailing = 'Objector' AND qz.PROV_TIN = z.PROV_TAX_ID)
    THEN 'ERROR'
    else 'Market Review/Preparing to Mail'
    END AS [Updated Bucket]
    ,COALESCE(q.INDdesc, f.IND_desc) AS INDdesc
    ,f.Time_Period_for_Dispute
    ,f.Renew_Term_Ind
    ,f.Renewal_Date
    ,z.SMG_ID
    ,'' AS OrderedRank
    INTO dbo.SQS_Bucketed_Details_SMG with (nolock)
    From #SQS_EDW_SOURCE_WithSMG z
    left join #F f ON f.PROV_TAX_ID = z.PROV_TAX_ID
    AND z.SYSTEMNAME = f.SYSTEM_NAME
    AND z.PROVIDERNAME = f.Provider
    Left join #Q q ON z.PROV_TAX_ID = q.TIN
    GROUP BY z.SYSTEMNAME
    --,Z.[SubsystemName]
    ,z.PROVIDERNAME
    ,z.STATECODE
    ,z.PROV_TAX_ID
    ,z.SRC_PAR_CD
    ,q.INDdesc
    ,f.IND_Desc
    ,f.Time_Period_for_Dispute
    ,f.Renew_Term_Ind
    ,f.Renewal_Date
    ,z.SMG_ID
    ,z.Hosp_Ind
    /************************** Drop temp tables*********************/
    --DROP TABLE #SQS_EDW_SOURCE_WithSMG
    --DROP TABLE #Q
    --DROP TABLE #F
    --DROP TABLE #HIHO_Records
    --DROP TABLE #SQS_TINtoSystem
    --DROP TABLE #SQS_EDW_SOURCE_WithSMG
    --DROP TABLE #sqs_objector_TINs

  • Query taking long time to run.

    The following query is taking long time to run, is there anything can be done to make it run faster by changing the sql etc.
    select distinct
    A.DEPTID,
    A.POSITION_NBR,
    A.EMPLID,
    A.EMPL_RCD_NBR,
    A.EFFDT,
    B.NAME,
    A.EMPL_STATUS,
    A.JOBCODE,
    A.ANNUAL_RT,
    A.STD_HOURS,
    A.PRIMARY_JOB,
    C.POSN_STATUS,
    case when A.POSITION_NBR = ' ' then 0 else C.STD_HOURS end,
    case when A.POSITION_NBR = ' ' then ' ' else C.DEPTID end
    from PS_JOB A,
    PS_PERSONAL_DATA B,
    PS_POSITION_DATA C
    where A.EMPLID = B.EMPLID
    and
    ((A.POSITION_NBR = C.POSITION_NBR
    and A.EFFSEQ = (select max(D.EFFSEQ)
    from PS_JOB D
    where D.EMPLID = A.EMPLID
    and D.EMPL_RCD_NBR = A.EMPL_RCD_NBR
    and D.EFFDT = A.EFFDT)
    and C.POSN_STATUS <> 'G'
    and C.EFFDT = (select max(E.EFFDT)
    from PS_POSITION_DATA E
    where E.POSITION_NBR = A.POSITION_NBR
    and E.EFFDT <= A.EFFDT)
    and C.EFFSEQ = (select max(F.EFFSEQ)
    from PS_POSITION_DATA F
    where F.POSITION_NBR = A.POSITION_NBR
    and F.EFFDT = C.EFFDT))
    or
    (A.POSITION_NBR = C.POSITION_NBR
    and A.EFFDT = (select max(D.EFFDT)
    from PS_JOB D
    where D.EMPLID = A.EMPLID
    and D.EMPL_RCD_NBR = A.EMPL_RCD_NBR
    and D.EFFDT <= C.EFFDT)
    and A.EFFSEQ = (select max(E.EFFSEQ)
    from PS_JOB E
    where E.EMPLID = A.EMPLID
    and E.EMPL_RCD_NBR = A.EMPL_RCD_NBR
    and E.EFFDT = A.EFFDT)
    and C.POSN_STATUS <> 'G'
    and C.EFFSEQ = (select max(F.EFFSEQ)
    from PS_POSITION_DATA F
    where F.POSITION_NBR = A.POSITION_NBR
    and F.EFFDT = C.EFFDT)))
    or
    (A.POSITION_NBR = ' '
    and A.EFFSEQ = (select max(E.EFFSEQ)
    from PS_JOB D
    where D.EMPLID = A.EMPLID
    and E.EMPL_RCD_NBR = A.EMPL_RCD_NBR
    and D.EFFDT = A.EFFDT)))

    Using distributive law A and (B or C) = (A and B) or (A and C) from right to left we can have:
    select distinct A.DEPTID,A.POSITION_NBR,A.EMPLID,A.EMPL_RCD_NBR,A.EFFDT,B.NAME,A.EMPL_STATUS,
                    A.JOBCODE,A.ANNUAL_RT,A.STD_HOURS,A.PRIMARY_JOB,C.POSN_STATUS,
                    case when A.POSITION_NBR = ' ' then 0 else C.STD_HOURS end,
                    case when A.POSITION_NBR = ' ' then ' ' else C.DEPTID end
      from PS_JOB A,PS_PERSONAL_DATA B,PS_POSITION_DATA C
    where A.EMPLID = B.EMPLID
       and (
             A.POSITION_NBR = C.POSITION_NBR
         and A.EFFSEQ = (select max(D.EFFSEQ)
                           from PS_JOB D
                          where D.EMPLID = A.EMPLID
                            and D.EMPL_RCD_NBR = A.EMPL_RCD_NBR
                            and D.EFFDT = A.EFFDT
         and C.EFFSEQ = (select max(F.EFFSEQ)
                           from PS_POSITION_DATA E
                          where E.POSITION_NBR = A.POSITION_NBR
                            and E.EFFDT = C.EFFDT
         and C.POSN_STATUS != 'G'
         and (
               C.EFFDT = (select max(E.EFFDT) 
                            from PS_POSITION_DATA E
                           where E.POSITION_NBR = A.POSITION_NBR
                             and E.EFFDT <= A.EFFDT
           or
               A.EFFDT = (select max(D.EFFDT) 
                            from PS_JOB D
                           where D.EMPLID = A.EMPLID
                             and D.EMPL_RCD_NBR = A.EMPL_RCD_NBR
                             and D.EFFDT <= C.EFFDT
         or
             A.POSITION_NBR = ' '
               and A.EFFSEQ = (select max(E.EFFSEQ)
                                 from PS_JOB D
                                where D.EMPLID = A.EMPLID
                                  and E.EMPL_RCD_NBR = A.EMPL_RCD_NBR
                                  and D.EFFDT = A.EFFDT
           )may not help much as the optimizer might have guessed it already
    Regards
    Etbin

  • Query taking long time for EXTRACTING the data more than 24 hours

    Hi ,
    Query taking long time for EXTRACTING the data more than 24 hours please find the query and explain plan details below even indexes avilable on table's goe's to FULL TABLE SCAN. please suggest me.......
    SQL> explain plan for select a.account_id,round(a.account_balance,2) account_balance,
    2 nvl(ah.invoice_id,ah.adjustment_id) transaction_id,
    to_char(ah.effective_start_date,'DD-MON-YYYY') transaction_date,
    to_char(nvl(i.payment_due_date,
    to_date('30-12-9999','dd-mm-yyyy')),'DD-MON-YYYY')
    due_date, ah.current_balance-ah.previous_balance amount,
    decode(ah.invoice_id,null,'A','I') transaction_type
    3 4 5 6 7 8 from account a,account_history ah,invoice i_+
    where a.account_id=ah.account_id
    and a.account_type_id=1000002
    and round(a.account_balance,2) > 0
    and (ah.invoice_id is not null or ah.adjustment_id is not null)
    and ah.CURRENT_BALANCE > ah.previous_balance
    and ah.invoice_id=i.invoice_id(+)
    AND a.account_balance > 0
    order by a.account_id,ah.effective_start_date desc; 9 10 11 12 13 14 15 16
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    | Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)|
    | 0 | SELECT STATEMENT | | 544K| 30M| | 693K (20)|
    | 1 | SORT ORDER BY | | 544K| 30M| 75M| 693K (20)|
    |* 2 | HASH JOIN | | 544K| 30M| | 689K (20)|
    |* 3 | TABLE ACCESS FULL | ACCOUNT | 20080 | 294K| | 6220 (18)|
    |* 4 | HASH JOIN OUTER | | 131M| 5532M| 5155M| 678K (20)|
    |* 5 | TABLE ACCESS FULL| ACCOUNT_HISTORY | 131M| 3646M| | 197K (25)|
    | 6 | TABLE ACCESS FULL| INVOICE | 262M| 3758M| | 306K (18)|
    Predicate Information (identified by operation id):
    2 - access("A"."ACCOUNT_ID"="AH"."ACCOUNT_ID")
    3 - filter("A"."ACCOUNT_TYPE_ID"=1000002 AND "A"."ACCOUNT_BALANCE">0 AND
    ROUND("A"."ACCOUNT_BALANCE",2)>0)
    4 - access("AH"."INVOICE_ID"="I"."INVOICE_ID"(+))
    5 - filter("AH"."CURRENT_BALANCE">"AH"."PREVIOUS_BALANCE" AND ("AH"."INVOICE_ID"
    IS NOT NULL OR "AH"."ADJUSTMENT_ID" IS NOT NULL))
    22 rows selected.
    Index Details:+_
    SQL> select INDEX_OWNER,INDEX_NAME,COLUMN_NAME,TABLE_NAME from dba_ind_columns where
    2 table_name in ('INVOICE','ACCOUNT','ACCOUNT_HISTORY') order by 4;
    INDEX_OWNER INDEX_NAME COLUMN_NAME TABLE_NAME
    OPS$SVM_SRV4 P_ACCOUNT ACCOUNT_ID ACCOUNT
    OPS$SVM_SRV4 U_ACCOUNT_NAME ACCOUNT_NAME ACCOUNT
    OPS$SVM_SRV4 U_ACCOUNT CUSTOMER_NODE_ID ACCOUNT
    OPS$SVM_SRV4 U_ACCOUNT ACCOUNT_TYPE_ID ACCOUNT
    OPS$SVM_SRV4 I_ACCOUNT_ACCOUNT_TYPE ACCOUNT_TYPE_ID ACCOUNT
    OPS$SVM_SRV4 I_ACCOUNT_INVOICE INVOICE_ID ACCOUNT
    OPS$SVM_SRV4 I_ACCOUNT_PREVIOUS_INVOICE PREVIOUS_INVOICE_ID ACCOUNT
    OPS$SVM_SRV4 U_ACCOUNT_NAME_ID ACCOUNT_NAME ACCOUNT
    OPS$SVM_SRV4 U_ACCOUNT_NAME_ID ACCOUNT_ID ACCOUNT
    OPS$SVM_SRV4 I_LAST_MODIFIED_ACCOUNT LAST_MODIFIED ACCOUNT
    OPS$SVM_SRV4 I_ACCOUNT_INVOICE_ACCOUNT INVOICE_ACCOUNT_ID ACCOUNT
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_ACCOUNT ACCOUNT_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_ACCOUNT SEQNR ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_INVOICE INVOICE_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_ADINV INVOICE_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_CIA CURRENT_BALANCE ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_CIA INVOICE_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_CIA ADJUSTMENT_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_CIA ACCOUNT_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_LMOD LAST_MODIFIED ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_ADINV ADJUSTMENT_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_PAYMENT PAYMENT_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_ADJUSTMENT ADJUSTMENT_ID ACCOUNT_HISTORY
    OPS$SVM_SRV4 I_ACCOUNT_HISTORY_APPLIED_DT APPLIED_DATE ACCOUNT_HISTORY
    OPS$SVM_SRV4 P_INVOICE INVOICE_ID INVOICE
    OPS$SVM_SRV4 U_INVOICE CUSTOMER_INVOICE_STR INVOICE
    OPS$SVM_SRV4 I_LAST_MODIFIED_INVOICE LAST_MODIFIED INVOICE
    OPS$SVM_SRV4 U_INVOICE_ACCOUNT ACCOUNT_ID INVOICE
    OPS$SVM_SRV4 U_INVOICE_ACCOUNT BILL_RUN_ID INVOICE
    OPS$SVM_SRV4 I_INVOICE_BILL_RUN BILL_RUN_ID INVOICE
    OPS$SVM_SRV4 I_INVOICE_INVOICE_TYPE INVOICE_TYPE_ID INVOICE
    OPS$SVM_SRV4 I_INVOICE_CUSTOMER_NODE CUSTOMER_NODE_ID INVOICE
    32 rows selected.
    Regards,
    Bathula
    Oracle-DBA

    I have some suggestions. But first, you realize that you have some redundant indexes, right? You have an index on account(account_name) and also account(account_name, account_id), and also account_history(invoice_id) and account_history(invoice_id, adjustment_id). No matter, I will suggest some new composite indexes.
    Also, you do not need two lines for these conditions:
    and round(a.account_balance, 2) > 0
    AND a.account_balance > 0
    You can just use: and a.account_balance >= 0.005
    So the formatted query isselect a.account_id,
           round(a.account_balance, 2) account_balance,
           nvl(ah.invoice_id, ah.adjustment_id) transaction_id,
           to_char(ah.effective_start_date, 'DD-MON-YYYY') transaction_date,
           to_char(nvl(i.payment_due_date, to_date('30-12-9999', 'dd-mm-yyyy')),
                   'DD-MON-YYYY') due_date,
           ah.current_balance - ah.previous_balance amount,
           decode(ah.invoice_id, null, 'A', 'I') transaction_type
      from account a, account_history ah, invoice i
    where a.account_id = ah.account_id
       and a.account_type_id = 1000002
       and (ah.invoice_id is not null or ah.adjustment_id is not null)
       and ah.CURRENT_BALANCE > ah.previous_balance
       and ah.invoice_id = i.invoice_id(+)
       AND a.account_balance >= .005
    order by a.account_id, ah.effective_start_date desc;You will probably want to select:
    1. From ACCOUNT first (your smaller table), for which you supply a literal on account_type_id. That should limit the accounts retrieved from ACCOUNT_HISTORY
    2. From ACCOUNT_HISTORY. We want to limit the records as much as possible on this table because of the outer join.
    3. INVOICE we want to access last because it seems to be least restricted, it is the biggest, and it has the outer join condition so it will manufacture rows to match as many rows as come back from account_history.
    Try the query above after creating the following composite indexes. The order of the columns is important:create index account_composite_i on account(account_type_id, account_balance, account_id);
    create index acct_history_comp_i on account_history(account_id, invoice_id, adjustment_id, current_balance, previous_balance, effective_start_date);
    create index invoice_composite_i on invoice(invoice_id, payment_due_date);All the columns used in the where clause will be indexed, in a logical order suited to the needs of the query. Plus each selected column is indexed as well so that we should not need to touch the tables at all to satisfy the query.
    Try the query after creating these indexes.
    A final suggestion is to try larger sort and hash area sizes and a manual workarea policy.alter session set workarea_size_policy = manual;
    alter session set sort_area_size = 2147483647;
    alter session set hash_area_size = 2147483647;

  • Sql code taking long time

    Hello Everyone,
    In Oracle 10g,I have table emp_history and column name hired_date,which has the
    values in the following format 7/8/2011 12:55:55 PM
    ('mm/dd/yyyy hh12:mi:ss AM') ana this table has more than 50 thousand records,
    when I tried to get the employees whose hired_date between 01/04/2011 and 30/04/2011
    its taking long time(16 to 19 minutes) just to fetch 845 records.
    I tried the following codes,
    select * from emp_history where to_char(hired_date,'mmddyyyy') between
    04012011' and 04302011' and ...;and
      select * from emp_history where to_char(hired_date,'ddmmyyyy') between
    '01042011' and 30042011' and ....It having some other where condition also but If I commented the above where condition alone its working fine,
    If I include i taking long time.
    Can anyone tell me how to modify the code.
    Thank you.
    Edited by: Gurujothi on Aug 3, 2012 4:21 AM

    Do you have an index on HIRED_DATE column? If yes then your index will not be considered.
    You need to write your query like this.
    select *
      from emp_history
    where hired_date between to_date('04012011', 'mmddyyyy') and (to_date('04302011', 'mmddyyyy') + 1) - interval '1' second
       and ...;Use of function on a column makes that column index unusable.
    Further to assist you please read the following link and post the required details
    {message:id=9360003}

  • Simple query is taking long time

    Hi Experts,
    The below query is taking long time.
    [code]SELECT   FS.*
      FROM   ORL.FAX_STAGE FS
             INNER JOIN
                   ORL.FAX_SOURCE FSRC
                INNER JOIN
                   GLOBAL_BU_MAPPING GBM
                ON GBM.BU_ID = FSRC.BUID
             ON UPPER (FSRC.FAX_NUMBER) = UPPER (FS.DESTINATION)
    WHERE       FSRC.IS_DELETED = 'N'
             AND GBM.BU_ID IS NOT NULL
             AND UPPER (FS.FAX_STATUS) ='COMPLETED';[/code]
    this query is returning 1645457 records.
    [code]PLAN_TABLE_OUTPUT
    | Id  | Operation           | Name                   | Rows  | Bytes | Cost (%CPU)|
    |   0 | SELECT STATEMENT    |                        |   625K|   341M| 45113   (1)|
    |   1 |  HASH JOIN          |                        |   625K|   341M| 45113   (1)|
    |   2 |   NESTED LOOPS      |                        |   611 | 14664 |    22   (0)|
    |   3 |    TABLE ACCESS FULL| FAX_SOURCE             |  2290 | 48090 |    22   (0)|
    |   4 |    INDEX RANGE SCAN | GLOBAL_BU_MAPPING_BUID |     1 |     3 |     0   (0)|
    |   5 |   TABLE ACCESS FULL | FAX_STAGE              |  2324K|  1214M| 45076   (1)|
    PLAN_TABLE_OUTPUT
    Note
       - 'PLAN_TABLE' is old version
    15 rows selected.[/code]
    The distinct number of records in each table.
    [code]SELECT FAX_STATUS,count(*)
    FROM fax_STAGE
    GROUP BY FAX_STATUS;
    FAX_STATUS    COUNT(*)
    BROKEN          10
    Broken - New    9
    Completed    2324493
    New             20
    SELECT is_deleted,COUNT(*)
    FROM  FAX_SOURCE
    GROUP BY IS_DELETED;
    IS_DELETED COUNT(*)
    N         2290
    Y         78[/code]
    Total number of records in each table.
    [code]SELECT COUNT(*) FROM ORL.FAX_SOURCE FSRC-- 2368
    SELECT COUNT(*) FROM ORL.FAX_STAGE--2324532
    SELECT COUNT(*) FROM APPS_GLOBAL.GLOBAL_BU_MAPPING--9
    [/code]
    To improve the performance of this query I have created the following indexes.
    [code]Functional based index on UPPER (FSRC.FAX_NUMBER) ,UPPER (FS.DESTINATION) and UPPER (FS.FAX_STATUS).
    Bitmap index on FSRC.IS_DELETED.
    Normal Index on GBM.BU_ID and FSRC.BUID.
    [/code]
    But still the performance is bad for this query.
    What can I do apart from this to improve the performance of this query.
    Please help me .
    Thanks in advance.

    <I have created the following indexes.
    CREATE INDEX ORL.IDX_DESTINATION_RAM ON ORL.FAX_STAGE(UPPER("DESTINATION"))
    CREATE INDEX ORL.IDX_FAX_STATUS_RAM ON ORL.FAX_STAGE(LOWER("FAX_STATUS"))
    CREATE INDEX ORL.IDX_UPPER_FAX_STATUS_RAM ON ORL.FAX_STAGE(UPPER("FAX_STATUS"))
    CREATE INDEX ORL.IDX_BUID_RAM ON ORL.FAX_SOURCE(BUID)
    CREATE INDEX ORL.IDX_FAX_NUMBER_RAM ON ORL.FAX_SOURCE(UPPER("FAX_NUMBER"))
    CREATE BITMAP INDEX ORL.IDX_IS_DELETED_RAM ON ORL.FAX_SOURCE(IS_DELETED)
    After creating the following indexes performance got improved.
    But our DBA said that new BITMAP index at FAX_SOURCE table (ORL.IDX_IS_DELETED_RAM) can cause locks
    on multiple rows if IS_DELETED column is in use. Please proceed with detailed tests.
    I am sending the explain plan before creating indexes and after indexes has been created.
    SELECT  FS.*
    FROM  ORL.FAX_STAGE FS
                    INNER JOIN
                    ORL.FAX_SOURCE FSRC
                  INNER JOIN
                      GLOBAL_BU_MAPPING GBM
                    ON GBM.BU_ID = FSRC.BUID
                ON UPPER (FSRC.FAX_NUMBER) = UPPER (FS.DESTINATION)
    WHERE      FSRC.IS_DELETED = 'N'
              AND GBM.BU_ID IS NOT NULL
              AND UPPER (FS.FAX_STATUS) =:B1;
    --OLD without indexes
    PLAN_TABLE_OUTPUT
    Plan hash value: 3076973749
    | Id  | Operation          | Name                  | Rows  | Bytes | Cost (%CPU)| Time    |
    |  0 | SELECT STATEMENT    |                        |  141K|    85M| 45130  (1)| 00:09:02 |
    |*  1 |  HASH JOIN          |                        |  141K|    85M| 45130  (1)| 00:09:02 |
    |  2 |  NESTED LOOPS      |                        |  611 | 18330 |    22  (0)| 00:00:01 |
    |*  3 |    TABLE ACCESS FULL| FAX_SOURCE            |  2290 | 59540 |    22  (0)| 00:00:01 |
    |*  4 |    INDEX RANGE SCAN | GLOBAL_BU_MAPPING_BUID |    1 |    4 |    0  (0)| 00:00:01 |
    |*  5 |  TABLE ACCESS FULL | FAX_STAGE              | 23245 |    13M| 45106  (1)| 00:09:02 |
    PLAN_TABLE_OUTPUT
    Predicate Information (identified by operation id):
      1 - access(UPPER("FSRC"."FAX_NUMBER")=UPPER("FS"."DESTINATION"))
      3 - filter("FSRC"."IS_DELETED"='N')
      4 - access("GBM"."BU_ID"="FSRC"."BUID")
          filter("GBM"."BU_ID" IS NOT NULL)
      5 - filter(UPPER("FS"."FAX_STATUS")=SYS_OP_C2C(:B1))
    21 rows selected.
    --NEW with indexes.
    PLAN_TABLE_OUTPUT
    Plan hash value: 665032407
    | Id  | Operation                        | Name                    | Rows  | Bytes | Cost (%CPU)| Time    |
    |  0 | SELECT STATEMENT                |                          |  5995 |  3986K|  3117  (1)| 00:00:38 |
    |*  1 |  HASH JOIN                      |                          |  5995 |  3986K|  3117  (1)| 00:00:38 |
    |  2 |  NESTED LOOPS                  |                          |  611 | 47658 |    20  (5)| 00:00:01 |
    |*  3 |    VIEW                          | index$_join$_002        |  2290 |  165K|    20  (5)| 00:00:01 |
    |*  4 |    HASH JOIN                    |                          |      |      |            |      |
    |*  5 |      HASH JOIN                  |                          |      |      |            |      |
    PLAN_TABLE_OUTPUT
    |  6 |      BITMAP CONVERSION TO ROWIDS|                          |  2290 |  165K|    1  (0)| 00:00:01 |
    |*  7 |        BITMAP INDEX SINGLE VALUE | IDX_IS_DELETED_RAM      |      |      |            |      |
    |  8 |      INDEX FAST FULL SCAN      | IDX_BUID_RAM            |  2290 |  165K|    8  (0)| 00:00:01 |
    |  9 |      INDEX FAST FULL SCAN        | IDX_FAX_NUMBER_RAM      |  2290 |  165K|    14  (0)| 00:00:01 |
    |* 10 |    INDEX RANGE SCAN              | GLOBAL_BU_MAPPING_BUID  |    1 |    4 |    0  (0)| 00:00:01 |
    |  11 |  TABLE ACCESS BY INDEX ROWID    | FAX_STAGE                | 23245 |    13M|  3096  (1)| 00:00:38 |
    |* 12 |    INDEX RANGE SCAN              | IDX_UPPER_FAX_STATUS_RAM |  9298 |      |  2434  (1)| 00:00:30 |
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
      1 - access(UPPER("DESTINATION")="FSRC"."SYS_NC00035$")
      3 - filter("FSRC"."IS_DELETED"='N')
      4 - access(ROWID=ROWID)
      5 - access(ROWID=ROWID)
      7 - access("FSRC"."IS_DELETED"='N')
      10 - access("GBM"."BU_ID"="FSRC"."BUID")
          filter("GBM"."BU_ID" IS NOT NULL)
      12 - access(UPPER("FAX_STATUS")=SYS_OP_C2C(:B1))
    31 rows selected
    Please confirm on the DBA comment.Is this bitmap index locks rows in my case.
    Thanks.>

  • CDHDR table query taking long time

    Hi all,
    Select query from CDHDR table is taking long time,in where condition i am giving OBJECTCLASS = 'MAT_FULL' udate = sy-datum and langu = 'EN'.
    any suggestion to improve the performance.i want to select all the article which got changed on current date
    regards
    shibu

    This will always be slow for large data volumes, since CDHDR is designed for quick access by object ID (in this case material number), not by date.
    I'm afraid you would need to introduce a secondary index on OBJECTCLAS and UDATE, if that query is crucial enough to warrant the additional disk space and processing time taken by the new index.
    Greetings
    Thomas

  • Sap bi--query taking long time to exexute

    Hi
    When i try  run the bex query ,its taking long time,please suggest
    Thanks
    sreedhar

    Hi
    When i try  run the bex query ,its taking long time,please suggest
    Thanks
    sreedhar

  • How to write SQL query and apply aggregate functions on it

    Hello experts,
    Iu2019ve a task to write SQL query on tree tables and do inner join on them. Iu2019ve accomplish this task by using T-CODE SQVI. However now I need to write a query and apply SQL functions on it i.e. Add, Count, Max and Min etc. Please can someone tell me how I can write SQL query with aggregate functions in SAP?
    Thanks a lot in advance

    HI Mr. Cool
    you can see the below code for using aggregate functions.
    where ARTIST and SEATSOCCU are the field names for which you want to perform these functions.
    DATA: TOTAL_ENTRIES TYPE I,
          TOTAL_ATT TYPE I,
          MAX_ATT TYPE I,
          AVG_ATT TYPE I.
    SELECT COUNT( DISTINCT ARTIST )
           SUM( SEATSOCCU )
           MAX( SEATSOCCU )
           AVG( SEATSOCCU ) FROM YCONCERT INTO (TOTAL_ENTRIES, TOTAL_ATT,
    MAX_ATT, AVG_ATT).
    Thanks
    Lalit Gupta

  • Single SQl Query with different where conditions

    Experts,
    I have a requirement to design a report. Here are the details
    I have Report table layout
    Profit center Gross sales (This Year) Gross Sales (Last Year) % change Year of Year
    The Report has a selection of entering the Start Date.
    I have a single table in oracle which has profit center and Gross Sales Values on daily basis.
    I want to write a single sql query to calculate both Gross Sales current year and Gross Sales Last Year. I can calculate Gross Sales Current Year by putting the where condition for start date = Current Year Date which i pass through report. I want to calculate the Gross Sales Last Year in the Same query by putting the different where condition i.e start date = Last Year date based on the date input.
    I dont know how to put two where conditions in single query for two different columns.
    Any help will be appreciated.
    Thanks in advance
    Regards
    Santosh

    instead of changing your where clause couldn't you just determine the yearly totals from your table and then use the lag statement to get last years total?
    something like this?
    I just made up 10,000 days worth of sales and called it fake table it is supposed to represent a variant of the table you were describing as your base table.
    with fake_table as
    ( select trunc(sysdate + level) the_day,
    level daily_gross_sales
    from dual
    connect by level < 10001
    select yr, year_gross_sale, lag(year_gross_sale) over (order by yr) prev_year_gross_sale,
    (year_gross_sale - lag(year_gross_sale) over (order by yr))/year_gross_sale * 100 percent_change
    from
    (select distinct yr, year_gross_sale from
    select the_day,
    daily_gross_sales,
    extract(year from the_day) yr,
    extract(year from add_months(the_day,12)) next_yr,
    sum(daily_gross_sales) over (partition by extract(year from the_day)) year_gross_sale
    from fake_table
    order by yr
    )

  • Sql query taking long time

    the below query is taking very long time.
    select /*+ PARALLEL(a,8) PARALLEL(b,8) */ a.personid,a.winning_id, b.questionid from
    winning_id_cleanup a , rm_personquestion b
    where a.personid = b.personid and (a.winning_id,b.questionid) not in
    (select /*+ PARALLEL(c,8) */ c.personid,c.questionid from rm_personquestion c where c.personid=a.winning_id);
    where the rm_personquestion table is having 45 million rows and winning_id_cleanup is having 1 million rows.
    please tell me how to tune this query?

    Please post u'r query at PL/SQL
    It's not for SQL and PL/SQL

  • Sql Query is running fine in one database but running from long in other

    Hi All,
    Please advice me on below:
    One query is running fine on 11gr2 database with having 2GB SGA and cost of the running query is 15, but the same query is running from long time in other database having same 2GB SGA.
    Below is teh Query:
    SELECT CDU.USER_NAME, DECODE(:B2 , 'QUEUE','begin
    dbms_aqadm.grant_queue_privilege(''ALL'','''||:B1
    ||''','''||CDU.USER_NAME||''',true); end;', 'grant '||DECODE(:B2 ,
    'TABLE','SELECT,INSERT,UPDATE,DELETE'||DECODE(CDU.ADMIN,'Y',',REFERENCES
    ',''), 'VIEW',DECODE(:B3 ,NULL,'SELECT','SELECT,INSERT,UPDATE,DELETE'||D
    ECODE(CDU.ADMIN,'Y',',REFERENCES','')), 'TYPE','EXECUTE',
    'SEQUENCE','SELECT', 'EXECUTE')||' on
    '||PACK_UTILS.GET_SCHEMA_OWNER||'.'||:B1 ||' to
    "'||CDU.USER_NAME||'"'||DECODE(CDU.ADMIN,'Y',' WITH GRANT OPTION',''))
    AS GRANT_SOURCE, 'create or replace synonym
    "'||CDU.USER_NAME||'"."'||:B1 ||'" for
    "'||PACK_UTILS.GET_SCHEMA_OWNER||'"."'||:B1 ||'"' AS SYNONYM_SOURCE,
    NVL2( S.TABLE_NAME, 'Y', 'N' ) SYNONYM_EXISTS FROM CD_USERS CDU,
    ALL_SYNONYMS S, ALL_USERS U WHERE :B2 IN
    ('TYPE','TABLE','VIEW','FUNCTION','PROCEDURE','PACKAGE','SEQUENCE','QUEU
    E','SYNONYM') AND CDU.USER_TYPE = 'S' AND CDU.USER_NAME = U.USERNAME
    AND CDU.USER_NAME = S.OWNER AND :B1 = S.TABLE_NAME
    Please advise me as application team is chasing me like anything. what I can find out is that Cost is different in both databases.

    Sorry forr Late reply friends..
    below are the Explian plans for both databases:
                                                      BAD database
    PLAN_TABLE_OUTPUT
    SQL_ID  3bp3rynsds42r, child number 0
    SELECT CDU.USER_NAME, DECODE(:B2 , 'QUEUE','begin
    dbms_aqadm.grant_queue_privilege(''ALL'','''||:B1
    ||''','''||CDU.USER_NAME||''',true); end;', 'grant '||DECODE(:B2 ,
    'TABLE','SELECT,INSERT,UPDATE,DELETE'||DECODE(CDU.ADMIN,'Y',',REFERENCES
    ',''), 'VIEW',DECODE(:B3 ,NULL,'SELECT','SELECT,INSERT,UPDATE,DELETE'||D
    ECODE(CDU.ADMIN,'Y',',REFERENCES','')), 'TYPE','EXECUTE',
    'SEQUENCE','SELECT', 'EXECUTE')||' on
    '||PACK_UTILS.GET_SCHEMA_OWNER||'.'||:B1 ||' to
    "'||CDU.USER_NAME||'"'||DECODE(CDU.ADMIN,'Y',' WITH GRANT OPTION',''))
    PLAN_TABLE_OUTPUT
    AS GRANT_SOURCE, 'create or replace synonym
    "'||CDU.USER_NAME||'"."'||:B1 ||'" for
    "'||PACK_UTILS.GET_SCHEMA_OWNER||'"."'||:B1 ||'"' AS SYNONYM_SOURCE,
    NVL2( S.TABLE_NAME, 'Y', 'N' ) SYNONYM_EXISTS FROM CD_USERS CDU,
    ALL_SYNONYMS S, ALL_USERS U WHERE :B2 IN
    ('TYPE','TABLE','VIEW','FUNCTION','PROCEDURE','PACKAGE','SEQUENCE','QUEU
    E','SYNONYM') AND CDU.USER_TYPE = 'S' AND CDU.USER_NAME = U.USERNAME
    AND CDU.USER_NAME = S.OWNER AND :B1 = S.TABLE_NAME
    Plan hash value: 2404940060
    PLAN_TABLE_OUTPUT
    | Id  | Operation                                            | Name               | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                                     |                    |       |       |       |    94 (100)|          |
    |*  1 |  FILTER                                              |                    |       |       |       |            |          |
    |*  2 |   HASH JOIN                                          |                    |    81 |  6723 |       |    94   (0)| 00:00:01 |
    |   3 |    NESTED LOOPS OUTER                                |                    |    81 |  6480 |       |    91   (0)| 00:00:01 |
    |*  4 |     HASH JOIN                                        |                    |    81 |  3726 |       |    10   (0)| 00:00:01 |
    |*  5 |      HASH JOIN                                       |                    |   137 |  3699 |       |     7   (0)| 00:00:01 |
    |   6 |       TABLE ACCESS FULL                              | TS$                |     7 |    21 |       |     3   (0)| 00:00:01 |
    |*  7 |       TABLE ACCESS FULL                              | USER$              |   137 |  3288 |       |     4   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |*  8 |      TABLE ACCESS FULL                               | CD_USERS           |    82 |  1558 |       |     3   (0)| 00:00:01 |
    |   9 |     VIEW                                             | ALL_SYNONYMS       |     1 |    34 |       |     1   (0)| 00:00:01 |
    |  10 |      SORT UNIQUE                                     |                    |       |       |       |            |          |
    |  11 |       UNION-ALL PARTITION                            |                    |       |       |       |            |          |
    |* 12 |        FILTER                                        |                    |       |       |       |            |          |
    |  13 |         NESTED LOOPS                                 |                    |     1 |   116 |       |    60   (0)| 00:00:01 |
    |  14 |          NESTED LOOPS                                |                    |     1 |    94 |       |    59   (0)| 00:00:01 |
    |  15 |           NESTED LOOPS                               |                    |    12 |   684 |       |    23   (0)| 00:00:01 |
    |  16 |            TABLE ACCESS BY INDEX ROWID               | USER$              |     1 |    19 |       |     1   (0)| 00:00:01 |
    |* 17 |             INDEX UNIQUE SCAN                        | I_USER1            |     1 |       |       |     0   (0)|          |
    |  18 |            TABLE ACCESS BY INDEX ROWID               | SYN$               |    12 |   456 |       |    22   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |* 19 |             INDEX SKIP SCAN                          | I_SYN2             |    12 |       |       |    12   (0)| 00:00:01 |
    |* 20 |           TABLE ACCESS BY INDEX ROWID                | OBJ$               |     1 |    37 |       |     3   (0)| 00:00:01 |
    |* 21 |            INDEX RANGE SCAN                          | I_OBJ1             |     1 |       |       |     2   (0)| 00:00:01 |
    |* 22 |          INDEX RANGE SCAN                            | I_USER2            |     1 |    22 |       |     1   (0)| 00:00:01 |
    |* 23 |         FIXED TABLE FULL                             | X$KZSPR            |    17 |   119 |       |     0   (0)|          |
    |* 24 |         FILTER                                       |                    |       |       |       |            |          |
    |* 25 |          FILTER                                      |                    |       |       |       |            |          |
    |  26 |           NESTED LOOPS                               |                    |    27 |  2430 |       |     6   (0)| 00:00:01 |
    |  27 |            NESTED LOOPS                              |                    |     1 |    78 |       |     4   (0)| 00:00:01 |
    |  28 |             NESTED LOOPS                             |                    |     1 |    56 |       |     3   (0)| 00:00:01 |
    |  29 |              TABLE ACCESS BY INDEX ROWID             | USER$              |     1 |    19 |       |     1   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |* 30 |               INDEX UNIQUE SCAN                      | I_USER1            |     1 |       |       |     0   (0)|          |
    |* 31 |              INDEX RANGE SCAN                        | I_OBJ5             |     1 |    37 |       |     2   (0)| 00:00:01 |
    |* 32 |             INDEX RANGE SCAN                         | I_USER2            |     1 |    22 |       |     1   (0)| 00:00:01 |
    |* 33 |            INDEX RANGE SCAN                          | I_OBJAUTH1         |    28 |   336 |       |     2   (0)| 00:00:01 |
    |* 34 |          FIXED TABLE FULL                            | X$KZSRO            |     1 |     3 |       |     0   (0)|          |
    |  35 |          NESTED LOOPS                                |                    |     1 |    30 |       |     3   (0)| 00:00:01 |
    |* 36 |           INDEX SKIP SCAN                            | I_USER2            |     1 |    20 |       |     1   (0)| 00:00:01 |
    |* 37 |           INDEX RANGE SCAN                           | I_OBJ4             |     1 |    10 |       |     2   (0)| 00:00:01 |
    |  38 |         NESTED LOOPS                                 |                    |     1 |    30 |       |     3   (0)| 00:00:01 |
    |* 39 |          INDEX SKIP SCAN                             | I_USER2            |     1 |    20 |       |     1   (0)| 00:00:01 |
    |* 40 |          INDEX RANGE SCAN                            | I_OBJ4             |     1 |    10 |       |     2   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |* 41 |        FILTER                                        |                    |       |       |       |            |          |
    |  42 |         NESTED LOOPS                                 |                    |     1 |   129 |       |  4301   (2)| 00:00:39 |
    |  43 |          NESTED LOOPS                                |                    |     1 |   129 |       |  4301   (2)| 00:00:39 |
    |  44 |           NESTED LOOPS                               |                    |     1 |    91 |       |  4299   (2)| 00:00:39 |
    |  45 |            NESTED LOOPS                              |                    |     1 |    69 |       |  4298   (2)| 00:00:39 |
    |  46 |             NESTED LOOPS                             |                    |     2 |    64 |       |  4292   (2)| 00:00:39 |
    |  47 |              TABLE ACCESS BY INDEX ROWID             | USER$              |     1 |    19 |       |     1   (0)| 00:00:01 |
    |* 48 |               INDEX UNIQUE SCAN                      | I_USER1            |     1 |       |       |     0   (0)|          |
    |  49 |              VIEW                                    | _ALL_SYNONYMS_TREE |     2 |    26 |       |  4291   (2)| 00:00:39 |
    |* 50 |               CONNECT BY NO FILTERING WITH START-WITH|                    |       |       |       |            |          |
    |* 51 |                FILTER                                |                    |       |       |       |            |          |
    PLAN_TABLE_OUTPUT
    |* 52 |                 HASH JOIN                            |                    | 18370 |  2080K|       |  4291   (2)| 00:00:39 |
    |  53 |                  INDEX FULL SCAN                     | I_USER2            |   207 |  4554 |       |     1   (0)| 00:00:01 |
    |* 54 |                  HASH JOIN                           |                    | 18370 |  1686K|       |  4290   (2)| 00:00:39 |
    |  55 |                   TABLE ACCESS FULL                  | USER$              |   207 |  3933 |       |     4   (0)| 00:00:01 |
    |* 56 |                   HASH JOIN                          |                    |  2922K|   209M|    18M|  4269   (1)| 00:00:39 |
    |* 57 |                    INDEX FAST FULL SCAN              | I_OBJ2             |   387K|    13M|       |  1323   (1)| 00:00:12 |
    |  58 |                    TABLE ACCESS FULL                 | SYN$               |   400K|    14M|       |   566   (2)| 00:00:06 |
    |  59 |                 NESTED LOOPS                         |                    |     1 |    30 |       |     3   (0)| 00:00:01 |
    |* 60 |                  INDEX SKIP SCAN                     | I_USER2            |     1 |    20 |       |     1   (0)| 00:00:01 |
    |* 61 |                  INDEX RANGE SCAN                    | I_OBJ4             |     1 |    10 |       |     2   (0)| 00:00:01 |
    |* 62 |                FILTER                                |                    |       |       |       |            |          |
    PLAN_TABLE_OUTPUT
    |  63 |                 TABLE ACCESS BY INDEX ROWID          | SYN$               |     1 |    38 |       |     3   (0)| 00:00:01 |
    |* 64 |                  INDEX UNIQUE SCAN                   | I_SYN1             |     1 |       |       |     2   (0)| 00:00:01 |
    |* 65 |                 FILTER                               |                    |       |       |       |            |          |
    |* 66 |                  FILTER                              |                    |       |       |       |            |          |
    |  67 |                   NESTED LOOPS                       |                    |    27 |  2430 |       |     6   (0)| 00:00:01 |
    |  68 |                    NESTED LOOPS                      |                    |     1 |    78 |       |     4   (0)| 00:00:01 |
    |  69 |                     NESTED LOOPS                     |                    |     1 |    56 |       |     3   (0)| 00:00:01 |
    |  70 |                      TABLE ACCESS BY INDEX ROWID     | USER$              |     1 |    19 |       |     1   (0)| 00:00:01 |
    |* 71 |                       INDEX UNIQUE SCAN              | I_USER1            |     1 |       |       |     0   (0)|          |
    |* 72 |                      INDEX RANGE SCAN                | I_OBJ5             |     1 |    37 |       |     2   (0)| 00:00:01 |
    |* 73 |                     INDEX RANGE SCAN                 | I_USER2            |     1 |    22 |       |     1   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |* 74 |                    INDEX RANGE SCAN                  | I_OBJAUTH1         |    28 |   336 |       |     2   (0)| 00:00:01 |
    |* 75 |                  FIXED TABLE FULL                    | X$KZSRO            |     1 |     3 |       |     0   (0)|          |
    |  76 |                  NESTED LOOPS                        |                    |     1 |    30 |       |     3   (0)| 00:00:01 |
    |* 77 |                   INDEX SKIP SCAN                    | I_USER2            |     1 |    20 |       |     1   (0)| 00:00:01 |
    |* 78 |                   INDEX RANGE SCAN                   | I_OBJ4             |     1 |    10 |       |     2   (0)| 00:00:01 |
    |* 79 |                 FIXED TABLE FULL                     | X$KZSPR            |    17 |   119 |       |     0   (0)|          |
    |* 80 |             TABLE ACCESS BY INDEX ROWID              | OBJ$               |     1 |    37 |       |     3   (0)| 00:00:01 |
    |* 81 |              INDEX RANGE SCAN                        | I_OBJ1             |     1 |       |       |     2   (0)| 00:00:01 |
    |* 82 |            INDEX RANGE SCAN                          | I_USER2            |     1 |    22 |       |     1   (0)| 00:00:01 |
    |* 83 |           INDEX UNIQUE SCAN                          | I_SYN1             |     1 |       |       |     1   (0)| 00:00:01 |
    |* 84 |          TABLE ACCESS BY INDEX ROWID                 | SYN$               |     1 |    38 |       |     2   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |  85 |         NESTED LOOPS                                 |                    |     1 |    30 |       |     3   (0)| 00:00:01 |
    |* 86 |          INDEX SKIP SCAN                             | I_USER2            |     1 |    20 |       |     1   (0)| 00:00:01 |
    |* 87 |          INDEX RANGE SCAN                            | I_OBJ4             |     1 |    10 |       |     2   (0)| 00:00:01 |
    |  88 |    TABLE ACCESS FULL                                 | TS$                |     7 |    21 |       |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter((:B2='TYPE' OR :B2='TABLE' OR :B2='VIEW' OR :B2='FUNCTION' OR :B2='PROCEDURE' OR :B2='PACKAGE' OR
                  :B2='SEQUENCE' OR :B2='QUEUE' OR :B2='SYNONYM'))
    PLAN_TABLE_OUTPUT
       2 - access("U"."TEMPTS#"="TTS"."TS#")
       4 - access("CDU"."USER_NAME"="U"."NAME")
       5 - access("U"."DATATS#"="DTS"."TS#")
       7 - filter("U"."TYPE#"=1)
       8 - filter("CDU"."USER_TYPE"='S')
      12 - filter(((INTERNAL_FUNCTION("O"."SPARE3") OR ("S"."NODE" IS NULL AND  IS NOT NULL) OR  IS NOT NULL) AND
                  (("O"."TYPE#"<>4 AND "O"."TYPE#"<>5 AND "O"."TYPE#"<>7 AND "O"."TYPE#"<>8 AND "O"."TYPE#"<>9 AND "O"."TYPE#"<>10 AND
                  "O"."TYPE#"<>11 AND "O"."TYPE#"<>12 AND "O"."TYPE#"<>13 AND "O"."TYPE#"<>14 AND "O"."TYPE#"<>22 AND "O"."TYPE#"<>87 AND
                  "O"."TYPE#"<>88) OR BITAND("U"."SPARE1",16)=0 OR (SYS_CONTEXT('userenv','current_edition_name')='ORA$BASE' AND
                  "U"."TYPE#"<>2) OR ("U"."TYPE#"=2 AND "U"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id'))) OR  IS NOT
                  NULL)))
    PLAN_TABLE_OUTPUT
      17 - access("U"."NAME"="CDU"."USER_NAME")
      19 - access("S"."NAME"=:B1)
           filter("S"."NAME"=:B1)
      20 - filter("O"."SPARE3"="U"."USER#")
      21 - access("O"."OBJ#"="S"."OBJ#" AND "O"."TYPE#"=5)
           filter("O"."TYPE#"=5)
      22 - access("O"."OWNER#"="U"."USER#")
      23 - filter((((-"KZSPRPRV")=(-45) OR (-"KZSPRPRV")=(-47) OR (-"KZSPRPRV")=(-48) OR (-"KZSPRPRV")=(-49) OR
                  (-"KZSPRPRV")=(-50)) AND "INST_ID"=USERENV('INSTANCE')))
      24 - filter((("BA"."GRANTOR#"=USERENV('SCHEMAID') OR  IS NOT NULL) AND (("O"."TYPE#"<>4 AND "O"."TYPE#"<>5 AND
                  "O"."TYPE#"<>7 AND "O"."TYPE#"<>8 AND "O"."TYPE#"<>9 AND "O"."TYPE#"<>10 AND "O"."TYPE#"<>11 AND "O"."TYPE#"<>12 AND
    PLAN_TABLE_OUTPUT
                  "O"."TYPE#"<>13 AND "O"."TYPE#"<>14 AND "O"."TYPE#"<>22 AND "O"."TYPE#"<>87 AND "O"."TYPE#"<>88) OR
                  BITAND("U"."SPARE1",16)=0 OR (INTERNAL_FUNCTION("O"."TYPE#") AND
                  ((SYS_CONTEXT('userenv','current_edition_name')='ORA$BASE' AND "U"."TYPE#"<>2) OR ("U"."TYPE#"=2 AND
                  "U"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id'))) OR  IS NOT NULL)))))
      25 - filter(:B1 IS NULL)
      30 - access("BU"."NAME"=:B1)
      31 - access("BU"."USER#"="O"."SPARE3" AND "O"."NAME"=:B1)
      32 - access("O"."OWNER#"="U"."USER#")
      33 - access("BA"."OBJ#"="O"."OBJ#")
      34 - filter("KZSROROL"=:B1)
      36 - access("U2"."TYPE#"=2 AND "U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id')))
    PLAN_TABLE_OUTPUT
           filter(("U2"."TYPE#"=2 AND "U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id'))))
      37 - access("O2"."DATAOBJ#"=:B1 AND "O2"."TYPE#"=88 AND "O2"."OWNER#"="U2"."USER#")
      39 - access("U2"."TYPE#"=2 AND "U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id')))
           filter(("U2"."TYPE#"=2 AND "U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id'))))
      40 - access("O2"."DATAOBJ#"=:B1 AND "O2"."TYPE#"=88 AND "O2"."OWNER#"="U2"."USER#")
      41 - filter((("O"."TYPE#"<>4 AND "O"."TYPE#"<>5 AND "O"."TYPE#"<>7 AND "O"."TYPE#"<>8 AND "O"."TYPE#"<>9 AND
                  "O"."TYPE#"<>10 AND "O"."TYPE#"<>11 AND "O"."TYPE#"<>12 AND "O"."TYPE#"<>13 AND "O"."TYPE#"<>14 AND "O"."TYPE#"<>22 AND
                  "O"."TYPE#"<>87 AND "O"."TYPE#"<>88) OR BITAND("U"."SPARE1",16)=0 OR
                  (SYS_CONTEXT('userenv','current_edition_name')='ORA$BASE' AND "U"."TYPE#"<>2) OR ("U"."TYPE#"=2 AND
                  "U"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id'))) OR  IS NOT NULL))
      48 - access("U"."NAME"="CDU"."USER_NAME")
    PLAN_TABLE_OUTPUT
      50 - access("S"."BASE_SYN_ID"=PRIOR NULL)
           filter( IS NOT NULL)
      51 - filter((("O"."TYPE#"<>4 AND "O"."TYPE#"<>5 AND "O"."TYPE#"<>7 AND "O"."TYPE#"<>8 AND "O"."TYPE#"<>9 AND
                  "O"."TYPE#"<>10 AND "O"."TYPE#"<>11 AND "O"."TYPE#"<>12 AND "O"."TYPE#"<>13 AND "O"."TYPE#"<>14 AND "O"."TYPE#"<>22 AND
                  "O"."TYPE#"<>87 AND "O"."TYPE#"<>88) OR BITAND("U"."SPARE1",16)=0 OR
                  (SYS_CONTEXT('userenv','current_edition_name')='ORA$BASE' AND "U"."TYPE#"<>2) OR ("U"."TYPE#"=2 AND
                  "U"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id'))) OR  IS NOT NULL))
      52 - access("O"."OWNER#"="U"."USER#")
      54 - access("S"."OWNER"="BU"."NAME" AND "BU"."USER#"="O"."SPARE3")
      56 - access("S"."NAME"="O"."NAME")
      57 - filter("O"."TYPE#"=5)
    PLAN_TABLE_OUTPUT
      60 - access("U2"."TYPE#"=2 AND "U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id')))
           filter(("U2"."TYPE#"=2 AND "U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id'))))
      61 - access("O2"."DATAOBJ#"=:B1 AND "O2"."TYPE#"=88 AND "O2"."OWNER#"="U2"."USER#")
      62 - filter(( IS NOT NULL OR ("S"."NODE" IS NULL AND  IS NOT NULL)))
      64 - access("S"."OBJ#"=:B1)
      65 - filter((("BA"."GRANTOR#"=USERENV('SCHEMAID') OR  IS NOT NULL) AND (("O"."TYPE#"<>4 AND "O"."TYPE#"<>5 AND
                  "O"."TYPE#"<>7 AND "O"."TYPE#"<>8 AND "O"."TYPE#"<>9 AND "O"."TYPE#"<>10 AND "O"."TYPE#"<>11 AND "O"."TYPE#"<>12 AND
                  "O"."TYPE#"<>13 AND "O"."TYPE#"<>14 AND "O"."TYPE#"<>22 AND "O"."TYPE#"<>87 AND "O"."TYPE#"<>88) OR
                  BITAND("U"."SPARE1",16)=0 OR (INTERNAL_FUNCTION("O"."TYPE#") AND
                  ((SYS_CONTEXT('userenv','current_edition_name')='ORA$BASE' AND "U"."TYPE#"<>2) OR ("U"."TYPE#"=2 AND
                  "U"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id'))) OR  IS NOT NULL)))))
    PLAN_TABLE_OUTPUT
      66 - filter(:B1 IS NULL)
      71 - access("BU"."NAME"=:B1)
      72 - access("BU"."USER#"="O"."SPARE3" AND "O"."NAME"=:B1)
      73 - access("O"."OWNER#"="U"."USER#")
      74 - access("BA"."OBJ#"="O"."OBJ#")
      75 - filter("KZSROROL"=:B1)
      77 - access("U2"."TYPE#"=2 AND "U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id')))
           filter(("U2"."TYPE#"=2 AND "U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id'))))
      78 - access("O2"."DATAOBJ#"=:B1 AND "O2"."TYPE#"=88 AND "O2"."OWNER#"="U2"."USER#")
      79 - filter((((-"KZSPRPRV")=(-45) OR (-"KZSPRPRV")=(-47) OR (-"KZSPRPRV")=(-48) OR (-"KZSPRPRV")=(-49) OR
                  (-"KZSPRPRV")=(-50)) AND "INST_ID"=USERENV('INSTANCE')))
    PLAN_TABLE_OUTPUT
      80 - filter("O"."SPARE3"="U"."USER#")
      81 - access("O"."OBJ#"="ST"."SYN_ID" AND "O"."TYPE#"=5)
           filter("O"."TYPE#"=5)
      82 - access("O"."OWNER#"="U"."USER#")
      83 - access("S"."OBJ#"="ST"."SYN_ID")
           filter("O"."OBJ#"="S"."OBJ#")
      84 - filter("S"."NAME"=:B1)
      86 - access("U2"."TYPE#"=2 AND "U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id')))
           filter(("U2"."TYPE#"=2 AND "U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id'))))
      87 - access("O2"."DATAOBJ#"=:B1 AND "O2"."TYPE#"=88 AND "O2"."OWNER#"="U2"."USER#")
    209 rows selected
    ==============================================================================================
                                                                     Good one
    PLAN_TABLE_OUTPUT
    SQL_ID  3bp3rynsds42r, child number 0
    SELECT CDU.USER_NAME, DECODE(:B2 , 'QUEUE','begin
    dbms_aqadm.grant_queue_privilege(''ALL'','''||:B1
    ||''','''||CDU.USER_NAME||''',true); end;', 'grant '||DECODE(:B2 ,
    'TABLE','SELECT,INSERT,UPDATE,DELETE'||DECODE(CDU.ADMIN,'Y',',REFERENCES
    ',''), 'VIEW',DECODE(:B3 ,NULL,'SELECT','SELECT,INSERT,UPDATE,DELETE'||D
    ECODE(CDU.ADMIN,'Y',',REFERENCES','')), 'TYPE','EXECUTE',
    'SEQUENCE','SELECT', 'EXECUTE')||' on
    '||PACK_UTILS.GET_SCHEMA_OWNER||'.'||:B1 ||' to
    "'||CDU.USER_NAME||'"'||DECODE(CDU.ADMIN,'Y',' WITH GRANT OPTION',''))
    PLAN_TABLE_OUTPUT
    AS GRANT_SOURCE, 'create or replace synonym
    "'||CDU.USER_NAME||'"."'||:B1 ||'" for
    "'||PACK_UTILS.GET_SCHEMA_OWNER||'"."'||:B1 ||'"' AS SYNONYM_SOURCE,
    NVL2( S.TABLE_NAME, 'Y', 'N' ) SYNONYM_EXISTS FROM CD_USERS CDU,
    ALL_SYNONYMS S, ALL_USERS U WHERE :B2 IN
    ('TYPE','TABLE','VIEW','FUNCTION','PROCEDURE','PACKAGE','SEQUENCE','QUEU
    E','SYNONYM') AND CDU.USER_TYPE = 'S' AND CDU.USER_NAME = U.USERNAME
    AND CDU.USER_NAME = S.OWNER AND :B1 = S.TABLE_NAME
    Plan hash value: 2146531909
    PLAN_TABLE_OUTPUT
    | Id  | Operation                                          | Name               | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                                   |                    |       |       |       |    15 (100)|          |
    |*  1 |  FILTER                                            |                    |       |       |       |            |          |
    |   2 |   NESTED LOOPS OUTER                               |                    |     3 |   273 |       |    15   (0)| 00:00:01 |
    |   3 |    NESTED LOOPS                                    |                    |     3 |   153 |       |    12   (0)| 00:00:01 |
    |   4 |     NESTED LOOPS                                   |                    |     3 |   144 |       |     9   (0)| 00:00:01 |
    |   5 |      NESTED LOOPS                                  |                    |     3 |   135 |       |     6   (0)| 00:00:01 |
    |*  6 |       TABLE ACCESS FULL                            | USER$              |    55 |  1375 |       |     4   (0)| 00:00:01 |
    |*  7 |       TABLE ACCESS BY INDEX ROWID                  | CD_USERS           |     1 |    20 |       |     1   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |*  8 |        INDEX UNIQUE SCAN                           | I1_CD_USERS        |     1 |       |       |     0   (0)|          |
    |   9 |      TABLE ACCESS CLUSTER                          | TS$                |     1 |     3 |       |     1   (0)| 00:00:01 |
    |* 10 |       INDEX UNIQUE SCAN                            | I_TS#              |     1 |       |       |     0   (0)|          |
    |  11 |     TABLE ACCESS CLUSTER                           | TS$                |     1 |     3 |       |     1   (0)| 00:00:01 |
    |* 12 |      INDEX UNIQUE SCAN                             | I_TS#              |     1 |       |       |     0   (0)|          |
    |  13 |    VIEW                                            | ALL_SYNONYMS       |     1 |    40 |       |     1   (0)| 00:00:01 |
    |  14 |     SORT UNIQUE                                    |                    |       |       |       |            |          |
    |  15 |      UNION-ALL PARTITION                           |                    |       |       |       |            |          |
    |* 16 |       FILTER                                       |                    |       |       |       |            |          |
    |  17 |        NESTED LOOPS                                |                    |     1 |   116 |       |    19   (0)| 00:00:01 |
    |  18 |         NESTED LOOPS                               |                    |     1 |    94 |       |    18   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |  19 |          NESTED LOOPS                              |                    |     1 |    56 |       |    15   (0)| 00:00:01 |
    |  20 |           TABLE ACCESS BY INDEX ROWID              | USER$              |     1 |    20 |       |     1   (0)| 00:00:01 |
    |* 21 |            INDEX UNIQUE SCAN                       | I_USER1            |     1 |       |       |     0   (0)|          |
    |  22 |           TABLE ACCESS BY INDEX ROWID              | SYN$               |     1 |    36 |       |    14   (0)| 00:00:01 |
    |* 23 |            INDEX SKIP SCAN                         | I_SYN2             |     1 |       |       |    12   (0)| 00:00:01 |
    |* 24 |          TABLE ACCESS BY INDEX ROWID               | OBJ$               |     1 |    38 |       |     3   (0)| 00:00:01 |
    |* 25 |           INDEX RANGE SCAN                         | I_OBJ1             |     1 |       |       |     2   (0)| 00:00:01 |
    |* 26 |         INDEX RANGE SCAN                           | I_USER2            |     1 |    22 |       |     1   (0)| 00:00:01 |
    |* 27 |        FIXED TABLE FULL                            | X$KZSPR            |    17 |   119 |       |     0   (0)|          |
    |* 28 |        FILTER                                      |                    |       |       |       |            |          |
    |* 29 |         FILTER                                     |                    |       |       |       |            |          |
    PLAN_TABLE_OUTPUT
    |  30 |          NESTED LOOPS                              |                    |     3 |   279 |       |     5   (0)| 00:00:01 |
    |  31 |           NESTED LOOPS                             |                    |     1 |    80 |       |     4   (0)| 00:00:01 |
    |  32 |            NESTED LOOPS                            |                    |     1 |    58 |       |     3   (0)| 00:00:01 |
    |  33 |             TABLE ACCESS BY INDEX ROWID            | USER$              |     1 |    20 |       |     1   (0)| 00:00:01 |
    |* 34 |              INDEX UNIQUE SCAN                     | I_USER1            |     1 |       |       |     0   (0)|          |
    |* 35 |             INDEX RANGE SCAN                       | I_OBJ5             |     1 |    38 |       |     2   (0)| 00:00:01 |
    |* 36 |            INDEX RANGE SCAN                        | I_USER2            |     1 |    22 |       |     1   (0)| 00:00:01 |
    |* 37 |           INDEX RANGE SCAN                         | I_OBJAUTH1         |     3 |    39 |       |     1   (0)| 00:00:01 |
    |* 38 |         FIXED TABLE FULL                           | X$KZSRO            |     1 |     3 |       |     0   (0)|          |
    |  39 |         NESTED LOOPS                               |                    |     1 |    32 |       |     3   (0)| 00:00:01 |
    |* 40 |          INDEX SKIP SCAN                           | I_USER2            |     1 |    20 |       |     1   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |* 41 |          INDEX RANGE SCAN                          | I_OBJ4             |     1 |    12 |       |     2   (0)| 00:00:01 |
    |  42 |        NESTED LOOPS                                |                    |     1 |    32 |       |     3   (0)| 00:00:01 |
    |* 43 |         INDEX SKIP SCAN                            | I_USER2            |     1 |    20 |       |     1   (0)| 00:00:01 |
    |* 44 |         INDEX RANGE SCAN                           | I_OBJ4             |     1 |    12 |       |     2   (0)| 00:00:01 |
    |* 45 |       FILTER                                       |                    |       |       |       |            |          |
    |  46 |        NESTED LOOPS                                |                    |     1 |   129 |       |  1065   (1)| 00:00:13 |
    |  47 |         NESTED LOOPS                               |                    |     1 |   107 |       |  1064   (1)| 00:00:13 |
    |  48 |          NESTED LOOPS                              |                    |     1 |    69 |       |  1061   (1)| 00:00:13 |
    |  49 |           NESTED LOOPS                             |                    |     2 |    66 |       |  1059   (1)| 00:00:13 |
    |  50 |            TABLE ACCESS BY INDEX ROWID             | USER$              |     1 |    20 |       |     1   (0)| 00:00:01 |
    |* 51 |             INDEX UNIQUE SCAN                      | I_USER1            |     1 |       |       |     0   (0)|          |
    PLAN_TABLE_OUTPUT
    |  52 |            VIEW                                    | _ALL_SYNONYMS_TREE |     2 |    26 |       |  1058   (1)| 00:00:13 |
    |* 53 |             CONNECT BY NO FILTERING WITH START-WITH|                    |       |       |       |            |          |
    |* 54 |              FILTER                                |                    |       |       |       |            |          |
    |* 55 |               HASH JOIN                            |                    |   705 | 81780 |       |  1058   (1)| 00:00:13 |
    |  56 |                INDEX FULL SCAN                     | I_USER2            |   124 |  2728 |       |     1   (0)| 00:00:01 |
    |* 57 |                HASH JOIN                           |                    |   705 | 66270 |       |  1057   (1)| 00:00:13 |
    |  58 |                 TABLE ACCESS FULL                  | USER$              |   124 |  2480 |       |     4   (0)| 00:00:01 |
    |* 59 |                 HASH JOIN                          |                    | 66964 |  4839K|  2232K|  1052   (1)| 00:00:13 |
    |  60 |                  TABLE ACCESS FULL                 | SYN$               | 47615 |  1673K|       |    78   (2)| 00:00:01 |
    |* 61 |                  INDEX FAST FULL SCAN              | I_OBJ5             | 47862 |  1776K|       |   752   (1)| 00:00:10 |
    |  62 |               NESTED LOOPS                         |                    |     1 |    32 |       |     3   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |* 63 |                INDEX SKIP SCAN                     | I_USER2            |     1 |    20 |       |     1   (0)| 00:00:01 |
    |* 64 |                INDEX RANGE SCAN                    | I_OBJ4             |     1 |    12 |       |     2   (0)| 00:00:01 |
    |* 65 |              FILTER                                |                    |       |       |       |            |          |
    |  66 |               TABLE ACCESS BY INDEX ROWID          | SYN$               |     1 |    36 |       |     2   (0)| 00:00:01 |
    |* 67 |                INDEX UNIQUE SCAN                   | I_SYN1             |     1 |       |       |     1   (0)| 00:00:01 |
    |* 68 |               FILTER                               |                    |       |       |       |            |          |
    |* 69 |                FILTER                              |                    |       |       |       |            |          |
    |  70 |                 NESTED LOOPS                       |                    |     3 |   279 |       |     5   (0)| 00:00:01 |
    |  71 |                  NESTED LOOPS                      |                    |     1 |    80 |       |     4   (0)| 00:00:01 |
    |  72 |                   NESTED LOOPS                     |                    |     1 |    58 |       |     3   (0)| 00:00:01 |
    |  73 |                    TABLE ACCESS BY INDEX ROWID     | USER$              |     1 |    20 |       |     1   (0)| 00:00:01 |
    PLAN_TABLE_OUTPUT
    |* 74 |                     INDEX UNIQUE SCAN              | I_USER1            |     1 |       |       |     0   (0)|          |
    |* 75 |                    INDEX RANGE SCAN                | I_OBJ5             |     1 |    38 |       |     2   (0)| 00:00:01 |
    |* 76 |                   INDEX RANGE SCAN                 | I_USER2            |     1 |    22 |       |     1   (0)| 00:00:01 |
    |* 77 |                  INDEX RANGE SCAN                  | I_OBJAUTH1         |     3 |    39 |       |     1   (0)| 00:00:01 |
    |* 78 |                FIXED TABLE FULL                    | X$KZSRO            |     1 |     3 |       |     0   (0)|          |
    |  79 |                NESTED LOOPS                        |                    |     1 |    32 |       |     3   (0)| 00:00:01 |
    |* 80 |                 INDEX SKIP SCAN                    | I_USER2            |     1 |    20 |       |     1   (0)| 00:00:01 |
    |* 81 |                 INDEX RANGE SCAN                   | I_OBJ4             |     1 |    12 |       |     2   (0)| 00:00:01 |
    |* 82 |               FIXED TABLE FULL                     | X$KZSPR            |    17 |   119 |       |     0   (0)|          |
    |* 83 |           TABLE ACCESS BY INDEX ROWID              | SYN$               |     1 |    36 |       |     1   (0)| 00:00:01 |
    |* 84 |            INDEX UNIQUE SCAN                       | I_SYN1             |     1 |       |       |     0   (0)|          |
    PLAN_TABLE_OUTPUT
    |* 85 |          TABLE ACCESS BY INDEX ROWID               | OBJ$               |     1 |    38 |       |     3   (0)| 00:00:01 |
    |* 86 |           INDEX RANGE SCAN                         | I_OBJ1             |     1 |       |       |     2   (0)| 00:00:01 |
    |* 87 |         INDEX RANGE SCAN                           | I_USER2            |     1 |    22 |       |     1   (0)| 00:00:01 |
    |  88 |        NESTED LOOPS                                |                    |     1 |    32 |       |     3   (0)| 00:00:01 |
    |* 89 |         INDEX SKIP SCAN                            | I_USER2            |     1 |    20 |       |     1   (0)| 00:00:01 |
    |* 90 |         INDEX RANGE SCAN                           | I_OBJ4             |     1 |    12 |       |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
    PLAN_TABLE_OUTPUT
       1 - filter((:B2='TYPE' OR :B2='TABLE' OR :B2='VIEW' OR :B2='FUNCTION' OR :B2='PROCEDURE' OR :B2='PACKAGE' OR
                  :B2='SEQUENCE' OR :B2='QUEUE' OR :B2='SYNONYM'))
       6 - filter("U"."TYPE#"=1)
       7 - filter("CDU"."USER_TYPE"='S')
       8 - access("CDU"."USER_NAME"="U"."NAME")
      10 - access("U"."DATATS#"="DTS"."TS#")
      12 - access("U"."TEMPTS#"="TTS"."TS#")
      16 - filter(((INTERNAL_FUNCTION("O"."SPARE3") OR ("S"."NODE" IS NULL AND  IS NOT NULL) OR  IS NOT NULL) AND
                  (("O"."TYPE#"<>4 AND "O"."TYPE#"<>5 AND "O"."TYPE#"<>7 AND "O"."TYPE#"<>8 AND "O"."TYPE#"<>9 AND "O"."TYPE#"<>10 AND
                  "O"."TYPE#"<>11 AND "O"."TYPE#"<>12 AND "O"."TYPE#"<>13 AND "O"."TYPE#"<>14 AND "O"."TYPE#"<>22 AND "O"."TYPE#"<>87 AND
                  "O"."TYPE#"<>88) OR BITAND("U"."SPARE1",16)=0 OR (SYS_CONTEXT('userenv','current_edition_name')='ORA$BASE' AND
    PLAN_TABLE_OUTPUT
                  "U"."TYPE#"<>2) OR ("U"."TYPE#"=2 AND "U"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id'))) OR  IS NOT
                  NULL)))
      21 - access("U"."NAME"="CDU"."USER_NAME")
      23 - access("S"."NAME"=:B1)
           filter("S"."NAME"=:B1)
      24 - filter("O"."SPARE3"="U"."USER#")
      25 - access("O"."OBJ#"="S"."OBJ#" AND "O"."TYPE#"=5)
           filter("O"."TYPE#"=5)
      26 - access("O"."OWNER#"="U"."USER#")
      27 - filter((((-"KZSPRPRV")=(-45) OR (-"KZSPRPRV")=(-47) OR (-"KZSPRPRV")=(-48) OR (-"KZSPRPRV")=(-49) OR
                  (-"KZSPRPRV")=(-50)) AND "INST_ID"=USERENV('INSTANCE')))
    PLAN_TABLE_OUTPUT
      28 - filter((("BA"."GRANTOR#"=USERENV('SCHEMAID') OR  IS NOT NULL) AND (("O"."TYPE#"<>4 AND "O"."TYPE#"<>5 AND
                  "O"."TYPE#"<>7 AND "O"."TYPE#"<>8 AND "O"."TYPE#"<>9 AND "O"."TYPE#"<>10 AND "O"."TYPE#"<>11 AND "O"."TYPE#"<>12 AND
                  "O"."TYPE#"<>13 AND "O"."TYPE#"<>14 AND "O"."TYPE#"<>22 AND "O"."TYPE#"<>87 AND "O"."TYPE#"<>88) OR
                  BITAND("U"."SPARE1",16)=0 OR (INTERNAL_FUNCTION("O"."TYPE#") AND
                  ((SYS_CONTEXT('userenv','current_edition_name')='ORA$BASE' AND "U"."TYPE#"<>2) OR ("U"."TYPE#"=2 AND
                  "U"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id'))) OR  IS NOT NULL)))))
      29 - filter(:B1 IS NULL)
      34 - access("BU"."NAME"=:B1)
      35 - access("BU"."USER#"="O"."SPARE3" AND "O"."NAME"=:B1)
      36 - access("O"."OWNER#"="U"."USER#")
      37 - access("BA"."OBJ#"="O"."OBJ#")
    PLAN_TABLE_OUTPUT
      38 - filter("KZSROROL"=:B1)
      40 - access("U2"."TYPE#"=2 AND "U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id')))
           filter(("U2"."TYPE#"=2 AND "U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id'))))
      41 - access("O2"."DATAOBJ#"=:B1 AND "O2"."TYPE#"=88 AND "O2"."OWNER#"="U2"."USER#")
      43 - access("U2"."TYPE#"=2 AND "U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id')))
           filter(("U2"."TYPE#"=2 AND "U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id'))))
      44 - access("O2"."DATAOBJ#"=:B1 AND "O2"."TYPE#"=88 AND "O2"."OWNER#"="U2"."USER#")
      45 - filter((("O"."TYPE#"<>4 AND "O"."TYPE#"<>5 AND "O"."TYPE#"<>7 AND "O"."TYPE#"<>8 AND "O"."TYPE#"<>9 AND
                  "O"."TYPE#"<>10 AND "O"."TYPE#"<>11 AND "O"."TYPE#"<>12 AND "O"."TYPE#"<>13 AND "O"."TYPE#"<>14 AND "O"."TYPE#"<>22 AND
                  "O"."TYPE#"<>87 AND "O"."TYPE#"<>88) OR BITAND("U"."SPARE1",16)=0 OR
                  (SYS_CONTEXT('userenv','current_edition_name')='ORA$BASE' AND "U"."TYPE#"<>2) OR ("U"."TYPE#"=2 AND
    PLAN_TABLE_OUTPUT
                  "U"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id'))) OR  IS NOT NULL))
      51 - access("U"."NAME"="CDU"."USER_NAME")
      53 - access("S"."BASE_SYN_ID"=PRIOR NULL)
           filter( IS NOT NULL)
      54 - filter((("O"."TYPE#"<>4 AND "O"."TYPE#"<>5 AND "O"."TYPE#"<>7 AND "O"."TYPE#"<>8 AND "O"."TYPE#"<>9 AND
                  "O"."TYPE#"<>10 AND "O"."TYPE#"<>11 AND "O"."TYPE#"<>12 AND "O"."TYPE#"<>13 AND "O"."TYPE#"<>14 AND "O"."TYPE#"<>22 AND
                  "O"."TYPE#"<>87 AND "O"."TYPE#"<>88) OR BITAND("U"."SPARE1",16)=0 OR
                  (SYS_CONTEXT('userenv','current_edition_name')='ORA$BASE' AND "U"."TYPE#"<>2) OR ("U"."TYPE#"=2 AND
                  "U"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id'))) OR  IS NOT NULL))
      55 - access("O"."OWNER#"="U"."USER#")
      57 - access("S"."OWNER"="BU"."NAME" AND "BU"."USER#"="O"."SPARE3")
    PLAN_TABLE_OUTPUT
      59 - access("S"."NAME"="O"."NAME")
      61 - filter("O"."TYPE#"=5)
      63 - access("U2"."TYPE#"=2 AND "U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id')))
           filter(("U2"."TYPE#"=2 AND "U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id'))))
      64 - access("O2"."DATAOBJ#"=:B1 AND "O2"."TYPE#"=88 AND "O2"."OWNER#"="U2"."USER#")
      65 - filter(( IS NOT NULL OR ("S"."NODE" IS NULL AND  IS NOT NULL)))
      67 - access("S"."OBJ#"=:B1)
      68 - filter((("BA"."GRANTOR#"=USERENV('SCHEMAID') OR  IS NOT NULL) AND (("O"."TYPE#"<>4 AND "O"."TYPE#"<>5 AND
                  "O"."TYPE#"<>7 AND "O"."TYPE#"<>8 AND "O"."TYPE#"<>9 AND "O"."TYPE#"<>10 AND "O"."TYPE#"<>11 AND "O"."TYPE#"<>12 AND
                  "O"."TYPE#"<>13 AND "O"."TYPE#"<>14 AND "O"."TYPE#"<>22 AND "O"."TYPE#"<>87 AND "O"."TYPE#"<>88) OR
                  BITAND("U"."SPARE1",16)=0 OR (INTERNAL_FUNCTION("O"."TYPE#") AND
    PLAN_TABLE_OUTPUT
                  ((SYS_CONTEXT('userenv','current_edition_name')='ORA$BASE' AND "U"."TYPE#"<>2) OR ("U"."TYPE#"=2 AND
                  "U"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id'))) OR  IS NOT NULL)))))
      69 - filter(:B1 IS NULL)
      74 - access("BU"."NAME"=:B1)
      75 - access("BU"."USER#"="O"."SPARE3" AND "O"."NAME"=:B1)
      76 - access("O"."OWNER#"="U"."USER#")
      77 - access("BA"."OBJ#"="O"."OBJ#")
      78 - filter("KZSROROL"=:B1)
      80 - access("U2"."TYPE#"=2 AND "U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id')))
           filter(("U2"."TYPE#"=2 AND "U2"."SPARE2"=TO_NUMBER(SYS_CONTEXT('userenv','current_edition_id'))))
      81 - access("O2"."DATAOBJ#"=:B1 AND "O2"."TY

  • SQL Query taking longer time as seen from Trace file

    Below Query Execution timings:
    Any help will be benefitial as its affecting business needs.
    SELECT MATERIAL_DETAIL_ID
    FROM
    GME_MATERIAL_DETAILS WHERE BATCH_ID = :B1 FOR UPDATE OF ACTUAL_QTY NOWAIT
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.70 0 0 0 0
    Execute 2256 8100.00 24033.51 627 12298 31739 0
    Fetch 2256 900.00 949.82 0 12187 0 30547
    total 4513 9000.00 24984.03 627 24485 31739 30547
    Thanks and Regards

    Thanks Buddy.
    Data Collected from Trace file:
    SELECT STEP_CLOSE_DATE
    FROM
    GME_BATCH_STEPS WHERE BATCH_ID
    IN (SELECT
    DISTINCT BATCH_ID FROM
    GME_MATERIAL_DETAILS START WITH BATCH_ID = :B2 CONNECT BY PRIOR PHANTOM_ID=BATCH_ID)
    AND NVL(STEP_CLOSE_DATE, :B1) > :B1
    call count cpu elapsed disk query current rows
    Parse 1 0.00 0.54 0 0 0 0
    Execute 2256 800.00 1120.32 0 0 0 0
    Fetch 2256 9100.00 13551.45 396 77718 0 0
    total 4513 9900.00 14672.31 396 77718 0 0
    Misses in library cache during parse: 0
    Optimizer goal: CHOOSE
    Parsing user id: 66 (recursive depth: 1)
    Rows Row Source Operation
    0 TABLE ACCESS BY INDEX ROWID GME_BATCH_STEPS
    13160 NESTED LOOPS
    6518 VIEW
    6518 SORT UNIQUE
    53736 CONNECT BY WITH FILTERING
    30547 NESTED LOOPS
    30547 INDEX RANGE SCAN GME_MATERIAL_DETAILS_U1 (object id 146151)
    30547 TABLE ACCESS BY USER ROWID GME_MATERIAL_DETAILS
    23189 NESTED LOOPS
    53736 BUFFER SORT
    53736 CONNECT BY PUMP
    23189 TABLE ACCESS BY INDEX ROWID GME_MATERIAL_DETAILS
    23189 INDEX RANGE SCAN GME_MATERIAL_DETAILS_U1 (object id 146151)
    4386 INDEX RANGE SCAN GME_BATCH_STEPS_U1 (object id 146144)
    In the Package there are lots of SQL Statements using CONNECT BY CLAUSE.
    Does the use of CONNECT BY Clause degrades performance?
    As you can see the Rows Section is 0 but the Query and elapsed time is taking longer
    Regards

Maybe you are looking for

  • How to remove and fill in areas of a picture

    I am using the 30 day trial of Photoshop and trying to use online Help to learn the "how to's" BUT I'm finding it dificult to always follow the videos and explanations. I want to remove unwanted areas of a photo and then fill in those areas to match

  • Changes in BW queries are not showing in EP

    Hi, I have created two BW Query iViews. It was working fine. But when the query is changed from BW server, it's showing error message as:- System error in program SAPLRRS2 and form INITFL_ASSIGN-01- And in the second query it's showing "No Applicable

  • Aperture 3 low resolution previews

    Hello all, I've been using Aperture 3 for a few weeks now and loving it. I read in the forums about how previews are set to low resolution and i've been having problems trying to get them back to a high resolution image file. I've imported the photos

  • Simple calculations in Universe not working for XI 3.0

    Simple calculations in Universe using key figures are not working in XI 3.0(without any Fix Pack) Below is the steps I followed. 1. Using key figure [Jan] I am trying to round the values by deviding it by 1000. <EXPRESSION>@Select([Jan])/1000</EXPRES

  • Error in ERM: Function module does not exist

    Hi all, Lately, we are experiencing a frequent error in ERM (5.3 SP 15.0) that we had not had before. We are unsure what caused the error. The message displayed to the user is "Unhandled error". The log error message is "Message Code is 651 Messsage