|Lesson 4||Deficiencies of rule-based SQL optimization |
|Objective||List the disadvantages of the rule-based optimizer. |
Disadvantages of rule-based SQL optimization
As we discussed, there are cases where the rule-based optimizer fails. This is most
common in cases where a table has many indexes and the rule-based optimizer fails to choose the best index to service a query.
This generally happens because the rule-based optimizer is not aware of the number of distinct values in an index and the distribution of values within the index. Let us illustrate this point with an example shown in the following Slide Show.
So what can we do about the problem shown in the FlipBook?
There are several remedies:
- Add an index hint:
SELECT /*+ INDEX dept_ix */
- Add a cost-based hint:
SELECT /*+ ALL_ROWS */
- Invalidate the STATUS index.
Invalidating an index is a common trick that is used when the rule-based optimizer makes a bad choice of indexes.
Disabling unwanted indexes
Unwanted indexes can be disabled by mixing data type on the index. For example, we know that the status field is a numeric index, so we could concatenate a null character value to the predicate to invalidate it. Oracle will see the data type mismatch, and bypass that index. In the example below, we have concatenated a null character “” to the status predicate:
department = ‘FINANCE’
status = 3||0;
Now let us look at tricks for repositioning items in the FROM clause to improve the speed of rule-based SQL queries.