I need to delete approx. of 30 billion of rows from an Oracle table that has about 100 + billion of rows. I have all the IDs of the rows I need to delete in a temporary table. Currently I am using single delete statement as below, also using SUBPARTITION and created Index on the temp_table. However this took 4+ hrs to complete in PRODUCTION.
DELETE FROM table_name SUBPARTITION(subpartition_name) WHERE id IN (SELECT id FROM temp_table);
COMMIT;
Is there a way I can optimize this to run bit fast.
Just for a note :
- The oracle table I am referring is common for multiple clients, so the below option is not suitable here. Creating new table and move the required data into it and drop the old table followed by renaming the new table to old table.
- Delete in Batch : Looping over the temp table and deleting something like below, is taking more time in non-prod environment, and not sure how it goes in production env.
DECLARE
vCT NUMBER(38) := 0;
BEGIN
FOR t IN (SELECT id FROM temp_table) LOOP
DELETE FROM table_name WHERE id = t.id;
......
......
COMMIT;
END IF;
END LOOP;
COMMIT;
END;
- Option to create individual DELETE statement is also not feasible here as the record count is in Billions.
I did checked, there are partitions and sub-partitions on the table which I am utilizing it, and there is no child table dependent on it.
Please suggest.