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 first UNIQUE 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 suitable UNIQUE 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的更多相关文章

  1. 14.8.9 Clustered and Secondary Indexes

    14.8.9 Clustered and Secondary Indexes 每个InnoDB 表有一个特殊的索引称为 clustered index 用于存储数据. 通常, clustered in ...

  2. 14.2.5.2 Clustered and Secondary Indexes

    14.2.5.2 Clustered and Secondary Indexes : 每个InnoDB 表 有一个特别的索引称为clustered index 行数据存储的地方. 典型的,cluste ...

  3. 在InnoDB,记录在 non-clustered indexes(也被称为secondary indexes) 包含了主键值

    In InnoDB, the records in non-clustered indexes (also called secondary indexes) contain the primary ...

  4. Clustered和Nonclustered Indexes 各自得特点和区别及长短处

    1 簇索引 簇索引对表的物理数据页中的数据按列进行排序然后再重新存储到磁盘上即簇索 引与数据是混为一体的它的叶节点中存储的是实际的数据由于簇索引对表中的数据一 一进行了排序因此用簇索引查找数据很快但由 ...

  5. InnoDB On-Disk Structures(二)--Indexes (转载)

    转载.节选于 https://dev.mysql.com/doc/refman/8.0/en/innodb-indexes.html This section covers topics relate ...

  6. Mysql加锁过程详解

    1.背景 MySQL/InnoDB的加锁分析,一直是一个比较困难的话题.我在工作过程中,经常会有同事咨询这方面的问题.同时,微博上也经常会收到MySQL锁相关的私信,让我帮助解决一些死锁的问题.本文, ...

  7. mysql事务和锁InnoDB

    背景 MySQL/InnoDB的加锁分析,一直是一个比较困难的话题.我在工作过程中,经常会有同事咨询这方面的问题.同时,微博上也经常会收到MySQL锁相关的私信,让我帮助解决一些死锁的问题.本文,准备 ...

  8. [MySQL FAQ]系列 — 为什么InnoDB表要建议用自增列做主键

    我们先了解下InnoDB引擎表的一些关键特征: InnoDB引擎表是基于B+树的索引组织表(IOT): 每个表都需要有一个聚集索引(clustered index): 所有的行记录都存储在B+树的叶子 ...

  9. MySQL 加锁处理分析

    1    背景    1 1.1    MVCC:Snapshot Read vs Current Read    2 1.2    Cluster Index:聚簇索引    3 1.3    2P ...

随机推荐

  1. 【CODEFORCES】 C. Captain Marmot

    C. Captain Marmot time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  2. go项目布局(摘录)

    go的项目结构布局 或 包结构布局 这一块大家似乎还在摸索吧, 常用的应该还是类似于java的mvc布局, 但网上也有不同的布局方式,查阅github上的一些源码,也有大量的采用. 我把自己碰到的资料 ...

  3. android动画具体解释二 属性动画原理

    property动画是一个强大的框架,它差点儿能使你动画不论什么东西. 你能够定义一个动画来改变对象的不论什么属性,不论其是否被绘制于屏幕之上. 一个属性动画在一定时间内多次改变一个属性(对象的一个字 ...

  4. memcached 命令行举例

    1.启动Memcache  常用参数
memcached 1.4.3 
 -p <num> 设置端口号(默认不设置为: 11211) 
 -U <num> UDP监听端口 (默 ...

  5. java中的参数传递——值传递、引用传递

    参数是按值而不是按引用传递的说明 Java 应用程序有且仅有的一种参数传递机制,即按值传递. 在 Java 应用程序中永远不会传递对象,而只传递对象引用.因此是按引用传递对象.Java 应用程序按引用 ...

  6. 92. Reverse Linked List II【Medium】

    92. Reverse Linked List II[Medium] Reverse a linked list from position m to n. Do it in-place and in ...

  7. Android-Dialog风格Activity开发

    1.设置窗口风格 : ①在Manifest中设置主题属性android:theme="@android:style/Theme.Dialog",或者 Theme.Holo.Dial ...

  8. servelet 直接输出内容

    package helloworld; import java.io.IOException; import javax.servlet.ServletException; import javax. ...

  9. Linux命令之umask

    一 权限掩码umask umask是chmod配套的,总共为4位(gid/uid,属主,组权,其它用户的权限),不过通常用到的是后3个,例如你用chmod 755 file(此时这文件的权限是属主读( ...

  10. 获取云硬盘列表bug

    有段时间没写博客了,主要还是刚进新公司,多少有点不适应(真会给自己找理由,明明是手里没技术,肚子里没货,能写啥!).前面几个星期都在修一修horizon的bug,这个没啥很大难度,就是用了一个djan ...