1、现在有TABLEA表,该表中有三百万条数据,要将TABLEA表中数据导到TABLEB中,在插入之前已经将TABLEB表中索引删除,我现在是用merge into 实现的,速度非常慢;
merge into tableb b
using (select phone
from tablea) b
on (a.phone= b.phone)
when matched then
update set a.phone = a.phone
when not matched then
insert(a.phone) values(b.phone);
2、现在有TABLEC表,该表中有千万条数据,如果UPDATE TABLEC全表的话,用语句:update tableb set readmail = readmail || ',3'很慢;
请教高手我要实现这两个功能,该如何优化以达到速度最快最优效果?
真诚的感谢每一位回复的人,谢谢。
merge into tableb b
using (select phone
from tablea) b
on (a.phone= b.phone)
when matched then
update set a.phone = a.phone
when not matched then
insert(a.phone) values(b.phone);
2、现在有TABLEC表,该表中有千万条数据,如果UPDATE TABLEC全表的话,用语句:update tableb set readmail = readmail || ',3'很慢;
请教高手我要实现这两个功能,该如何优化以达到速度最快最优效果?
真诚的感谢每一位回复的人,谢谢。
when matched时,不做处理。。
TABLEC中的相关索引先删除再执行
merge into tableb b
using (select phone
from tablea) a --不好意思,之前这里写错了。。
on (a.phone= b.phone)
when matched then
update set a.phone = a.phone
when not matched then
insert(a.phone) values(b.phone);
select phone from tablea a
where not exists(select 1 from tableb where phone=a.phone)
tablea,tableb三表都只有一个字段 phone,phone主键
tablec表有两字段,phone和readmail,phone主键更正下问题2:
2、现在有TABLEC表,该表中有千万条数据,如果UPDATE TABLEC全表的话,用语句:update tablec set readmail = readmail || ',3'很慢;
alter table TABLEB nologging;
insert /*+ APPEND */ into TABLEB SELECT 。。
alter system tableb disable all triggers;
执行完毕之后,启动触发器
alter system tableb enable all triggers;2,除了主键索引之外,tableb表剩余的索引全部删除掉。等执行完毕之后,重建索引(索引重建很快,我的800万数据的表的6个索引重建才花了2分钟而已)3,用批量操作语句,
insert into tableb select ......;
update tableb b set b.update tableb set readmail = readmail || ',3';
tablec表有两字段,phone和readmail,phone主键
能不能在后续的处理过程中稍微处理一下呢,譬如select readmail||',3' from TABLEC
using tablea a
on (a.phone= b.phone)
when not matched then
insert(b.phone) values(a.phone); 这样不就行了吗
insert /*+ append */ into tableb.....2.create table test nologging as select readmail||',3' from TABLEC;
drop table TABLEC;
alter table test rename to TABLEC;
试试when matched then
update set a.phone = a.phone where 1=2
能否后面跟条件
set a.phone = a.phone 这个不必要的更新会降低效率
9i必须指定when matched then
6楼的就是批插入,以phone建立索引或主健,不要删除