| United States-English |
|
|
|
![]() |
ALLBASE/SQL Performance and Monitoring Guidelines: HP 9000 Computer Systems > Chapter 3 Guidelines on Query DesignUsing OR Predicates |
|
An index scan may be used for a query that has an OR predicate. Most predicates involving OR factors are transformed to conjunctive normal form to make the choice of an index scan during optimization more likely. In addition, the optimization of OR predicates involves internally ANDing additional factors to the predicate you supply in order to eliminate duplicates. Conjunctive normal form expresses a predicate as the conjunction of factors rather than the disjunction of factors. For example, if a predicate has the following elements:
there are two factors in disjunctive normal form. ALLBASE/SQL transforms the predicate as follows:
Now there are 4 factors in conjunctive normal form. The transformation of a predicate into conjunctive normal form increases the number of factors in the predicate. This can result in exceeding the maximum number of factors in a predicate (currently 256). You can avoid this problem by writing your predicates in conjunctive normal form yourself, as in the following:
The only exception to this rule is a predicate containing OR and BETWEEN, as in the following:
Each BETWEEN predicate is actually a conjunction of two range predicates:
Such a predicate is not in conjunctive normal form. However, in this case, you should not rewrite the predicate in conjunctive normal form, nor does ALLBASE/SQL transform the predicate. Both range predicates from a BETWEEN predicate can be used in a single index scan. Therefore, ALLBASE/SQL can make best use of this predicate when it is in the original form. For index scan plans to be chosen for an OR factor (for example, c1=10 OR c2=20), the following conditions must be met:
Based on these conditions, here are some suggestions for query and index design:
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||