Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends ,


There is a SP which has more than 15 Unions and each returns result set with huge rows

How can i increase performance of that SP


Thanks in Advance

Shreeniwas
Posted
Comments
Mike Meinz 28-Feb-13 7:59am    
A good first step would be to let those that you want help from see the database table schema and the SELECT statement(s) that require optimization.

A second step would be to question why a database is designed such that a query requires 15 UNION operators.
Jörgen Andersson 2-Mar-13 15:41pm    
It's a pity one can't upvote a comment.
SriNivas IT 28-Feb-13 8:15am    
I replaced union to union all

and with common table expression i used with distinct due to duplicacy

Like that


with cte_result
(
select colums.... from A
union all
select colums.... from B
union all
select colums.... from C
....
....
....
....
)
select distinct * from cte_result

can this increase some performance????
Mike Meinz 28-Feb-13 8:53am    
If there are Where clauses associated with each Select statement, then (generally) having well-constructed indexes for the keys used in the Where clauses will help. I'm sorry but I don't have anything further to offer you.
AspDotNetDev 28-Feb-13 12:17pm    
I was going to suggest a UNION ALL, but it seems you've already done that. Not sure what type of performance you're getting, but the problem may something aside from the unions. You could avoid the DISTINCT and then filter the results on the machine that's getting the results.

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