christian wrote:
Ok, that was a trick question. I know what you mean. Here is why it's useful:
1. You do an INSERT and you commit it.
2a. You start a new transaction and DELETE the row.
2b. The DELETE commit fails.
Your conversation state is the same after step 1 and after step 2b. You lost nothing.
Would you rather not even try? Wouldn't you say that 2b is extremely rare, rare enough to justify that this exceptional state gets exceptional handling by the user?
It depends on what you mean under "lost". Yes, you do not loose the records but you obtain the garbage - inserted orphan records and this means that the database is not in consistent state anymore - we lost consistent state.
Here we do not need to try because (luckily) we know in advance what happens: data will be not in consistent state very soon. For the sake of discussion I can tell about one real example. I worked on the project which had to provide
(for some transition time) an interface
(bridge) from the existing database repository to the new I2 supply management software. At that time they had two pieces - one theirs with an (Java) API and another from the acquired company where there was no API to access I2 repository. I needed to use both parts of this software. They suggested to use JDBC for the second part. But it was obvious that there would be two separate connections that had to be run in one transaction. They suggested to rollback one transaction and manually
(in code) undo the results the second one. I pointed out immediately that it would not work, but the customer insisted on the suggested implementation. The reality was garbage records surfaced on the first test run.
Another thing. According this books recommendation we can similarly obsolete two phase commit for multiple resources - rollback one and undo others
(on the grounds "extremely rare" let say if we have two resources). Who is going to buy it - rhetorical question. Going further we see that embedding transaction management in the database kernel is not simply convenience but rather necessity - we can not rollback manually by undoing partly failed action.
As far as I am concerned this "solution" should be eliminated from this excellent book.