Git Product home page Git Product logo

bigdelete's Introduction

bigdelete

bigdelete handles lots of deletes from and Oracle table

When the amount of data to be deleted from an Oracle table gets really big, the usual approaches may not work anymore:

  • simple DELETE statetemt with or without a WHERE clause: may cause huge UNDO usage, table scans which take forever etc
  • "create table as select" from the original table and rename the new and old tables: not an online operation
  • TODO online move table, with or without a WHERE clause
  • TODO describe other mothods I tried and why they failed

With bigdelete I am following this approach:

  • generate a list of ROWIDs to be deleted from a table; save them in a file
  • call bigdelete, piping the list of ROWIDs to it.
  • bigdelete opens a number of parallel sessions (the -threads parameter) and in each one deletes N ROWIDs at a time (the -commit parameter), using the ROWIDs from its standard input, until all are deleted.
  • the process for each sessions is:
    • insert N ROWIDs into a temp table (called bigdeletemp)
    • run "delete from target_table where rowid in (select rid from bigdeletetemp)
    • commit
    • repeat until no more ROWIDs read in stdin

I needed the operation to be totally online, just as if someone would have deleted the records

  • Note that the list of ROWIDs could be generated on the fly (maybe with a script calling sqlplus) and then have this output piped to bigdelete. However this will likely be a problem because the cursor used to extract the ROWIDs will still be open when data will start to be deleted, and this will be very slow because of the UNDO needed for keeping this cursor consistent and for the delete itself.

Version history information:

version 1: delete from table where rowid in (a,b,c...), max 1000

executed in N sessions

SQLs are not reused - lots of hard parses

version 2: prepare insert statement

truncate table bigdeletetemp - if not temp table with delete on commit
insert into bigdeletetemp values (a)
insert into bigdeletetemp values (b)
insert into bigdeletetemp values (c)
...
commit (?)
start transaction
delete from table where rowid in (select rid from bigdeletetemp)
commit transaction

executed in N sessions

SQLs are reused

bigdeletetemp table is hardcoded - it can be a synonym to any table with the structure:

drop table bigdeletetemp; create global temporary table bigdeletetemp (rid rowid) on commit delete rows;

DB transactions in Go: https://go.dev/doc/database/execute-transactions

bigdelete's People

Contributors

valrusu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.