After all, I achieved the best performance so far moving one billion rows from my source to target table and my PO is happy with this but, I am thinking if there is a better way of doing it?
Here is my code snippet, Thanks to marmiteBomber for correcting my script here.
DECLARE
v_parallel_degree NUMBER := 8;
PROCEDURE MOVE_DATA(p_target_tabname VARCHAR2,
p_source_tabname VARCHAR2,
p_part_name VARCHAR2)
AS
BEGIN
EXECUTE IMMEDIATE 'INSERT /*+PARALLEL(DEFAULT)*/ INTO '|| p_target_tabname || ' NOLOGGING
SELECT /*+PARALLEL(dmf,DEFAULT)*/*
FROM ' || p_source_tabname ||' PARTITION('|| p_part_name ||');
END;
BEGIN
EXECUTE IMMEDIATE 'ALTER SESSION ENABLE PARALLEL DML';
EXECUTE IMMEDIATE 'ALTER SESSION FORCE PARALLEL QUERY PARALLEL ' || v_parallel_degree;
EXECUTE IMMEDIATE 'ALTER SESSION FORCE PARALLEL DDL PARALLEL ' || v_parallel_degree;
EXECUTE IMMEDIATE 'DROP INDEX idx_pk';
FOR i IN (SELECT partition_name
FROM DBA_PARTITIONS
WHERE table_name = 'MYSOURCETABLE')
LOOP
MOVE_DATA('MYTARGETTABLE','MYSOURCETABLE',i.partition_name);
END LOOP;
EXECUTE IMMEDIATE 'CREATE UNIQUE INDEX idx_pk ON MYTARGETTABLE
(COL1,COL2,COL3)
LOCAL
NOLOGGING PARALLEL ' || v_parallel_degree;
END;
Now with this code, creating the index after the insert is taking around 1 hour. I have done some research and found instead of drop and create the index on the partition table, we can set the index to UNUSABLE and rebuild the same. But in my case after modifying the index to UNUSABLE I am not able to insert the data and facing an exception ORA-01502: index … or partition of such index is in unusable state
If I get this strategy to work, I have a plan to submit a job which will start a new session to rebuild the index and continue to my next partition in the current session.
Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
PL/SQL Release 12.1.0.2.0 - Production
CORE 12.1.0.2.0 Production
will be upgraded to 19c.
Any suggestions are appreciated in advance.
Thanks VB