zoukankan      html  css  js  c++  java
  • mysql索引

    索引的命名:用户可以在多个列上建立索引,这种索引叫做复合索引(组合索引)(联合索引)

    一:创建索引
    首先创建一个表:create table t1 (id int primary key,username varchar(20),password varchar(20));

    创建单个索引的语法:create index 索引名 on 表名(字段名)

    索引名一般是:表名_字段名

    给id创建索引:create index t1_id on t1(id);

    创建联合索引的语法:create index 索引名 on 表名(字段名1,字段名2)

    给username和password创建联合索引:create index t1_username_password on t1(username,password)

    二:索引失效
    1、对单字段建了索引,where条件多字段。
    select * from template t where t.logicdb_id = 4 and t.sync_status = 1

    2、建立联合索引,where条件单字段。与上面情况正好相反。
    select * from template t where t.sync_status = 4

    3、对索引列运算,运算包括(+、-、*、/、!、<>、%、like'%_'(%放在前面)(两边都加%不失效)、or、in、exist等),导致索引失效

    4、类型错误,如字段类型为varchar,where条件用number。
    错误写法:select * from template t where t.template_id = 1

    正确写法:select * from template t where t.template_id = '1'

    5、对索引应用内部函数,这种情况下应该建立基于函数的索引。
    select * from template t where ROUND(t.logicdb_id) = 1

    6、查询表的效率要比应用索引查询快的时候。

    7、is null 索引失效;is not null Betree索引生效。导致的原因,个人认为应该是,mysql没有在null写进索引。还要看应用的数据库而定。


    三:查询索引
    show index from t

    四:删除索引
    drop index idx_col1_col2 on t1

  • 相关阅读:
    matab plot指令和低通滤波器的响应图
    matlab中hold指令、figure指令及subplot指令的使用
    matlab中axis的使用
    matlab switch case 和 try catch用法示例
    matlab中使用elseif和if嵌套的对比
    matlab中运用项目思维分析问题并解决问题
    matlab图像显示程序模板
    matlab最简单程序模板
    第06篇 MyEclipse 2016 安装/破解
    第05篇. Tomcat和JDK的内存配置
  • 原文地址:https://www.cnblogs.com/ljy-skill/p/8579206.html
Copyright © 2011-2022 走看看