The main tool for tuning MySQL queries is the EXPLAIN statement (https://dev.mysql.com/doc/refman/8.0/en/explain.html) and one of the hurdles on the learning curve of the EXPLAIN statement is explaining what EXPLAIN is explaining. Basically EXPLAIN is prepended to a SELECT, TABLE, DELETE, UPDATE, INSERT or REPLACE statement. To add to an already steep learning curve is that there are many types of EXPLAIN in MySQL.
Let Me Explain
It is very simple to add EXPLAIN at the very beginning of a query to see how the server wants to execute a query.
EXPLAIN SELECT col1, col2 FROM my_table;
The output will show the query plan (the actual query the optimizer will instruct the MySQL server to run) and some preliminary information about how the query plan was picked among the many possible options. Learning to use EXPLAIN to tune queries is a long process and beyond the …
[Read more]