insert into pntmall_point_detail(PNTMALL_PNT_ID, ........... HPT_LEFT_POINT,HPT_FULLREDEMPT_STATUS) SELECT PNTMALL_PNT_ID,.......,PNTMALL_NUM,0 FROM pntmall_point_detail_tmp a WHERE NOT EXISTS (SELECT b.PNTMALL_PNT_ID FROM pntmall_point_detail b WHERE a.PNTMALL_PNT_ID = b.PNTMALL_PNT_ID);
PNTMALL_POINT_DETAIL包含3800万条数据,cost 6 hours。
优化后
delete from pntmall_point_detail_tmp a where exists (select 1 from pntmall_point_detail b where a.PNTMALL_PNT_ID = b.PNTMALL_PNT_ID); insert into pntmall_point_detail(PNTMALL_PNT_ID, ........... HPT_LEFT_POINT,HPT_FULLREDEMPT_STATUS) SELECT PNTMALL_PNT_ID,.......,PNTMALL_NUM,0 FROM pntmall_point_detail_tmp a
cost 5 minutes。
其实还可以进一步优化
drop indexBER.INDEX_POD_PNTMALL_HAIERUID; drop indexBER.PNTMALL_POINT_ID_HAIERUID; delete from pntmall_point_detail_tmp a where exists (select 1from pntmall_point_detailb where a.PNTMALL_PNT_ID =b.PNTMALL_PNT_ID); insert/*+append*/into pntmall_point_detail(PNTMALL_PNT_ID,.... HPT_LEFT_POINT,HPT_FULLREDEMPT_STATUS) SELECT PNTMALL_PNT_ID,....,PNTMALL_NUM,0 FROM pntmall_point_detail_tmp a; create index BER.INDEX_POD_PNTMALL_HAIERUID on BER.PNTMALL_POINT_DETAIL (PNTMALL_HAIERUID) online nologing; create unique index BER.PNTMALL_POINT_ID_HAIERUID on BER.PNTMALL_POINT_DETAIL (PNTMALL_PNT_ID) online nologing;
总体优化思路,不要在insert中加入过多的判断语句,删索引,append,重建索引,如果是归档模式,alter table nologing;append 只适用于insert select 这种方式,而且insert后要加commit,否则无法进行其他DML操作。
实测 append 1600万条数据,cost 8s
时间: 2024-10-24 11:56:51