一个关于sql效率的问题。
我这边有一个sql:
select * from tab1 where id in (select id from tab2 where ???) or type = 'aa'
这个sql 执行的效率相当低。一般都要花1。5-2秒,tab1中的数据也不是很多,也才1w多点。tab2就更少了。
我试着把 or type = 'aa'去掉,速度很快,几十毫秒。
仅把id in (select id from tab2 where ???) 去掉,速度也快。
仅把select id from tab2 where ??? 改成把这条语句查出来的值直接写进去,也是很快。
但是放在一起就变的很慢了。