L表数据量:77179753

J表数据量:42201

原表left join :

select count(1) from l left join j on j.userID=l.userid 
where l.appID=1000 and l.loginTime>='2018-01-01' and l.loginTime<'2018-02-01'

等半天不出结果!



临时

表left join :


select l.* into #tmp
from l where l.appID=1000 and l.loginTime>='2018-01-01' and l.loginTime<'2018-02-01'

select count(1) from #tmp l left join j on j.userID=l.userid

查询结果:45459


速度很快!