key,unique index,联合索引
来源:互联网 发布:南宁知远科技有限公司 编辑:程序博客网 时间:2024/06/06 06:56
1.key与index
Note that “primary” is called PRIMARY KEY not INDEX.
KEY is something on the logical level, describes your table and database design (i.e. enforces referential integrity …)
INDEX is something on the physical level, helps improve access time for table operations.
Behind every PK there is (usually) unique index created (automatically).
key是主键,更多的指的是逻辑上的事,反应了你的数据表的格式和设计,例如主键,外键就是对数据完整性和唯一性的约束;key 唯一值,不能重复,用来确定某一行的。
而index索引指的是物理层面的东西,有助于提高表的访问,排序速度
2.unique index
唯一索引是index中的一种,建立了Unique Index表示此列数据不可重复。
一个表只能有一个PRIMARY KEY,但可以有多个UNIQUE KEY
3.使用unique index
CREATE TABLE test
(
id
int(10) NOT NULL auto_increment,
date
date NOT NULL,
type
varchar(100) NOT NULL,
sub_type
varchar(100) NOT NULL,
domain_name
varchar(128) NOT NULL,
url
text NOT NULL,
parameters
text NOT NULL,
hash
varchar(100) NOT NULL,
PRIMARY KEY (id
),
UNIQUE KEY date
(date
,hash
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
4.联合索引
当查询条件出现类似这类情况时‘where xx=xx && xx=xx && xx>xx’ 即查询的结果需要通过至少两个维度确定的需要联合索引
索引是key index (a,b,c). 可以支持a ;a,b;a,b,c 3种组合进行查找,但不支持 b,c进行查找 .左优先原则
下面的情况都会用到这个索引:
col_a = “some value”;
col_a = “some value” and col_b = “some value”;
col_a = “some value” and col_b = “some value” and col_c = “some value”;
col_b = “some value” and col_a = “some value” and col_c = “some value”;
对于最后一条语句,mysql会自动优化成第三条的样子
索引原则
1.索引越少越好
原因:主要在修改数据时,第个索引都要进行更新,降低写速度。
2.最窄的字段放在键的左边
3.避免file sort排序,临时表和表扫描.
- key,unique index,联合索引
- mysql 创建、删除 索引 key 、primary key 、unique key 与index区别
- 学习笔记--mysql索引(一) 索引使用,index,key,primary key, unique
- 不允许对索引显式地使用 DROP INDEX,该索引正用于 UNIQUE KEY
- Primary key and Unique index
- Unique Constraint, Primary Key and Unique Index
- mysql建立索引的优缺点|创建索引alter或create索引分类(PRIMARY KEY,UNIQUE KEY,FULLTEXT,INDEX)作用查看索引show index from table
- PRIMARY KEY、UNIQUE KEY、INDEX区别
- PRIMARY KEY、UNIQUE KEY、INDEX区别
- PRIMARY KEY、UNIQUE KEY、INDEX区别
- 主键(primary key)和唯一索引(unique index)区别
- mysql key primary key unique index index的区别
- mysql中key 、primary key 、unique key 与index区别
- mysql中key 、primary key 、unique key 与index区别
- mysql中key 、primary key 、unique key 与index区别
- mysql中key 、primary key 、unique key 与index区别
- mysql中key 、primary key 、unique key 与index区别
- mysql中key 、primary key 、unique key 与index区别
- C++中用rand()和srand()产生为随机数方法介绍
- leetcode347:Top K Frequent Elements(medium)
- 数据的逻辑结构和数据的物理结构
- 看来这是门技术活
- NPM来安装jquery
- key,unique index,联合索引
- 第一篇关于深度学习的博客
- EventBus 3 源码分析
- React Native环境搭建
- hdu 5493 Queue(逆序对,线段树)
- 旋转卡壳大解析
- 简单的javascript学习03
- Loadrunner 测试网页下载文件的脚本实例
- linux开机启动详细流程