1

いくつかの情報と文字列 ID を持つ 1 つのテーブル (Table1) があります。

いくつかの詳細情報と同様の文字列 ID を持つ別のテーブル (Table2) があります (中間に余分な文字がありません)。

私はもともとテーブルに参加していました

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

しかし、それは遅すぎたので、既に Table2 の PrimaryID にマップされている新しい列を Table1 に作成し、その列にインデックスを付けることにしました。

したがって、その新しい列を更新するには、次のようにします。

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 に答える