Apologies, this went to wrong mailbox first...
----------------------------------------------------------

Thank you very much for taking the time - this did answer my question.

If I may one more question related to this:  Let's say I am using transactions 
as validation stops on a long list of inputs - So
that the main program does some checking along the way, I have two choices, I 
can start with a BEGIN and do COMMIT at the very end,
and possibly ROLLBACK everything once I get an error and start over. 
Alternatively (and this is obviously what I want to do), I can
do BEGIN, then check say 1000 records, then COMMIT, then BEGIN, check 1000, 
COMMIT, etc. This way if I get an error, I need only
rollback a little bit.

The question is, how high is the overhead on BEGIN-COMMITs?
In other words... Should I try to maybe change the program to do all checking 
in one pass, then write to the DB in another pass?
(which is better if Transaction overhead is high, but worse if Transaction 
overhead is negligible).

Thanks again!

On 2013/06/08 17:16, Simon Slavin wrote:
 On 8 Jun 2013, at 3:35pm, RSmith<[email protected]>   wrote:
 These two pieces of code do not do the same thing.

 (A) talks about three sets of changes: one overall set, which includes two 
different subsets.  Consider you were updating your league tables after a day 
in which two tennis matches were played.  You need to make a change to details 
about match A, then a change to details about match B, and you also need to 
make changes to your league positions.  The change to details about  match A 
have nothing to do with the change to details about match B.  So you have 
released SAVEPOINT A before you start SAVEPOINT B.

 (B) talks about a nested set of changes.  You do not want the change to 
SAVEPOINT A to happen unless the change to SAVEPOINT B worked.  Here, suppose 
you are recording the result of a race.  You have to modify both the details of 
the race and the individual stats of the winner.  Here, if there is a problem 
with modifying the result of the race (SAVEPOINT B) then you need to make sure 
that you do not modify the stats of the individual runner (SAVEPOINT A)

 As you can see, the two options are suitable for different situations.  You 
should use whatever structure reflects the changes you are making.

 But your basic question was about how long these things took.  Assuming that 
you do reach RELEASE (and not ROLLBACK) on both, they will take near-enough the 
same time.  However, the BEGIN/COMMIT in (B) is not needed because all the 
changes made are in at least one SAVEPOINT.  Leaving it out may speed up your 
program slightly.  THe outer SAVEPOINT has exactly the same effect as having a 
BEGIN/COMMIT.

 Simon.


_______________________________________________
sqlite-users mailing list
[email protected]
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to