通过临时表创建索引用 空间换时间避免频繁读取原表信息
/*正常写法*/ DELETE from activity where id not in ( SELECT id from activity_data); /*优化后写法*/ DELETE from activity where id not in (select * from (SELECT id from activity_data) t);
<!-- update pay_record SET pr_pay_state = #{prPayState} , pr_pay_money = pr_total_money,pr_pay_time = #{prPayTime} WHERE pr_id in(SELECT pr_id FROM pay_record_related WHERE merge_id = #{mergeId})--> update pay_record SET pr_pay_state = #{prPayState} , pr_pay_money = pr_total_money,pr_pay_time = #{prPayTime} WHERE pr_id in(select * from (SELECT pr_id FROM pay_record_related WHERE merge_id = #{mergeId}) t)