函数索引创建(转载)

mysql版本需要是5.7及以上版本才支持建立函数索引

建立函数索引需要两步

1.创建虚拟列

alter table t_log add column create_time_index datetime GENERATED ALWAYS AS (date_format(create_time,'%Y-%m-%d'));

上面这条语句解释

执行上面这语句后,会在表中增加一个字段也就是create_time_index,这个字段其实是个虚拟的,不用管

t_log:表名

create_time_index:列名

datetime:列类型

date_format(create_time,'%Y-%m-%d'):需要加索引的函数

2.添加索引

alter table t_log add index_create_time_idx(create_time_index);

上面语句解释

t_log:表名

index_create_time_idx:索引名称

create_time_index:上面创建的列名

到此函数索引建立完成

猜你喜欢

转载自blog.csdn.net/mezheng/article/details/82775245