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 ...
随机推荐
- event.returnvalue = false的使用
event.returnvalue false代表不接收事件返回值 <script language="JavaScript"> //Ctrl+s保存 document ...
- pandas时间序列滑窗
时间序列数据统计-滑动窗口 窗口函数 import pandas as pd import numpy as np ser_obj = pd.Series(np.random.randn(1000), ...
- MySQL学习总结(四)数据的基本操作以及MySQL运算符和常用函数
数据库是存储数据库对象的仓库,数据库的基本对象是表,表用来存储数据.关于数据的操作也就是我们常说的CRUD,C指的是CREATE(插入数据记录).R指的是READ(查询数据记录).U指的是UPDATE ...
- tcp/ip ---IP路由选择
从概念上说, I P路由选择是简单的,特别对于主机来说.如果目的主机与源主机直接相连(如点对点链路)或都在一个共享网络上(以太网或令牌环网),那么I P数据报就直接送到目的主机上.否则,主机把数据报发 ...
- 推荐系统学习03-SVDFeature
介绍 SVDFeature是由Apex Data & Knowledge Management Lab在KDD CUP11竞赛中开发出来的工具包.它的目的是有效地解决基于特征的矩阵分解.新的模 ...
- ScrollView嵌套ListView冲突问题的最优解决方式
项目做多了之后.会发现事实上ScrollView嵌套ListVew或者GridView等非经常常使用,可是你也会发现各种奇怪问题产生.依据个人经验如今列出常见问题以及代码最少最简单的解决方法. 问题一 ...
- 【算法拾遗(java描写叙述)】--- 插入排序(直接插入排序、希尔排序)
插入排序基本思想 每次将一个待排序的记录按其keyword大小插入到前面已经拍好序的子文件的适当位置,直到全部记录插入完毕为止. 直接插入排序 基本思想 直接插入排序的基本操作是将一个记录插入到已排好 ...
- 小程序图表功能wxchart实现
在开发小程序过程中,有项目用到图表功能, 其实Echart.js有小程序的库,我们要吧引入进来,然后配置初始化一下,就可以达到目的了.接下来就开始步骤吧 首先下载JS库:http://download ...
- cmpp 短信平台
背景: 物联网一般是在设备上安装sim卡,通过2g网络来进行设备与云端系统的交互,网络都是通过移动的基站来进行网络传输的,所以一旦移动的基站有变动,比如流量降级,光缆割接,其他故障登 都会导致2g络的 ...
- Java时间类总结
java.util.Date 包含有年月日时分秒,精确到毫秒级别. 官方解释: // The class Date represents a specific instant in time, wit ...