千万数据量update优化?

[复制链接]
查看11 | 回复9 | 2005-11-4 08:50:09 | 显示全部楼层 |阅读模式
oracle

ra9201
table: test24千万
table: test11千万
功能:
update test1
set test1.c2 = (select test2.c2 from test2 where test2.c1 = test1.c1)
请问从性能上考虑,应该怎样update.?
怎么以最快的时间完成update..
回复

使用道具 举报

千问 | 2005-11-4 08:50:09 | 显示全部楼层
从实际意思上,至少外边应该加个条件吧,不然就全给UPDATE了
update test1
set test1.c2 = (select test2.c2 from test2 where test2.c1 = test1.c1)
where test1.c1 in (select test2.c1 from test2);
回复

使用道具 举报

千问 | 2005-11-4 08:50:09 | 显示全部楼层
建议使用分区表。
回复

使用道具 举报

千问 | 2005-11-4 08:50:09 | 显示全部楼层
如果这样考虑的话,还需要加一个条件
update test1
set test1.c2 = (select test2.c2 from test2 where test2.c1 = test1.c1 )
whereexists (select 1 from test2 where test2.c1=test1.c1and test1.c2test.c2)
数据量没有太大的差异情况下,最好不要用IN 或NOT IN
回复

使用道具 举报

千问 | 2005-11-4 08:50:09 | 显示全部楼层
分段更新
回复

使用道具 举报

千问 | 2005-11-4 08:50:09 | 显示全部楼层
partition by c1
回复

使用道具 举报

千问 | 2005-11-4 08:50:09 | 显示全部楼层
1.Create table test1_dup
as select distinct a,.. b a... , b.c2
from test1 a, test2 b
where a.c1 = b.c2(+)
2.create index / grant on test1_bak
3.drop test1
4.rename test1_bak to test1
回复

使用道具 举报

千问 | 2005-11-4 08:50:09 | 显示全部楼层
最初由 rollingpig 发布
[B]1.Create table test1_dup
as select distinct a,.. b a... , b.c2
from test1 a, test2 b
where a.c1 = b.c2(+)
2.create index / grant on test1_bak
3.drop test1
4.rename test1_bak to test1 [/B]

谢谢各位发言
这样的资料量需要每天更新一次,要写成一次procedure.
rollingpig做法,我在>(itpub)
拜读过.
但是这样需要手动去做.
公司希望每天自动更新.?
回复

使用道具 举报

千问 | 2005-11-4 08:50:09 | 显示全部楼层
写一个存储过程,用游标作
回复

使用道具 举报

千问 | 2005-11-4 08:50:09 | 显示全部楼层
rollingpig的方法也可以使用存储过程来实现,使用动态sql,不过drop操作可能会影响其它
使用到这个表的程序,导致其无效,需重新编译,这个你要综合考虑了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行