一、首先,聚集索引和非聚集索引的根本区别是表记录的排列顺序和与索引的排列顺序是否一致。
因为聚集索引的完整数据记录(行数据,表记录)在叶子节点数据域,整个索引结构按照B+ Tree的结构有序(B+树数据结构性质决定),所以表记录的排列顺序和索引的排列顺序是一致的。
二、其次,MyISAM的索引方式也叫做“非聚集”的,之所以这么称呼是为了与InnoDB的聚集索引区分。
MyISAM的索引 有主索引和辅助索引,主索引和辅助索引的索引文件仅仅保存数据记录的地址,叶子节点data域是没有完整的数据记录的(行数据)。
InnoDB的索引 有主键索引和辅助索引,主键索引的叶子节点的data域保存了完整的数据记录(行数据);但是辅助索引的叶子节点却没有完整的数据记录(行数据),所以走辅助索引查找行数据会有一次回表的查询
关于聚集索引 辅助索引的概念和关系问题,官方文档里面有描述的:All indexes other than the clustered index are known as secondary indexes.15.6.2.1 Clustered and Secondary Indexesdev.mysql.com
2. 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.)
A secondary index can be used to satisfy queries that only require values from the indexed columns. For more complex queries, it can be used to identify the relevant rows in the table, which are then retrieved through lookups using the clustered index.https://dev.mysql.com/doc/refman/8.0/en/glossary.html#glos_secondary_indexdev.mysql.com
3. clustered index
The InnoDB term for a primary key index.https://dev.mysql.com/doc/refman/8.0/en/glossary.html#glos_clustered_indexdev.mysql.com