python学习笔记(76) 索引

desc userinfo 3;  # 显示所有列

普通索引:

  index 索引名(列名)  # 创建表的时候

  creat index 索引名 on 表名(列名)

  drop index 索引名 on 表名

唯一索引:

  unique 索引名(列名)  # 创建表的时候

  creat unique index 索引名 on 表名(列名)

  drop unique index 索引名 on 表名

联合(组合)索引: 

扫描二维码关注公众号,回复: 4371089 查看本文章

  creat index 索引名 on 表名(列名,列名)  # unique同理

  drop index 索引名 on 表名

主键:

  primary key (列名)

  alter table 表名 add primary key(列名)  # 后天创建

作用:

  约束

  加速查找

索引:

  普通索引:加速查找

  主键索引:加速查找 + 不能为空 + 不能重复

  唯一索引:加速查找 + 不能重复

  联合索引(多列):

    联合主键索引

    联合唯一索引

    联合普通索引

    最左前缀匹配

加速查找:

  select * from tb1 where name = 'asd'

  select * from tb1 where id = 999

  无索引:从前到后依次查找

  索引:

     创建以某种格式存储的额外文件

     查询快,插入更新删除慢

     命中索引

  

  索引种类(某种格式存储):

    hash索引:

      单值速度快

      取范围速度慢(顺序被打乱)

    btree索引:

      二叉树(默认,速度快)

覆盖索引:

  select email fron tb1 where email = ''

  在索引文件中直接获取数据,不去表里取

索引合并:  

  select email fron tb1 where email = '' and id = 999

  把多个单列索引合并使用

  # 没有组合索引效率高

猜你喜欢

转载自www.cnblogs.com/farion/p/10068225.html