For SQL statements that contain search conditions linked with OR, the Optimizer initially analyzes each search condition individually.
b1 AND b2 AND (b3 OR (b4 AND b5))
The expressions b1, b2 and (b3 OR (b4 AND b5)) are initially analyzed individually. If the Optimizer finds an equality condition for key columns for b1 or b2, then it does not have to consider (b3 OR (b4 AND b5)) when selecting the search strategy since the search range cannot be effectively restricted any further.
If the system does not find any equality conditions for key columns, then the other search conditions linked with OR (not yet considered by the system) are analyzed. The Optimizer proceeds as follows:
..
1. Transformation into the disjunctive normal form
b1 AND b2 AND (b3 OR (b4 AND b5))
is transformed into the disjunctive normal form
(b1 AND b2 AND b3) OR (b1 AND b2 AND b4 AND b5)
2.
Analysis of
the new expression
The new parenthesized expressions are analyzed separately.
3.
Determine
costs
The costs
of the various search strategies for the parenthesized expressions of the
disjunctive normal form are totaled. If this total is lower than the initial
determined cost for the search strategy, without considering the search
conditions linked with OR, then these various search strategies are
used.
If the total costs of (b1 AND b2 AND b3) and (b1 AND b2 AND b4 AND b5) are lower than the costs for the search strategy for b1 and b2, then the strategies for (b1 AND b2 AND b3) and (b1 AND b2 AND b4 AND b5) are used.