Oracle 5.0 Reference Manual page 715

Table of Contents

Advertisement

• In some cases, a query can be optimized to retrieve values without consulting the data rows. If a
query uses only columns from a table that are numeric and that form a leftmost prefix for some key,
the selected values may be retrieved from the index tree for greater speed:
SELECT
key_part3
WHERE key_part1=1
Suppose that you issue the following
mysql>
SELECT * FROM tbl_name WHERE col1=val1 AND col2=val2;
If a multiple-column index exists on
separate single-column indexes exist on
Merge optimization (see
restrictive index by deciding which index finds fewer rows and using that index to fetch the rows.
If the table has a multiple-column index, any leftmost prefix of the index can be used by the optimizer
to find rows. For example, if you have a three-column index on
indexed search capabilities on (col1),
MySQL cannot use an index if the columns do not form a leftmost prefix of the index. Suppose that you
have the
SELECT
SELECT * FROM
SELECT * FROM
SELECT * FROM
SELECT * FROM
If an index exists on
fourth queries do involve indexed columns, but
of
(col1, col2,
B-Tree Index Characteristics
A B-tree index can be used for column comparisons in expressions that use the
[876],
[876],
>=
<
[896]
comparisons if the argument to
LIKE
wildcard character. For example, the following
SELECT * FROM
SELECT * FROM
In the first statement, only rows with
second statement, only rows with
The following
SELECT * FROM
SELECT * FROM
In the first statement, the
the
[896]
LIKE
If you use
... LIKE '%string%'
Turbo Boyer-Moore algorithm to initialize the pattern for the string and then uses this pattern to perform
the search more quickly.
A search using
Any index that does not span all
the query. In other words, to be able to use an index, a prefix of the index must be used in every
[880]
group.
AND
The following
How MySQL Uses Indexes
FROM
tbl_name
col1
Section 8.3.1.4, "Index Merge
statements shown here:
tbl_name
WHERE col1=val1;
tbl_name
WHERE
col1=val1
tbl_name
WHERE col2=val2;
tbl_name
WHERE
col2=val2
(col1, col2,
col3).
[876], or
<=
BETWEEN
tbl_name
WHERE
key_col
tbl_name
WHERE
key_col
'Patrick' <= key_col < 'Patricl'
'Pat' <= key_col < 'Pau'
statements do not use indexes:
SELECT
tbl_name
WHERE
key_col
tbl_name
WHERE
key_col
[896]
LIKE
value is not a constant.
and
col_name IS NULL
AND
clauses use indexes:
WHERE
statement:
SELECT
and col2, the appropriate rows can be fetched directly. If
and col2, the optimizer will attempt to use the Index
col1
Optimization"), or attempt to find the most
col2), and
(col1,
AND col2=val2;
AND col3=val3;
col3), only the first two queries use the index. The third and
and
(col2)
[877]
operators. The index also can be used for
[896]
is a constant string that does not start with a
LIKE
statements use indexes:
SELECT
LIKE 'Patrick%';
LIKE 'Pat%_ck%';
LIKE '%Patrick%';
LIKE other_col;
value begins with a wildcard character. In the second statement,
is longer than three characters, MySQL uses the
string
employs indexes if
col_name
[880]
levels in the
WHERE
695
col3), you have
(col1, col2,
(col1, col2,
col3).
are not leftmost prefixes
(col2, col3)
[875],
=
are considered. In the
are considered.
is indexed.
clause is not used to optimize
[876],
>

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents