Reading rows using a range scan on a secondary index can result in many random disk accesses to the base table when the table is large and not stored in the storage engine's cache. With the Disk-Sweep Multi-Range Read (MRR) optimization, MySQL tries to reduce the number of random disk access for range scans by first scanning the index only and collecting the keys for the relevant rows. Then the keys are sorted and finally the rows are retrieved from the base table using the order of the primary key. The motivation for Disk-sweep MRR is to reduce the number of random disk accesses and instead achieve a more sequential scan of the base table data.
首先对二级索引进行范围扫描，对于符合条件的 key, 按照主键进行排序，然后一起根据key来读取基表。
The Multi-Range Read optimization provides these benefits:
MRR enables data rows to be accessed sequentially rather than in random order, based on index tuples. The server obtains a set of index tuples that satisfy the query conditions, sorts them according to data row ID order, and uses the sorted tuples to retrieve data rows in order. This makes data access more efficient and less expensive.
MRR enables batch processing of requests for key access for operations that require access to data rows through index tuples, such as range index scans and equi-joins that use an index for the join attribute. MRR iterates over a sequence of index ranges to obtain qualifying index tuples. As these results accumulate, they are used to access the corresponding data rows. It is not necessary to acquire all index tuples before starting to read data rows.
MRR的主要优势：将随机IO转换成顺序IO；使用在 索引范围扫描 和 使用索引进行join 时；
The following scenarios illustrate when MRR optimization can be advantageous:
Scenario A: MRR can be used for
MyISAM tables for index range scans and equi-join operations.
A portion of the index tuples are accumulated in a buffer.
The tuples in the buffer are sorted by their data row ID.
Data rows are accessed according to the sorted index tuple sequence.
When MRR is used, the
Extra column in
EXPLAIN output shows
Example query for which MRR can be used, assuming that there is an index on
SELECT * FROM t WHERE key_part1 >= 1000 AND key_part1 < 2000 AND key_part2 = 10000;
MySQL的MRR一次扫描多少个二级索引，然后进行回表，其使用到的内存是参考 read_rnd_buffer_size 的值来决定的。
MRR 仅仅针对 二级索引 的范围扫描 和 使用二级索引进行 join 的情况。
MRR 的优势是将多个随机IO转换成较少数量的顺序IO。所以对于 SSD 来说价值还是有的，但是相比机械磁盘来说意义小一些。