Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Need help improving performance with bulk collect

1008849May 21 2013 — edited May 21 2013
Hi,
I need help improving the performance with bulk collect. I've a column added to a fact table with 7million records. I'm trying to update that new column by joining to a mapping & staging table. The fact table is partitioned using range partition and staging table is partitioned is using hash partition.

It with bulk collect i'm able to complete the update to fact table in 2hrs. In Prod we have 4 times the data, so it would take ideally 8hrs which is not acceptable. Is there a way i can achieve parallelism in bulk collect and make the code run a bit faster.

Oracle version 11.2
PROCEDURE update_fact_tab
AS
	CURSOR cur_update_fact_tab
	IS
	SELECT ftr.id_t, mtran.id_source
	FROM stag_tab stg,fact_tab ftr,mapping_tab mtran
	WHERE stg.ext_id=ftr.ext_id
	AND   stg.seq_num=ftr.seq_num
	AND   stg.ext_sys_id=mtran.ext_sys_id
	AND   ftr.id_t_source in (1,2)
	AND   stg.prefix = 'R';
	
    l_count PLS_INTEGER;
    
    type ids_t is table of pls_integer index by binary_integer;    
    type string_t is table of varchar2(255) index by binary_integer; 

    l_id_t ids_t;
    l_id_source ids_t;
    
    BEGIN
    l_count :=0;
		
	OPEN cur_update_fact_tab;
	LOOP
		FETCH cur_update_fact_tab BULK COLLECT INTO l_id_t,l_id_source LIMIT 50000;
		EXIT WHEN l_id_t.COUNT = 0;
		
			FORALL i in 1..l_id_t.count
				
			update fact_tab
			set id_source=l_id_source(i)
			where id_t=l_id_t(i);
			
			COMMIT;
			
			l_count := l_count+l_id_t.COUNT;

			IF (MOD (l_count + 1, 500000) = 1 and l_count <> 0) THEN
			 sp_log ('done another 500000. total :'  || l_count);
			END IF;
			
	END LOOP;
	
	CLOSE cur_update_fact_tab;
	
END update_fact_tab;	
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 18 2013
Added on May 21 2013
10 comments
1,050 views