Hints in Oracle have been around since version 8. Hints are
like compiler directives that tell Oracle what path to take when optimizing a
SQL statement (generally speaking.) However, Oracle will ignore the hint if it
can’t do it or it is formatted poorly.
Most tuning products for SQL will make use of hints if
statement re-arrangement doesn’t solve the problem. In later versions of
Oracle, outlines became available. You see in many applications the SQL is
considered source code and the end user is of course not allowed to modify
them. If you cannot place the hint into the code then of course hints could not
be used for those applications with source code restrictions. Outlines allowed
hints to be tied to a SQL statement ID tag (a signature) and to be applied at
run time by creating a execution plan containing the hints and storing that
plan to be used when the SQL with the proper ID was recognized by the Oracle
kernel. Profiles were the first stage of execution plan stabilization (ensuring
that for a specific SQL statement the execution plan stayed the same, even with
changes in the underlying statistics at the table and index level.)
Now in 10g and beyond Oracle provides not only hints and
outlines, but a new execution plan stabilization mechanism called profiles.
Profiles alter the costs of various optimizer branches to optimize a specific
piece of SQL code.
Generally speaking adding hints was considered to be the
last thing you did if you couldn’t get the SQL optimizer to properly optimize
the SQL statement through the use of indexes, statement rewrite or
initialization parameter adjustments. Why? Well, by adding hints to SQL
statements you generated possible documentation issues if you didn’t properly
document where hints had been placed in the application code and why. The use
of hints also could result in excessively stable plans that wouldn’t change
even if they needed to, not a good situation to be in. Finally hints are
changed, dropped and deprecated in each release of Oracle, so with each patch
or upgrade you would need to re-verify each hinted statement to be sure Oracle
didn’t send along a little surprise in the upgrade or patch.
In my opinion it is a
good practice to only use hints when no other method of SQL statement
optimization can be applied. This also applies to outlines and profiles if you
don’t have access to change source code.
No comments:
Post a Comment