当前位置:网站首页>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;不足之处,请大家批评指正;
边栏推荐
- The solution to the height collapse problem
- DNS分离解析和智能解析
- console.log alternatives you didn't know about
- Leetcode 450. 删除二叉搜索树中的节点
- "Life Is Like First Seen" is ill-fated, full of characters, and the contrast of Zhu Yawen's characters is too surprising
- 【FPGA】day18-ds18b20实现温度采集
- 2022-08-10 第六小组 瞒春 学习笔记
- En-us is an invalid culture error solution when Docker links sqlserver
- 【ADI低功耗2k代码】基于ADuCM4050的ADXL363、TMP75的加速度、温度检测及串口打印、蜂鸣器播放音乐(孤勇者)
- 2022-08-10 The sixth group Hiding spring study notes
猜你喜欢

What should I do if the channel ServerID is incorrect when EasyCVR is connected to a Hikvision Dahua device and selects another cluster server?

【FPGA】day21-移动平均滤波器

CTO said that the number of rows in a MySQL table should not exceed 2000w, why?

浮点数在内存中的存储方式

【FPGA】day18-ds18b20实现温度采集

机器学习怎么学?机器学习流程

The development of the massage chair control panel makes the massage chair simple and intelligent

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

"Life Is Like First Seen" is ill-fated, full of characters, and the contrast of Zhu Yawen's characters is too surprising

分布式和集群的区别和联系
随机推荐
【C语言】入门
程序化交易与主观交易对盈利曲线的影响!
The problem that Merge will be lost again after code Revert has been solved
多串口RS485工业网关BL110
What kind of programming trading strategy types can be divided into?
The "top pillar" slides, and new growth is extremely difficult to shoulder the heavy responsibility. Is Ali "squatting" to jump higher?
Redis老了吗?Redis与Dragonfly性能比较
【FPGA】day21-移动平均滤波器
【Yugong Series】August 2022 Go Teaching Course 036-Type Assertion
按摩椅控制板的开发让按摩椅变得简约智能
What problems should we pay attention to when building a programmatic trading system?
Briefly, talk about the use of @Transactional in the project
pathman_config、pathman_config_params 删除后,如何重建?
I didn't expect MySQL to ask these...
Detailed explanation of VIT source code
【FPGA】day19-二进制转换为十进制(BCD码)
用户如何克服程序化交易中的情绪问题?
Paper Accuracy - 2017 CVPR "High-Resolution Image Inpainting using Multi-Scale Neural Patch Synthesis"
字体反扒
Summary of debugging skills