Oracle 5.0 Reference Manual page 675

Table of Contents

Advertisement

This result was obtained on a Pentium II 400MHz system. It shows that MySQL can execute 1,000,000
simple addition expressions in 0.32 seconds on that system.
All MySQL functions should be highly optimized, but there may be some exceptions.
BENCHMARK()
8.3.1.1. Speed of
SELECT
In general, when you want to make a slow
is whether you can add an index. All references between different tables should usually be done with
indexes. You can use the
Section 8.2.1, "Optimizing Queries with
Some general tips for speeding up queries on
• To help MySQL better optimize queries, use
a table after it has been loaded with data. This updates a value for each index part that indicates
the average number of rows that have the same value. (For unique indexes, this is always 1.)
MySQL uses this to decide which index to choose when you join two tables based on a nonconstant
expression. You can check the result from the table analysis by using
tbl_name
shows index distribution information.
• To sort an index and data according to an index, use
records=1
if you have a unique index from which you want to read all rows in order according to the index. The
first time you sort a large table this way, it may take a long time.
8.3.1.2.
Clause Optimization
WHERE
This section discusses optimizations that can be made for processing
use
SELECT
statements.
Work on the MySQL optimizer is ongoing, so this section is incomplete. MySQL performs a great many
optimizations, not all of which are documented here.
Some of the optimizations performed by MySQL follow:
• Removal of unnecessary parentheses:
((a AND b) AND c OR (((a AND b) AND (c AND d))))
-> (a AND b AND c) OR (a AND b AND c AND d)
• Constant folding:
(a<b AND b=c) AND a=5
-> b>5 AND b=c AND a=5
• Constant condition removal (needed because of constant folding):
(B>=5 AND B=5) OR (B=6 AND 5=5) OR (B=7 AND 5=6)
-> B=5 OR B=6
• Constant expressions used by indexes are evaluated only once.
COUNT(*)
for
MyISAM
one table.
• Early detection of invalid constant expressions. MySQL quickly detects that some
statements are impossible and returns no rows.
Optimizing
[957]
is an excellent tool for finding out if some function is a problem for your queries.
Statements
EXPLAIN
and examining the
Cardinality
(assuming that you want to sort on index 1). This is a good way to make queries faster
statements, but the same optimizations apply for
[970]
on a single table without a
and
tables. This is also done for any
MEMORY
Statements
SELECT
SELECT ... WHERE
statement to determine which indexes are used for a SELECT. See
EXPLAIN", and
Section 8.5.3, "How MySQL Uses
tables:
MyISAM
ANALYZE TABLE
value.
myisamchk --description --verbose
myisamchk --sort-index --sort-
is retrieved directly from the table information
WHERE
655
query faster, the first thing to check
or run
myisamchk --analyze
SHOW INDEX FROM
clauses. The examples
WHERE
clauses in
WHERE
DELETE
expression when used with only
NOT NULL
Indexes".
on
and
UPDATE
SELECT

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents