Link to home
Start Free TrialLog in
Avatar of bruno_boccara
bruno_boccaraFlag for France

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.


ASKER CERTIFIED SOLUTION
Avatar of Raynard7
Raynard7

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bruno_boccara

ASKER

I removed the distinct but it didn't change anything.
I still have the Sort / Distinct Sort with 94% cost.
I also have indexes on columns used in condition1 and condition2
Avatar of Raynard7
Raynard7

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.
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.
glad its now working