MySQL隐式转换(inexplicit conversion)

探讨了在SQL查询中使用属性隐式转换可能导致全表扫描,而非预期的索引命中。例如,数字类型的字段在字符串比较时,无法利用到已建立的索引,从而影响查询效率。

禁止使用属性隐式转换

解读:SELECT uid FROM t_user WHERE phone=13812345678 会导致全表扫描,而不能命中phone索引。而SELECT uid FROM t_user WHERE phone=‘13812345678’可以索引

原因如下:https://www.jianshu.com/p/6f34e9708a80

select avg(play_cnt) as play_cnt, avg(song_cnt) as song_cnt, avg(play_duration) as play_duration from ( select dt, avg(play_cnt) as play_cnt, avg(song_cnt) as song_cnt, avg(dau_play_duration) as play_duration from ( select a.dt ,rid ,count(distinct song_id) as song_cnt ,sum(effective_play_cnt) as play_cnt ,sum(effective_play_duration) as dau_play_duration from ( SELECT dt --------小米电视用户活跃dws表 ,cast(rid as bigint) as rid FROM music_dws.dws_user_iot_dau_general_analysis_di WHERE dt between '${start_date}' AND '${end_date}' and os_type = 'TV' and iot_channel = 'xiaomitv' and rid is not null group by 1,2 ) a join ( SELECT dt, user_id FROM music_dimension.dim_par_user_vip_by_type_base_dd WHERE dt between '${start_date}' AND '${end_date}' AND vip_type in ('black','svip','tv_vip') AND current_effect_status = '1' GROUP BY 1,2 ) b on b.user_id = a.rid and b.dt = a.dt left join ( SELECT -----歌曲播放明细 dt ,cast(user_id as bigint) as user_id ,song_id ,sum(effective_play_cnt_1d) as effective_play_cnt ,sum(effective_play_duration_1d)/60 as effective_play_duration from music_dws.dws_soc_user_song_di where dt between '${start_date}' and '${end_date}' and app = 'music' and os in ('andrtv','api_andrtv') group by 1,2,3 ) c on c.dt = a.dt and c.user_id = a.rid group by 1,2 ) a group by 1 ) a 🤖 错误内容 数据类型错误,JOIN条件字段类型不兼容。 错误位置:第30行。 错误原因:JOIN条件b.user_id = a.rid中,b.user_id是bigint类型,而a.rid是string类型,类型不匹配。 修正建议:将a.rid转换为bigint类型,保持类型一致。 数据类型错误,JOIN条件字段类型不兼容。 错误位置:第47行。 错误原因:JOIN条件c.user_id = a.rid中,c.user_id是bigint类型,而a.rid是string类型,类型不匹配。 修正建议:将a.rid转换为bigint类型,保持类型一致。这个纠错对不对
最新发布
09-23
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值