On 2016/01/14 5:54 PM, Olivier Mascia wrote:
> Hello,
>
> Let a transaction (started with BEGIN TRANSACTION) which did only reads.
> Is it any better to end it by COMMIT TRANSACTION or ROLLBACK TRANSACTION, or 
> is it completely insignificant?
>

Those two statements do very different things, but in the case of *only 
reads* the effect is similar.  The differences inside SQLite (if both 
are not reduced to a no-op) will be very small to insignificant, but the 
differences to the programmer and code legibility is significant.

What if the day comes that you or another programmer decide to, even for 
test purposes, add a little update line to one such transaction/script? 
Either you might forgot that you were rolling back all the time and then 
run a program that now won't actually work, costing you a lot of time 
debugging, or you might know the rollback strategy is in place, and then 
have to change it, which now causes you time and effort, not to mention 
adding more untested code to your system with possible debugging time 
and errors creeping in.

Best thing to do in the code is stick to what is the sensible intent. If 
your intent isn't specifically to "undo" any changes, then don't use 
rollback.

If your system really needs to squeeze every ounce of speed out of a 
transaction, please test both methods for your specific transaction, 
note the faster one (if any), use it and document it very well for 
future. (It might work different for your specific transaction/script 
than for one of ours). I am however willing to bet the difference is 
insignificant and suggest always use the normal intended way - i.e. 
COMMIT, not ROLLBACK.

Cheers,
Ryan


Reply via email to