Oracle 5.0 Reference Manual page 699

Table of Contents

Advertisement

Assume that there is an index
access method can be used for the following queries:
SELECT c1, c2 FROM t1 GROUP BY c1, c2;
SELECT DISTINCT c1, c2 FROM t1;
SELECT c1, MIN(c2) FROM t1 GROUP BY c1;
SELECT c1, c2 FROM t1 WHERE c1 <
SELECT MAX(c3), MIN(c3), c1, c2 FROM t1 WHERE c2 >
SELECT c2 FROM t1 WHERE c1 <
SELECT c1, c2 FROM t1 WHERE c3 =
The following queries cannot be executed with this quick select method, for the reasons given:
• There are aggregate functions other than
SELECT c1, SUM(c2) FROM t1 GROUP BY c1;
• The columns in the
SELECT c1, c2 FROM t1 GROUP BY c2, c3;
• The query refers to a part of a key that comes after the
equality with a constant:
SELECT c1, c3 FROM t1 GROUP BY c1, c2;
Were the query to include
8.3.1.12.2. Tight Index Scan
A tight index scan may be either a full index scan or a range index scan, depending on the query
conditions.
When the conditions for a loose index scan are not met, it still may be possible to avoid creation of
temporary tables for
reads only the keys that satisfy these conditions. Otherwise, it performs an index scan. Because this
method reads all keys in each range defined by the
are no range conditions, we term it a tight index scan. With a tight index scan, the grouping operation is
performed only after all keys that satisfy the range conditions have been found.
For this method to work, it is sufficient that there is a constant equality condition for all columns in
a query referring to parts of the key coming before or in between parts of the
constants from the equality conditions fill in any "gaps" in the search keys so that it is possible to form
complete prefixes of the index. These index prefixes then can be used for index lookups. If we require
sorting of the
MySQL also avoids extra sorting operations because searching with prefixes in an ordered index
already retrieves all the keys in order.
Assume that there is an index
do not work with the loose index scan access method described earlier, but still work with the tight
index scan access method.
• There is a gap in the
SELECT c1, c2, c3 FROM t1 WHERE c2 = 'a' GROUP BY c1, c3;
• The
GROUP BY
constant for that part:
SELECT c1, c2, c3 FROM t1 WHERE c1 = 'a' GROUP BY c2, c3;
8.3.1.13.
DISTINCT
combined with
DISTINCT
Optimizing
idx(c1,c2,c3)
const
const
const
clause do not form a leftmost prefix of the index:
GROUP BY
WHERE c3 =
queries. If there are range conditions in the
GROUP BY
result, and it is possible to form search keys that are prefixes of the index,
GROUP BY
idx(c1,c2,c3)
BY, but it is covered by the condition
GROUP
does not begin with the first part of the key, but there is a condition that provides a
Optimization
ORDER BY
Statements
SELECT
on table t1(c1,c2,c3,c4). The loose index scan
GROUP BY c1, c2;
const
GROUP BY c1, c2;
GROUP BY c1, c2;
[971]
or
MIN()
MAX()
GROUP BY
const, loose index scan could be used.
clause, or scans the whole index if there
WHERE
on table t1(c1,c2,c3,c4). The following queries
needs a temporary table in many cases.
679
GROUP BY c1, c2;
[971]:
part, and for which there is no
clause, this method
WHERE
GROUP BY
c2 =
'a':
key. The

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents