MySQL8之JSON数组查询总结

目前有三种查询方式对JSON数组进行查询,SQL脚本如下所示:

select t0.* from acc_account_item t0  
where JSON_OVERLAPS (executable_store_ids -> '$[*]',CAST( '["86aafddcd17a4af68cc18b84fc933e93","305daadfde5b4167abcf2b57e37fcfbc"]' AS JSON ))
  select t0.* from acc_account_item t0  
where   t0.tenant_id = '86b23699cff44e75afd9b6a3970ee81a' and JSON_OVERLAPS(executable_store_ids, JSON_ARRAY("86aafddcd17a4af68cc18b84fc933e93"))
select t0.* from acc_account_item t0  
where   t0.tenant_id = '86b23699cff44e75afd9b6a3970ee81a' and JSON_CONTAINS(executable_store_ids, '"305daadfde5b4167abcf2b57e37fcfbc"')

以上是三种种查询方式,具体要看下哪种方式走了索引,经过验证,发现第二种和第三种SQL是不走索引的,只有第一种SQL语句走索引。

posted @ 2023-05-16 09:17  郭慕荣  阅读(1412)  评论(0编辑  收藏  举报