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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Fastest way to batch delete data from a table with 1 billion rows

OraCJan 30 2021 — edited Jan 30 2021

Hi,
I need some help deleting batches from a really large online transactions table (up to 1 billion records). I hope to delete around 9 million records daily. 9 million more are being added daily. I have an off-peak time window when customer usage is limited so I can try to run this optimally, but I'm also conscious of not impacting any potential customers too much by specify too high a batch size below(10,000). Its Oracle 12.2 Standard Edition so unfortunately partitioning is not an option. I've come up with the following but its just not deleting fast enough. The initial select seems to be ok, its more about my loop. Is there a more efficient way of batching this?
DECLARE
cursor cur is
select /*+ index_ffs(a,P_ITD) parallel_index(a,P_ITD,4) */ C_ID from ITD a WHERE CREATED < '27-NOV-20 12.00.00.000000 AM';
TYPE CII_TYPE IS TABLE OF NUMBER;
CII_TYPE_TBL CII_TYPE;
BEGIN
OPEN CUR;
LOOP
FETCH CUR BULK COLLECT INTO CII_TYPE_TBL LIMIT 10000;
FORALL i IN 1..CII_TYPE_TBL.COUNT
DELETE FROM ITD WHERE C_ID=CII_TYPE_TBL(i);
COMMIT;
EXIT WHEN CUR%NOTFOUND;
END LOOP;
CLOSE CUR;
END;
/
P_ITD is the primary key constraint on the ITD table on C_ID
CREATED_ON is also indexed separately.
Thanks

Comments

843793
I can't remember exactly how it works, but I'm pretty sure you won't be allowed to compile code that breaks genericity.

Remember, a generic class provides genericity, but you provide the parameter. The only situation that breaks this is if member variables are public - which they shouldn't be.
843793
Hi,
According to the GJ specification, the compiler does store extra parameter information in the class files. There is a process called 'retrofitting' which allows to add this extra information to existing classes.
The Java 2 Collection classes which come with the generics compiler were retrofitted in this way. If, however, you use the 'raw types' it is possible to compile code which violates type constraints, and which will fail only at runtime (the compiler will give an unchecked warning, though).
843793
No its not a limitation but the nature of late binding. Sure you can use a precompiled class like it were a library and access the methods directly since you will know what the signatures are. You are within your rights to create as many illegal casts as you want. The point is Generics will not itself create any bad casts. Nobody can stop a mad programmer...
1 - 3

Post Details

Added on Jan 30 2021
25 comments
28,634 views