MySQL InnoDB MRR Optimization Guide

MySQL InnoDB MRR Optimization Guide

Preface

MRR is the abbreviation of Multi-Range Read, which aims to reduce random disk access and convert random access into more sequential access. Applicable to range/ref/eq_ref type queries.

Implementation principle:

1. After searching the secondary index, find the required data based on the obtained primary key in the clustered index.

2. The order of the primary keys obtained by secondary index search is uncertain, because the order of the secondary index is not necessarily consistent with the order of the clustered index;

3. If there is no MRR, data pages may be read out of order during clustered index lookup, which is extremely unfriendly to mechanical hard drives.

4. MRR optimization methods:

  • Put the found secondary index key value in a cache;
  • Sort the key values ​​in the cache by primary key;
  • The actual data file is accessed based on the sorted primary key declustered index.

5. When the optimizer uses MRR, “Using MRR” will appear in the Extra column of the execution plan.

6. If the order of the secondary index used in the query is consistent with the order of the result set, then the result set needs to be sorted after using MRR.

Using MRR can also reduce the number of times pages in the buffer pool are replaced and batch process key value query operations.

You can use the command select @@optimizer_switch; to check whether MRR is enabled:

index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,engine_condition_pushdown=on,index_condition_pushdown=on,mrr=off,mrr_cost_based=on,block_nested_loop=on,batched_key_access=off,materialization=on,semijoin=on,loosescan=on,firstmatch=on,duplicateweedout=on,subquery_materialization_cost_based=on,use_index_extensions=on,condition_fanout_filter=on,derived_merge=on,use_invisible_indexes=off,skip_scan=on

mrr_cost_based=on indicates whether to use MRR in a cost based manner.

Use set @@optimizer_switch='mrr=on/off'; command to turn MRR on or off.

select @@read_rnd_buffer_size ; The parameter is used to control the buffer size of the key value. The default value is 256K. When it is larger than the parameter value, the executor sorts the cached data according to the primary key, and then obtains the row data through the primary key.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM.

You may also be interested in:
  • MySQL learning summary: a preliminary understanding of the architectural design of the InnoDB storage engine
  • MySQL InnoDB row_id boundary overflow verification method steps
  • How to ensure transaction characteristics of MySQL InnoDB?
  • MySQL startup error InnoDB: Unable to lock/ibdata1 error
  • In-depth explanation of the locking mechanism in MySQL InnoDB
  • Detailed explanation of how MySQL (InnoDB) handles deadlocks
  • MySQL Learning (VII): Detailed Explanation of the Implementation Principle of Innodb Storage Engine Index
  • MySQL slow_log table cannot be modified to innodb engine detailed explanation
  • Explanation of the configuration and use of MySQL storage engine InnoDB
  • Detailed explanation of MySQL Innodb storage structure and storage of Null values

<<:  Detailed explanation of React event binding

>>:  Centos7 Zabbix3.4 email alarm configuration (solving the problem that the email content is xx.bin attachment)

Recommend

Priority analysis of and or queries in MySQL

This may be an issue that is easily overlooked. F...

Getting Started Guide to MySQL Sharding

Preface Relational databases are more likely to b...

JavaScript implementation of the back to top button example

This article shares the specific code for JavaScr...

Some parameter descriptions of text input boxes in web design

In general guestbooks, forums and other places, t...

Analysis of the use of the MySQL database show processlist command

In actual project development, if we have a lot o...

MySQL 8.0.23 Major Updates (New Features)

Author: Guan Changlong is a DBA in the Delivery S...

3D tunnel effect implemented by CSS3

The effect achievedImplementation Code html <d...

Use of MySQL DATE_FORMAT function

Suppose Taobao encourages people to shop during D...

MySQL uses custom functions to recursively query parent ID or child ID

background: In MySQL, if there is a limited level...

Example of implementing dynamic verification code on a page using JavaScript

introduction: Nowadays, many dynamic verification...

Detailed explanation of chmod command usage in Linux

chmod Command Syntax This is the correct syntax w...