将业务查询的一些实体类 直接以JSON的形式存到数据库,以下是SQL代码查询的实例
data(“customer” :{“id”:“111”,“name”:“123”},“product” :{“id”:“111”,“name”:“123”});
select json_unquote(data -> '$.order_id') as order_id,
json_unquote(data -> '$.customer.name') as customer_name
from this_table
where data-> '$.customer.id' = 11;
解决方案为,建立一个虚拟列以 customer.id 为例
alter table this_table add customer_id int as (json_unquote(data -> '$.customer.id')) virtual;
create index idx_customer_id on this_table(customer_id);