MySQL范围优化和多部分索引

时间:2018-11-19 16:16:44

标签: mysql database mysql-5.7 mysql-5.6 mysql-5.5

嗨,我是MySQL World的新手。

当我了解MySQL范围优化时,有人提出了与多部分索引有关的问题。

MySQL 5.7 Doc

http://jorgenloland.blogspot.com/2011/08/mysql-range-access-method-explained.html

问题1: 单间隔和连续间隔是什么意思?

问题2: 与分段索引和键相关

表结构 创建表订单(customer_id int,value int,name varchar(20),primary key(customer_id,value));

A)

mysql> explain select * from orders where customer_id  <= 2  and value = 1;

+----+-------------+--------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
| id | select_type | table  | partitions | type  | possible_keys | key     | key_len | ref  | rows | filtered | Extra       |
+----+-------------+--------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
|  1 | SIMPLE      | orders | NULL       | range | PRIMARY       | PRIMARY | 8       | NULL |    4 |    25.00 | Using where |
+----+-------------+--------+------------+-------+---------------+---------+---------+------+------+----------+-------------+

B)

mysql> explain select * from orders where customer_id  < 2  and value = 1;

+----+-------------+--------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
| id | select_type | table  | partitions | type  | possible_keys | key     | key_len | ref  | rows | filtered | Extra       |
+----+-------------+--------+------------+-------+---------------+---------+---------+------+------+----------+-------------+
|  1 | SIMPLE      | orders | NULL       | range | PRIMARY       | PRIMARY | 4       | NULL |    4 |    25.00 | Using where |
+----+-------------+--------+------------+-------+---------------+---------+---------+------+------+----------+-------------+

为什么说明语句(A)将keylen显示为 8 ,而(B)将keylen显示为 4

0 个答案:

没有答案