mysql加了索引还是慢_有人能解释一下 mysql 加了索引反而超级慢吗?

mysql> desc channel_details;

+---------------+-------------+------+-----+-------------------+----------------+

| Field | Type | Null | Key | Default | Extra |

+---------------+-------------+------+-----+-------------------+----------------+

| id | int(11) | NO | PRI | NULL | auto_increment |

| year | int(11) | NO | MUL | NULL | |

| month | int(11) | NO | | NULL | |

| point_of_time | varchar(32) | NO | | NULL | |

| channel | varchar(32) | NO | MUL | NULL | |

| ratings | float | NO | | NULL | |

| type | int(11) | NO | MUL | NULL | |

| age | int(11) | NO | MUL | NULL | |

| time_at | datetime | NO | | CURRENT_TIMESTAMP | |

+---------------+-------------+------+-----+-------------------+----------------+

9 rows in set (0.01 sec)

mysql> select * from channel_details where channel like "%" and year>=2017 and year<=2017 and type=29 limit 10;

+---------+------+-------+---------------+-------------+---------+------+-----+---------------------+

| id | year | month | point_of_time | channel | ratings | type | age | time_at |

+---------+------+-------+---------------+-------------+---------+------+-----+---------------------+

| 7124305 | 2017 | 1 | 02:00 | ??????????? | 0 | 29 | 40 | 2017-02-15 15:03:54 |

| 7124306 | 2017 | 1 | 02:01 | ??????????? | 0 | 29 | 40 | 2017-02-15 15:03:54 |

| 7124307 | 2017 | 1 | 02:02 | ??????????? | 0 | 29 | 40 | 2017-02-15 15:03:54 |

| 7124308 | 2017 | 1 | 02:03 | ??????????? | 0 | 29 | 40 | 2017-02-15 15:03:54 |

| 7124309 | 2017 | 1 | 02:04 | ??????????? | 0 | 29 | 40 | 2017-02-15 15:03:54 |

| 7124310 | 2017 | 1 | 02:05 | ??????????? | 0 | 29 | 40 | 2017-02-15 15:03:54 |

| 7124311 | 2017 | 1 | 02:06 | ??????????? | 0 | 29 | 40 | 2017-02-15 15:03:54 |

| 7124312 | 2017 | 1 | 02:07 | ??????????? | 0 | 29 | 40 | 2017-02-15 15:03:54 |

| 7124313 | 2017 | 1 | 02:08 | ??????????? | 0.001 | 29 | 40 | 2017-02-15 15:03:54 |

| 7124314 | 2017 | 1 | 02:09 | ??????????? | 0.001 | 29 | 40 | 2017-02-15 15:03:54 |

+---------+------+-------+---------------+-------------+---------+------+-----+---------------------+

10 rows in set (19.53 sec)

mysql> select * from channel_details where channel like "%" and year>=2017 and year<=2017 limit 10;

+---------+------+-------+---------------+-------------+---------+------+-----+---------------------+

| id | year | month | point_of_time | channel | ratings | type | age | time_at |

+---------+------+-------+---------------+-------------+---------+------+-----+---------------------+

| 7124305 | 2017 | 1 | 02:00 | ??????????? | 0 | 29 | 40 | 2017-02-15 15:03:54 |

| 7124306 | 2017 | 1 | 02:01 | ??????????? | 0 | 29 | 40 | 2017-02-15 15:03:54 |

| 7124307 | 2017 | 1 | 02:02 | ??????????? | 0 | 29 | 40 | 2017-02-15 15:03:54 |

| 7124308 | 2017 | 1 | 02:03 | ??????????? | 0 | 29 | 40 | 2017-02-15 15:03:54 |

| 7124309 | 2017 | 1 | 02:04 | ??????????? | 0 | 29 | 40 | 2017-02-15 15:03:54 |

| 7124310 | 2017 | 1 | 02:05 | ??????????? | 0 | 29 | 40 | 2017-02-15 15:03:54 |

| 7124311 | 2017 | 1 | 02:06 | ??????????? | 0 | 29 | 40 | 2017-02-15 15:03:54 |

| 7124312 | 2017 | 1 | 02:07 | ??????????? | 0 | 29 | 40 | 2017-02-15 15:03:54 |

| 7124313 | 2017 | 1 | 02:08 | ??????????? | 0.001 | 29 | 40 | 2017-02-15 15:03:54 |

| 7124314 | 2017 | 1 | 02:09 | ??????????? | 0.001 | 29 | 40 | 2017-02-15 15:03:54 |

+---------+------+-------+---------------+-------------+---------+------+-----+---------------------+

10 rows in set (0.07 sec)

mysql> explain select * from channel_details where channel like "%" and year>=2017 and year<=2017 and type=29 limit 10;

+----+-------------+-----------------+------------+------+---------------+------+---------+-------+---------+----------+-------------+

| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |

+----+-------------+-----------------+------------+------+---------------+------+---------+-------+---------+----------+-------------+

| 1 | SIMPLE | channel_details | NULL | ref | type,year | type | 4 | const | 4969150 | 5.56 | Using where |

+----+-------------+-----------------+------------+------+---------------+------+---------+-------+---------+----------+-------------+

1 row in set, 1 warning (0.00 sec)

mysql> explain select * from channel_details where channel like "%" and year>=2017 and year<=2017 limit 10;

+----+-------------+-----------------+------------+-------+---------------+------+---------+------+---------+----------+-----------------------------------------------+

| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |

+----+-------------+-----------------+------------+-------+---------------+------+---------+------+---------+----------+-----------------------------------------------+

| 1 | SIMPLE | channel_details | NULL | range | year | year | 4 | NULL | 4969150 | 11.11 | Using index condition; Using where; Using MRR |

+----+-------------+-----------------+------------+-------+---------------+------+---------+------+---------+----------+-----------------------------------------------+

mysql> select count(*) from channel_details group by year;

+----------+

| count(*) |

+----------+

| 141218 |

| 6498910 |

| 4226453 |

+----------+

3 rows in set (4.36 sec)

mysql> select count(*) from channel_details group by type;

+----------+

| count(*) |

+----------+

| 3573680 |

| 3647171 |

| 3645730 |

+----------+

3 rows in set (2.54 sec)

mysql> select count(*) from channel_details group by year,type;

+----------+

| count(*) |

+----------+

| 141218 |

| 2072158 |

| 2213376 |

| 2213376 |

| 1360304 |

| 1433795 |

| 1432354 |

+----------+

7 rows in set (27.02 sec)

都是同样的索引类型,速度却相差巨大。有人可以解释一下吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值