For a WHERE clause that contains multiple Boolean operators,
qualification descriptors are nested.For a WHERE clause that contains multiple expressions, columns, or
constants, use parameter descriptors along with nested qualification
descriptors.
Nested qualification descriptors
The following
example combines a function with multiple Boolean operators:
WHERE year > 95 AND (quarter = 1 OR quarter = 3)
The OR operator combines two functions, equal(quarter,1) and equal(quarter,3). If either is true, the combination
is true. The AND operator combines the result of the greaterthan(year,95) with the result of the Boolean OR operator.
If a WHERE clause
contains multiple conditions, the database server constructs a qualification
descriptor that contains multiple, nested qualification descriptors.
The following example shows a WHERE clause that contains multiple
levels of Boolean qualifications. At each level, a Boolean operator
combines results from two previous qualifications:
WHERE region = "southwest" AND
(balance < 90 OR aged <= 30)
The following example shows how the functions from the
previous example are nested in the top-level qualification descriptor:
AND(equal(region,'southwest'),
OR(lessthan(balance,90), lessthanequal(aged,30)))
The nested qualification descriptors for the preceding
WHERE clause have a hierarchical relationship, as the following figure
shows.
Figure 1. Hierarchy
of nested qualification descriptors
The WHERE clause is processed in the following order:
- The Q1 qualification descriptor handles the lessthan(balance,90) function.
- The Q2 qualification descriptor handles the lessthanequal(aged,30) function.
- The Q3 qualification descriptor handles the OR operation on the
results of the Q1 and Q2 descriptors.
- The Q4 qualification descriptor handles the equal(region,’southwest’) function.
- The Q5 qualification descriptor handles the AND operation on the
results of the Q4 and Q3 descriptors.
Parameter
descriptors and qualification descriptors
If a WHERE clause
has multiple expressions, columns, or constants, use parameter descriptors
to describe all the parameters in the qualifications. A parameter
descriptor is also necessary if the qualification consists of a function
that takes a single value. Qualification descriptors and parameter
descriptors can be nested to reflect the qualification hierarchy.
Nested qualification and parameter descriptors are processed recursively.
The following example has multiple levels of qualifications:
WHERE udr1(a,7,4)>5 AND b=2 AND udr2(c)
The following example shows how the functions from the previous example
are nested:
AND (greaterthan(udr1(a,7,4),5), AND (equals(b,2), udr2(c)))
The nested qualification descriptors and parameter descriptors
for the preceding WHERE clause have a hierarchical relationship, as
the following figure shows.
Figure 2. Hierarchy of nested qualification
and parameter descriptors
The WHERE clause is processed in the following order:
- The Q1 qualification descriptor starts evaluating the greaterthan function, whose parameters are described in
the P1 parameter descriptor. The P1 parameter descriptor contains
two parameters: an expression, which is contained in the Q2 qualification
descriptor, and the constant 5.
- The Q2 qualification descriptor evaluates the expression udr1, whose parameters are described in the P2 parameter
descriptor. The P2 parameter descriptor contains three parameters:
the column a, the constant 7, and the constant 4.
- The Q1 qualification descriptor uses the result of the Q2 qualification
descriptor to complete the evaluation of the greaterthan function.
- The Q3 qualification descriptor evaluates the equals function, whose parameters are described in the P3 parameter descriptor.
The P3 parameter descriptor contains two parameters: a column b and the constant 2.
- The Q4 qualification descriptor evaluates the expression udr2, whose parameters are describes in the P4 parameter
descriptor. The P4 parameter descriptor contains one parameter: the
column c.
- The Q5 qualification descriptor evaluates the AND operator on
the results of the Q1, Q3, and Q4 qualification descriptors.