Chapter 8 Optimization第8章 优化

Table of Contents目录

8.1 Optimization Overview优化概述
8.2 Optimizing SQL Statements优化SQL语句
8.2.1 Optimizing SELECT Statements优化SELECT语句
8.2.2 Optimizing Subqueries, Derived Tables, View References, and Common Table Expressions优化子查询、派生表、视图引用和公共表表达式
8.2.3 Optimizing INFORMATION_SCHEMA Queries用SCHEMA查询优化信息
8.2.4 Optimizing Performance Schema Queries优化性能架构查询
8.2.5 Optimizing Data Change Statements优化数据更改语句
8.2.6 Optimizing Database Privileges优化数据库权限
8.2.7 Other Optimization Tips其他优化提示
8.3 Optimization and Indexes优化与索引
8.3.1 How MySQL Uses IndexesMySQL如何使用索引
8.3.2 Primary Key Optimization主键优化
8.3.3 SPATIAL Index Optimization空间索引优化
8.3.4 Foreign Key Optimization外键优化
8.3.5 Column Indexes列索引
8.3.6 Multiple-Column Indexes多列索引
8.3.7 Verifying Index Usage验证索引用法
8.3.8 InnoDB and MyISAM Index Statistics CollectionInnoDB和MyISAM索引统计集合
8.3.9 Comparison of B-Tree and Hash IndexesB-树和散列索引的比较
8.3.10 Use of Index Extensions索引扩展的使用
8.3.11 Optimizer Use of Generated Column Indexes优化器使用生成的列索引
8.3.12 Invisible Indexes不可见索引
8.3.13 Descending Indexes降序索引
8.3.14 Indexed Lookups from TIMESTAMP Columns从时间戳列进行索引查找
8.4 Optimizing Database Structure优化数据库结构
8.4.1 Optimizing Data Size优化数据大小
8.4.2 Optimizing MySQL Data Types优化MySQL数据类型
8.4.3 Optimizing for Many Tables为多个表优化
8.4.4 Internal Temporary Table Use in MySQLMySQL中内部临时表的使用
8.4.5 Limits on Number of Databases and Tables数据库和表的数量限制
8.4.6 Limits on Table Size表大小限制
8.4.7 Limits on Table Column Count and Row Size表列计数和行大小限制
8.5 Optimizing for InnoDB TablesInnoDB表的优化
8.5.1 Optimizing Storage Layout for InnoDB Tables优化InnoDB表的存储布局
8.5.2 Optimizing InnoDB Transaction Management优化InnoDB事务管理
8.5.3 Optimizing InnoDB Read-Only Transactions优化InnoDB只读事务
8.5.4 Optimizing InnoDB Redo Logging优化InnoDB Redo日志
8.5.5 Bulk Data Loading for InnoDB TablesInnoDB表的批量数据加载
8.5.6 Optimizing InnoDB Queries优化InnoDB查询
8.5.7 Optimizing InnoDB DDL Operations优化InnoDB DDL操作
8.5.8 Optimizing InnoDB Disk I/O优化InnoDB磁盘I/O
8.5.9 Optimizing InnoDB Configuration Variables优化InnoDB配置变量
8.5.10 Optimizing InnoDB for Systems with Many Tables多表系统的InnoDB优化
8.6 Optimizing for MyISAM Tables优化MyISAM表
8.6.1 Optimizing MyISAM Queries优化MyISAM查询
8.6.2 Bulk Data Loading for MyISAM TablesMyISAM表的批量数据加载
8.6.3 Optimizing REPAIR TABLE Statements优化修复表语句
8.7 Optimizing for MEMORY Tables优化内存表
8.8 Understanding the Query Execution Plan了解查询执行计划
8.8.1 Optimizing Queries with EXPLAIN使用EXPLAIN优化查询
8.8.2 EXPLAIN Output Format解释输出格式
8.8.3 Extended EXPLAIN Output Format扩展解释输出格式
8.8.4 Obtaining Execution Plan Information for a Named Connection获取命名连接的执行计划信息
8.8.5 Estimating Query Performance估计查询性能
8.9 Controlling the Query Optimizer控制查询优化器
8.9.1 Controlling Query Plan Evaluation控制查询计划评估
8.9.2 Switchable Optimizations可切换优化
8.9.3 Optimizer Hints优化器提示
8.9.4 Index Hints索引提示
8.9.5 The Optimizer Cost Model优化器成本模型
8.9.6 Optimizer Statistics优化器统计信息
8.10 Buffering and Caching缓冲和缓存
8.10.1 InnoDB Buffer Pool OptimizationInnoDB缓冲池优化
8.10.2 The MyISAM Key CacheMyISAM密钥缓存
8.10.3 Caching of Prepared Statements and Stored Programs预处理语句和存储程序的缓存
8.11 Optimizing Locking Operations优化锁定操作
8.11.1 Internal Locking Methods内部锁定方法
8.11.2 Table Locking Issues表锁定问题
8.11.3 Concurrent Inserts并发插入
8.11.4 Metadata Locking元数据锁定
8.11.5 External Locking外部锁定
8.12 Optimizing the MySQL Server优化MySQL服务器
8.12.1 Optimizing Disk I/O优化磁盘I/O
8.12.2 Using Symbolic Links使用符号链接
8.12.3 Optimizing Memory Use优化内存使用
8.13 Measuring Performance (Benchmarking)衡量绩效(基准)
8.13.1 Measuring the Speed of Expressions and Functions测量表达式和函数的速度
8.13.2 Using Your Own Benchmarks使用自己的基准
8.13.3 Measuring Performance with performance_schema用绩效模式衡量绩效
8.14 Examining Server Thread (Process) Information正在检查服务器线程(进程)信息
8.14.1 Accessing the Process List访问进程列表
8.14.2 Thread Command Values线程命令值
8.14.3 General Thread States常规线程状态
8.14.4 Replication Source Thread States复制源线程状态
8.14.5 Replication I/O Thread States复制I/O线程状态
8.14.6 Replication SQL Thread States复制SQL线程状态
8.14.7 Replication Connection Thread States复制连接线程状态
8.14.8 NDB Cluster Thread StatesNDB群集线程状态
8.14.9 Event Scheduler Thread States事件计划程序线程状态

