Home » RDBMS Server » Performance Tuning » sql hint
sql hint [message #466883] Wed, 21 July 2010 10:42 Go to next message
prashant_ora
Messages: 196
Registered: July 2010
Senior Member
what is the disadvantage of oracle sql hint?
Re: sql hint [message #466890 is a reply to message #466883] Wed, 21 July 2010 11:15 Go to previous messageGo to next message
Michel Cadot
Messages: 68716
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Not stable (but for very few of them).
You don't and can't know how it will work in the next patch/patchset/PSU/version.

Regards
Michel

[Updated on: Wed, 21 July 2010 11:16]

Report message to a moderator

Re: sql hint [message #466977 is a reply to message #466890] Wed, 21 July 2010 19:17 Go to previous messageGo to next message
rleishman
Messages: 3728
Registered: October 2005
Location: Melbourne, Australia
Senior Member
Not sure I completely agree with you Michel. Can you provide some examples of hints where functionality has changed between releases/patches? I would have said they were at least as stable as regular syntax. The only ones I can think of are RULE and FIRST_ROWS, but they haven't changed functionality, they've just been deprecated.

The main disadvantage of hints is that you eliminate possible access paths from the Cost Based Optimizer. A plan that is bad today may be good in the future because your data changes. Or perhaps in a later release/patch, an even better execution plan will become available, but cannot be used because of your hint.

The approach I take when I get a bad execution plan is to try to work out WHY Oracle chose it. Assuming statistics are thorough and up to date, it is usually because it estimated some non-selective predicate as selective (and used an index on it) or because it estimated some selective predicate as non-selective, and chose NOT to use an index on it.

You can use "gentle" hints, such as NO_INDEX(tab), to discourage Oracle from using bad indexes. Or even better CARDINALITY(tab nnn) to tell Oracle how many rows you think a table will contribute to the result set. These hints don't exclude as many potential access paths, so they still give Oracle an opportunity to choose more optimal plans later on.

Ross Leishman
Re: sql hint [message #466980 is a reply to message #466977] Wed, 21 July 2010 20:57 Go to previous messageGo to next message
rahulvb
Messages: 924
Registered: October 2009
Location: Somewhere Near Equator.
Senior Member
From Michels Statement "Not stable" ,
My Take is if CBO does not use hint ( May be due to Stat) then it is treated as commnet.
hope I am Right.
Re: sql hint [message #467015 is a reply to message #466980] Thu, 22 July 2010 00:56 Go to previous messageGo to next message
Michel Cadot
Messages: 68716
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
Can you provide some examples of hints where functionality has changed between releases/patches?

Not immediately but I can give the principle.
Optimizer applies the hints AFTER internal rewriting of the query, you know these internal rewriting algorithms change at every version, almost every patchset and some one-off patch or PSU.
Now if you put a hint on one query to force some access paths that optimize it for a version, it could be that at the next one the internal rewriting leads to a suboptimal plan due to this hint.

Regards
Michel
Re: sql hint [message #467024 is a reply to message #467015] Thu, 22 July 2010 01:11 Go to previous messageGo to next message
rleishman
Messages: 3728
Registered: October 2005
Location: Melbourne, Australia
Senior Member
But wouldn't it be fair to say that SQL execution plans are just as unstable with or without hints? An optimal plan may also change when a new release/patch provides a rewrite/optimisation that the CBO prefers. I don't see how this behaviour is any more prevalent in the presence of hints. As an example, Cost Based Transformations in 10g caused a lot of previously stable queries - both hinted and unhinted - to go awry.

If I was upgrading the server to a release with a new optimization feature, it wouldn't just be the hinted queries I would be concerned about.

Ross Leishman
Re: sql hint [message #467031 is a reply to message #467024] Thu, 22 July 2010 01:26 Go to previous messageGo to next message
Michel Cadot
Messages: 68716
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
But wouldn't it be fair to say that SQL execution plans are just as unstable with or without hints?

No, as, theorically (when some designer/developer do not go crazy), new plans (when not using hints) should be better at each version when using hints it can only be worse (if plan changes).

Regards
Michel
Re: sql hint [message #467037 is a reply to message #467024] Thu, 22 July 2010 01:55 Go to previous messageGo to next message
Michel Cadot
Messages: 68716
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Here's an example given by J. Lewis in his book Cost-based Oracle fundamentals

Go to bottom page 250 and read the section about "ordered" hint.

Regards
Michel
Re: sql hint [message #467242 is a reply to message #467037] Fri, 23 July 2010 00:18 Go to previous message
rleishman
Messages: 3728
Registered: October 2005
Location: Melbourne, Australia
Senior Member
Fairly specific case, and not really a complaint that can be directed at hints in general.

>> Not stable (but for a very few of them)

In fact, if you think about the general classes of hints: optimization goals, access path, join operation, parallel, join order; Join Order is the only type of hint I can conceive that might exhibit this problem - with all of the others the original plan should always still be one of the alternative plans the optimizer can choose. Even though the optimizer may find a better plan, it should never do worse than the original plan with all other hint classes.

In fact, of the Join Order hints, this wouldn't happen to LEADING, so it's really only a very specific problem with the ORDERED hint and Query Transformation.

I'm still not sure I'd be prepared to level the accusation of "unstable" against hints in general.

Ross Leishman
Previous Topic: CPU used by user SQLs
Next Topic: SETTING PARAMETER
Goto Forum:
  


Current Time: Mon Nov 25 05:22:08 CST 2024