Optimizing
SELECT
Statements
659
NULL 1 'xyz'
NULL 2 'foo'
1 1 'abc'
1 1 'xyz'
1 2 'abc'
2 1 'aaa'
The condition
key_part1 = 1
defines this interval:
(1,-inf,-inf) <= (
key_part1
,
key_part2
,
key_part3
) < (1,+inf,+inf)
The interval covers the 4th, 5th, and 6th tuples in the preceding data set and can be used by the range
access method.
By contrast, the condition
key_part3 = 'abc'
does not define a single interval and cannot be used
by the range access method.
The following descriptions indicate how range conditions work for multiple-part indexes in greater
detail.
• For
HASH
indexes, each interval containing identical values can be used. This means that the interval
can be produced only for conditions in the following form:
key_part1
cmp
const1
AND
key_part2
cmp
const2
AND ...
AND
key_partN
cmp
constN
;
Here,
const1
,
const2
, … are constants,
cmp
is one of the
=
[875]
,
<=>
[876]
, or
IS
NULL
[877]
comparison operators, and the conditions cover all index parts. (That is, there are
N
conditions, one for each part of an
N
-part index.) For example, the following is a range condition for a
three-part
HASH
index:
key_part1
= 1 AND
key_part2
IS NULL AND
key_part3
= 'foo'
For the definition of what is considered to be a constant, see
Section 8.3.1.3.1, “The Range Access
Method for Single-Part Indexes”
.
• For a
BTREE
index, an interval might be usable for conditions combined with
AND
[880]
, where
each condition compares a key part with a constant value using
=
[875]
,
<=>
[876]
,
IS
NULL
[877]
,
>
[876]
,
<
[876]
,
>=
[876]
,
<=
[876]
,
!=
[876]
,
<>
[876]
,
BETWEEN
[877]
,
or
LIKE 'pattern'
[896]
(where
'pattern'
does not start with a wildcard). An interval can
be used as long as it is possible to determine a single key tuple containing all rows that match the
condition (or two intervals if
<>
[876]
or
!=
[876]
is used).
The optimizer attempts to use additional key parts to determine the interval as long as the
comparison operator is
=
[875]
,
<=>
[876]
, or
IS NULL
[877]
. If the operator is
>
[876]
,
<
[876]
,
>=
[876]
,
<=
[876]
,
!=
[876]
,
<>
[876]
,
BETWEEN
[877]
, or
LIKE
[896]
, the
optimizer uses it but considers no more key parts. For the following expression, the optimizer
uses
=
[875]
from the first comparison. It also uses
>=
[876]
from the second comparison but
considers no further key parts and does not use the third comparison for interval construction:
key_part1
= 'foo' AND
key_part2
>= 10 AND
key_part3
> 10
The single interval is:
('foo',10,-inf) < (
key_part1
,
key_part2
,
key_part3
) < ('foo',+inf,+inf)
It is possible that the created interval contains more rows than the initial condition. For example,
the preceding interval includes the value
('foo', 11, 0)
, which does not satisfy the original
condition.
• If conditions that cover sets of rows contained within intervals are combined with
OR
[881]
,
they form a condition that covers a set of rows contained within the union of their intervals. If the
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...