Re: Explicit subtransactions for PL/Tcl

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Victor Wagner <vitus(at)wagner(dot)pp(dot)ru>
Cc: PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Explicit subtransactions for PL/Tcl
Date: 2017-03-08 15:49:33
Message-ID: CAFj8pRBk9ji+5=jAb8s+0=fdCyz60MvPEchmW4jqx=XjDjH4zA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi

2017-01-08 18:57 GMT+01:00 Victor Wagner <vitus(at)wagner(dot)pp(dot)ru>:

>
> Collegues!
>
> Recently I've found out that PL/Python have very nice feature - explicit
> subtransaction object, which allows to execute block of code in the
> context of subtransaction.
>
> I've quite surprised that other PL languages, shipped with PostgreSQL do
> not have such useful construction.
>
> If it might require considerable trickery to add such functionality into
> PL/Perl, Tcl allows to add new control stuctures very easily.
>
> I'm attaching the patch which implements subtransaction command for
> PL/Tcl which does almost same as PL/Python plpy.subtransction context
> manager object does: executes a block of Tcl code in the context of
> subtransaction, rolls subtransaction back if error occures and commits
> it otherwise.
>
> It looks like
>
> subtransaction {
> ...some Tcl code...
> }
>
> Typically one would use it inside Tcl catch statement:
>
> if [catch {
> subtransaction {
> spi_exec "insert into..."
> ...
> }
> } errormsg] {
> # Handle an error
> }
>
> See documentation and tests included in the patch for more complete
> examples.
>
> Just like corresponding Python construction, this command doesn't
> replace language builtin exception handling, just adds subtransaction
> support to it.
>
> Patch includes sufficiently less tests than python subtransaction tests,
> because Tcl implementation is way simpler than python one, and doesn't
> have syntactic variatons which depend on language version.
>
> Also entering and exiting subtransactions are in the same piece of code
> rather than in separate __enter__ and __exit__ methods as in Python, so
> there is no possibility to call exit without enter or vice versa.
>

I did a review of this patch

1. This functionality has sense and nobody was against this feature.

2. This patch does what is proposed - it introduce new TCL function that
wraps PostgreSQL subtransaction

3. This patch is really simple due massive using subtransactions already -
every SPI called from TCL is wrapped to subtransaction.

4. A documentation is good - although I am not sure if it is well
structured - is <sect2> level necessary? Probably there will not be any
other similar command.

5. There are a basic regress tests, and all tests passed, but I miss a
path, where subtransaction is commited - now rollback is every time

6. The code has some issues with white chars

7. I don't understand why TopMemoryContext is used there? Maybe some
already used context should be there.

+<->BeginInternalSubTransaction(NULL);
+<->MemoryContextSwitchTo(TopTransactionContext);
+<->

Regards

Pavel

>
> --
> Victor Wagner <vitus(at)wagner(dot)pp(dot)ru>
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2017-03-08 15:59:09 Re: new gcc 7.0.1 warnings
Previous Message Andreas Karlsson 2017-03-08 15:34:55 Re: REINDEX CONCURRENTLY 2.0