Delete procedure gets slower and slower with fewer records
536286Sep 27 2006 — edited Sep 27 2006I have a stored procedure that purges a couple of tables, one with a FK to the other with ON DELETE CASCADE. When I first started the procedure it was deleting at a rate of 65K records per minute. I've found that the more records it deletes the slower it gets. It is now down to only 15K records per minute. Here are some pertinent facts about these two tables that may or may not influence your suggestion:
- The first table has 50 million records and the second has 100 million
- I've deleted 5 million records so far from the first table and 10 million from the second
- My goal is to trim the table down to the last 90 days worth of data, about 8 million records in the first table
- The second table has a nvarchar2(2000) field in it which I'm sure must slow things down
- the audit_datetime field is indexed
- the explain plan shows that it does a range scan on the audit_datetime index, it seems to be efficient
Here's the sql statement inside a loop, it deletes 1000 records at a time.
delete from first_table where rowid in
(select rowid from first_table where first_table.audit_datetime < to_date(sysdate - :days_to_keep) and rownum <= 1000)
Any suggestions that you can give are very appreciated.
Jeremy