zoukankan      html  css  js  c++  java
  • 《MySQL数据库》索引详解

    前言

    索引在数据库中至关重要,必须要牢牢掌握,在看索引篇之前必须掌握InnoDB 的数据结构:https://www.cnblogs.com/jssj/p/devil_osiris.html

    索引创建与删除

    主键索引创建:

    mysql> alter table ic_user add primary key(id); 

    主键索引删除:

    mysql> alter table ic_user drop primary key;

    唯一索引创建:

    mysql> alter table ic_user add unique (name);

    唯一索引删除:

    mysql> alter table ic_user drop index name;

    普通索引创建:

    mysql> alter table ic_user add index index_name(name);

    普通索引删除:

    mysql> alter table ic_user drop index index_name;

    前缀索引创建:

    mysql> alter table t add key(password(7));

    前缀索引删除:

    mysql> alter table t drop index password;

    创建索引规范

    (1) 必须要有主键,如果没有可以做为主键条件的列,创建无关列

    (2) 经常做为where条件列  order by  group by  join on, distinct 的条件(业务:产品功能+用户行为)

    (3) 最好使用唯一值多的列作为索引,如果索引列重复值较多,可以考虑使用联合索引

    (4) 列值长度较长的索引列,我们建议使用前缀索引.

    (5) 降低索引条目,一方面不要创建没用索引,不常使用的索引清理,percona toolkit(xxxxx)

    (6) 索引维护要避开业务繁忙期

    其他

    select * from sys.schema_unused_indexes;    -- 查询不常被使用的索引 

    总结

    This moment will nap, you will have a dream; But this moment study,you will interpret a dream.
  • 相关阅读:
    eclipse下载
    maven-jdk版本配置
    winform中的ListBox和ComboBox绑定数据
    C和C#两种方式实现邮件的简单接收
    .Net遍历窗体上控件
    C和C#两种方式实现邮件的简单发送
    Gtk基础学习总结(二)
    Gtk基础学习总结(一)
    你要知道的C与C++的区别
    C程序中引用自定义的C函数模块
  • 原文地址:https://www.cnblogs.com/jssj/p/13381697.html
Copyright © 2011-2022 走看看