Groups | Blog | Home
all groups > sql server (alternate) > december 2004 >

sql server (alternate) : Hints



newtophp2000 NO[at]SPAM yahoo.com
12/26/2004 8:43:11 PM
I am kind of confused about the way SQL Server 2000 handles the hints
that users supply with their SQL statements.

[quoted text, click to view]
in SQL statements known as table hints. Sometimes, multiple uses of
this form in a statement is OK. Then there is the OPTION clause for
specifying statement hints. However, the documentation on OPTION
section discourages their use.

Being relatively new to SQL Server and still learning about it, what is
the general practice? Use hints or not? And if so, how (through WITH
or OPTION clauses)?

Cheers!
Greg D. Moore (Strider)
12/27/2004 5:01:28 AM

[quoted text, click to view]

Generally, "don't".

Usually SQL server will make better guesses than you can.


[quoted text, click to view]

--CELKO--
12/27/2004 1:48:15 PM
[quoted text, click to view]

1) "Trust in the Optimizer, Luke!" It is usually smarter than you are.
What happens when you give a bad hint?

2) Once you write a query with a hint, that hint stays there. Even if
the pathological situation that made you use a hint heals up. Nobody
will dare remove it later, since it looks important.

3) Every product that supports hints has a different syntax and
underlying model, so your hint code will not port, and the logic of
your hint might not port either.

For example, in Sybase SQL Anywhere, you can give a guess as to what
percentage of the time a predicate will be TRUE. Their optimizer uses
that guess instead of it own computation to build the query. It is not
forced to use a particlar index or method. like other products.
nib
12/27/2004 4:08:17 PM
[quoted text, click to view]

That's funny! And too true!

Erland Sommarskog
12/27/2004 10:18:42 PM
(newtophp2000@yahoo.com) writes:
[quoted text, click to view]

Be very conservative with adding hints. In an ideal you would never have to
use them, but today I add two hints to one query: one index hint, and one
OPTION clause to turn of parallelism.

My general rule is that I add a hint, if 1) there is an apparent performance
problem and 2) there is an obvious choice of how the query plan should go.
The one hint I am the least conservative is OPTION (MAXDOP 1), because
even if the query would execute faster with parallelism, it will not at
least monopolize all processors in the machine. (And often parallel plans
are more ineffecient than the non-parallel plans.) The hint I am most
conservative of using is the join hint - you dump in a word between
INNER and JOIN, since this use of this hint results in a warning.

Whether to use WITH or OPTION depends on what you want to force. They
serve different purposes, therefore you cannot say that one is better
than the other.
--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
--CELKO--
12/28/2004 6:35:35 AM
[quoted text, click to view]

Remember the quote from early UNIX days? "There is nothing more
permanent than a temporary patch!"
AddThis Social Bookmark Button