Oracle 5.0 Reference Manual page 676

Table of Contents

Advertisement

is merged with
HAVING
(COUNT()
[970],
MIN()
• For each table in a join, a simpler
and also to skip rows as soon as possible.
All constant tables are read first before any other tables in the query. A constant table is any of the
following:
• An empty table or a table with one row.
• A table that is used with a
parts are compared to constant expressions and are defined as
All of the following tables are used as constant tables:
SELECT * FROM t WHERE primary_key=1;
SELECT * FROM t1,t2
WHERE t1.primary_key=1 AND t2.primary_key=t1.id;
• The best join combination for joining the tables is found by trying all possibilities. If all columns in
and
ORDER BY
GROUP BY
joining.
• If there is an
ORDER BY
contains columns from tables other than the first table in the join queue, a temporary table is created.
• If you use the
SQL_SMALL_RESULT
• Each table index is queried, and the best index is used unless the optimizer believes that it is more
efficient to use a table scan. At one time, a scan was used based on whether the best index spanned
more than 30% of the table, but a fixed percentage no longer determines the choice between using
an index or a scan. The optimizer now is more complex and bases its estimate on additional factors
such as table size, number of rows, and I/O block size.
• In some cases, MySQL can read rows from the index without even consulting the data file. If all
columns used from the index are numeric, only the index tree is used to resolve the query.
• Before each row is output, those that do not match the
Some examples of queries that are very fast:
SELECT COUNT(*) FROM tbl_name;
SELECT MIN(key_part1),MAX(key_part1) FROM tbl_name;
SELECT MAX(key_part2) FROM
WHERE key_part1=constant;
SELECT ... FROM
tbl_name
ORDER BY key_part1,key_part2,... LIMIT 10;
SELECT ... FROM
tbl_name
ORDER BY
key_part1
MySQL resolves the following queries using only the index tree, assuming that the indexed columns
are numeric:
SELECT
key_part1,key_part2
SELECT COUNT(*) FROM
WHERE
key_part1=val1
SELECT
key_part2
FROM
The following queries use indexing to retrieve the rows in sorted order without a separate sorting pass:
Optimizing
SELECT
if you do not use
WHERE
[971], and so on).
is constructed to get a fast
WHERE
clause on a
WHERE
clauses come from the same table, that table is preferred first when
clause and a different
option, MySQL uses an in-memory temporary table.
tbl_name
DESC,
key_part2
DESC, ... LIMIT 10;
FROM
tbl_name
WHERE key_part1=val;
tbl_name
AND key_part2=val2;
tbl_name
GROUP BY key_part1;
656
Statements
or aggregate functions
GROUP BY
WHERE
or a
PRIMARY KEY
UNIQUE
NOT
clause, or if the
GROUP BY
clause are skipped.
HAVING
evaluation for the table
index, where all index
NULL.
or
ORDER BY
GROUP BY

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents