Oracle 5.0 Reference Manual page 696

Table of Contents

Advertisement

SELECT * FROM t1 ORDER BY -key;
• You are joining many tables, and the columns in the
table that is used to retrieve rows. (This is the first table in the
[646]
join type.)
const
• You have different
ORDER BY
• You index only a prefix of a column named in the
be used to fully resolve the sort order. For example, if you have a
the first 10 bytes, the index cannot distinguish values past the 10th byte and a
needed.
• The type of table index used does not store rows in order. For example, this is true for a
in a
table.
MEMORY
Availability of an index for sorting may be affected by the use of column aliases. Suppose that the
column
is indexed. In this statement, the name of the column in the select list is a. It refers to
t1.a
t1.a, so for the reference to
SELECT a FROM t1 ORDER BY a;
In this statement, the name of the column in the select list is also a, but it is the alias name. It refers to
ABS(a), so for the reference to
SELECT ABS(a) AS a FROM t1 ORDER BY a;
In the following statement, the
select list. But there is a column in
used. (The resulting sort order may be completely different from the order for ABS(a), of course.)
SELECT ABS(a) AS b FROM t1 ORDER BY a;
By default, MySQL sorts all
in the query as well. If you include an
col1, col2, ...
the same column list, MySQL optimizes it away without any speed penalty, although the sorting still
occurs. If a query includes
suppress sorting by specifying
INSERT INTO foo
SELECT a, COUNT(*) FROM bar GROUP BY a ORDER BY NULL;
With
EXPLAIN SELECT ... ORDER
the query. It cannot if you see
Queries with
EXPLAIN". Filesort uses a fixed-length row-storage format similar to that used by the
storage engine. Variable-length types such as
MEMORY
MySQL has two
filesort
only the
columns. The modified method uses not just the
ORDER BY
columns used in the query.
The optimizer selects which
when
or
columns are involved, in which case it uses the original algorithm.
BLOB
TEXT
The original
filesort
1. Read all rows according to key or by table scanning. Rows that do not match the
skipped.
2. For each row, store a pair of values in a buffer (the sort key and the row pointer). The size of the
buffer is the value of the
Optimizing
SELECT
and
GROUP BY
in the
BY, the index can be used:
a
ORDER
in the
a
ORDER
refers to a name that is not the name of a column in the
ORDER BY
named a, so the
t1
GROUP BY col1, col2, ...
but you want to avoid the overhead of sorting the result, you can
GROUP BY
NULL. For example:
ORDER BY
BY, you can check whether MySQL can use indexes to resolve
Using filesort
algorithms for sorting and retrieving results. The original method uses
algorithm to use. It normally uses the modified algorithm except
filesort
algorithm works as follows:
sort_buffer_size
676
Statements
are not all from the first nonconstant
ORDER BY
EXPLAIN
expressions.
clause. In this case, the index cannot
ORDER BY
CHAR(20)
BY, the index cannot be used:
uses that, and the index can be
ORDER BY
queries as if you specified
clause explicitly that contains
ORDER BY
in the
column. See
Extra
are stored using a fixed length.
VARCHAR
ORDER BY
[493]
system variable.
output that does not have a
column, but index only
will be
filesort
index
HASH
ORDER BY
Section 8.2.1, "Optimizing
columns, but all the
clause are
WHERE

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents