When you submit a query to MySQL for execution, it is not as simple as just reading the data and returning it. True, for simple queries requesting all data from a single table, there are not many options how to retrieve the data. However, most queries are more complex – some much more complex – and executing the query exactly as it is written is by no means given to be the most efficient way to get to the result. You already touched on some of this complexity when reading about indexes. You can add to the choice of index, the join order, the algorithm used to execute the joins, various join optimizations, and more. That is where the optimizer comes into play.
Vladimir ZadorozhnyLaura F. BrightLouiqa RaschidTolga UrhanMaría-Esther Vidal
Jack ChenSamir JindelRobert WalzerRajkumar SenNika JimsheleishvilliMichael M. Andrews