日期:2014-05-16  浏览次数:21020 次

求教一个sql的性能
目前本人有一句sql大致如下
queue表中的数据每个批次并不相同,有时一百多,有时一万多
而 card 和 cis 数据量巨大 在千万和亿级别,tbl_1表中大概几万数据,card表中的唯一索引是 card_no ,cis 表中的唯一索引是 cis_no
现在有两种写法,不知道那种执行更快

select
a.card_no,
b.card_desc,
c.cis_name
from queue a , card b ,cis c , tbl_1 d
where a.card_no = b.card_no
and a.cis_no = c.cis_no
and a.col1 = d.col1
and 。。。。。
2

select
a.card_no,
(select b.card_desc
from card b
where a.card_no = b.card_no) card_desc,
(select
c.cis_name
from cis c
where a.cis_no = c.cis_no
) cis_name
from queue a , tbl_1 d
where a.col1 = d.col1
and 。。。。。
目前生产上用的是方法1链接用的是 nest loop,可是当queue表中的数据多的时候 ,走nest loop很伤,但是觉得如果改走hash的话 又由于 card 和 cis实在太大 ,开销太大,速度也慢
于是想用方法2 ,queue和tbl_1 用hash链接,而card_desc ,cis_name 改用子查询, 但是不知道速度是否会变快 ,各位大师可否给点指导意见,万分感谢

------解决方案--------------------
这也不是一定的,有时子查询效率高些,有时关联高些
------解决方案--------------------
第二种 肯定效率低。试试with as 语句或者使用oracle提示