Consider the following statement, where
SELECT * FROM t1 WHERE
(key1 < 'abc' AND (key1 LIKE 'abcde%' OR key1 LIKE '%b')) OR
(key1 < 'bar' AND nonkey = 4) OR
(key1 < 'uux' AND key1 > 'z');
The extraction process for key
1. Start with original
(key1 < 'abc' AND (key1 LIKE 'abcde%' OR key1 LIKE '%b')) OR
(key1 < 'bar' AND nonkey = 4) OR
(key1 < 'uux' AND key1 > 'z')
2. Remove
correct way to remove them is to replace them with TRUE, so that we do not miss any matching
rows when doing the range scan. Having replaced them with TRUE, we get:
(key1 < 'abc' AND (key1 LIKE 'abcde%' OR TRUE)) OR
(key1 < 'bar' AND TRUE) OR
(key1 < 'uux' AND key1 > 'z')
3. Collapse conditions that are always true or false:
•
(key1 LIKE 'abcde%' OR TRUE)
•
(key1 < 'uux' AND key1 > 'z')
Replacing these conditions with constants, we get:
(key1 < 'abc' AND TRUE) OR (key1 < 'bar' AND TRUE) OR (FALSE)
Removing unnecessary
(key1 < 'abc') OR (key1 < 'bar')
4. Combining overlapping intervals into one yields the final condition to be used for the range scan:
(key1 < 'bar')
In general (and as demonstrated by the preceding example), the condition used for a range scan is
less restrictive than the
satisfy the range condition but not the full
The range condition extraction algorithm can handle nested
arbitrary depth, and its output does not depend on the order in which conditions appear in
clause.
Currently, MySQL does not support merging multiple ranges for the
spatial indexes. To work around this limitation, you can use a
except that you put each spatial predicate in a different SELECT.
8.3.1.3.2. The Range Access Method for Multiple-Part Indexes
Range conditions on a multiple-part index are an extension of range conditions for a single-part index.
A range condition on a multiple-part index restricts index rows to lie within one or several key tuple
intervals. Key tuple intervals are defined over a set of key tuples, using ordering from the index.
For example, consider a multiple-part index defined as
key_part3), and the following set of key tuples listed in key order:
key_part1
NULL
Optimizing
key1
clause:
WHERE
and
nonkey = 4
key1 LIKE '%b'
and
TRUE
clause. MySQL performs an additional check to filter out rows that
WHERE
key_part2
key_part3
1
'abc'
Statements
SELECT
is an indexed column and
key1
is as follows:
because they cannot be used for a range scan. The
is always true
is always false
constants, we obtain:
FALSE
clause.
WHERE
key1(key_part1, key_part2,
658
is not indexed:
nonkey
AND [880]/OR
[881]
constructs of
[647]
access method for
range
with identical
UNION
WHERE
statements,
SELECT
Need help?
Do you have a question about the 5.0 and is the answer not in the manual?
Questions and answers