Skip to Main Content
  • Questions
  • Best practice to delete large volumn of data

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Salman Khan.

Asked: January 18, 2023 - 1:00 pm UTC

Last updated: January 18, 2023 - 1:33 pm UTC

Version: 12c

Viewed 100+ times

You Asked

Hi,

I have a use case where my table contains ~19 million records and the performance is slow now. I have old data as well in the data and I can easily remove old data.
Now I have two possibilities, either prepare delete queries with limit or create partition say on monthly basis and then delete the partition.
As per my know with delete queries the table space will not be reclaimed automatically but with partition deletion it would.

Kindly suggest a better way considering the above scenario.

and Chris said...

There are several things you could try:

- A filtered table move (ALTER TABLE ... MOVE INCLUDING ROWS WHERE ...); added in 12.2
- Using CREATE TABLE AS SELECT to "delete" data
- Partition drop/truncate

I discuss these in detail at:

https://blogs.oracle.com/sql/post/how-to-delete-millions-of-rows-fast-with-sql

More to Explore

SQL

The Oracle documentation contains a complete SQL reference.