GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Oracle  >  PL/SQL
Go To First  |  Previous Question  |  Next Question 
 PL/SQL  |  Question 119 of 241    Print  
i want to tune the below query for performance issue can u please help me the query is

SELECT DISTINCT
A.BUSINESS_UNIT,
A.CUST_ID,
A.ASOF_DT
FROM PS_ITEM_ACTIVITY A
WHERE A.BUSINESS_UNIT = '1100G'
AND A.ITEM LIKE 'OA%'
AND A.PO_LINE = 0
AND A.ENTRY_REASON <> 'CLEAR'
AND A.ASOF_DT > '01-JAN-1900'
AND A.USER1 = ' '

UNION

SELECT DISTINCT
A.BUSINESS_UNIT,
A.CUST_ID,
A.ASOF_DT
FROM PS_PENDING_ITEM A
WHERE A.BUSINESS_UNIT = '1100G'
AND A.ITEM LIKE 'OA%'
AND A.PO_LINE = 0
AND A.ENTRY_REASON <> 'CLEAR'
AND A.ASOF_DT > '01-JAN-1900'
AND A.USER1 = ' '
AND A.POSTED_FLAG = 'N'
AND ERROR_FLAG = ' '

  
Total Answers and Comments: 6 Last Update: October 03, 2009     Asked by: snehal 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
October 05, 2006 01:07:07   #1  
Chiranjeevi        

RE: i want to tune the below query for performance iss...
As the query uses UNION I suggest you not to use DISTINCT again as UNION eliminates repitions.
 
Is this answer useful? Yes | No
October 17, 2006 03:55:53   #2  
snehal        

RE: i want to tune the below query for performance iss...

hi Chiranjeevi

thanks for ur help but i can't eliminate the use of distinct as i want to select distinct rows from each the tables with particular combination which i select and after selecting the distinct combination from both tables i have to union them so please suggest some other solution if u can thanks once again.


 
Is this answer useful? Yes | No
October 17, 2006 09:49:23   #3  
Sushant        

RE: i want to tune the below query for performance iss...

instead of using distinct use group by....

its faster..

group by is pre condition where as distinct is post condition so groupy by is expctd to b much faster and the diffrence is quite visible if u hav lots of data


 
Is this answer useful? Yes | No
November 03, 2006 07:39:33   #4  
Tejinder        

RE: i want to tune the below query for performance iss...

create a view of the above query without using distinct clause and then execute query by using view with distinct clause and group by function.


 
Is this answer useful? Yes | No
February 22, 2007 09:55:26   #5  
Radhika        

RE: i want to tune the below query for performance iss...
If you are sure that each query will fetch distinct set of records i.e records returned by query 1 will not be available in query 2 then Union All can be used.Union tries to eliminate the duplicate records which results in a performance overhead. Union all will return all records.
 
Is this answer useful? Yes | No
October 03, 2009 04:50:08   #6  
nagarajbng Member Since: September 2009   Contribution: 1    

RE: i want to tune the below query for performance issue can u please help me the query is SELECT DISTINCTA.BUSINESS_UNIT,A.CUST_ID,A.ASOF_DTFROM PS_ITEM_ACTIVITY A WHERE A.BUSINESS_UNIT = '1100G'AND A.ITEM LIKE 'OA%' AND A.PO_LINE = 0AND A.ENTRY_REASON

If you are using the UNION keyword then there is no need of using the distinct keyword in your query or else you can use UNION ALL keyword

or

Below I am sending the modified query

In your query which column will filter more then that column you have to place in the last position less filter before that last column and which one will filter least that column you have to place in the first position in the where clause.

SELECT DISTINCT
A.BUSINESS_UNIT
A.CUST_ID
A.ASOF_DT
FROM PS_ITEM_ACTIVITY A
WHERE A.PO_LINE 0
AND A.BUSINESS_UNIT '1100G'
AND A.ENTRY_REASON <> 'CLEAR'
AND A.ASOF_DT > '01-JAN-1900'
AND A.USER1 ' '
AND A.ITEM LIKE 'OA '

UNION

SELECT DISTINCT
A.BUSINESS_UNIT
A.CUST_ID
A.ASOF_DT
FROM PS_PENDING_ITEM A
WHERE A.PO_LINE 0
AND A.BUSINESS_UNIT '1100G'
AND A.ENTRY_REASON <> 'CLEAR'
AND A.ASOF_DT > '01-JAN-1900'
AND A.USER1 ' '
AND A.POSTED_FLAG 'N'
AND ERROR_FLAG ' '
AND A.ITEM LIKE 'OA '

Thanks & Regards
NTR


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape