时间:2021-07-01 10:21:17 帮助过:15人阅读
MySQL [test_db]> explain select * from test_users where user_id =‘1273656‘;
+----+-------------+------------+------------+------+---------------+-----------+---------+-------+------+----------+-------+
| id | select_type | table      | partitions | type | possible_keys | key       | key_len | ref   | rows | filtered | Extra |
+----+-------------+------------+------------+------+---------------+-----------+---------+-------+------+----------+-------+
|  1 | SIMPLE      | test_users | NULL       | ref  | testindex     | testindex | 44      | const |    1 |   100.00 | NULL  |
+----+-------------+------------+------------+------+---------------+-----------+---------+-------+------+----------+-------+
1 row in set, 1 warning (0.05 sec)
MySQL [test_db]> explain select * from test_users where user_id =1273656;
+----+-------------+------------+------------+------+---------------+------+---------+------+--------+----------+-------------+
| id | select_type | table      | partitions | type | possible_keys | key  | key_len | ref  | rows   | filtered | Extra       |
+----+-------------+------------+------------+------+---------------+------+---------+------+--------+----------+-------------+
|  1 | SIMPLE      | test_users | NULL       | ALL  | testindex     | NULL | NULL    | NULL | 306078 |    10.00 | Using where |
+----+-------------+------------+------------+------+---------------+------+---------+------+--------+----------+-------------+
1 row in set, 3 warnings (0.04 sec)
可以发现第一条sql的 type = ref,key = testindex,第二条sql的 type = ALL,key = null也就是没用到任何索引而是全文扫描
mysql索引创建和使用细节
标签:partition 开发 from ssi 组合 pre pos 扫描 xpl