当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
2021年软件测试面试题大全
CAN光端机解决泰和安TX3016C消防主机长距离联网问题 实现CAN与光纤之间的双向数据智能转换
其他重要协议(DNS,ICMP,NAT,交换机)
12个MySQL慢查询的原因分析
HSCTF2022-re题解
UE4 蓝图实现AI随机移动
力扣练习——33 原子的数量
pg数据库报错问题,有懂的吗
通关剑指 Offer——剑指 Offer II 008. 和大于等于 target 的最短子数组
MySQL安装教程
Luogu P2437 Bee Route
The practice of alibaba, data synchronization component canal
P1012 [NOIP1998 Improve Group] Spelling
ORA-04044:此处不允许过程、函数、程序包或类型,系统分析与解决
递归实现指数型枚举(DAY 91)
使用pycharm debug 深度学习代码
从DES走到AES(现代密码的传奇之路)
Learn about the sequential storage structure of binary tree - heap
递归实现排列型枚举(DAY 93)
MES系统物料管理的五大功能,建议收藏