|
数据表:
sol_defects 10万行
sol_runcard 99万行
SQL1:
select d.*
from sol_runcard r, sol_defects d
where d.sn_key = r.sn_key
and d.seq# = 1
and d.ws_id <> 11
and r.wo_key = 86810;
数据4行,执行时间31妙;
SQL2:
select d.*
from sol_runcard r, sol_defects d
where d.sn_key = r.sn_key
--and d.seq# = 1
and d.ws_id <> 11
and r.wo_key = 86810;
数据5行,执行时间2妙;
仅仅增加了一个Number字段条件进行过滤,性能相差就又如此大。
使用执行计划进行跟踪,发现SQL1使用的是Merge Join, 而SQL2使用的是Hash Join。请问高手这是怎么回事?
我现在使用强制Hash,执行速度是4秒,SQL如下:
select /*+ use_hash(d,r)*/d.*
from sol_runcard r, sol_defects d
where d.sn_key = r.sn_key
and d.seq# = 1
and d.ws_id <> 11
and r.wo_key = 86810;
还有其他办法吗?让速度尽量快起来。 |
|