zoukankan      html  css  js  c++  java
  • [日常] mysql的索引使用情况测试

    1.索引(Index)是帮助MySQL高效获取数据的数据结构,可以理解为“排好序的快速查找数据结构”,在数据之外,数据库系统还维护着满足特定查找算法的数据结构,这些数据结构以某种方式引用(指向)数据,这样就可以在这些数据结构上实现高级查找算法

    2.建表的时候创建索引,创建群发已发送邮件表:
    create table mass_mail_send(
      id int auto_increment primary key,
      sender varchar(125) not null default '',
      mass_id int not null default 0,
      subject varchar(255) not null default '',
      location varchar(255) not null default '',
      send_time int not null default 0,
      user_email_id int not null default 0,
      index (mass_id),
      index (user_email_id)
    )engine=innodb charset utf8;

    3.在mass_id和user_email_id上创建了普通索引

    4.使用explain检测索引是否被用到了

    select_type:SIMPLE(普通的select),PRIMARY(有子查询),UNION(有联合查询)
    table:输出行所用的表
    type:连接类型 从最好到最差的连接类型为const、eq_reg、ref、range、indexhe和all
    possible_keys:显示可能应用在这张表中的索引
    key: 实际使用的索引
    key_len:使用的索引的长度。在不损失精确性的情况下,长度越短越好

    5.查看索引的使用情况统计

    1.show status like 'Handler_read%';查看索引的使用情况
    Handler_read_first 全索引扫描
    Handler_read_key 数值越高越好,高效的使用了索引
    Handler_read_next 越小越好
    Handler_read_rnd 没有使用索引或者使用太多排序
    Handler_read_prev 代表读取索引的上列,一般发生在ORDER BY … DESC。
    Handler_read_rnd_next 进行数据文件扫描,越小越好

  • 相关阅读:
    visitortheoryreflection.cs
    adaptertheory.cs
    factorymethodavocados.cs
    compositetheorynswithShare.cs
    在.NET/Mono上运行Java:Jeroens Frijters谈IKVM.NET
    Building ASP.NET Server ControlsTextbox.cs
    compositephotolibrary.cs
    proxyspacebook.cs
    adapterpluggabletheory.cs
    Building ASP.NET Server ControlsFancyLabel.cs
  • 原文地址:https://www.cnblogs.com/taoshihan/p/8509587.html
Copyright © 2011-2022 走看看