2011-03-18 168 views
1

我有一个表(表1)与一些信息和字符串ID为什么此Sybase IQ更新声明如此之慢?

我有另一个表(表2)与一些更多的信息和类似的字符串ID(它缺少一个额外的字符在中间)。

我最初加入表上

t2.StringID = substring(t1.StringID,0,2)+substring(t1.StringID,4,7) 

但那是太慢了,所以我决定创建于表1,其已被映射到表2的PrimaryID那山坳新列,然后指数。

因此,要更新新的专栏中,我这样做:

select distinct PrimaryID, 
       substring(t2.StringID,0,2)+ 
       substring(t2.StringID,4,7)) as StringIDFixed 
into #temp 
from Table2 t2 

update Table1 tl 
set t1.T2PrimaryID = isnull(t.PrimaryID, 0) 
from Table1 t11, #temp t 
where t11.StringID = t.StringIDFixed 
and t1.T2PrimaryID is null 

它创造了几秒钟的临时表,但更新已现在运行了25分钟,我不知道这是否会甚至完成。

表1有45MM行,表2具有1.5MM

我知道这是数据的一个矮胖的量,不过,我觉得这不应该是那么难。

它是Sybase IQ 12.7

任何想法?

谢谢。

回答

3

在临时表上创建了一个索引,花了几秒钟,然后重新运行相同的更新,然后只花费了7秒。

create index idx_temp_temp on #temp (StringIDFixed) 

我讨厌Sybase。

+1

我的团队不是Sybase的粉丝。感谢您发布答案。 – 2011-04-07 14:19:32

1
select distinct isnull(t2.PrimaryID, 0), 
       substring(t2.StringID,0,2)+ 
       substring(t2.StringID,4,7)) as StringIDFixed 
into #temp 
from Table2 t2 

create HG index idx_temp_temp_HG on #temp (StringIDFixed) 
or 
create LF index idx_temp_temp_LF on #temp (StringIDFixed) 

--check if in Table1 exists index HG or LF in StringID if not.. create index 

update Table1 tl 
set t1.T2PrimaryID = t.PrimaryID 
from Table1 t11, #temp t 
where t11.StringID = t.StringIDFixed 

-- check if is necesary 
-- and t1.T2PrimaryID is null replace for t11.T2PrimaryID is null 
0

考虑用内连接取代您的更新以避免大数据集上的isnull()函数。

update Table1 
set a.T2PrimaryID = b.PrimaryID 
from  Table1 a 
inner join #temp b 
on a.StringID = b.StringIDFixed 
相关问题