Re: Nested Transactions, Abort All

From: Alvaro Herrera <alvherre(at)dcc(dot)uchile(dot)cl>
To: Dennis Bjorklund <db(at)zigo(dot)dhs(dot)org>
Cc: Thomas Swan <tswan(at)idigx(dot)com>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Nested Transactions, Abort All
Date: 2004-07-06 16:25:30
Message-ID: 20040706162529.GE8235@dcc.uchile.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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)

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Stephen Frost 2004-07-06 16:49:46 Re: Nested Transactions, Abort All
Previous Message Yannick Lecaillez 2004-07-06 16:17:16 Postgresql on SAN