SQL语句优化问题

来源:百度知道 编辑:UC知道 时间:2024/06/23 19:18:33
我的数据库表Temp_Tb_Vipinfo、Tb_Bussrecord中各有100万条数据,下面这条语句执行要55秒之多,请问怎么优化?
select * from Temp_Tb_Vipinfo t where t.zch in
(select b.zch from Tb_Bussrecord b where b.rec_context like '%%' and b.rec_type=0)
注:网上很多人都说把in换成exist,这根本就不可行,exist就是一个Boolean值,之能说明后面的语句是否有值,无法做到关联表的内容按条件筛选所以请不要再回答这个,谢谢
and t.member_name like '%%'

select t.xxx1,t.xxx2,t.xxx3
from Temp_Tb_Vipinfo t
left join Tb_Bussrecord b on t.zch=b.zch
where b.rec_type=0 and b.rec_context like '%%'

另外,这个'%%'似乎太多余了吧

直接删除and b.rec_context like '%%'

把这个语句咔嚓了,用连接看看,in的效率很低

like 太可怕了,一定要用,建立全文索引,用freetext

ps:你是什么数据库啊

还是想说一下exist的问题,你可以试试
select * from Temp_Tb_Vipinfo t where exist
(select * from Tb_Bussrecord b where t.zch=b.zch and b.rec_type=0)

这条语句的意思是这条记录如果存在t.zch=b.zch and b.rec_type=0
那么就返回这条记录
应该是对的