MySQL-JSON与虚拟列结合使用提升性能

1-获取 json中的属性值 【  列名 -> '$.属性名'  】

 

select extra -> '$.car_name' from m_table where  '$.car_name'="jojo";

 

2-优化查询性能,构建虚拟列,并在虚拟列上加索引 (json_extract:从指定数据中提取属性值;json_unquote:解除与json的引用;virtual:为虚拟列,只读不写

新增虚拟列(虚拟列 只读不写,但是更新 原列中的属性值,虚拟列的值也会同步更新)

 

alter table m_table add column `car_name` varchar(30)  GENERATED ALWAYS AS

(json_unquote(json_extract(`extra`,_utf8mb4,'$.car_name')))  virtual null

 

建立索引:

create index idx_car_name on m_table(car_name);

posted @ 2022-04-04 11:26  魔杰Lee  阅读(1370)  评论(0编辑  收藏  举报