为什么此 Sybase IQ 更新声明如此缓慢?

发布于 2024-10-24 01:06:47 字数 822 浏览 4 评论 0原文

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

我还有另一个表(Table2),其中包含更多信息和一个类似的字符串 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

有什么想法吗?

谢谢。

I have one table (Table1) with some info and a string ID

I have another table (Table2) with some more info and a similar string ID (it is missing an extra char in the middle).

I was originally joining the tables on

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

But that was too slow, so I decided to create a new column on Table1 which is already mapped to the PrimaryID of Table2, and then index that col.

So, to update that new column I do this:

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  

It creates the temp table in a few seconds, but the update has been running for 25 minutes now, and I dont know if it will even ever finish.

Table 1 has 45MM rows, Table 2 has 1.5MM

I know that's a chunky amount of data, but still, i feel like this shouldnt be that hard.

It's Sybase IQ 12.7

Any ideas?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

你在看孤独的风景 2024-10-31 01:06:47

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

create index idx_temp_temp on #temp (StringIDFixed)

我讨厌赛贝斯。

Created an index on the temp table which took a few seconds, and then re ran the same update which then only took 7 seconds.

create index idx_temp_temp on #temp (StringIDFixed)

I hate Sybase.

夜光 2024-10-31 01:06:47
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  
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  
迷雾森÷林ヴ 2024-10-31 01:06:47

考虑用内部联接替换更新,以避免在大数据集上使用 isnull() 函数。

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

Consider replacing your update with an inner join to avoid the isnull() function on a big dataset.

update Table1 
set a.T2PrimaryID = b.PrimaryID
from        Table1  a
inner join  #temp   b
on a.StringID = b.StringIDFixed
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文