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

Question about custom attributes of html tags

In previous development, we used the default attr...

Markup language - CSS layout

Click here to return to the 123WORDPRESS.COM HTML ...

MySQL query_cache_type parameter and usage details

The purpose of setting up MySQL query cache is: C...

Tomcat uses Log4j to output catalina.out log

Tomcat's default log uses java.util.logging, ...

MySQL 5.7.17 installation graphic tutorial (windows)

I recently started learning database, and I feel ...

CSS3 to achieve floating cloud animation

Operation effect html <head> <meta chars...

Install two MySQL5.6.35 databases under win10

Record the installation of two MySQL5.6.35 databa...

Using CSS to implement image frame animation and curve motion

The basic principle of all animations is to displ...

Steps and pitfalls of upgrading linux mysql5.5 to mysql5.7

Table of contents Linux MySQL 5.5 upgraded to MyS...

Docker installs ClickHouse and initializes data testing

Clickhouse Introduction ClickHouse is a column-or...