This chapter explains how to optimize MySQL performance and provides examples. 本章介绍如何优化MySQL性能并提供示例。Optimization involves configuring, tuning, and measuring performance, at several levels. 优化包括在多个级别上配置、调优和度量性能。Depending on your job role (developer, DBA, or a combination of both), you might optimize at the level of individual SQL statements, entire applications, a single database server, or multiple networked database servers. 根据您的工作角色(开发人员、DBA或两者的组合),您可以在单个SQL语句、整个应用程序、单个数据库服务器或多个联网数据库服务器的级别上进行优化。Sometimes you can be proactive and plan in advance for performance, while other times you might troubleshoot a configuration or code issue after a problem occurs. 有时,您可以积极主动地提前计划性能,而有时,您可能会在出现问题后对配置或代码问题进行故障排除。Optimizing CPU and memory usage can also improve scalability, allowing the database to handle more load without slowing down.优化CPU和内存使用也可以提高可伸缩性,允许数据库在不降低速度的情况下处理更多负载。

8.1 Optimization Overview
8.2 Optimizing SQL Statements
8.3 Optimization and Indexes
8.4 Optimizing Database Structure
8.5 Optimizing for InnoDB Tables
8.6 Optimizing for MyISAM Tables
8.7 Optimizing for MEMORY Tables
8.8 Understanding the Query Execution Plan
8.9 Controlling the Query Optimizer
8.10 Buffering and Caching
8.11 Optimizing Locking Operations
8.12 Optimizing the MySQL Server
8.13 Measuring Performance (Benchmarking)
8.14 Examining Server Thread (Process) Information