Tuesday, July 20, 2010

Using SQL Hints

I can get around SQL Server fairly well, but I'm not a guru. One trick I was shown today was the use of SQL Hints. Here is a real world scenario where they really help out.

I had a query that was taking about 44 seconds in enterprise manager. My boss came over and showed that the main drag was nested queries (by viewing the execution plan in the query analyzer).

So we added the following hint.

Select blah blah

from blah blah

where blah blah

option ( hash join )

Wow, 44 seconds to less then 1 second. Also option ( merge join ) dropped the query execution time down to less then a second as well.

Is it then or than? Oh well. Public school system

No comments: