zoukankan      html  css  js  c++  java
  • MYSQL索引优化法则

    目录

      一首诗送给各位:

      全值匹配我最爱,最左前缀要遵守;
      带头大哥不能死,中间兄弟不能断;
      索引列上少计算,范围之后全失效;
      Like百分写最右,覆盖索引不写星;
      不等空值还有or,索引失效要少用;
      VAR引号不可丢,SQL高级也不难!

      举个栗子:
      假设index(a,b,c)

      where语句 索引是否被用到 原因
      where a=3 使用到a 全值匹配
      where a=3 and b=5 使用到a,b 全值匹配
      where a=3 and b=5 and c=4 使用到a,b,c 全值匹配
      where b=3 or where b=3 and c=4 or where c=4 NULL 因为按照创建索引的顺序第一个索引列a没有被用到,导致后面的索引失效。
      where a=3 and c=5 使用到a b没有被用到,导致c失效
      where a=3 and b>4 and c=5 使用到a b为范围查询索引失效导致C也失效
      where a=3 and b like 'kk%' and c =4 使用到a,b,c 这里的b是可以用到的因为百分号在最右结合最左前缀原则,虽然%相当于范围查询但是在最右,最左边是定值。
      where a=3 and b like '%kk' and c=4 使用到a b中间断开失效导致c也失效
      where a=3 and b like '%kk%' and c=4 使用到a b断开
      where a=3 and b like 'k%kk%' and c=4 使用到a,b,c 同上上上
    • 相关阅读:
      python wsdl connection refused 111
      我要学算法
      linux 定时任务
      mysql语句
      Firefox配置Fiddler
      windows下安装spynner
      做一个完整的项目需要技能
      快速排序
      《实时控制软件设计》总结
      asp实现在微信jsdk分享从a页面跳转到b页面然后分享后点开又回a页面
    • 原文地址:https://www.cnblogs.com/xhj928675426/p/14459124.html
    Copyright © 2011-2022 走看看