On 8 Jun 2013, at 3:35pm, RSmith <[email protected]> wrote:

> A) so to have:
> BEGIN
>  SAVEPOINT A
>  ...
>  RELEASE A
>  SAVEPOINT B
>  ...
>  RELEASE B
>  ...
> COMMIT;
> 
> B) or to have:
> BEGIN
>  SAVEPOINT A
>   ...
>    SAVEPOINT B
>      ...
>    RELEASE B
>  ...
>  RELEASE A
> COMMIT;
> 
> I realise both ways have code efficiency issues, but just is there a real 
> execution speed difference?

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