I was recently trying to optimize a big SQL statement (a dozen of JOINs and APPLYs), commenting some joins and filters and looking at execution times and plans until I pinpointed the "culprit" JOIN that was making my statement run in minutes rather than in a few seconds.An appropriate index existed in the joined table but it turned out that SQL Server Optimizer was not using it. Forcing SQL Server to use the right index using the WITH INDEX hint solved the problem.I read some articles about the pros and cons of using the WITH INDEX hint and I would appreciate any enlightening commentary on the subject. More specifically, can it be that I reached some limits of the optimizer and using the WITH INDEX hint is the best solution or should I never use such hints and try rewrite my statement until it performs well at all times?
↧