为什么此 Sybase IQ 更新声明如此缓慢?
我有一个表(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在临时表上创建索引需要几秒钟,然后重新运行相同的更新,然后只需要 7 秒钟。
我讨厌赛贝斯。
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.
I hate Sybase.
考虑用内部联接替换更新,以避免在大数据集上使用 isnull() 函数。
Consider replacing your update with an inner join to avoid the isnull() function on a big dataset.