mysql 基于虚拟列创建函数索引

1.创建虚拟列

alter table otc_transaction_complete 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 otc_transaction_complete add INDEX index_create_time_idx(create_time_index);

posted @ 2020-10-27 17:22  DiligentCoder  阅读(1058)  评论(0编辑  收藏  举报