I had SQL query that was taking 9 hours for execution. See below:
Select Field1, Field2
From A
Where Field3 IN (45 unique values here)
Whe
Two possibilities that I can see:
1) There might be a billion records with Field3 = 10001 so that'll be really slow. And there might be no records with the other values, so that would be very fast.
2) the issue could be the method that the DB uses to run the query. for example there may be a cut off point where it will probably switch from using the index to a full table scan. the optimizer isn't always right. when it's wrong you have to dance around it.