After connection management, the next component involved is the query cache. This stores the result sets of read (SELECT) statements that have executed in the recent past. Before further processing, if there is a cache hit, results are returned from the cache itself.
MySQL parses queries to create an internal structure called the parse tree, and then performs query planning and optimization on it. These include rewrites, choosing indexes, choosing the order in which it will read tables, and so on. A pass hints to the optimizer through special keywords in the query.
The optimizer component is also responsible for the EXPLAIN feature, which helps developers in figuring out how a query is performing. Using EXPLAIN is as simple ...