Was wondering if anyone can shed some light on this.This query takes 3 seconds when also opening the cursor and doing the FETCH NEXT:DECLARE crSubscriber CURSOR FOR SELECT BillToID, Percentage, Taxable FROM ClaimSubscription WHERE ClaimID = @ClaimID ORDER BY Percentage DESC
However, this query takes only 0.001 seconds:SELECT BillToID, Percentage, Taxable FROM ClaimSubscription WHERE ClaimID = @ClaimID ORDER BY Percentage DESC
And this one also takes only 0.001 seconds when opening the cursor and doing the FETCH NEXT:DECLARE crSubscriber CURSOR FOR SELECT BillToID, Percentage, Taxable FROM ClaimSubscription WHERE ClaimID = @ClaimID
I looked at the execution path and in the slow query, SQL Server chooses to use the index on the column Percentage, rather than the Index on column ClaimID.So I can't understand why it would not choose the optimum index. And I can't understand why it chooses a different index bewteen the select with the cursor and the select without the cursor - after all, it is the exact same select statement?To me, I wonder if it is a bug in SQL Server? Or can anyone shed some light on this?In any event, I was able to repair the slow query by using an index hint (with (Index(claimID))