当前位置:网站首页>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;不足之处,请大家批评指正;
边栏推荐
- Kubernetes集群搭建Zabbix监控平台
- 【FPGA】day22-SPI协议回环
- DNS separation resolution and intelligent resolution
- UNI-APP_iphone bottom safe area
- AI+医疗:使用神经网络进行医学影像识别分析
- C language recv() function, recvfrom() function, recvmsg() function
- What problems should we pay attention to when building a programmatic trading system?
- 多商户商城系统功能拆解26讲-平台端分销设置
- Leetcode 669. 修剪二叉搜索树
- 【FPGA】设计思路——I2C协议
猜你喜欢
一次简单的 JVM 调优,学会拿去写到简历里
Power Cabinet Data Monitoring RTU
Design and Realization of Employment Management System in Colleges and Universities
The last update time of the tables queried by the two nodes of the rac standby database is inconsistent
【FPGA】设计思路——I2C协议
Interchangeability and Measurement Techniques - Tolerance Principles and Selection Methods
The development of the massage chair control panel makes the massage chair simple and intelligent
按摩椅控制板的开发让按摩椅变得简约智能
Detailed explanation of VIT source code
console.log alternatives you didn't know about
随机推荐
DNS separation resolution and intelligent resolution
分布式和集群的区别和联系
Interchangeable Measurement Techniques - Geometric Errors
What should I do if the channel ServerID is incorrect when EasyCVR is connected to a Hikvision Dahua device and selects another cluster server?
FTP错误代码列表
【FPGA】day21-移动平均滤波器
E-commerce project - mall time-limited seckill function system
常用认证机制
Traversal of DOM tree-----modify styles, select elements, create and delete nodes
电商项目——商城限时秒杀功能系统
Homework 8.10 TFTP protocol download function
[ADI low-power 2k code] Based on ADuCM4050, ADXL363, TMP75 acceleration, temperature detection and serial port printing, buzzer playing music (lone warrior)
Getting Started with Raspberry Pi (5) System Backup
[BX]和loop
基于改进YOLOv5轻量化的烟火检测
Kubernetes集群搭建Zabbix监控平台
互换性与测量技术-公差原则与选用方法
Detailed explanation of VIT source code
STC8H development (15): GPIO drive Ci24R1 wireless module
Is Redis old?Performance comparison between Redis and Dragonfly