【 TiDB 使用环境】生产环境 /测试/ Poc
【 TiDB 版本】
【复现路径】做过哪些操作出现的问题
【遇到的问题:问题现象及影响】
【资源配置】
select * from db1.account where id in (select
case when JSON_EXTRACT(response,'$.status') = 'OK' then JSON_EXTRACT(response,'$.result.one_face_with_multi_cards[0].user_id')
else ' ' end as concat_top_max_user_id
from db1.face where account_id = 1000000
and option_type = 2
order by id desc limit 1)
执行计划造成db1.account全表扫描
db1.account.id, decimal(20,0) BINARY)->Column#65,明显发生了强制转换。
如果先把结果查出来再执行select * from db1.account where id (xxxx)走的Batch_Point_Get_1
随后把子查询改为这样cast(case …when… end as unsigned)
使用了conver也是一样
最后又在case分支执行cast转换,最终这样
cast(case when JSON_EXTRACT(response,'$.status') = 'OK' then cast(JSON_EXTRACT(response,'$.result.one_face_with_multi_cards[0].user_id') as unsigned)
else '' end as unsigned)
最终语句是这样:
select * from db1.account where id in (select
cast(case when JSON_EXTRACT(response,'$.status') = 'OK' then cast(JSON_EXTRACT(response,'$.result.one_face_with_multi_cards[0].user_id') as unsigned)
else '' end as unsigned) as concat_top_max_user_id
from db1.face where account_id = 1000000
and option_type = 2
order by id desc limit 1)
终于解决了,为啥需要两次cast转换?