Subject Re: [Firebird-Architect] Autonomous Transaction Routines
Author Adriano dos Santos Fernandes
Nando Dessena escreveu:
> Adriano,
> I understand the requirements for the autonomous transaction feature.
> I am not sure why it should be linked to routines, though. Wouldn't it
> be better to allow for BEGIN TRANSACTION, COMMIT and ROLLBACK
> statements in PSQL? It will give all advantages of your idea, plus:
>
> a) ability to execute only part of a trigger or SP in an autonomous
> transaction;
>
> b) ability to execute an anonymous block in an autonomous transaction
> (admittedly not terribly useful, if not to avoid the need to process
> COMMIT and ROLLBACK on the client for simple scripts);
>
...
> c) ability to execute more than one SPs in the same autonomous
> transaction, without having to wrap them into a single calling SP.
>
This point is not wrong with routines, since one autonomous routine
could call a non-autonomous procedure and the second one will run inside
the same transaction of the caller.

If both are autonomous, two independent transactions should be started.

> Maybe, instead of BEGIN TRANSACTION and COMMIT/ROLLBACK (which would
> also require a WHEN..DO block for rollback), a more compact syntax
> could be invented, such as:
>
> BEGIN AUTONOMOUS TRANSACTION
>
> ... code here
>
> END AUTONOMOUS TRANSACTION -- commits.
>
I really like your suggestion.

This one is more powerful and don't require ODS changes or client
changes (metadata extraction).

But if we go this way, we need to be more careful at implementation
details, for example cursors should not be allowed to be accessed in two
different transactions, I suppose.

> P.S. I have a fear that this is a feature very easy to misuse, but I guess
> Firebird can't do much about that except produce good documentation
> that lists the cases in which to use autonomous transactions, and the
> cases in which it's better to avoid them.
Yes, the user should use it with caution to:
1) not start many transactions
2) prevent deadlocks

But this is something users already should care at client application side.


Adriano