I’ve got a query that is taking a very long time to run due to a select similar to:
SELECT
Count( Distinct t1.v1),
Count (Distinct
Case t2.v1 When 'blah' then t1.v1
Else null
End ),
....
FROM t1
LEFT JOIN t2 ON t1.v3 = t2.v3
WHERE t1.myDate BETWEEN @start and @end
AND t2.v5 = @id
Can anyone suggest any good methods for improving this performance?
As there are No Where clause predicates (no filters) on this query it will involve a complete table scan or index scan no matter what you do (unless the inner join restricts the resultset…).
So the only improvement that you can get is possibly to affect what type of join is being done. To improve the performance of the join, make sure there is an index on the t1.v3 and t2.v3 columns….