Quantcast
Channel: SCN: Message List - SAP Adaptive Server Enterprise (SAP ASE) for Custom Applications
Viewing all articles
Browse latest Browse all 3587

Re: How to delete many rows in a big table, but not all the rows ( truncate table can't be used in this case )

$
0
0

Unless this is an in-memory database (IMDB) you cannot disable logging.

 

Based on your other comments, and assuming you don't have a maintenance window of time where there's no activity against the table, and assuming this isn't part of a warm standby replication environment (where you could switch your application to the standby), your best bet is to set up a script that runs a loop, deleting a small batch of rows at a time until there are no more rows to delete.

 

You haven't mentioned how a) many rows are in the table, b) how many rows need to be deleted or c) how you determine which rows need to be deleted.  So a few recommendations ...

 

Deleting too many rows with a single DELETE statement can cause your locks to escalate to a table-level exclusive lock, which would block your application users.  So you'll want to delete a small number of rows at a time to minimize the blocking of application users.

 

If you delete too many rows in too short a period of time you can fill your log, which would lead to a suspension of application user activity until the checkpoint process runs (and truncates the log).  You can alleviate this problem by periodically putting your looping process to sleep (waitfor delay "HH:MM::SS") thus giving the checkpoint process time to come around and truncate the log.  Alternatively, since the database is marked with 'trunc log on chkpt' you could have your process periodically issue a 'dump tran/truncate only' to clear out the log.  Primary concern is to make sure you don't fill up your log (and block your application user activity) before the log can be truncated.

 

You may also want to look at how you plan on finding the rows that need to be deleted.  If you have to perform a table scan every time you delete a few rows then you'll want to consider using a table-scanning cursor to reduce the volume of IOs (ie, scan the table once instead of thousands/millions of times).  The cursor's WHERE clause will determine which rows to look for (to DELETE), while the select/projection list will contain the PK column(s) to be captured into local @variables.  You can then use these local @variables in the WHERE clause of the DELETE statement  to zero in on the desired row(s) to delete.


Viewing all articles
Browse latest Browse all 3587

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>