Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am new to oracle client and have assigned a task to enhance the performance of the following query as it is taking too much time to fetch the records on SSRS reporting side. Can anybody help on this.

Thanks in advance.....
SQL
-------BEGIN 2D
SELECT a.id ID, a.name NAME,'222' TYPE, 1 AS ORD, 'Navigation' CATEGORY,
(SELECT Decode (Count(*),1,0,Count(*)) from files_v WHERE sur_id = a.id AND sur_type = '222' AND data_type = 'Navigation') total,
NULL  DOCTYPE
FROM
sur_222 a
left join dataset_222_n b ON b.sur_222_id=a.id AND b.data_type='Navigation' 
WHERE
a.id IN  (:ID)
GROUP BY a.id, a.name
-------END 2D
UNION ALL
------BEGIN 3D
SELECT a.id ID, a.name NAME, '333' TYPE, 1 AS ORD, 'Navigation' CATEGORY,
(SELECT Decode (Count(*),1,0,Count(*)) FROM files_v WHERE sur_id = a.id AND sur_type = '333' AND data_type = 'Navigation') total,
NULL  DOCTYPE  
FROM
sur_333 a
left join dataset_333_n b ON b.sur_333_id=a.id AND b.data_type='Navigation'
WHERE
a.id IN  (:ID)
GROUP BY a.id, a.name
------END 3D
Posted
Updated 3-Oct-12 20:15pm
v2

1 solution

SQL

Start with removing the left joins.
You're not using any fields from the joined tables (b) and as the joins are being of the left kind, means that no rows are sorted away from the first table (a) in the joins.


And, I'm getting the impression that the database isn't normalized, or are the tables actually views?

<edit>I've made some assumptions, try this:
SQL
WITH tab AS (
    SELECT  a.id ID
           ,a.name NAME
           ,'222' TYPE
           ,1 AS ORD
           ,'Navigation' CATEGORY
           ,NULL  DOCTYPE
    FROM    sur_222 a
    WHERE   a.id IN  (:ID)
    -------END 2D
    UNION ALL
    ------BEGIN 3D
    SELECT  a.id ID
           ,a.name NAME
           ,'333' TYPE
           ,1 AS ORD
           ,'Navigation' CATEGORY
           ,NULL  DOCTYPE  
    FROM    sur_333 a
    WHERE   a.id IN  (:ID)
    )
SELECT  ID
       ,NAME
       ,TYPE
       ,ORD
       ,CATEGORY
       ,Decode (Count(*),1,0,Count(*)) total
       ,DOCTYPE
FROM    tab a, files_v v
WHERE   sur_id = a.id
AND     sur_type = TYPE
AND     data_type = 'Navigation'
GROUP BY ID
        ,NAME
        ,TYPE
        ,ORD
        ,CATEGORY
        ,DOCTYPE
</edit>
 
Share this answer
 
v2
Comments
AmitGajjar 5-Oct-12 22:10pm    
correct 5+

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900