当前位置:网站首页>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';当执行这两条时也可以看出,下面的语句会因为无法全部通过索引查到,所以会进行回表查询操作。获取数据。
如有错误欢迎指正
边栏推荐
- Acl2022 | bert2bert: an efficient pre training method of parameter reuse, which significantly reduces the training cost of oversized models
- SoC development environment and hardware development preparation
- php伪协议实现命令执行详情
- 自媒体视频创作如何选择领域?
- Introduction to database system -- Chapter 1 -- Introduction (important knowledge points)
- 一次SQL查询优化原理分析(900W+数据从17s到300ms)
- Redis cache avalanche
- 用少儿编程思维塑造青少年领悟能力
- C language -- 10 first knowledge of structure
- ThinkPHP v6.0.x反序列化漏洞复现
猜你喜欢

Detailed explanation of Lora module wireless transceiver communication technology

解读创客空间下的教育新生态

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

【MySQL】表结构的增删查改操作(DDL)

SQL第四练:字符串处理函数

Abbexa low sample size chicken lysozyme C (Lyz) ELISA Kit

What should be paid attention to when designing Multilayer PCB?

Course design of imitation pottery ticket of wechat applet

Understanding of related concepts of target detection

【MySQL】常见数据类型总结
随机推荐
自制Table錶格
Codeforces Round #798 (Div. 2)
Naturalspeech model synthetic speech achieves human speech level for the first time in CMOS test
Leetcode advanced road - 167 Sum of two numbers II - input ordered array
Abbexa cell free DNA kit instructions
Record today's MySQL failures
NFT版权/版税
SQL Server2019安装的详细步骤实战记录(亲测可用)
Redis cache breakdown
系统重装以及查询系统性能
In 2021, the average salary will be released, and the IT industry will not be surprised
初中毕业生,选择中职学校也可以升入高等学府
Abbexa 8-OHdG CLIA kit solution
As a programmer, is it really that important for the underlying principles?
Abbexa acrylamide peg NHS instructions
2022-06-09 rk817 PMU battery temperature detection
标配双安全气囊,价格屠夫长安Lumin 4.89万起售
C language -- 1 c language cognition
详解MATLAB中与矩阵运算有关的算术运算符(加、减、乘、除、点乘、点除、乘方)
【MySQL】表的约束