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

    索引分类:

    (1)普通索引

    (2)唯一索引

    (3)主键索引

    (4)组合索引

    索引的作用:加速查找和约束

    创建索引:

      (1).创建普通索引:create index index_name on table_name(cloum_name);

            (2).创建唯一索引:unique

           (3).创建主键索引:primary key

           (4).创建组合索引:create index index_name on table_name(cloum_name1,cloum_name2);

    删除索引:drop index index_name

    覆盖索引,合并索引

    (二)、执行计划

      查看当前sql的运行状况

           走索引还是不走索引?explain  sql语句

      type all 全表扫描

      type index 扫描索引

      (2)使用limit

      (3)范围查找时,type range 比index和all 效率高

      (4)type index_merg

      (5)type ref 根据索引值查找一个或多个值

      (6)type eq_ref 连接时使用primary key 或unique

      (7)type const 表最多有一个匹配行,因为仅有一行,在这行的列值可被优化器剩余部分认为是常数,const表很快,因为它们只读取一次

      

  • 相关阅读:
    LeetCode "Median of Two Sorted Arrays"
    LeetCode "Distinct Subsequences"
    LeetCode "Permutation Sequence"

    LeetCode "Linked List Cycle II"
    LeetCode "Best Time to Buy and Sell Stock III"
    LeetCode "4Sum"
    LeetCode "3Sum closest"
    LeetCode "3Sum"
    LeetCode "Container With Most Water"
  • 原文地址:https://www.cnblogs.com/tanghu/p/9728647.html
Copyright © 2011-2022 走看看