- 10.8.1 使用 EXPLAIN 优化查询10.8.1 Optimizing Queries with EXPLAIN
- 10.8.2 EXPLAIN 输出格式10.8.2 EXPLAIN Output Format
- 10.8.3 扩展 EXPLAIN 输出格式10.8.3 Extended EXPLAIN Output Format
- 10.8.4 获取指定连接的执行计划信息10.8.4 Obtaining Execution Plan Information for a Named Connection
- 10.8.5 评估查询性能10.8.5 Estimating Query Performance
根据您的表、列、索引的详细信息以及 WHERE 子句中的条件,MySQL 优化器会考虑多种技术,以高效地执行 SQL 查询中的查找。对一个大型表的查询可以在不读取所有行的情况下进行;涉及多个表的连接可以在不比较所有行组合的情况下进行。优化器选择执行以实现最有效查询的一组操作称为 “查询执行计划”,也称为 EXPLAIN 计划。您的目标是识别 EXPLAIN 计划中表明查询优化良好的方面,并学习 SQL 语法和索引技术,以在发现某些低效操作时改进计划。Depending on the details of your tables, columns, indexes, and the
conditions in your WHERE clause, the MySQL
optimizer considers many techniques to efficiently perform the
lookups involved in an SQL query. A query on a huge table can be
performed without reading all the rows; a join involving several
tables can be performed without comparing every combination of
rows. The set of operations that the optimizer chooses to perform
the most efficient query is called the “query execution
plan”, also known as the
EXPLAIN plan. Your goals are to
recognize the aspects of the
EXPLAIN plan that indicate a query
is optimized well, and to learn the SQL syntax and indexing
techniques to improve the plan if you see some inefficient
operations.