Hi I've got a query which shows and creates two different execution plans based on the value of a variable....the problem is that one is significantly slower than the other and it only happens with a particular value.
basically the query looks like this....
select
from tblA a
join tblB b
join tblC c
left outer join tblD d
where a.value = 1 and (b.value2 = 1 or b.value2 = 3)
typically when this query executes it's very fast
however when i change the a.value to lets say 2 rather than 1 it becomes extremely slow and the query plan changes.
it works fine for values 3, 4, 5, etc...just 2 for some reason switches the query plan.
it changes at the very beginning of the query plan...let's say if the faster query plan typically starts the query with a table scan on tblB based on the where clause and when i change the value to 2 it changes the plan to start with an index scan on tblA where a.value = 2. Note both plans contain the same elements however they're just in different positions... Also when i view the statistics the slower query plan (a.value = 2) has significantly more logical reads on tblA.
can anyone give me any suggestions on how to furthur diagnose/resolve this problem?
Thanks
basically the query looks like this....
select
from tblA a
join tblB b
join tblC c
left outer join tblD d
where a.value = 1 and (b.value2 = 1 or b.value2 = 3)
typically when this query executes it's very fast
however when i change the a.value to lets say 2 rather than 1 it becomes extremely slow and the query plan changes.
it works fine for values 3, 4, 5, etc...just 2 for some reason switches the query plan.
it changes at the very beginning of the query plan...let's say if the faster query plan typically starts the query with a table scan on tblB based on the where clause and when i change the value to 2 it changes the plan to start with an index scan on tblA where a.value = 2. Note both plans contain the same elements however they're just in different positions... Also when i view the statistics the slower query plan (a.value = 2) has significantly more logical reads on tblA.
can anyone give me any suggestions on how to furthur diagnose/resolve this problem?
Thanks