当前位置:网站首页>MYSQLg advanced ------ return table
MYSQLg advanced ------ return table
2022-08-11 03:37:00 【If you never betray, dependent life and death I will】
You need to check the return form before 先对 聚簇索引和非聚簇索引 innoDB和MyISAM有一定的了解; Interested in seeing it for yourself :地址
一、什么是回表?
这先要从InnoDB的索引实现说起,InnoDB有两大类索引:
聚集索引(clustered index)
普通索引(secondary index)
The primary key index contains all the data for that row,A normal index contains only the index sumid
Actually a non-clustered index The process is the so-called back table;
通俗的来讲就是:如果select There are non-indexed columns in the required columns,A single index query cannot obtain all the information,You need to find the corresponding column in the tableID; 在根据ID去去查询
Corresponds to the data of the specific column in the table,这个过程就是回表;The information of all columns can be obtained according to one index query,就不需要回表;(也就是聚集索引)
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) DEFAULT NULL,
`deptId` int(11) DEFAULT NULL,
PRIMARY KEY (`id`) ,
KEY `fk_dept_id`(`deptId`)
)ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8;
INSERT INTO `atguigudb`.`user` (`id`, `name`, `deptId`) VALUES (1, '小闫', 10);
INSERT INTO `atguigudb`.`user` (`id`, `name`, `deptId`) VALUES (2, '老闫', 10);
INSERT INTO `atguigudb`.`user` (`id`, `name`, `deptId`) VALUES (3, '小闫01', 10);
INSERT INTO `atguigudb`.`user` (`id`, `name`, `deptId`) VALUES (4, '小闫02', 10);
INSERT INTO `atguigudb`.`user` (`id`, `name`, `deptId`) VALUES (5, '小闫03', 10);
Execute the following without returning to the table,Because of the query method based on the primary key,只需要查询ID这颗B+树即可;The primary key is unique according to this unique index,MYSQLYou can be sure to search for this record;
id为主键索引,主键索引就是聚集索引
The leaf nodes of a clustered index contain records for entire rows,Get all the information in one query,Therefore, no return form is required
# 直接访问id 找到对应的值
select id,name,deptId FROM USER WHERE name='3';
下面这个sqlIt just needs to be returned:因为name 是普通的索引,the way of his query,需要先查询name的索引树,然后得到id的主键为3,再到idThe index tree performs a query.即先定位主键值,Relocation record,Although the index is used in this process,But in fact, the bottom layer performs two index queries,This process is the return form;
#非聚簇索引 find by valueid 根据id找到对应的值
select id,name,deptId FROM USER WHERE name="小闫01";
select id,name,deptId FROM USER WHERE name='3';

详细的 请查看 博客
Hope it can help you understand better;不足之处,请大家批评指正;
边栏推荐
- C语言 recv()函数、recvfrom()函数、recvmsg()函数
- 学编程的第十三天
- Leetcode 450. 删除二叉搜索树中的节点
- 电商项目——商城限时秒杀功能系统
- QueryDet: Cascading Sparse Query Accelerates Small Object Detection at High Resolution
- The thirteenth day of learning programming
- 【FPGA】day20-I2C读写EEPROM
- typedef定义结构体数组类型
- Interchangeable Measurement Techniques - Geometric Errors
- 【愚公系列】2022年08月 Go教学课程 035-接口和继承和转换与空接口
猜你喜欢

【FPGA】设计思路——I2C协议

Redis老了吗?Redis与Dragonfly性能比较

【愚公系列】2022年08月 Go教学课程 035-接口和继承和转换与空接口
![[yu gong series] Go program 035-08 2022 interfaces and inheritance and transformation and empty interface](/img/cb/41e5f553b0b776dccf0e39f9bf377f.png)
[yu gong series] Go program 035-08 2022 interfaces and inheritance and transformation and empty interface

I didn't expect MySQL to ask these...

互换性测量与技术——偏差与公差的计算,公差图的绘制,配合与公差等级的选择方法

CTO说MySQL单表行数不要超过2000w,为啥?

多商户商城系统功能拆解26讲-平台端分销设置

Interchangeability and Measurement Technology—Surface Roughness Selection and Marking Method

C语言之自定义类型------结构体
随机推荐
How can users overcome emotional issues in programmatic trading?
DNS separation resolution and intelligent resolution
C language recv() function, recvfrom() function, recvmsg() function
[yu gong series] Go program 035-08 2022 interfaces and inheritance and transformation and empty interface
typedef定义结构体数组类型
Interchangeability Measurements and Techniques - Calculation of Deviations and Tolerances, Drawing of Tolerance Charts, Selection of Fits and Tolerance Classes
What problems should we pay attention to when building a programmatic trading system?
按摩椅控制板的开发让按摩椅变得简约智能
【FPGA】day19-二进制转换为十进制(BCD码)
uni-app - 获取汉字拼音首字母(根据中文获取拼音首字母)
Graphical LeetCode - 640. Solving Equations (Difficulty: Moderate)
rac备库双节点查询到的表最后更新时间不一致
没想到MySQL还会问这些...
我的 archinstall 使用手册
App Basic Framework Construction丨Log Management - KLog
【FPGA】day20-I2C读写EEPROM
uni-app - 城市选择索引列表 / 通过 A-Z 排序的城市列表(uview 组件库 IndexList 索引列表)
你不知道的 console.log 替代品
学编程的第十三天
Differences and connections between distributed and clustered