zoukankan      html  css  js  c++  java
  • MySQL索引相关

    MySQL添加索引:

    使用某数据库 scheam

    use ua;

    show tables;

    查看表结构

      desc ua.log;

    查看索引

      show index from ua.log;

    添加组合索引

      ALTER TABLE `log` ADD INDEX index_log_type ( `log_type`, `op_type`, `is_deleted`,`created_dt`);

      ALTER TABLE `log` ADD INDEX index_op_type ( `op_type`, `log_type`, `is_deleted`,`created_dt`);

     删除索引

      alter table `ua`.`log` drop index index_op_type;

      -- drop index index_name on table_name ;

      -- alter table table_name drop index index_name ;

      -- alter table table_name drop primary key ;

     添加单列索引

      ALTER TABLE `log` ADD INDEX index_op_type (`op_type`);

    添加主键索引

      alter table `log` add primary key (`id`);

    添加唯一索引

      alter table `ua`.`log` add unique (`id`);

     添加普通索引

      alter table `ua`.`log` add index index_opt_type (`op_type`);

     添加全文索引

      alter table `ua`.`log` add fulltext full_remark (`remark`);

    添加多列索引或者组合索引

      alter table `ua`.`log` add index index_op_type ( `op_type`, `log_type`, `is_deleted`,`created_dt`);

    主键索引&唯一索引&组合索引&普通索引 设置索引类型BTREE

    全文索引   设置索引类型 FULLTEXT

    -- explain select * form log;
    执行计划:
    -- key_len : MySQL中使用索引字节长度
    -- key 真实使用的key
    -- rows : mysql 预估为了找到所需的行而要读取的行数
    -- possible_keys : 可能使用的索引

    未加索引情况
    explain select * from log t where t.op_code1='2231' and t.op_code2='2';

    主键索引&唯一索引
    explain select * from log t where t.id='186451';

  • 相关阅读:
    C#库
    大话设计模式--简单工厂模式
    weka平台下手动造.arff的数据
    NIM博弈的必胜取法
    求一个全排列函数: 如p([1,2,3])输出:[123],[132],[213],[231],[312],[321]. 求一个组合函数 如p([1,2,3])输出:[1],[2],[3],[1,2],[2,3],[1,3],[1,2,3]
    哥德巴赫猜想
    C#格式化输出
    meta文件里指定资源
    chromatic aberration
    uber shader
  • 原文地址:https://www.cnblogs.com/badboys/p/14972148.html
Copyright © 2011-2022 走看看