If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Bulk update vs Individual update

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-27-10, 13:54
db2user24 db2user24 is offline
Registered User
 
Join Date: Nov 2007
Posts: 248
Bulk update vs Individual update

Hi,

If I have readings in a table and want to divide the values by some number, is it true that iterating through the range ( which can be 1 day, 1 week, 1 month, 6 months.. anything) and using the update command for each individual row is a better idea than a bulk update for the whole range? Would it put less of a 'burden' on the server if I go the individual update route?

here is an example of the command --
update <tablename> set readingval = readingval / <number> where .....

thanks!!
Reply With Quote
  #2 (permalink)  
Old 07-27-10, 14:04
dav1mo dav1mo is offline
Registered User
 
Join Date: Dec 2007
Location: Richmond, VA
Posts: 782
The problems with doing something like this in its entirety is the locking and logging. Can your application handle not being to access a large block of pages in this table (depending on the range you are updating) without your users crying foul? Are your logs large enough to handle all of the logging (again, depending on the size of the range you are dealing with)?
By running a cursor, then updating each row returned, you can add commit after n updates and restart logic. By doing this you are allowing other users access to the information you are updating either after/before you get to it. The restart logic would allow you to pick back up where you left off if the process were to abort or you had to cancel it for some reason.
Dave
Reply With Quote
  #3 (permalink)  
Old 07-27-10, 14:45
db2user24 db2user24 is offline
Registered User
 
Join Date: Nov 2007
Posts: 248
thanks for the response.. I forgot to mention that this is being done in a stored procedure and the table that is being accessed is a global temp table. I think the cursor method with commit is probably the best way too.. how can I check if the logs are large enough to handle the logging? will something like this work --

--update statement
SET updateStatement = 'UPDATE <table> SET val = val / ? WHERE Id = ? AND
datetime > ? and datetime <= ?';


PREPARE s1 FROM updateStatement;

WHILE (startInterval <= endTime) DO
BEGIN
EXECUTE s1 USING param_val, param_id, param_start, param_end;

SET startInterval = --- new start interval
SET endInterval = ---- new end interval

<<ADD COMMIT HERE >>
END;
END WHILE;
Reply With Quote
  #4 (permalink)  
Old 07-28-10, 07:34
stolze stolze is offline
Registered User
 
Join Date: Jan 2007
Location: Jena, Germany
Posts: 2,662
If it is a temp table, you don't have to care about logging because operations on such tables are not logged.
__________________
Knut Stolze
IBM DB2 Analytics Accelerator
IBM Germany Research & Development
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On