Hi all,
I have a question that may be able to be resolve here and greatly appreciate any information. It involves SQL Server 2005.
I have a stored procedure that runs ok considering the volume of data that I am dealing with. However, I did a query plan on it and it showed an area that had a cost of 39% and a table scan. In looking at that a little further, it came down to a value that was put into the WHERE clause, for instance,
WHERE a='test'
AND b=1
AND c='hello'
I'm just looking at how I can made it a little better. The situation or cost is associated with the b=1. Right now, if I remove that then the stored procedure actually runs 3 times faster based on the statistics (albeit, remember, this is relatively quick already) but I will need that b=1 in there.
The interesting thing is that the query plan is actually showing it as a table scan. However, that column "b" is actually defined as a non-clustered index. My question is HOW can I have it use the index on the AND statement. (like a FORCED INDEX or INDEX HINT but not on the table. (NOTE: I did implement an INDEX HINT for it on the TABLE but I obviously can only have one and the INNER JOIN was already using an index so adding the index hint appeared to negate the other and ran much longer.))
I'm not sure why the optimizer is doing this but does anybody know any way to force an index use on a WHERE statement?
Any info would be greatly appreciated.
I have a question that may be able to be resolve here and greatly appreciate any information. It involves SQL Server 2005.
I have a stored procedure that runs ok considering the volume of data that I am dealing with. However, I did a query plan on it and it showed an area that had a cost of 39% and a table scan. In looking at that a little further, it came down to a value that was put into the WHERE clause, for instance,
WHERE a='test'
AND b=1
AND c='hello'
I'm just looking at how I can made it a little better. The situation or cost is associated with the b=1. Right now, if I remove that then the stored procedure actually runs 3 times faster based on the statistics (albeit, remember, this is relatively quick already) but I will need that b=1 in there.
The interesting thing is that the query plan is actually showing it as a table scan. However, that column "b" is actually defined as a non-clustered index. My question is HOW can I have it use the index on the AND statement. (like a FORCED INDEX or INDEX HINT but not on the table. (NOTE: I did implement an INDEX HINT for it on the TABLE but I obviously can only have one and the INNER JOIN was already using an index so adding the index hint appeared to negate the other and ran much longer.))
I'm not sure why the optimizer is doing this but does anybody know any way to force an index use on a WHERE statement?
Any info would be greatly appreciated.