DB2 10.5 on Windows Server
If I have something like this...
START TRANSACTION
CALL WEB SERVICE; (can take up to 8 seconds)
UPDATE TABLE1;
UPDATE TABLE2;
DELETE FROM TABLE3;
COMMIT TRANSACTION;
How would DB2 handle the tables during the life of the transaction? Would it only lock a table when the change is made or would if lock the tables at the start of the transaction? I am not familiar with DB2 transactions and while the IBM info pages describe how they work, none of it answers this question.
I am making the assumption that they are similar to transactions in SQL Server although I do see some references to SAVEPOINTS which I am not sure I understand. I think that might not apply to DB2 on windows.
Thank you so much for any help in advance.
Jim
Locking works similarly on most database engines these days, though the vendors use different terminology (just like they use different looking SQL)....
By default, DB2 will NOT lock a table to perform a change (update/insert/delete, etc.) Instead, DB2 will lock the row being changed. With just that single row locked, every other row in the table is available to every other task.
DB2 also utilizes something called "lock escalation". To reduce the number of locks being managed, DB2 will merge similar locks into a higher level lock, "escalating" the lock to the next larger group. If DB2 detects that a task has multiple row locks in the same block it can escalate the locks to a single page (block) lock, reserving every row in the page for the current task.
In your example, the UPDATE(s) to Table 1 all occur during the statement execution. When it completes, all of the row locks and page locks required to update Table 1 are held while the next statements in the transaction are executed. Only when the updates to all of the tables are complete does DB2 commit the changes and release the locks.
That's a little different from most clients (Developer Studio, TOAD, etc.) which usually commit the changes automatically after every statement.
Kent