Query Optimization and Performance Tuning

Query optimization and performance tuning is the practice of making MySQL answer the same question with less work: fewer rows examined, less disk I/O, less memory churn, and less time spent waiting on locks. It spans reading execution plans, designing indexes that the optimizer actually chooses, rewriting queries into forms the optimizer can reason about, tuning join strategy, sizing InnoDB's caches, and configuring server variables to match the workload. This chapter is new reference material (not part of the original book) written for MySQL 8.4 LTS and MySQL 9.x.

This chapter is organized into the following topics:


Read this chapter after Query Optimizer and Indexes in earlier chapters – those cover what the optimizer is and how indexes are declared; this chapter covers how to diagnose and fix a slow query in a running system.