zoukankan      html  css  js  c++  java
  • [MySQL]ANALYZE TABLE 更新索引基数

    MySQL使用存储的键分布基数来确定表连接顺序
    在决定对查询中的特定表使用哪些索引时,也会使用使用键分布基数

    ANALYZE TABLE 表名 可以更新表的索引基数,使其更接近非重复的记录数,记录数可以使用show index from 表 来查询cardinality字段

    mysql> show index from index_test;
    +------------+------------+--------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
    | Table      | Non_unique | Key_name           | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
    +------------+------------+--------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
    | index_test |          0 | PRIMARY            |            1 | id          | A         |           5 |     NULL | NULL   |      | BTREE      |         |               |
    | index_test |          1 | score_index        |            1 | score       | A         |           2 |     NULL | NULL   |      | BTREE      |         |               |
    | index_test |          1 | name_gid_age_index |            1 | name        | A         |           3 |     NULL | NULL   |      | BTREE      |         |               |
    | index_test |          1 | name_gid_age_index |            2 | gid         | A         |           3 |     NULL | NULL   |      | BTREE      |         |               |
    | index_test |          1 | name_gid_age_index |            3 | age         | A         |           6 |     NULL | NULL   |      | BTREE      |         |               |
    +------------+------------+--------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
    5 rows in set (0.00 sec)
    
    mysql> select * from index_test;
    +----+------------+-----+-----+-------+
    | id | name       | gid | age | score |
    +----+------------+-----+-----+-------+
    |  1 | taoshihan  |   2 |   0 |     0 |
    |  2 | taoshihan1 |   2 |   0 |     0 |
    |  3 | taoshihan2 |   3 |  10 |    10 |
    |  4 | taoshihan  |   2 |   1 |     0 |
    |  5 | taoshihan  |   2 |   2 |     0 |
    |  6 | taoshihan  |   2 |   3 |     0 |
    +----+------------+-----+-----+-------+
    6 rows in set (0.03 sec)
    
    mysql> ANALYZE TABLE index_test;
    +--------------------+---------+----------+----------+
    | Table              | Op      | Msg_type | Msg_text |
    +--------------------+---------+----------+----------+
    | my_test.index_test | analyze | status   | OK       |
    +--------------------+---------+----------+----------+
    1 row in set (0.13 sec)
    
    mysql> show index from index_test;
    +------------+------------+--------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
    | Table      | Non_unique | Key_name           | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
    +------------+------------+--------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
    | index_test |          0 | PRIMARY            |            1 | id          | A         |           6这里变了 |     NULL | NULL   |      | BTREE      |         |               |
    | index_test |          1 | score_index        |            1 | score       | A         |           2 |     NULL | NULL   |      | BTREE      |         |               |
    | index_test |          1 | name_gid_age_index |            1 | name        | A         |           3 |     NULL | NULL   |      | BTREE      |         |               |
    | index_test |          1 | name_gid_age_index |            2 | gid         | A         |           3 |     NULL | NULL   |      | BTREE      |         |               |
    | index_test |          1 | name_gid_age_index |            3 | age         | A         |           6 |     NULL | NULL   |      | BTREE      |         |               |
    +------------+------------+--------------------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
    5 rows in set (0.07 sec)
    

      

  • 相关阅读:
    MSSQL_打开xp_cmdshell
    想在win7 32bit的情况下装个64位虚拟机的想法
    查看系统已运行了多久
    sql弄个表结构出来..
    在win下的cmd 的find
    告别google.com.hk的龟速
    VC常用数据类型使用转换详解
    C++中的文件输入/输出ios:xx eat Processing(zz)
    X86汇编语言学习手记(1)
    程序员数据结构笔记
  • 原文地址:https://www.cnblogs.com/taoshihan/p/12372874.html
Copyright © 2011-2022 走看看