Home / Companies / PlanetScale / Blog / Post Details
Content Deep Dive

Why isn’t MySQL using my index?

Blog post from PlanetScale

Post Details
Company
Date Published
Author
Aaron Francis
Word Count
3,042
Language
English
Hacker News Points
11
Summary

MySQL does not use an index until it has determined that it can be used and the optimizer has chosen it as the best option. This process involves considering all possible indexes for a query, calculating selectivity and cardinality to determine which index is most useful, and then choosing between multiple viable options based on these factors. Indexes are only considered if they are relevant to the query, such as when searching for strings that start with a particular substring or when joining two tables. However, there are certain scenarios in which an index cannot be used, including wildcard searches, composite indexes, joining on mismatched columns, and obfuscation of indexed columns. In these cases, MySQL may use alternative methods to access the data, such as scanning the table directly or using a range scan on the index. To ensure optimal performance, it's essential to understand how MySQL uses indexes and to carefully plan and maintain your database schema.