pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Fujii Masao <masao.fujii@oss.nttdata.com>
To: Arthur Nascimento <tureba@gmail.com>
To: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #16867: savepoints vs. commit and chain
Date: Tue, 16 Feb 2021 13:49:33 +0900
Message-ID: <473dba6b-dfb3-b5a8-93c6-af3787893728@oss.nttdata.com> (raw)
In-Reply-To: <CALVFHFaBUXnCxv2kfG67=3NR=WPkVGgE_5Cf9S-LDPNYAwUORQ@mail.gmail.com>
References: <16867-3475744069228158@postgresql.org>
	<CALVFHFaBUXnCxv2kfG67=3NR=WPkVGgE_5Cf9S-LDPNYAwUORQ@mail.gmail.com>



On 2021/02/16 6:47, Arthur Nascimento wrote:
> On Mon, 15 Feb 2021 at 17:54, PG Bug reporting form
> <noreply@postgresql.org> wrote:
>> On a trivial transaction, I might do:
>>
>> =# begin;
>> *=# commit and chain;
>> *=# -- In this point I'm inside a second transaction
> 
> I forgot to mention that this case also works as expected:
> 
> =# begin;
> *=# savepoint foo;
> *=# release foo;
> *=# commit and chain;
> *=# -- In this point I'm also inside a second transaction
> 
> So it's only the unmatched savepoint/release transactions that are an issue.
> 
> I also attached the change I did to psql locally.

LGTM.

> But since it didn't
> solve the issue, it's mostly for curiosity's sake.

In the server side, ISTM that CommitTransactionCommand() needs to handle
the COMMIT AND CHAIN in TBLOCK_SUBCOMMIT case, but it forgot to do that.
Patch attached. I'm not sure if this is a bug or an intentional behavior.
Probably we need to look at the past discussion about AND CHAIN feature.

Regards,

-- 
Fujii Masao
Advanced Computing Technology Center
Research and Development Headquarters
NTT DATA CORPORATION

Attachments:

savepoint_and_chain.patch (text/plain, 2.5K) download diff --git a/src/backend/access/transam/xact.c b/src/backend/access/transam/xact.c index 17fbc41bbb..4e6a3df6b8 100644 --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -3105,6 +3105,13 @@ CommitTransactionCommand(void) Assert(s->parent == NULL); CommitTransaction(); s->blockState = TBLOCK_DEFAULT; + if (s->chain) + { + StartTransaction(); + s->blockState = TBLOCK_INPROGRESS; + s->chain = false; + RestoreTransactionCharacteristics(); + } } else if (s->blockState == TBLOCK_PREPARE) { diff --git a/src/test/regress/expected/transactions.out b/src/test/regress/expected/transactions.out index 1b03310029..75dc6558d8 100644 --- a/src/test/regress/expected/transactions.out +++ b/src/test/regress/expected/transactions.out @@ -774,6 +774,46 @@ SHOW transaction_deferrable; (1 row) INSERT INTO abc VALUES (5); +COMMIT; +START TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ WRITE, DEFERRABLE; +SHOW transaction_isolation; + transaction_isolation +----------------------- + repeatable read +(1 row) + +SHOW transaction_read_only; + transaction_read_only +----------------------- + off +(1 row) + +SHOW transaction_deferrable; + transaction_deferrable +------------------------ + on +(1 row) + +SAVEPOINT x; +COMMIT AND CHAIN; -- TBLOCK_SUBCOMMIT +SHOW transaction_isolation; + transaction_isolation +----------------------- + repeatable read +(1 row) + +SHOW transaction_read_only; + transaction_read_only +----------------------- + off +(1 row) + +SHOW transaction_deferrable; + transaction_deferrable +------------------------ + on +(1 row) + COMMIT; -- different mix of options just for fun START TRANSACTION ISOLATION LEVEL SERIALIZABLE, READ WRITE, NOT DEFERRABLE; diff --git a/src/test/regress/sql/transactions.sql b/src/test/regress/sql/transactions.sql index bf1016489d..d1b6ed0280 100644 --- a/src/test/regress/sql/transactions.sql +++ b/src/test/regress/sql/transactions.sql @@ -458,6 +458,17 @@ SHOW transaction_deferrable; INSERT INTO abc VALUES (5); COMMIT; +START TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ WRITE, DEFERRABLE; +SHOW transaction_isolation; +SHOW transaction_read_only; +SHOW transaction_deferrable; +SAVEPOINT x; +COMMIT AND CHAIN; -- TBLOCK_SUBCOMMIT +SHOW transaction_isolation; +SHOW transaction_read_only; +SHOW transaction_deferrable; +COMMIT; + -- different mix of options just for fun START TRANSACTION ISOLATION LEVEL SERIALIZABLE, READ WRITE, NOT DEFERRABLE; SHOW transaction_isolation;

view thread (9+ messages)  latest in thread

Message-ID: <473dba6b-dfb3-b5a8-93c6-af3787893728@oss.nttdata.com>
Permalink:  ../473dba6b-dfb3-b5a8-93c6-af3787893728@oss.nttdata.com/
Also on:    postgresql.org/message-id/473dba6b-dfb3-b5a8-93c6-af3787893728@oss.nttdata.com

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: masao.fujii@oss.nttdata.com, tureba@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #16867: savepoints vs. commit and chain
  In-Reply-To: <473dba6b-dfb3-b5a8-93c6-af3787893728@oss.nttdata.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox