Re: Nested Transactions, Abort All - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: Nested Transactions, Abort All
Date
Msg-id 20040706162529.GE8235@dcc.uchile.cl
Whole thread Raw
In response to Re: Nested Transactions, Abort All  (Dennis Bjorklund <db@zigo.dhs.org>)
Responses Re: Nested Transactions, Abort All
Re: Nested Transactions, Abort All
Re: Nested Transactions, Abort All
List pgsql-hackers
On Tue, Jul 06, 2004 at 08:15:14AM +0200, Dennis Bjorklund wrote:
> On Mon, 5 Jul 2004, Alvaro Herrera wrote:
> 
> > > begin/end because they are already in an explicit/implicit transaction
> > > by default...  How is the user/programmer to know when this is the case?
> > 
> > I'm not sure I understand you.  Of course you can issue begin/end.  What
> > you can't do is issue begin/end inside a function -- you always use
> > subbegin/subcommit in that case.
> 
> I've not understood why we need new tokens for this case. Maybe you've 
> explained it somewhere that I've missed. But surely the server know if you 
> are in a transaction or not, and can differentiate on the first BEGIN and 
> the next BEGIN.

I think the best argument for this is that we need a command to abort
the whole transaction tree, and another to commit the whole transaction
tree.  Those _have_ to be ROLLBACK (or ABORT) and COMMIT (or END),
because the spec says they work like that and it would be hell for an
interface like JDBC if they didn't.  So it's out of the picture to use
those commands to end a subtransaction.

Now, it's clear we need new commands to end a subtransaction.  Do we
also want a different command for begin?  I think so, just to be
consistent.

Conclusion: we need a different syntax.  So we invent an extension.  

We could use BEGIN NESTED for starting a subtransaction, roll it back
with ROLLBACK NESTED or some such, and commit with COMMIT NESTED.  But I
like SUBBEGIN etc best, and no one had an opinion when I asked.  So the
current code has SUBBEGIN, SUBCOMMIT, SUBABORT.  If people prefer
another syntax, then we can have a vote or core hackers can choose -- I
don't care what the syntax is, but it has to be different from BEGIN,
COMMIT, ROLLBACK.

We can later implement savepoints, which will have "SAVEPOINT foo" and
"ROLLBACK TO foo" as interface.  (Note that a subtransaction is slightly
different from a savepoint, so we can't use ROLLBACK TO <foo> in
subtransactions because that has a different meaning in savepoints).

-- 
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"La rebeldía es la virtud original del hombre" (Arthur Schopenhauer)



pgsql-hackers by date:

Previous
From: Alvaro Herrera
Date:
Subject: Re: Nested Transactions, Abort All
Next
From: Yannick Lecaillez
Date:
Subject: Postgresql on SAN