1

我有一个包含一些信息和字符串 ID 的表(Table1)

我有另一个表(表 2),其中包含更多信息和类似的字符串 ID(中间缺少一个额外的字符)。

我最初是在

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

但这太慢了,所以我决定在 Table1 上创建一个新列,该列已经映射到 Table2 的 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

有任何想法吗?

谢谢。

4

3 回答 3

3

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

create index idx_temp_temp on #temp (StringIDFixed)

我讨厌赛贝斯。

于 2011-03-18T14:03:21.120 回答
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  
于 2011-04-27T02:22:15.580 回答
0

考虑用内部连接替换更新以避免大数据集上的 isnull() 函数。

update Table1 
set a.T2PrimaryID = b.PrimaryID
from        Table1  a
inner join  #temp   b
on a.StringID = b.StringIDFixed
于 2013-10-21T09:52:28.553 回答