mysql8踩坑笔记:
sql如下
update biz_registration set status = "4"where section_id in (select section_id from biz_course // 应该是biz_course_section where course_id = #{courseId})and status = '0'and data_type = 1and registration_id > 0
写代码的时候疏忽了,biz_course_section写成了biz_course,按理说biz_course表是没有section_id字段的,本地测试应该会报错才对,结果它居然正常执行了!!导致功能上线的时候,执行语句判断该条件结果为true,然后就把所有注册数据的状态都改了。。。。
稍微做了一下测试,发现在in的左侧参数与右侧的select子查询的结果集一致时,且结果集字段并不存在于子查询from指定的表内,语句效果就等同于exists。
原本的SQL:
where section_id in (select section_id from biz_course // biz_course表不存在section_id字段where course_id = #{courseId})
等同于:
where exists (select * from biz_coursewhere course_id = #{courseId})
上线才踩坑,属实悲催,记录一下,防止以后因为同样的问题翻车,写代码还是要小心,细心,谁能想到这玩意儿会不报错呢【泪目】