Oracle 5.0 Reference Manual page 698

Table of Contents

Advertisement

to spread the load across several directories. Paths should be separated by colon characters (":")
on Unix and semicolon characters (";") on Windows, NetWare, and OS/2. The paths should be for
directories in file systems that are located on different physical disks, not different partitions on the
same disk.
8.3.1.12.
GROUP BY
The most general way to satisfy a
temporary table where all rows from each group are consecutive, and then use this temporary table
to discover groups and apply aggregate functions (if any). In some cases, MySQL is able to do much
better than that and to avoid creation of temporary tables by using index access.
The most important preconditions for using indexes for
reference attributes from the same index, and that the index stores its keys in order (for example, this
is a
BTREE
access also depends on which parts of an index are used in a query, the conditions specified for these
parts, and the selected aggregate functions.
There are two ways to execute a
sections. In the first method, the grouping operation is applied together with all range predicates (if
any). The second method first performs a range scan, and then groups the resulting tuples.
In MySQL,
GROUP BY
grouping. See
8.3.1.12.1. Loose Index Scan
The most efficient way to process
columns. With this access method, MySQL uses the property of some index types that the keys are
ordered (for example, BTREE). This property enables use of lookup groups in an index without having
to consider all keys in the index that satisfy all
a fraction of the keys in an index, so it is called a loose index scan. When there is no
a loose index scan reads as many keys as the number of groups, which may be a much smaller
number than that of all keys. If the
[647]
range
up the first key of each group that satisfies the range conditions, and again reads the least possible
number of keys. This is possible under the following conditions:
• The query is over a single table.
• The
GROUP BY
(If, instead of
that form a leftmost prefix of the index.) For example, if a table
loose index scan is applicable if the query has
has
GROUP BY c2, c3
not in the index).
• The only aggregate functions used in the select list (if any) are
and all of them refer to the same column. The column must be in the index and must follow the
columns in the
• Any other parts of the index than those from the
constants (that is, they must be referenced in equalities with constants), except for the argument of
[971]
MIN()
• For columns in the index, full column values must be indexed, not just a prefix. For example, with
VARCHAR(20), INDEX
If loose index scan is applicable to a query, the
in the
by
Extra
Optimizing
Optimization
index and not a
index). Whether use of temporary tables can be replaced by index
HASH
GROUP BY
is used for sorting, so the server may also apply
Section 8.3.1.11,
"ORDER BY
join type in
Section 8.2.1, "Optimizing Queries with
names only columns that form a leftmost prefix of the index and no other columns.
BY, the query has a
GROUP
(the columns are not a leftmost prefix) or
GROUP
BY.
or
[971]
functions.
MAX()
(c1(10)), the index cannot be used for loose index scan.
column.
Statements
SELECT
clause is to scan the whole table and create a new
GROUP BY
GROUP BY
query through index access, as detailed in the following
Optimization".
is when an index is used to directly retrieve the grouping
GROUP BY
conditions. This access method considers only
WHERE
clause contains range predicates (see the discussion of the
WHERE
clause, all distinct attributes refer to columns
DISTINCT
GROUP BY c1,
GROUP BY
EXPLAIN
678
are that all
GROUP BY
ORDER BY
EXPLAIN"), a loose index scan looks
has an index on (c1,c2,c3),
t1
c2,. It is not applicable if the query
GROUP BY c1, c2, c4 (c4
[971]
and
MIN()
referenced in the query must be
output shows
Using index for group-
columns
optimizations to
clause,
WHERE
is
[971],
MAX()
c1

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents