- MySQL 5.1 Reference Manual :: 7 Optimization :: 7.2 Optimizing SELECT and Other Statements
-
- MySQL 5.1 Reference Manual
- Preface, Notes, Licenses
- 1 General Information
- 2 Installing and Upgrading MySQL
- 3 Tutorial
- 4 MySQL Programs
- 5 MySQL Server Administration
- 6 Backup and Recovery
- 7 Optimization
- 8 Language Structure
- 9 Internationalization and Localization
- 10 Data Types
- 11 Functions and Operators
- 12 SQL Statement Syntax
- 13 Storage Engines
- 14 High Availability and Scalability
- 15 MySQL Enterprise Monitor
- 16 Replication
- 17 MySQL Cluster NDB 6.X/7.X
- 18 Partitioning
- 19 Stored Programs and Views
- 20 INFORMATION_SCHEMA Tables
- 21 Connectors and APIs
- 22 Extending MySQL
- A MySQL 5.1 Frequently Asked Questions
- B Errors, Error Codes, and Common Problems
- C MySQL Change History
- D Restrictions and Limits
- Index
- Standard Index
- C Function Index
- Command Index
- Function Index
- INFORMATION_SCHEMA Index
- Transaction Isolation Level Index
- JOIN Types Index
- Operator Index
- Option Index
- Privileges Index
- SQL Modes Index
- Status Variable Index
- Statement/Syntax Index
- System Variable Index
[+/-]
- 7.2.1. Optimizing Queries with
EXPLAIN
- 7.2.2. Estimating Query Performance
- 7.2.3. Speed of
SELECT
Queries - 7.2.4.
WHERE
Clause Optimization - 7.2.5. Range Optimization
- 7.2.6. Index Merge Optimization
- 7.2.7. Condition Pushdown Optimization
- 7.2.8.
IS NULL
Optimization - 7.2.9.
LEFT JOIN
andRIGHT JOIN
Optimization - 7.2.10. Nested-Loop Join Algorithms
- 7.2.11. Nested Join Optimization
- 7.2.12. Outer Join Simplification
- 7.2.13.
ORDER BY
Optimization - 7.2.14.
GROUP BY
Optimization - 7.2.15.
DISTINCT
Optimization - 7.2.16. Optimizing
IN
/=ANY
Subqueries - 7.2.17.
LIMIT
Optimization - 7.2.18. Using
optimizer_switch
to Control the Optimizer - 7.2.19. How to Avoid Table Scans
- 7.2.20.
INFORMATION_SCHEMA
Optimization - 7.2.21. Speed of
INSERT
Statements - 7.2.22. Speed of
UPDATE
Statements - 7.2.23. Speed of
DELETE
Statements - 7.2.24. Other Optimization Tips
First, one factor affects all statements: The more complex your permissions setup, the more overhead you have. Using simpler permissions when you issue
GRANT
statements enables MySQL to reduce permission-checking overhead when clients execute statements. For example, if you do not grant any table-level or column-level privileges, the server need not ever check the contents of thetables_priv
andcolumns_priv
tables. Similarly, if you place no resource limits on any accounts, the server does not have to perform resource counting. If you have a very high statement-processing load, it may be worth the time to use a simplified grant structure to reduce permission-checking overhead.If your problem is with a specific MySQL expression or function, you can perform a timing test by invoking the
BENCHMARK()
function using the mysql client program. Its syntax isBENCHMARK(
. The return value is always zero, but mysql prints a line displaying approximately how long the statement took to execute. For example:loop_count
,expression
)mysql>
SELECT BENCHMARK(1000000,1+1);
+------------------------+ | BENCHMARK(1000000,1+1) | +------------------------+ | 0 | +------------------------+ 1 row in set (0.32 sec)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()
is an excellent tool for finding out if some function is a problem for your queries.