MySQL uses a cost-based optimizer to determine the best way to execute a query. It usually does a great job, but not all the time. There are different reasons for that. In some cases, it might not have enough information about the data and plan queries in a non-optimal way.
The optimizer makes decisions based on statistics and some fixed costs per operation, but it does not understand the differences in hardware. For instance, disk access may have different costs depending on the type of storage used - SSD drives will have quicker access times than spindles, and can perform more operations in a given time.
However, it is possible to impact how a query will be executed, and this is the topic of today’s blog.
(Note that in MySQL 5.7, a lot of work has been done in order to improve this - users can modify the cost of different types of operations.)
This is the fourteenth installment in the …
[Read more]