Testing indexes
How to test indexes in MySQL without permanently applying them.
Profiling
Temporary indexes
The following snippet shows how to temporarily create an index, in order to evaluate its effect on execution plans.
Avoiding caching
MySQL has multiple levels of caching: first, query results themselves can be cached; second, recently loaded tables might be kept in memory. For accurate benchmark times, you want to avoid caching, and you want to flush tables from memory.
Tricks
If all columns in the select list are in an index (order-independent), the optimizer will be able to retrieve values from the index itself rather than the actual row, avoiding the overhead of loading the row into memory. This can help for very wide tables.
Notes
Replicas can have different indexes than primary (source). Though ideally you shouldn't need to run this on a production replica at all.
Last updated