博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MySQL之聚簇索引
阅读量:4228 次
发布时间:2019-05-26

本文共 654 字,大约阅读时间需要 2 分钟。

通过聚簇索引得到的三个建议:

1,每个InnoDB的表有一个特殊的索引:聚簇索引,存储了行的数据。通常聚簇索引就是指的主键索引,即InnoDB会用有主键的每张表的主键PRIMARY KEY创建聚簇索引,索引的每个节点保存了行数据,如果没有PRIMARY KEY主键,InnoDB则选择第一个UNIQUE NOT NULL的键用作创建聚簇索引,如果UNIQUE NOT NULL的键也没用,则 InnoDB在包含行ID值的合成列上内部生成隐藏的聚簇索引,行按照InnoDB分配给此类表中的行ID进行排序 行ID是一个6字节的字段,随插入新行而单调增加。因此,行ID排序的行在物理上是插入顺序。所以,第一个建议:每张表都加上PRIMARY KEY主键!

    2,通过聚簇索引访问行的速度很快,因为访问聚簇索引的节点直接可以获取到行数据,如果表格很大,聚簇索引通常会直接保存到磁盘通过I/O读取。所以,第二个建议:每张表的定义不要太大!

3,除聚簇索引之外的所有索引都称为 InnoDB中,辅助索引中的每个记录都包含该行的主键列以及为辅助索引指定的列(即创建索引时指定的列)。 InnoDB使用此行中的主键值搜索聚簇索引中的行。如果主键长,则辅助索引使用更多的空间,因此有一个较短的主键是有利的。所以,建议三:主键不要太长,在保证唯一的情况下应尽量短!

参考mysql-5.7官网文档:https://dev.mysql.com/doc/refman/5.7/en/innodb-index-types.html

转载地址:http://aejqi.baihongyu.com/

你可能感兴趣的文章
LightWave 3D 8 Revealed
查看>>
The Cg Tutorial: The Definitive Guide to Programmable Real-Time Graphics
查看>>
Operating Systems Design and Implementation (3rd Edition)
查看>>
Beginning Visual C# 2005
查看>>
Professional C# 2005
查看>>
Faster Smarter Beginning Programming
查看>>
The Essence of Object-Oriented Programming with Java and UML
查看>>
ROI of Software Process Improvement: Metrics for Project Managers and Software Engineers
查看>>
FileMaker 8 Functions and Scripts Desk Reference
查看>>
Web Security Field Guide
查看>>
Computer Animation: Algorithms and Techniques
查看>>
Multimedia-based Instructional Design
查看>>
3D Videocommunication : Algorithms, concepts and real-time systems in human centred communication
查看>>
Guide to Computer Animation
查看>>
Character Development and Storytelling for Games
查看>>
Six Sigma--The First 90 Days
查看>>
GSM, GPRS and Edge Performance: Evolution towards 3G/UMTS
查看>>
Advanced Linux 3D Graphics Programming
查看>>
3D Modeling and Animation: Synthesis and Analysis Techniques for the Human Body
查看>>
DirectX 3D Graphics Programming Bible
查看>>