我在SYBASE库中执行如下SQL,很久没有反应

A表32万记录,B表2万记录
其中col2是A表的主键 ;col5是B表的索引;col5在表中的重复率非常低 ,
执行如下SQL
select A.col2
from A,B
where B.col1='B'
and B.col2='B'
and B.col3='C'
and B.col4='dfdfdf'
and A.col2=B.col5
但20分钟后还没出来
[299 byte] By [toadnet-哓哓] at [2008-6-4]
# 1
select A.col2
from A
where A.col2 in (select B.col5 from B where B.col1='B'
and B.col2='B'
and B.col3='C'
and B.col4='dfdfdf'
)
可能能够快一些.
试一试?
nana11-汉堡 at 2007-10-22 > top of Msdn China Tech,其他数据库开发,Sybase...
# 2
select col5
from B
where col1='B'
and col2='B'
and col3='C'
and col4='dfdfdf'
and exists (select 1 from a where A.col2=B.col5)
看看这个语句的结果和效率!

Yang_-扬帆破浪 at 2007-10-22 > top of Msdn China Tech,其他数据库开发,Sybase...
# 3
对你的B表建索引(COL1,COL2,COL3,COL4)将会提高速度至少一个数量级!
Yang_-扬帆破浪 at 2007-10-22 > top of Msdn China Tech,其他数据库开发,Sybase...
# 4
这种SQL语句不经常用,但经常更新。若对其建索引,那么对更新影响较大。
toadnet-哓哓 at 2007-10-22 > top of Msdn China Tech,其他数据库开发,Sybase...
# 5
写一个过程
create procedure t
as

select distinct col5 as col5 into #t from B
where B.col1='B' and B.col2='B'and B.col3='C' and B.col4='dfdfdf'

select A.col2 from A,#t where A.col2=#t.col5
;
效率肯定不错
kaikaihe-开开 at 2007-10-22 > top of Msdn China Tech,其他数据库开发,Sybase...