当前位置:网站首页>Mysql return table
Mysql return table
2022-08-02 06:05:00 【Born in a good autumn】
Return form
Mysql return table refers to the index column queried by the secondary index under the InnoDB storage engine. If you need to find the data of all columns, you need to retrieve the data from the primary key index.This process is called backlisting.Because the data of the row is stored in the leaf nodes of the primary key B+tree, the B+ tree leaf nodes of the secondary index are stored (index columns, primary keys).
Example:
There is a user table id (primary key), username (secondary index), age
id is the primary key index username is the secondary index, when we return records through the secondary index query, for example:
select * from t where username = “bobo”;
① Find the bobo record and primary key id through the secondary index
2 Find the row record by going to the primary key index B+tree through the primary key id
There will be a problem here. When our user table has 150w records, sometimes the query does not go through the index, but scans the entire disk through All.Why is this?Let's briefly introduce the IO of full scan and index walk.
If the size of our row of data is 100 bytes, bobo has 50W rows of data. Suppose the B+tree height of the user table=3
If indexed by username: 3 IOs are required for each return to the table, and 50w records need to be returned to the table 50w times.Then IO = 50W * 3
Through full scan: one page can store 16k / 100 bytes = 16 * 1024 / 100 = 163 records, full scan requires 150w / 163 = 0.92W, which is almost 1w IO,
Through the above comparison, it must be more efficient overall, which is why sometimes we build an index, but our sql does not go into the index when it is detected by explain.Because the IO overhead of returning the table is still relatively large.
MRR
MRR simply means that the above return table is more efficient. If you need to return the table 50w times, the efficiency is too slow. At this time, Mysql sorts the primary key id that needs to be returned to the table, and then sorts the id after that.Go to the primary key B+ tree to fetch the database, which greatly increases the efficiency.We can judge whether MRR is used by the Using MRR in the Extra column in explain.
Let me introduce myself first. The editor graduated from Shanghai Jiaotong University in 2013. I worked in a small company and went to big factories such as Huawei and OPPO. I joined Alibaba in 2018, until now.I know that most junior and intermediate java engineers want to upgrade their skills, they often need to explore their own growth or sign up to study, but for training institutions, the tuition fee is nearly 10,000 yuan, which is really stressful.Self-learning that is not systematic is very inefficient and lengthy, and it is easy to hit the ceiling and the technology stops.Therefore, I collected a "full set of learning materials for java development" for everyone. The original intention is also very simple. I hope to help friends who want to learn by themselves but don't know where to start, and at the same time reduce everyone's burden.Add the business card below to get a full set of learning materials
边栏推荐
猜你喜欢

Mysql子查询关键字的使用(exists)

Does Conway's Law Matter for System Architecture?

数据湖:流计算处理框架Flink概述

12个MySQL慢查询的原因分析

Towhee 每周模型

MySQL如何对SQL做prepare预处理(解决IN查询SQL预处理仅能查询出一条记录的问题)
选择黑盒测试用例设计方法的综合策略方案总结

学内核之五:问题一,关于上下文切换

Crawler_crawl wasde monthly supply and demand balance table (example)

MySql字符串拆分实现split功能(字段分割转列、转行)
随机推荐
【语义分割】FCN
数据湖:流计算处理框架Flink概述
acwing 最大数
【无标题】
【疑问】最终推荐的loose pattern 如果依赖module 没有加载完毕,行为如何,是否报错
力扣 2127. 参加会议的最多员工数 拓扑剪枝与2360补充
行测不会概念
棋盘问题(DAY 94)
合作的小伙伴,缺乏主人翁(owner)意识,好苦恼
P1012 [NOIP1998 Improve Group] Spelling
CodeTON Round 2 (Div. 1 + Div. 2, Rated, Prizes!)
MySQL 8.0.29 解压版安装教程(亲测有效)
vs2022 编译libmodbus源码
【云原生】什么是CI/CD? | CI/CD 带来的好处
选择黑盒测试用例设计方法的综合策略方案总结
07-传统的生产者消费者问题、防止虚假唤醒
MySQL安装常见报错处理大全
【QT】Qt Creator生成动态库(DLL)并调用
UE4 创建开始游戏界面UI
MySQL 的 limit 分页查询及性能问题