当前位置:网站首页>Mysql的回表查询?如何避免?
Mysql的回表查询?如何避免?
2022-06-10 20:50:00 【一只小小狗】
使用索引查询的不同情况(1. 聚合索引、2. 非聚合索引(2.1 非主键索引、2.2 除了非主键索引还包含非索引字段))
- 通过主键查询 : 当我们查询条件是通过主键查询的时候,因为主键是聚集索引,这时直接就在索引的叶子节点就可以拿到数据;
- 通过普通索引查询的时候,这里得分两种情况 :
- select * from table where 中 xx =‘’ 的字段刚好是索引字段的话,那么直接就可以在索引中找到对应的值,不需要"回表查询",直接返回结果。
- select * from table where xx = ‘’ 中xx字段包含除了普通索引以外的字段的话,那么就会通过该记录拿到叶子节点的主键信息,拿到主键信息后再去聚合索引中找到主键对应的行信息,这个过程就叫做回表查询。
什么是回表查询?
使用普通索引的情况下,并且包含了非索引字段的时候,会通过该普通索引获取到叶子节点的主键信息,拿到主键信息后再去聚合索引中找到对应的行信息,这个过程就叫做回表查询。

回表查询实战

explain select name from test;这里看到这里只是单纯的使用了index。
explain select name from test where name='name1';显示了执行顺序 显示通过where条件然后再使用index。explain select * from test where name='name1';当执行这两条时也可以看出,下面的语句会因为无法全部通过索引查到,所以会进行回表查询操作。获取数据。
如有错误欢迎指正
边栏推荐
- Leetcode advanced path - the first unique character in a string
- How to realize the marketing purpose of small program integral mall
- ThinkPHP v6.0.x反序列化漏洞复现
- MySQL insère les résultats de la requête dans une autre table
- H265 Nalu type judgment and SPS data analysis
- Leetcode advanced path - reverse string
- 设计多层PCB板需要注意哪些事项?
- 【MySQL】表结构的增删查改操作(DDL)
- H. Relationship among Nalu, RBSP and sodb in 264
- MySQL数据库如何查看表占用空间大小
猜你喜欢
PHP pseudo protocol implementation command execution details

Acl2022 | bert2bert: an efficient pre training method of parameter reuse, which significantly reduces the training cost of oversized models

Signal and system review 1

Constructing the implementation strategy of steam education for children

Naturalspeech model synthetic speech achieves human speech level for the first time in CMOS test

Practical | how to use burp suite for password blasting!
Super detailed tutorial for installing mysql8 in centos7 (no pit!)

设计多层PCB板需要注意哪些事项?

Junior high school graduates who choose secondary vocational schools can also be promoted to institutions of higher learning

【MySQL】表数据的增删查改(DML)
随机推荐
C language learning review -- 1 basic knowledge review
An analysis of SQL query optimization principle (900w+ data from 17s to 300ms)
Codeforces Round #798 (Div. 2)
How to view the occupied space of a table in MySQL database
01js basic null and undefined difference type conversion = = code block logical operator
Course design of imitation pottery ticket of wechat applet
旋转菜单3.0
[nk] 牛客月赛51 G计算题
Can I make up the exam if I fail the soft exam? Here comes the answer
Naturalspeech model synthetic speech achieves human speech level for the first time in CMOS test
Exec function of PHP
Self made table
【phpstorm】 No data sources are configured to run this SQL and provide advanced c
ThinkPHP v6.0.x反序列化漏洞复现
Leetcode advanced road - 167 Sum of two numbers II - input ordered array
Leetcode advanced path - reverse string
Cordova plugin /jpush phonegap Aurora push_ Local push_ Message push
Practical | how to use burp suite for password blasting!
2022-06-09 RK817 PMU 电池温度检测
JS anchor positioning can extend many functions