(root@node01) > select count(*) from customer where year(c_since)=2020;
+----------+
| count(*) |
+----------+
| 702 |
+----------+
1 row in set (0.46 sec)
(root@node01) > explain select count(*) from customer where year(c_since)=2020;
+----+-------------+----------+------------+------+---------------+------+---------+------+--------+----------+-------------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+----------+------------+------+---------------+------+---------+------+--------+----------+-------------+
| 1 | SIMPLE | customer | NULL | ALL | NULL | NULL | NULL | NULL | 287382 | 100.00 | Using where |
+----+-------------+----------+------------+------+---------------+------+---------+------+--------+----------+-------------+
1 row in set, 1 warning (0.00 sec)
(root@node01) > alter table customer add key idx_customer_since((year(c_since)));
Query OK, 0 rows affected (6.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
(root@node01) > select count(*) from customer where year(c_since)=2020;
+----------+
| count(*) |
+----------+
| 702 |
+----------+
1 row in set (0.01 sec)
(root@node01) > explain select count(*) from customer where year(c_since)=2020;
+----+-------------+----------+------------+------+--------------------+--------------------+---------+-------+------+----------+-------+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+----------+------------+------+--------------------+--------------------+---------+-------+------+----------+-------+
| 1 | SIMPLE | customer | NULL | ref | idx_customer_since | idx_customer_since | 5 | const | 702 | 100.00 | NULL |
+----+-------------+----------+------------+------+--------------------+--------------------+---------+-------+------+----------+-------+
1 row in set, 1 warning (0.00 sec)
【MySQL 8.0】新特性:函数索引
原创dbprofessional 博主文章分类:MySQL ©著作权
©著作权归作者所有:来自51CTO博客作者dbprofessional的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
MySQL8.0索引新特性
持降序索引 在MySQL5.7和MySQL8.0中创建表 CREATE TABLE ts1(a int,b int,index idx_a
MySQL mysql 查询优化 执行计划 -
新特性解读 | MySQL 8.0 索引特性4-不可见索引
作者:杨涛涛MySQL 8.0 实现了索引的隐藏属性。当然这个特性很多
MySQL 数据库 mysql SQL