• mysql 执行计划走索引


    <pre name="code" class="html">mysql> desc AssignClientManager;
    +-----------------+----------+------+-----+---------+----------------+
    | Field           | Type     | Null | Key | Default | Extra          |
    +-----------------+----------+------+-----+---------+----------------+
    | sn              | int(11)  | NO   | PRI | NULL    | auto_increment |
    | clientSn        | int(11)  | NO   | MUL | NULL    |                |
    | clientManagerSn | int(11)  | NO   |     | NULL    |                |
    | status          | char(1)  | NO   |     | 1       |                |
    | createdTime     | datetime | YES  |     | NULL    |                |
    | updatedTime     | datetime | YES  |     | NULL    |                |
    +-----------------+----------+------+-----+---------+----------------+
    6 rows in set (0.00 sec)
    
    mysql> show index from AssignClientManager;
    +---------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
    | Table               | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |
    +---------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
    | AssignClientManager |          0 | PRIMARY  |            1 | sn          | A         |        4934 |     NULL | NULL   |      | BTREE      |         |               |
    | AssignClientManager |          1 | ACM_IDX1 |            1 | clientSn    | A         |        4458 |     NULL | NULL   |      | BTREE      |         |               |
    +---------------------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+
    2 rows in set (0.00 sec)
    
    mysql> explian select sn,clientSn from AssignClientManager;
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'explian select sn,clientSn from AssignClientManager' at line 1
    mysql> explain select sn,clientSn from AssignClientManager;
    +----+-------------+---------------------+------------+-------+---------------+----------+---------+------+------+----------+-------------+
    | id | select_type | table               | partitions | type  | possible_keys | key      | key_len | ref  | rows | filtered | Extra       |
    +----+-------------+---------------------+------------+-------+---------------+----------+---------+------+------+----------+-------------+
    |  1 | SIMPLE      | AssignClientManager | NULL       | index | NULL          | ACM_IDX1 | 4       | NULL | 4934 |   100.00 | Using index |
    +----+-------------+---------------------+------------+-------+---------------+----------+---------+------+------+----------+-------------+
    1 row in set, 1 warning (0.00 sec)
    
    mysql> explain SELECT COUNT(sn) FROM AssignClientManager where clientSn>5;
    +----+-------------+---------------------+------------+-------+---------------+----------+---------+------+------+----------+--------------------------+
    | id | select_type | table               | partitions | type  | possible_keys | key      | key_len | ref  | rows | filtered | Extra                    |
    +----+-------------+---------------------+------------+-------+---------------+----------+---------+------+------+----------+--------------------------+
    |  1 | SIMPLE      | AssignClientManager | NULL       | range | ACM_IDX1      | ACM_IDX1 | 4       | NULL | 4928 |   100.00 | Using where; Using index |
    +----+-------------+---------------------+------------+-------+---------------+----------+---------+------+------+----------+--------------------------+
    1 row in set, 1 warning (0.00 sec)
    
    mysql> explain select * from AssignClientManager where sn <100 and clientSn <200;
    +----+-------------+---------------------+------------+-------+------------------+---------+---------+------+------+----------+-------------+
    | id | select_type | table               | partitions | type  | possible_keys    | key     | key_len | ref  | rows | filtered | Extra       |
    +----+-------------+---------------------+------------+-------+------------------+---------+---------+------+------+----------+-------------+
    |  1 | SIMPLE      | AssignClientManager | NULL       | range | PRIMARY,ACM_IDX1 | PRIMARY | 4       | NULL |   99 |     4.95 | Using where |
    +----+-------------+---------------------+------------+-------+------------------+---------+---------+------+------+----------+-------------+
    1 row in set, 1 warning (0.01 sec)


    
                                        
    
  • 相关阅读:
    hdu1240 bfs 水题
    hdu 2102 BFS
    gym 101081E Polish Fortress 几何
    Gym 101081K Pope's work dp
    hdu 6188 贪心
    hdu 6186 水
    Codeforces Round #430 (Div. 2) A B 水 C dfs,思维 D trie,二进制
    hdu6152 拉姆齐定理
    hdu6165 缩点,dfs
    hdu6153 扩展KMP
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350731.html
Copyright © 2020-2023  润新知