I find a good interview question for a MySQL DBA position is to
ask what the following commands actually do in InnoDB, which has
been the default storage engine since MySQL 5.5. From my
perspective there is a lot of miss-understanding what still
applies.
ANALYZE TABLE
From the MySQL manual:
ANALYZE TABLE analyzes and stores the key distribution for a
table. During the analysis, the table is locked with a read lock
for InnoDB and MyISAM.
What this means is, as part of query optimization MySQL will
often have to decide which is the best index if there are
multiple candidates, which indexes should be avoided, and what
order should tables be joined in. Indexes need to eliminate work
- so if for example you were trying to index a column called
“Country” in a table full of all people in the USA, then it would
be faster to …
[Read more]