bruno_boccara
asked on
Execution Plan: How to reduce a Sort / Distinct Sort ?
Hi I have the following query:
select distinct a,b,c,d
from table
where condition1
UNION
select distinct a,b,c,d
from table
where condition2
The result returns me 6 lines from about 4000 lines of the table which is correct.
The problems is that the query is very slow, more than 4mn with a P4 Bi-processor 3Ghz !
After a look in the execution plan I notice that a Sort / distinct Sort takes me 94% of cost !
Is there a way to improve the query and to reduce the time of execution ?
Thanks & regards.
select distinct a,b,c,d
from table
where condition1
UNION
select distinct a,b,c,d
from table
where condition2
The result returns me 6 lines from about 4000 lines of the table which is correct.
The problems is that the query is very slow, more than 4mn with a P4 Bi-processor 3Ghz !
After a look in the execution plan I notice that a Sort / distinct Sort takes me 94% of cost !
Is there a way to improve the query and to reduce the time of execution ?
Thanks & regards.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I also have indexes on columns used in condition1 and condition2
is this from the same table or different tables? if it is from the same table can you combine the conditions into one statement?
how fast to the individual queries run? this may be the problem.
how fast to the individual queries run? this may be the problem.
ASKER
It's Ok I found the error.
there was an unwanted table in the from.
I will split the points between us to thanks you for your tries.
there was an unwanted table in the from.
I will split the points between us to thanks you for your tries.
glad its now working
ASKER
I still have the Sort / Distinct Sort with 94% cost.