Clustered and Secondary Indexes
Clustered and Secondary Indexes
secondary index
A type of InnoDB index that represents a subset of table columns. An InnoDB table can have zero, one, or many
secondary indexes. (Contrast with the clustered index, which is required for each InnoDB table, and stores the data for
all the table columns.)
Every InnoDB
table has a special index called the clustered index where the data for the rows is stored. Typically, the
clustered index is synonymous with the primary key. To get the best performance from queries, inserts, and other database
operations, you must understand how InnoDB uses the clustered index to optimize the most common lookup and DML
operations for each table.
When you define a
PRIMARY KEY
on your table,InnoDB
uses it as the clustered index. Define a primary key for each table
that you create. If there is no logical unique and non-null column or set of columns, add a new auto-increment column, whose
values are filled in automatically.
If you do not define a
PRIMARY KEY
for your table, MySQL locates the firstUNIQUE
index where all the key columns are
NOT NULL
and InnoDB
uses it as the clustered index.
If the table has no
PRIMARY KEY
or suitableUNIQUE
index,InnoDB
internally generates a hidden clustered index on a synthetic
column containing row ID values. The rows are ordered by the ID that InnoDB
assigns to the rows in such a table. The row ID is
a 6-byte field that increases monotonically as new rows are inserted. Thus, the rows ordered by the row ID are physically in
insertion order.
How the Clustered Index Speeds Up Queries
Accessing a row through the clustered index is fast because the index search leads directly to the page with all the row data.
If a table is large, the clustered index architecture often saves a disk I/O operation when compared to storage organizations
that store row data using a different page from the index record. (For example, MyISAM
uses one file for data rows and another
for index records.)
How Secondary Indexes Relate to the Clustered Index
All indexes other than the clustered index are known as secondary indexes. In InnoDB
, each record in a secondary index
contains the primary key columns for the row, as well as the columns specified for the secondary index. InnoDB
uses this primary
key value to search for the row in the clustered index.
If the primary key is long, the secondary indexes use more space, so it is advantageous to have a short primary key.
Clustered and Secondary Indexes的更多相关文章
- 14.8.9 Clustered and Secondary Indexes
14.8.9 Clustered and Secondary Indexes 每个InnoDB 表有一个特殊的索引称为 clustered index 用于存储数据. 通常, clustered in ...
- 14.2.5.2 Clustered and Secondary Indexes
14.2.5.2 Clustered and Secondary Indexes : 每个InnoDB 表 有一个特别的索引称为clustered index 行数据存储的地方. 典型的,cluste ...
- 在InnoDB,记录在 non-clustered indexes(也被称为secondary indexes) 包含了主键值
In InnoDB, the records in non-clustered indexes (also called secondary indexes) contain the primary ...
- Clustered和Nonclustered Indexes 各自得特点和区别及长短处
1 簇索引 簇索引对表的物理数据页中的数据按列进行排序然后再重新存储到磁盘上即簇索 引与数据是混为一体的它的叶节点中存储的是实际的数据由于簇索引对表中的数据一 一进行了排序因此用簇索引查找数据很快但由 ...
- InnoDB On-Disk Structures(二)--Indexes (转载)
转载.节选于 https://dev.mysql.com/doc/refman/8.0/en/innodb-indexes.html This section covers topics relate ...
- Mysql加锁过程详解
1.背景 MySQL/InnoDB的加锁分析,一直是一个比较困难的话题.我在工作过程中,经常会有同事咨询这方面的问题.同时,微博上也经常会收到MySQL锁相关的私信,让我帮助解决一些死锁的问题.本文, ...
- mysql事务和锁InnoDB
背景 MySQL/InnoDB的加锁分析,一直是一个比较困难的话题.我在工作过程中,经常会有同事咨询这方面的问题.同时,微博上也经常会收到MySQL锁相关的私信,让我帮助解决一些死锁的问题.本文,准备 ...
- [MySQL FAQ]系列 — 为什么InnoDB表要建议用自增列做主键
我们先了解下InnoDB引擎表的一些关键特征: InnoDB引擎表是基于B+树的索引组织表(IOT): 每个表都需要有一个聚集索引(clustered index): 所有的行记录都存储在B+树的叶子 ...
- MySQL 加锁处理分析
1 背景 1 1.1 MVCC:Snapshot Read vs Current Read 2 1.2 Cluster Index:聚簇索引 3 1.3 2P ...
随机推荐
- 打开eclipse中文件所在文件夹
在myeclipse中选中文件后能够打开文件所在文件夹,可是eclipse中没有直接打开文件路径的功能.须要我们自己加入. 选择:Run -> External Tools -> Exte ...
- JavaScript的特殊函数
1.匿名函数 onclick=function(){}就是匿名函数. 2.匿名函数的回调函数 <script> <span style="white-space:pre&q ...
- 深入PHP中慎用双等于(==)的详解
PHP比较运算符出现的频率实在是太高了,尤其是 ==if(a == b){// do something}但是,你真的掌握了 == 了吗?细节很重要!来看下面的代码,说出你认为正确的答案var_dum ...
- Java并发编程(十二)线程安全性的委托
在组合对象中如果每个组件都已经是线程安全的,是否需要再加一个额外的"线程安全层",需要视情况而定. final可以修饰未复制的属性,只要在静态代码块或者构造函数中赋值了即可. 独立 ...
- iOS图片加水印效果的实现并保存至相冊
图片加水印效果的实现并保存至相冊 实现效果如图: project下载:githubproject下载链接 代码: - (void)viewDidLoad { [super viewDidLoad]; ...
- Erlang 和 Elixir 互相调用 (转)
lixr设计目标之一就是要确保兼容性,可以兼容Erlang和其生态系统.Elixir和Erlang 都是运行同样的虚拟机平台(Erlang Virtual Machine).不管是在Erlang使用E ...
- spring入门之JdbcTemplate 操作crud
Spring 通过调用 JdbcTemplate来实现对数据库的增删改查,主要用到JdbcTemplate类的4个方法,首先,配置数据库信息,创建对象,代码通用: //设置数据库信息 DriverMa ...
- makefile编写---:= ?= += =的区别
在Makefile中我们经常看到 = := ?= +=这几个赋值运算符,那么他们有什么区别呢?我们来做个简单的实验 新建一个Makefile,内容为:ifdef DEFINE_VRE VRE = ...
- makefile编写---单个子目录编译模板
经过这次地库项目之后,虽然时间不久,跟团队在一起,虽然队员不一定在技术上有过人之处,但是来自大公司的员工,在工具使用和代码规范方面还是有点可鉴之处,在搭建主控模块是,就得面临makefile编写,因为 ...
- phpstorm将多个int数字拼接成字符串
场景:将程序输出的多个int数字拼成以','分隔的字符串 数据为 8680 24399 37619 45425 49635 139334 386918 429498 461616 523384 561 ...