pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #15977: Inconsistent behavior in chained transactions
30+ messages / 6 participants
[nested] [flat]

* BUG #15977: Inconsistent behavior in chained transactions
@ 2019-08-25 06:11  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 30+ messages in thread

From: PG Bug reporting form @ 2019-08-25 06:11 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: emuser20140816@gmail.com

The following bug has been logged on the website:

Bug reference:      15977
Logged by:          mtlh kdvt
Email address:      emuser20140816@gmail.com
PostgreSQL version: 12beta3
Operating system:   Windows
Description:        

When a ROLLBACK AND CHAIN command is executed in the implicit transaction
block, a new transaction will be started:
   db=# ROLLBACK AND CHAIN;
   WARNING:  there is no transaction in progress
   ROLLBACK
   db=# ROLLBACK AND CHAIN;
   ROLLBACK

However, a COMMIT AND CHAIN command won't start a new transaction:
   db=# COMMIT AND CHAIN;
   WARNING:  there is no transaction in progress
   COMMIT
   db=# COMMIT AND CHAIN;
   WARNING:  there is no transaction in progress
   COMMIT



^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-08-25 09:11  Fabien COELHO <coelho@cri.ensmp.fr>
  parent: PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 30+ messages in thread

From: Fabien COELHO @ 2019-08-25 09:11 UTC (permalink / raw)
  To: emuser20140816@gmail.com, PostgreSQL Bugs <pgsql-bugs@lists.postgresql.org>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>


> The following bug has been logged on the website:
>
> Bug reference:      15977
> Logged by:          mtlh kdvt
> Email address:      emuser20140816@gmail.com
> PostgreSQL version: 12beta3
> Operating system:   Windows
> Description:
>
> When a ROLLBACK AND CHAIN command is executed in the implicit transaction
> block, a new transaction will be started:
>   db=# ROLLBACK AND CHAIN;
>   WARNING:  there is no transaction in progress
>   ROLLBACK
>   db=# ROLLBACK AND CHAIN;
>   ROLLBACK
>
> However, a COMMIT AND CHAIN command won't start a new transaction:
>   db=# COMMIT AND CHAIN;
>   WARNING:  there is no transaction in progress
>   COMMIT
>   db=# COMMIT AND CHAIN;
>   WARNING:  there is no transaction in progress
>   COMMIT

Thanks for the report.

Indeed, I confirm, and I should have caught this one while reviewing…

Doc says:

"If AND CHAIN is specified, a new transaction is immediately started with 
the same transaction characteristics as the just finished one. Otherwise, 
no new transaction is started."

If there is no transaction in progress, the spec is undefined. Logically, 
ITSM that there should be no tx reset if none was in progress, so ROLLBACK 
has the wrong behavior?

A quick glance at the code did not yield any obvious culprit, but maybe 
I'm not looking at the right piece of code.

Doc could happend ", if any" to be clearer.

-- 
Fabien.

^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-08-28 19:29  fn ln <emuser20140816@gmail.com>
  parent: Fabien COELHO <coelho@cri.ensmp.fr>
  0 siblings, 1 reply; 30+ messages in thread

From: fn ln @ 2019-08-28 19:29 UTC (permalink / raw)
  To: Fabien COELHO <coelho@cri.ensmp.fr>; +Cc: PostgreSQL Bugs <pgsql-bugs@lists.postgresql.org>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>

 COMMIT AND CHAIN in implicit block leaves blockState as TBLOCK_STARTED,
which doesn't trigger the chaining.
but ROLLBACK AND CHAIN sets the blockState into TBLOCK_ABORT_PENDING, so
the chaining is triggered.

I think disabling s->chain beforehand should do the desired behavior.

2019年8月25日(日) 18:11 Fabien COELHO <coelho@cri.ensmp.fr>:

>
> > The following bug has been logged on the website:
> >
> > Bug reference:      15977
> > Logged by:          mtlh kdvt
> > Email address:      emuser20140816@gmail.com
> > PostgreSQL version: 12beta3
> > Operating system:   Windows
> > Description:
> >
> > When a ROLLBACK AND CHAIN command is executed in the implicit transaction
> > block, a new transaction will be started:
> >   db=# ROLLBACK AND CHAIN;
> >   WARNING:  there is no transaction in progress
> >   ROLLBACK
> >   db=# ROLLBACK AND CHAIN;
> >   ROLLBACK
> >
> > However, a COMMIT AND CHAIN command won't start a new transaction:
> >   db=# COMMIT AND CHAIN;
> >   WARNING:  there is no transaction in progress
> >   COMMIT
> >   db=# COMMIT AND CHAIN;
> >   WARNING:  there is no transaction in progress
> >   COMMIT
>
> Thanks for the report.
>
> Indeed, I confirm, and I should have caught this one while reviewing…
>
> Doc says:
>
> "If AND CHAIN is specified, a new transaction is immediately started with
> the same transaction characteristics as the just finished one. Otherwise,
> no new transaction is started."
>
> If there is no transaction in progress, the spec is undefined. Logically,
> ITSM that there should be no tx reset if none was in progress, so ROLLBACK
> has the wrong behavior?
>
> A quick glance at the code did not yield any obvious culprit, but maybe
> I'm not looking at the right piece of code.
>
> Doc could happend ", if any" to be clearer.
>
> --
> Fabien.

Attachments:

disable_implicit_xact_chaining.patch (application/octet-stream, 864B) download --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -3729,6 +3729,7 @@ (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), errmsg("there is no transaction in progress"))); s->blockState = TBLOCK_END; + chain = false; /* Do not chain the implicit transaction */ result = true; break; @@ -3798,6 +3799,7 @@ ereport(WARNING, (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), errmsg("there is no transaction in progress"))); + chain = false; /* Do not chain the implicit transaction */ result = true; break; @@ -3915,6 +3917,7 @@ (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), errmsg("there is no transaction in progress"))); s->blockState = TBLOCK_ABORT_PENDING; + chain = false; /* Do not chain the implicit transaction */ break; /*
^ permalink raw reply [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-08-29 06:30  Fabien COELHO <coelho@cri.ensmp.fr>
  parent: fn ln <emuser20140816@gmail.com>
  0 siblings, 1 reply; 30+ messages in thread

From: Fabien COELHO @ 2019-08-29 06:30 UTC (permalink / raw)
  To: fn ln <emuser20140816@gmail.com>; +Cc: PostgreSQL Bugs <pgsql-bugs@lists.postgresql.org>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>


Hello,

> COMMIT AND CHAIN in implicit block leaves blockState as TBLOCK_STARTED, 
> which doesn't trigger the chaining. but ROLLBACK AND CHAIN sets the 
> blockState into TBLOCK_ABORT_PENDING, so the chaining is triggered.
>
> I think disabling s->chain beforehand should do the desired behavior.

Patch applies with "patch", although "git apply" complained because of 
CRLF line terminations forced by the octet-stream mime type.

Patch compiles cleanly. Make check ok.

Patch works for me, and solution seems appropriate. It should be committed 
for pg 12.0.

There could be a test added in "regress/sql/transactions.sql", I'd suggest 
something like:

-- implicit transaction and not chained.
COMMIT AND CHAIN;
COMMIT;
ROLLBACK AND CHAIN;
ROLLBACK;

which should show the appropriate "no transaction in progress" warnings.

Doc could be made a little clearer about what to expect when there is no 
explicit transaction in progress.

-- 
Fabien.





^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-08-29 07:24  Fabien COELHO <coelho@cri.ensmp.fr>
  0 siblings, 0 replies; 30+ messages in thread

From: Fabien COELHO @ 2019-08-29 07:24 UTC (permalink / raw)
  To: fn ln <emuser20140816@gmail.com>; +Cc: PostgreSQL Bugs <pgsql-bugs@lists.postgresql.org>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>


> Patch works for me, and solution seems appropriate. It should be committed 
> for pg 12.0.

I have listed this as an open issue of the upcoming pg 12:

 	https://wiki.postgresql.org/wiki/PostgreSQL_12_Open_Items#Open_Issues

-- 
Fabien.





^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-08-29 11:39  fn ln <emuser20140816@gmail.com>
  parent: Fabien COELHO <coelho@cri.ensmp.fr>
  0 siblings, 1 reply; 30+ messages in thread

From: fn ln @ 2019-08-29 11:39 UTC (permalink / raw)
  To: Fabien COELHO <coelho@cri.ensmp.fr>; +Cc: PostgreSQL Bugs <pgsql-bugs@lists.postgresql.org>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>

Added two kinds of test for the implicit transaction: in single query and
in implicit block.
The patch file is now created with Unix-style line ending (LF).

2019年8月29日(木) 15:30 Fabien COELHO <coelho@cri.ensmp.fr>:

>
> Hello,
>
> > COMMIT AND CHAIN in implicit block leaves blockState as TBLOCK_STARTED,
> > which doesn't trigger the chaining. but ROLLBACK AND CHAIN sets the
> > blockState into TBLOCK_ABORT_PENDING, so the chaining is triggered.
> >
> > I think disabling s->chain beforehand should do the desired behavior.
>
> Patch applies with "patch", although "git apply" complained because of
> CRLF line terminations forced by the octet-stream mime type.
>
> Patch compiles cleanly. Make check ok.
>
> Patch works for me, and solution seems appropriate. It should be committed
> for pg 12.0.
>
> There could be a test added in "regress/sql/transactions.sql", I'd suggest
> something like:
>
> -- implicit transaction and not chained.
> COMMIT AND CHAIN;
> COMMIT;
> ROLLBACK AND CHAIN;
> ROLLBACK;
>
> which should show the appropriate "no transaction in progress" warnings.
>
> Doc could be made a little clearer about what to expect when there is no
> explicit transaction in progress.
>
> --
> Fabien.
>

Attachments:

implicit_xact_chain_test.patch (application/octet-stream, 1.8K) download --- a/src/test/regress/expected/transactions.out +++ b/src/test/regress/expected/transactions.out @@ -839,6 +839,36 @@ (1 row) ROLLBACK; +-- transaction cannot be chained outside a transaction block +COMMIT AND CHAIN; -- TBLOCK_STARTED +WARNING: there is no transaction in progress +COMMIT; -- TBLOCK_STARTED +WARNING: there is no transaction in progress +ROLLBACK AND CHAIN; -- TBLOCK_ABORT_PENDING +WARNING: there is no transaction in progress +ROLLBACK; -- TBLOCK_ABORT_PENDING +WARNING: there is no transaction in progress +-- implicit transaction cannot be chained as well +SET TRANSACTION READ WRITE\; COMMIT AND CHAIN; -- TBLOCK_END +WARNING: there is no transaction in progress +SHOW transaction_read_only; + transaction_read_only +----------------------- + on +(1 row) + +COMMIT; +WARNING: there is no transaction in progress +SET TRANSACTION READ WRITE\; ROLLBACK AND CHAIN; -- TBLOCK_ABORT_PENDING +WARNING: there is no transaction in progress +SHOW transaction_read_only; + transaction_read_only +----------------------- + on +(1 row) + +ROLLBACK; +WARNING: there is no transaction in progress SELECT * FROM abc ORDER BY 1; a --- --- a/src/test/regress/sql/transactions.sql +++ b/src/test/regress/sql/transactions.sql @@ -475,6 +475,22 @@ SHOW transaction_deferrable; ROLLBACK; +-- transaction cannot be chained outside a transaction block +COMMIT AND CHAIN; -- TBLOCK_STARTED +COMMIT; -- TBLOCK_STARTED + +ROLLBACK AND CHAIN; -- TBLOCK_ABORT_PENDING +ROLLBACK; -- TBLOCK_ABORT_PENDING + +-- implicit transaction cannot be chained as well +SET TRANSACTION READ WRITE\; COMMIT AND CHAIN; -- TBLOCK_END +SHOW transaction_read_only; +COMMIT; + +SET TRANSACTION READ WRITE\; ROLLBACK AND CHAIN; -- TBLOCK_ABORT_PENDING +SHOW transaction_read_only; +ROLLBACK; + SELECT * FROM abc ORDER BY 1; RESET default_transaction_read_only;
^ permalink raw reply [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-08-29 12:10  Fabien COELHO <coelho@cri.ensmp.fr>
  parent: fn ln <emuser20140816@gmail.com>
  0 siblings, 1 reply; 30+ messages in thread

From: Fabien COELHO @ 2019-08-29 12:10 UTC (permalink / raw)
  To: fn ln <emuser20140816@gmail.com>; +Cc: PostgreSQL Bugs <pgsql-bugs@lists.postgresql.org>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>


Hello,

> Added two kinds of test for the implicit transaction: in single query and
> in implicit block.

Ok.

> The patch file is now created with Unix-style line ending (LF).

Thanks.

Patch applies and compiles cleanly. However, "make check" is not ok
on the added tests.

    SHOW transaction_read_only;
     transaction_read_only
    -----------------------
   - on
   + off

ISTM that the run is right and the patch test output is wrong, i.e. the 
transaction_read_only is expected to stay as is.

-- 
Fabien.





^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-08-29 12:35  fn ln <emuser20140816@gmail.com>
  parent: Fabien COELHO <coelho@cri.ensmp.fr>
  0 siblings, 1 reply; 30+ messages in thread

From: fn ln @ 2019-08-29 12:35 UTC (permalink / raw)
  To: Fabien COELHO <coelho@cri.ensmp.fr>; +Cc: PostgreSQL Bugs <pgsql-bugs@lists.postgresql.org>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>

 transaction_read_only must be 'on' because AND CHAIN test sets the
default_transaction_read_only to 'on'.
Failure of this test means that the transaction was chained from an
implicit transaction, which is not our desired behavior.
Perhaps you are using a wrong binary?

2019年8月29日(木) 21:10 Fabien COELHO <coelho@cri.ensmp.fr>:

>
> Hello,
>
> > Added two kinds of test for the implicit transaction: in single query and
> > in implicit block.
>
> Ok.
>
> > The patch file is now created with Unix-style line ending (LF).
>
> Thanks.
>
> Patch applies and compiles cleanly. However, "make check" is not ok
> on the added tests.
>
>     SHOW transaction_read_only;
>      transaction_read_only
>     -----------------------
>    - on
>    + off
>
> ISTM that the run is right and the patch test output is wrong, i.e. the
> transaction_read_only is expected to stay as is.
>
> --
> Fabien.
>

^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-08-29 13:01  Fabien COELHO <coelho@cri.ensmp.fr>
  parent: fn ln <emuser20140816@gmail.com>
  0 siblings, 1 reply; 30+ messages in thread

From: Fabien COELHO @ 2019-08-29 13:01 UTC (permalink / raw)
  To: fn ln <emuser20140816@gmail.com>; +Cc: PostgreSQL Bugs <pgsql-bugs@lists.postgresql.org>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>


Hello,

> transaction_read_only must be 'on' because AND CHAIN test sets the
> default_transaction_read_only to 'on'.

> Failure of this test means that the transaction was chained from an 
> implicit transaction, which is not our desired behavior. Perhaps you are 
> using a wrong binary?

Nope, I blindly assumed that your patch was self contained, but it is not, 
and my test did not include the initial fix.

The usual approach is to send self-contained and numbered patches,
eg "chain-fix-1.patch", "chain-fix-2.patch", and so on, unless there are 
complex patches designed to be committed in stages.

For the expected result, I was wrongly assuming that "SET TRANSACTION" was 
session persistent, which is not the case, there is a "SET SESSION …" for 
that. Moreover, the usual transaction default is read-write, so I was a 
little surprise. It would help to show the (unusual) current setting 
before the test.

I also have registered the patch to the CF app:

 	https://commitfest.postgresql.org/24/2265/

But I cannot fill in your name, maybe you could register and add it, or it 
can be left blank.

-- 
Fabien.

^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-08-29 13:55  fn ln <emuser20140816@gmail.com>
  parent: Fabien COELHO <coelho@cri.ensmp.fr>
  0 siblings, 1 reply; 30+ messages in thread

From: fn ln @ 2019-08-29 13:55 UTC (permalink / raw)
  To: Fabien COELHO <coelho@cri.ensmp.fr>; +Cc: PostgreSQL Bugs <pgsql-bugs@lists.postgresql.org>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>

 > The usual approach is to send self-contained and numbered patches,
> eg "chain-fix-1.patch", "chain-fix-2.patch", and so on, unless there are
> complex patches designed to be committed in stages.
Thanks, I got it. I have never made a patch before so I'll keep it in my
mind.
Self-contained patch is now attached.

> it can be left blank
I'm fine with that.

Attachments:

disable_implicit_transaction_chaining-3.patch (application/octet-stream, 2.6K) download --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -3729,6 +3729,7 @@ (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), errmsg("there is no transaction in progress"))); s->blockState = TBLOCK_END; + chain = false; /* Do not chain the implicit transaction */ result = true; break; @@ -3798,6 +3799,7 @@ ereport(WARNING, (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), errmsg("there is no transaction in progress"))); + chain = false; /* Do not chain the implicit transaction */ result = true; break; @@ -3915,6 +3917,7 @@ (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), errmsg("there is no transaction in progress"))); s->blockState = TBLOCK_ABORT_PENDING; + chain = false; /* Do not chain the implicit transaction */ break; /* --- a/src/test/regress/expected/transactions.out +++ b/src/test/regress/expected/transactions.out @@ -839,6 +839,36 @@ (1 row) ROLLBACK; +-- transaction cannot be chained outside a transaction block +COMMIT AND CHAIN; -- TBLOCK_STARTED +WARNING: there is no transaction in progress +COMMIT; -- TBLOCK_STARTED +WARNING: there is no transaction in progress +ROLLBACK AND CHAIN; -- TBLOCK_ABORT_PENDING +WARNING: there is no transaction in progress +ROLLBACK; -- TBLOCK_ABORT_PENDING +WARNING: there is no transaction in progress +-- implicit transaction cannot be chained as well +SET TRANSACTION READ WRITE\; COMMIT AND CHAIN; -- TBLOCK_END +WARNING: there is no transaction in progress +SHOW transaction_read_only; + transaction_read_only +----------------------- + on +(1 row) + +COMMIT; +WARNING: there is no transaction in progress +SET TRANSACTION READ WRITE\; ROLLBACK AND CHAIN; -- TBLOCK_ABORT_PENDING +WARNING: there is no transaction in progress +SHOW transaction_read_only; + transaction_read_only +----------------------- + on +(1 row) + +ROLLBACK; +WARNING: there is no transaction in progress SELECT * FROM abc ORDER BY 1; a --- --- a/src/test/regress/sql/transactions.sql +++ b/src/test/regress/sql/transactions.sql @@ -475,6 +475,22 @@ SHOW transaction_deferrable; ROLLBACK; +-- transaction cannot be chained outside a transaction block +COMMIT AND CHAIN; -- TBLOCK_STARTED +COMMIT; -- TBLOCK_STARTED + +ROLLBACK AND CHAIN; -- TBLOCK_ABORT_PENDING +ROLLBACK; -- TBLOCK_ABORT_PENDING + +-- implicit transaction cannot be chained as well +SET TRANSACTION READ WRITE\; COMMIT AND CHAIN; -- TBLOCK_END +SHOW transaction_read_only; +COMMIT; + +SET TRANSACTION READ WRITE\; ROLLBACK AND CHAIN; -- TBLOCK_ABORT_PENDING +SHOW transaction_read_only; +ROLLBACK; + SELECT * FROM abc ORDER BY 1; RESET default_transaction_read_only;
^ permalink raw reply [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-08-29 14:58  Fabien COELHO <coelho@cri.ensmp.fr>
  parent: fn ln <emuser20140816@gmail.com>
  0 siblings, 1 reply; 30+ messages in thread

From: Fabien COELHO @ 2019-08-29 14:58 UTC (permalink / raw)
  To: fn ln <emuser20140816@gmail.com>; +Cc: PostgreSQL Bugs <pgsql-bugs@lists.postgresql.org>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>


> Thanks, I got it. I have never made a patch before so I'll keep it in my 
> mind. Self-contained patch is now attached.

v3 applies, compiles, "make check" ok.

I turned it ready on the app.

-- 
Fabien





^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-09-03 09:54  Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  parent: Fabien COELHO <coelho@cri.ensmp.fr>
  0 siblings, 3 replies; 30+ messages in thread

From: Peter Eisentraut @ 2019-09-03 09:54 UTC (permalink / raw)
  To: Fabien COELHO <coelho@cri.ensmp.fr>; fn ln <emuser20140816@gmail.com>; +Cc: PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>

On 2019-08-29 16:58, Fabien COELHO wrote:
> 
>> Thanks, I got it. I have never made a patch before so I'll keep it in my 
>> mind. Self-contained patch is now attached.
> 
> v3 applies, compiles, "make check" ok.
> 
> I turned it ready on the app.

Should we make it an error instead of a warning?

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-09-03 10:03  Fabien COELHO <coelho@cri.ensmp.fr>
  parent: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2 siblings, 0 replies; 30+ messages in thread

From: Fabien COELHO @ 2019-09-03 10:03 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: fn ln <emuser20140816@gmail.com>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>


>> v3 applies, compiles, "make check" ok.
>>
>> I turned it ready on the app.
>
> Should we make it an error instead of a warning?

ISTM that it made sense to have the same behavior as out of transaction 
COMMIT or ROLLBACK.

-- 
Fabien.





^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-09-03 13:27  fn ln <emuser20140816@gmail.com>
  parent: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2 siblings, 0 replies; 30+ messages in thread

From: fn ln @ 2019-09-03 13:27 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: Fabien COELHO <coelho@cri.ensmp.fr>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>

 We have three options:
  1. Prohibit AND CHAIN outside a transaction block, but do nothing in
plain COMMIT/ROLLBACK or AND NO CHAIN.
  2. Deal "there is no transaction in progress" (and "there is already a
transaction in progress" if needed) as an error.
  3. Leave as it is.

Option 1 makes overall behavior more inconsistent, and option 2 might cause
the backward-compatibility issues.
So I think 3 is a better solution for now.

2019年9月3日(火) 18:55 Peter Eisentraut <peter.eisentraut@2ndquadrant.com>:

> On 2019-08-29 16:58, Fabien COELHO wrote:
> >
> >> Thanks, I got it. I have never made a patch before so I'll keep it in
> my
> >> mind. Self-contained patch is now attached.
> >
> > v3 applies, compiles, "make check" ok.
> >
> > I turned it ready on the app.
>
> Should we make it an error instead of a warning?
>
> --
> Peter Eisentraut              http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>

^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-09-04 07:53  Andres Freund <andres@anarazel.de>
  parent: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  2 siblings, 1 reply; 30+ messages in thread

From: Andres Freund @ 2019-09-04 07:53 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: Fabien COELHO <coelho@cri.ensmp.fr>; fn ln <emuser20140816@gmail.com>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>

Hi,

On 2019-09-03 11:54:57 +0200, Peter Eisentraut wrote:
> On 2019-08-29 16:58, Fabien COELHO wrote:
> > 
> >> Thanks, I got it. I have never made a patch before so I'll keep it in my 
> >> mind. Self-contained patch is now attached.
> > 
> > v3 applies, compiles, "make check" ok.
> > 
> > I turned it ready on the app.

I don't think is quite sufficient. Note that the same problem also
exists for commits, one just needs force the commit to be part of a
multi-statement implicit transaction (i.e. a simple protocol exec /
PQexec(), with multiple statements).

E.g.:

postgres[32545][1]=# ROLLBACK;
WARNING:  25P01: there is no transaction in progress
LOCATION:  UserAbortTransactionBlock, xact.c:3914
ROLLBACK
Time: 0.790 ms
postgres[32545][1]=# SELECT 1\;COMMIT AND CHAIN;
WARNING:  25P01: there is no transaction in progress
LOCATION:  EndTransactionBlock, xact.c:3728
COMMIT
Time: 0.945 ms
postgres[32545][1]*=# COMMIT ;
COMMIT
Time: 0.539 ms

the \; bit forces psql to not split command into two separate protocol
level commands, but to submit them together.


> Should we make it an error instead of a warning?

Yea, I think for AND CHAIN we have to either error, or always start a
new transaction. I can see arguments for both, as long as it's
consistent.

The historical behaviour of issuing only WARNINGS when issuing COMMIT or
ROLLBACK outside of an explicit transaction seems to weigh in favor of
not erroring. Given that the result of such a transaction command is not
an error, the AND CHAIN portion should work.

Additionally, we actually have COMMIT; ROLLBACK; PREPARE TRANSACTION all
work meaningfully for implicit transactions. E.g.:

postgres[32545][1]=# CREATE TABLE test()\; PREPARE TRANSACTION 'frak';
WARNING:  25P01: there is no transaction in progress
LOCATION:  EndTransactionBlock, xact.c:3728
PREPARE TRANSACTION
Time: 15.094 ms
postgres[32545][1]=# \d test
Did not find any relation named "test".
postgres[32545][1]=# COMMIT PREPARED 'frak';
COMMIT PREPARED
Time: 4.727 ms
postgres[32545][1]=# \d test
               Table "public.test"
┌────────┬──────┬───────────┬──────────┬─────────┐
│ Column │ Type │ Collation │ Nullable │ Default │
├────────┼──────┼───────────┼──────────┼─────────┤
└────────┴──────┴───────────┴──────────┴─────────┘


The argument in the other direction is that not erroring out hides bugs,
like an accidentally already committed transaction (which is
particularly bad for ROLLBACK). We can't easily change that for plain
COMMIT/ROLLBACK due to backward compat concerns, but for COMMIT|ROLLBACK
AND CHAIN there's no such such concern.

I think there's an argument that we ought to behave differently for
COMMIT/ROLLBACK/PREPARE in implicit transactions where multiple commands
exist, and ones where that's not the case. Given that they all actually
have an effect if there's a preceding statement in the implicit
transaction, the WARNING doesn't actually seem that appropriate?

There's some arguments that it's sometimes useful to be able to force
committing an implicit transaction. Consider e.g. executing batch schema
modifications with some sensitivity to latency (and thus wanting to use
reduce latency by executing multiple statements via one protocol
message). There's a few cases where committing earlier is quite useful
in that scenario, e.g.:

CREATE TYPE test_enum AS ENUM ('a', 'b', 'c');
CREATE TABLE uses_test_enum(v test_enum);

without explicit commit:

postgres[32545][1]=# ALTER TYPE test_enum ADD VALUE 'd'\;INSERT INTO uses_test_enum VALUES('d');
ERROR:  55P04: unsafe use of new value "d" of enum type test_enum
LINE 1: ...t_enum ADD VALUE 'd';INSERT INTO uses_test_enum VALUES('d');
                                                                  ^
HINT:  New enum values must be committed before they can be used.
LOCATION:  check_safe_enum_use, enum.c:98


with explicit commit:

postgres[32545][1]=# ALTER TYPE test_enum ADD VALUE 'd'\;COMMIT\;INSERT INTO uses_test_enum VALUES('d');
WARNING:  25P01: there is no transaction in progress
LOCATION:  EndTransactionBlock, xact.c:3728
INSERT 0 1

There's also the case that one might want to batch execute statements,
but not have to redo them if a later command fails.

Greetings,

Andres Freund





^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-09-04 14:49  fn ln <emuser20140816@gmail.com>
  parent: Andres Freund <andres@anarazel.de>
  0 siblings, 1 reply; 30+ messages in thread

From: fn ln @ 2019-09-04 14:49 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; Fabien COELHO <coelho@cri.ensmp.fr>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>

I made another patch for suggested behavior (COMMIT/ROLLBACK AND CHAIN now
gives us an error when used in an implicit block).

2019年9月4日(水) 16:53 Andres Freund <andres@anarazel.de>:

> Hi,
>
> On 2019-09-03 11:54:57 +0200, Peter Eisentraut wrote:
> > On 2019-08-29 16:58, Fabien COELHO wrote:
> > >
> > >> Thanks, I got it. I have never made a patch before so I'll keep it in
> my
> > >> mind. Self-contained patch is now attached.
> > >
> > > v3 applies, compiles, "make check" ok.
> > >
> > > I turned it ready on the app.
>
> I don't think is quite sufficient. Note that the same problem also
> exists for commits, one just needs force the commit to be part of a
> multi-statement implicit transaction (i.e. a simple protocol exec /
> PQexec(), with multiple statements).
>
> E.g.:
>
> postgres[32545][1]=# ROLLBACK;
> WARNING:  25P01: there is no transaction in progress
> LOCATION:  UserAbortTransactionBlock, xact.c:3914
> ROLLBACK
> Time: 0.790 ms
> postgres[32545][1]=# SELECT 1\;COMMIT AND CHAIN;
> WARNING:  25P01: there is no transaction in progress
> LOCATION:  EndTransactionBlock, xact.c:3728
> COMMIT
> Time: 0.945 ms
> postgres[32545][1]*=# COMMIT ;
> COMMIT
> Time: 0.539 ms
>
> the \; bit forces psql to not split command into two separate protocol
> level commands, but to submit them together.
>
>
> > Should we make it an error instead of a warning?
>
> Yea, I think for AND CHAIN we have to either error, or always start a
> new transaction. I can see arguments for both, as long as it's
> consistent.
>
> The historical behaviour of issuing only WARNINGS when issuing COMMIT or
> ROLLBACK outside of an explicit transaction seems to weigh in favor of
> not erroring. Given that the result of such a transaction command is not
> an error, the AND CHAIN portion should work.
>
> Additionally, we actually have COMMIT; ROLLBACK; PREPARE TRANSACTION all
> work meaningfully for implicit transactions. E.g.:
>
> postgres[32545][1]=# CREATE TABLE test()\; PREPARE TRANSACTION 'frak';
> WARNING:  25P01: there is no transaction in progress
> LOCATION:  EndTransactionBlock, xact.c:3728
> PREPARE TRANSACTION
> Time: 15.094 ms
> postgres[32545][1]=# \d test
> Did not find any relation named "test".
> postgres[32545][1]=# COMMIT PREPARED 'frak';
> COMMIT PREPARED
> Time: 4.727 ms
> postgres[32545][1]=# \d test
>                Table "public.test"
> ┌────────┬──────┬───────────┬──────────┬─────────┐
> │ Column │ Type │ Collation │ Nullable │ Default │
> ├────────┼──────┼───────────┼──────────┼─────────┤
> └────────┴──────┴───────────┴──────────┴─────────┘
>
>
> The argument in the other direction is that not erroring out hides bugs,
> like an accidentally already committed transaction (which is
> particularly bad for ROLLBACK). We can't easily change that for plain
> COMMIT/ROLLBACK due to backward compat concerns, but for COMMIT|ROLLBACK
> AND CHAIN there's no such such concern.
>
> I think there's an argument that we ought to behave differently for
> COMMIT/ROLLBACK/PREPARE in implicit transactions where multiple commands
> exist, and ones where that's not the case. Given that they all actually
> have an effect if there's a preceding statement in the implicit
> transaction, the WARNING doesn't actually seem that appropriate?
>
> There's some arguments that it's sometimes useful to be able to force
> committing an implicit transaction. Consider e.g. executing batch schema
> modifications with some sensitivity to latency (and thus wanting to use
> reduce latency by executing multiple statements via one protocol
> message). There's a few cases where committing earlier is quite useful
> in that scenario, e.g.:
>
> CREATE TYPE test_enum AS ENUM ('a', 'b', 'c');
> CREATE TABLE uses_test_enum(v test_enum);
>
> without explicit commit:
>
> postgres[32545][1]=# ALTER TYPE test_enum ADD VALUE 'd'\;INSERT INTO
> uses_test_enum VALUES('d');
> ERROR:  55P04: unsafe use of new value "d" of enum type test_enum
> LINE 1: ...t_enum ADD VALUE 'd';INSERT INTO uses_test_enum VALUES('d');
>                                                                   ^
> HINT:  New enum values must be committed before they can be used.
> LOCATION:  check_safe_enum_use, enum.c:98
>
>
> with explicit commit:
>
> postgres[32545][1]=# ALTER TYPE test_enum ADD VALUE 'd'\;COMMIT\;INSERT
> INTO uses_test_enum VALUES('d');
> WARNING:  25P01: there is no transaction in progress
> LOCATION:  EndTransactionBlock, xact.c:3728
> INSERT 0 1
>
> There's also the case that one might want to batch execute statements,
> but not have to redo them if a later command fails.
>
> Greetings,
>
> Andres Freund
>

Attachments:

disable-implicit-transaction-chaining-v4.patch (application/octet-stream, 3.7K) download --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -3725,9 +3725,17 @@ * because there was no explicit BEGIN before this. */ case TBLOCK_IMPLICIT_INPROGRESS: - ereport(WARNING, - (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), - errmsg("there is no transaction in progress"))); + /* We disallow transaction chaining outside an explicit transaction block */ + if (chain) + ereport(ERROR, + (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), + /* translator: %s represents an SQL statement name */ + errmsg("%s can only be used in transaction blocks", + "COMMIT AND CHAIN"))); + else + ereport(WARNING, + (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), + errmsg("there is no transaction in progress"))); s->blockState = TBLOCK_END; result = true; break; @@ -3795,9 +3803,17 @@ * put us back into the default state. */ case TBLOCK_STARTED: - ereport(WARNING, - (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), - errmsg("there is no transaction in progress"))); + /* We disallow transaction chaining outside an explicit transaction block */ + if (chain) + ereport(ERROR, + (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), + /* translator: %s represents an SQL statement name */ + errmsg("%s can only be used in transaction blocks", + "COMMIT AND CHAIN"))); + else + ereport(WARNING, + (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), + errmsg("there is no transaction in progress"))); result = true; break; @@ -3911,9 +3927,17 @@ */ case TBLOCK_STARTED: case TBLOCK_IMPLICIT_INPROGRESS: - ereport(WARNING, - (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), - errmsg("there is no transaction in progress"))); + /* We disallow transaction chaining outside an explicit transaction block */ + if (chain) + ereport(ERROR, + (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), + /* translator: %s represents an SQL statement name */ + errmsg("%s can only be used in transaction blocks", + "ROLLBACK AND CHAIN"))); + else + ereport(WARNING, + (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), + errmsg("there is no transaction in progress"))); s->blockState = TBLOCK_ABORT_PENDING; break; --- a/src/test/regress/expected/transactions.out +++ b/src/test/regress/expected/transactions.out @@ -839,6 +839,28 @@ (1 row) ROLLBACK; +-- transaction chaining should not be used outside a transaction block +COMMIT AND CHAIN; -- error +ERROR: COMMIT AND CHAIN can only be used in transaction blocks +ROLLBACK AND CHAIN; -- error +ERROR: ROLLBACK AND CHAIN can only be used in transaction blocks +-- implicit transaction should not be chained as well +SET TRANSACTION READ WRITE\; COMMIT AND CHAIN; -- error +ERROR: COMMIT AND CHAIN can only be used in transaction blocks +SHOW transaction_read_only; + transaction_read_only +----------------------- + on +(1 row) + +SET TRANSACTION READ WRITE\; ROLLBACK AND CHAIN; -- error +ERROR: ROLLBACK AND CHAIN can only be used in transaction blocks +SHOW transaction_read_only; + transaction_read_only +----------------------- + on +(1 row) + SELECT * FROM abc ORDER BY 1; a --- --- a/src/test/regress/sql/transactions.sql +++ b/src/test/regress/sql/transactions.sql @@ -475,6 +475,17 @@ SHOW transaction_deferrable; ROLLBACK; +-- transaction chaining should not be used outside a transaction block +COMMIT AND CHAIN; -- error +ROLLBACK AND CHAIN; -- error + +-- implicit transaction should not be chained as well +SET TRANSACTION READ WRITE\; COMMIT AND CHAIN; -- error +SHOW transaction_read_only; + +SET TRANSACTION READ WRITE\; ROLLBACK AND CHAIN; -- error +SHOW transaction_read_only; + SELECT * FROM abc ORDER BY 1; RESET default_transaction_read_only;
^ permalink raw reply [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-09-05 12:16  Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  parent: fn ln <emuser20140816@gmail.com>
  0 siblings, 1 reply; 30+ messages in thread

From: Peter Eisentraut @ 2019-09-05 12:16 UTC (permalink / raw)
  To: fn ln <emuser20140816@gmail.com>; Andres Freund <andres@anarazel.de>; +Cc: Fabien COELHO <coelho@cri.ensmp.fr>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>

On 2019-09-04 16:49, fn ln wrote:
> I made another patch for suggested behavior (COMMIT/ROLLBACK AND CHAIN
> now gives us an error when used in an implicit block).

I'm content with this patch.  Better disable questionable cases now and
maybe re-enable them later if someone wants to make a case for it.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-09-05 21:11  Andres Freund <andres@anarazel.de>
  parent: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  0 siblings, 1 reply; 30+ messages in thread

From: Andres Freund @ 2019-09-05 21:11 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: fn ln <emuser20140816@gmail.com>; Fabien COELHO <coelho@cri.ensmp.fr>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>

Hi,


On 2019-09-05 14:16:11 +0200, Peter Eisentraut wrote:
> On 2019-09-04 16:49, fn ln wrote:
> > I made another patch for suggested behavior (COMMIT/ROLLBACK AND CHAIN
> > now gives us an error when used in an implicit block).
> 
> I'm content with this patch.

Would need tests.


> Better disable questionable cases now and maybe re-enable them later
> if someone wants to make a case for it.

I do think the fact that COMMIT in multi-statement implicit transaction
has some usecase, is an argument for just implementing it properly...


Greetings,

Andres Freund





^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-09-06 07:54  Michael Paquier <michael@paquier.xyz>
  parent: Andres Freund <andres@anarazel.de>
  0 siblings, 2 replies; 30+ messages in thread

From: Michael Paquier @ 2019-09-06 07:54 UTC (permalink / raw)
  To: Andres Freund <andres@anarazel.de>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; fn ln <emuser20140816@gmail.com>; Fabien COELHO <coelho@cri.ensmp.fr>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>

On Thu, Sep 05, 2019 at 02:11:35PM -0700, Andres Freund wrote:
> On 2019-09-05 14:16:11 +0200, Peter Eisentraut wrote:
>> I'm content with this patch.
> 
> Would need tests.

The latest patch sends adds coverage for all the new code paths
added.  Do you have something else in mind?

>> Better disable questionable cases now and maybe re-enable them later
>> if someone wants to make a case for it.
> 
> I do think the fact that COMMIT in multi-statement implicit transaction
> has some usecase, is an argument for just implementing it properly...

Like Peter, I would also keep an ERROR for now, as we could always
relax that later on.

Looking at the latest patch, the comment blocks on top of TBLOCK_STARTED
and TBLOCK_IMPLICIT_INPROGRESS in EndTransactionBlock() need an update
to mention the difference of behavior with chained transactions.  And
the same comment rework should be done in UserAbortTransactionBlock()
for TBLOCK_IMPLICIT_INPROGRESS/TBLOCK_STARTED?
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-09-07 06:54  Fabien COELHO <coelho@cri.ensmp.fr>
  parent: Michael Paquier <michael@paquier.xyz>
  1 sibling, 1 reply; 30+ messages in thread

From: Fabien COELHO @ 2019-09-07 06:54 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; Andres Freund <andres@anarazel.de>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; fn ln <emuser20140816@gmail.com>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>


Hello,

>> I do think the fact that COMMIT in multi-statement implicit transaction
>> has some usecase, is an argument for just implementing it properly...
>
> Like Peter, I would also keep an ERROR for now, as we could always
> relax that later on.

I can agree with both warning and error, but for me the choice should be 
consistent with the current behavior of COMMIT and ROLLBACK in the same 
context.

  pg> CREATE OR REPLACE PROCEDURE warn(msg TEXT) LANGUAGE plpgsql AS
      $$ BEGIN RAISE WARNING 'warning: %', msg ; END ; $$;

Then an out-of-transaction multi-statement commit:

  pg> CALL warn('1') \; COMMIT \; CALL warn('2') ;
    WARNING:  warning: 1
    WARNING:  there is no transaction in progress
    WARNING:  warning: 2
    CALL

But v4 creates an non uniform behavior that I find surprising and 
unwelcome:

  pg> CALL warn('1') \; COMMIT AND CHAIN \; CALL warn('2') ;
    WARNING:  warning: 1
    ERROR:  COMMIT AND CHAIN can only be used in transaction blocks

Why "commit" & "commit and chain" should behave differently in the same 
context? For me they can error or warn, but consistency implies that they 
should do the exact same thing.



^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-09-07 09:58  fn ln <emuser20140816@gmail.com>
  parent: Fabien COELHO <coelho@cri.ensmp.fr>
  0 siblings, 1 reply; 30+ messages in thread

From: fn ln @ 2019-09-07 09:58 UTC (permalink / raw)
  To: Fabien COELHO <coelho@cri.ensmp.fr>; +Cc: Michael Paquier <michael@paquier.xyz>; Andres Freund <andres@anarazel.de>; Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>

> Looking at the latest patch, the comment blocks on top of TBLOCK_STARTED
> and TBLOCK_IMPLICIT_INPROGRESS in EndTransactionBlock() need an update
> to mention the difference of behavior with chained transactions.  And
> the same comment rework should be done in UserAbortTransactionBlock()
> for TBLOCK_IMPLICIT_INPROGRESS/TBLOCK_STARTED?
I made another patch for that.
I don't have much confidence with my English spelling so further
improvements may be needed.

> If it is too much a change and potential regression, then I think that the
> "and chain" variants should be consistent and just raise warnings.
We don't have an exact answer for implicit transaction chaining behavior
yet.
So I think it's better to disable this feature until someone discovers the
use cases for this.
Permitting AND CHAIN without a detailed specification might cause troubles
in future.

Attachments:

disable-implicit-transaction-chaining-v5.patch (application/octet-stream, 5.1K) download --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -3721,13 +3721,21 @@ break; /* - * In an implicit transaction block, commit, but issue a warning - * because there was no explicit BEGIN before this. + * We are in an implicit transaction block. If AND CHAIN was + * specified, we abort this transaction; otherwise commit, but + * issue a warning because there was no explicit BEGIN before this. */ case TBLOCK_IMPLICIT_INPROGRESS: - ereport(WARNING, - (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), - errmsg("there is no transaction in progress"))); + if (chain) + ereport(ERROR, + (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), + /* translator: %s represents an SQL statement name */ + errmsg("%s can only be used in transaction blocks", + "COMMIT AND CHAIN"))); + else + ereport(WARNING, + (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), + errmsg("there is no transaction in progress"))); s->blockState = TBLOCK_END; result = true; break; @@ -3789,15 +3797,26 @@ break; /* - * The user issued COMMIT when not inside a transaction. Issue a - * WARNING, staying in TBLOCK_STARTED state. The upcoming call to + * The user issued COMMIT when not inside a transaction. For + * COMMIT without transaction chaining, we just issue a WARNING, + * staying in TBLOCK_STARTED state. The upcoming call to * CommitTransactionCommand() will then close the transaction and * put us back into the default state. + * + * We disallow transaction chaining outside an explicit transaction + * block, so issue an ERROR if the user told us to do that. */ case TBLOCK_STARTED: - ereport(WARNING, - (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), - errmsg("there is no transaction in progress"))); + if (chain) + ereport(ERROR, + (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), + /* translator: %s represents an SQL statement name */ + errmsg("%s can only be used in transaction blocks", + "COMMIT AND CHAIN"))); + else + ereport(WARNING, + (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), + errmsg("there is no transaction in progress"))); result = true; break; @@ -3899,10 +3918,13 @@ break; /* - * The user issued ABORT when not inside a transaction. Issue a - * WARNING and go to abort state. The upcoming call to - * CommitTransactionCommand() will then put us back into the - * default state. + * The user issued ABORT when not inside a transaction. For + * ROLLBACK without transaction chaining, issue a WARNING and go + * to abort state. The upcoming call to CommitTransactionCommand() + * will then put us back into the default state. + * + * We disallow transaction chaining outside an explicit transaction + * block, so issue an ERROR if the user told us to do that. * * We do the same thing with ABORT inside an implicit transaction, * although in this case we might be rolling back actual database @@ -3911,9 +3933,16 @@ */ case TBLOCK_STARTED: case TBLOCK_IMPLICIT_INPROGRESS: - ereport(WARNING, - (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), - errmsg("there is no transaction in progress"))); + if (chain) + ereport(ERROR, + (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), + /* translator: %s represents an SQL statement name */ + errmsg("%s can only be used in transaction blocks", + "ROLLBACK AND CHAIN"))); + else + ereport(WARNING, + (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), + errmsg("there is no transaction in progress"))); s->blockState = TBLOCK_ABORT_PENDING; break; --- a/src/test/regress/expected/transactions.out +++ b/src/test/regress/expected/transactions.out @@ -839,6 +839,28 @@ (1 row) ROLLBACK; +-- transaction chaining should not be used outside a transaction block +COMMIT AND CHAIN; -- error +ERROR: COMMIT AND CHAIN can only be used in transaction blocks +ROLLBACK AND CHAIN; -- error +ERROR: ROLLBACK AND CHAIN can only be used in transaction blocks +-- implicit transaction should not be chained as well +SET TRANSACTION READ WRITE\; COMMIT AND CHAIN; -- error +ERROR: COMMIT AND CHAIN can only be used in transaction blocks +SHOW transaction_read_only; + transaction_read_only +----------------------- + on +(1 row) + +SET TRANSACTION READ WRITE\; ROLLBACK AND CHAIN; -- error +ERROR: ROLLBACK AND CHAIN can only be used in transaction blocks +SHOW transaction_read_only; + transaction_read_only +----------------------- + on +(1 row) + SELECT * FROM abc ORDER BY 1; a --- --- a/src/test/regress/sql/transactions.sql +++ b/src/test/regress/sql/transactions.sql @@ -475,6 +475,17 @@ SHOW transaction_deferrable; ROLLBACK; +-- transaction chaining should not be used outside a transaction block +COMMIT AND CHAIN; -- error +ROLLBACK AND CHAIN; -- error + +-- implicit transaction should not be chained as well +SET TRANSACTION READ WRITE\; COMMIT AND CHAIN; -- error +SHOW transaction_read_only; + +SET TRANSACTION READ WRITE\; ROLLBACK AND CHAIN; -- error +SHOW transaction_read_only; + SELECT * FROM abc ORDER BY 1; RESET default_transaction_read_only;
^ permalink raw reply [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-09-07 10:16  Andres Freund <andres@anarazel.de>
  parent: Michael Paquier <michael@paquier.xyz>
  1 sibling, 0 replies; 30+ messages in thread

From: Andres Freund @ 2019-09-07 10:16 UTC (permalink / raw)
  To: Michael Paquier <michael@paquier.xyz>; +Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; fn ln <emuser20140816@gmail.com>; Fabien COELHO <coelho@cri.ensmp.fr>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>

Hi,

On 2019-09-06 16:54:15 +0900, Michael Paquier wrote:
> On Thu, Sep 05, 2019 at 02:11:35PM -0700, Andres Freund wrote:
> > On 2019-09-05 14:16:11 +0200, Peter Eisentraut wrote:
> >> I'm content with this patch.
> > 
> > Would need tests.
> 
> The latest patch sends adds coverage for all the new code paths
> added.  Do you have something else in mind?

Missed them somehow. But I don't think they're quite sufficient. I think
at least we also need tests that test things like multi-statement
exec_simple-query() *with* explicit transactions and chaining.


> >> Better disable questionable cases now and maybe re-enable them later
> >> if someone wants to make a case for it.
> > 
> > I do think the fact that COMMIT in multi-statement implicit transaction
> > has some usecase, is an argument for just implementing it properly...
> 
> Like Peter, I would also keep an ERROR for now, as we could always
> relax that later on.

I mean, I agree it's better to err that way, but it still seems
unnecessary to design things in a way that prevents legit cases, that we
then may have to allow later. Error -> no error is a behavioural change
too, even if obviously less likely to cause problems.


Greetings,

Andres Freund





^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-09-07 13:23  Fabien COELHO <coelho@cri.ensmp.fr>
  parent: fn ln <emuser20140816@gmail.com>
  0 siblings, 1 reply; 30+ messages in thread

From: Fabien COELHO @ 2019-09-07 13:23 UTC (permalink / raw)
  To: fn ln <emuser20140816@gmail.com>; +Cc: Michael Paquier <michael@paquier.xyz>; Andres Freund <andres@anarazel.de>; Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>


> I made another patch for that.
> I don't have much confidence with my English spelling so further
> improvements may be needed.
>
>> If it is too much a change and potential regression, then I think that the
>> "and chain" variants should be consistent and just raise warnings.

> We don't have an exact answer for implicit transaction chaining behavior
> yet.

> So I think it's better to disable this feature until someone discovers the
> use cases for this.

> Permitting AND CHAIN without a detailed specification might cause troubles
> in future.

I think that it would be too bad to remove this feature for a small 
implementation-dependent corner case.

Documentation says that COMMIT/ROLLBACK [AND CHAIN] apply to the "current 
transaction", and "BEGIN initiates a transaction block".

If there is no BEGIN, there is no "current transaction", so basically the 
behavior is unspecified, whether AND CHAIN or not, and we are free 
somehow.

In such case, I'm simply arguing for consistency: whatever the behavior, 
the chain and no chain variants should behave the same.

Now, I'd prefer error in all cases, no doubt about that, which might be 
considered a regression. A way around that could be to have a GUC decide 
between a strict behavior (error) and the old behavior (warning).

-- 
Fabien.





^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-09-07 16:32  fn ln <emuser20140816@gmail.com>
  parent: Fabien COELHO <coelho@cri.ensmp.fr>
  0 siblings, 2 replies; 30+ messages in thread

From: fn ln @ 2019-09-07 16:32 UTC (permalink / raw)
  To: Fabien COELHO <coelho@cri.ensmp.fr>; +Cc: Michael Paquier <michael@paquier.xyz>; Andres Freund <andres@anarazel.de>; Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>

> Missed them somehow. But I don't think they're quite sufficient. I think
> at least we also need tests that test things like multi-statement
> exec_simple-query() *with* explicit transactions and chaining.
Added a few more tests for that.

> Now, I'd prefer error in all cases, no doubt about that, which might be
> considered a regression. A way around that could be to have a GUC decide
> between a strict behavior (error) and the old behavior (warning).
I think it's more better to have a GUC to disable implicit transaction
'block' feature, because that's probably the root of all issues.

2019年9月7日(土) 22:23 Fabien COELHO <coelho@cri.ensmp.fr>:

>
> > I made another patch for that.
> > I don't have much confidence with my English spelling so further
> > improvements may be needed.
> >
> >> If it is too much a change and potential regression, then I think that
> the
> >> "and chain" variants should be consistent and just raise warnings.
>
> > We don't have an exact answer for implicit transaction chaining behavior
> > yet.
>
> > So I think it's better to disable this feature until someone discovers
> the
> > use cases for this.
>
> > Permitting AND CHAIN without a detailed specification might cause
> troubles
> > in future.
>
> I think that it would be too bad to remove this feature for a small
> implementation-dependent corner case.
>
> Documentation says that COMMIT/ROLLBACK [AND CHAIN] apply to the "current
> transaction", and "BEGIN initiates a transaction block".
>
> If there is no BEGIN, there is no "current transaction", so basically the
> behavior is unspecified, whether AND CHAIN or not, and we are free
> somehow.
>
> In such case, I'm simply arguing for consistency: whatever the behavior,
> the chain and no chain variants should behave the same.
>
> Now, I'd prefer error in all cases, no doubt about that, which might be
> considered a regression. A way around that could be to have a GUC decide
> between a strict behavior (error) and the old behavior (warning).
>
> --
> Fabien.
>

Attachments:

disable-implicit-transaction-chaining-v6.patch (application/octet-stream, 9.2K) download --- a/src/backend/access/transam/xact.c +++ b/src/backend/access/transam/xact.c @@ -3721,13 +3721,21 @@ break; /* - * In an implicit transaction block, commit, but issue a warning - * because there was no explicit BEGIN before this. + * We are in an implicit transaction block. If AND CHAIN was + * specified, we abort this transaction; otherwise commit, but + * issue a warning because there was no explicit BEGIN before this. */ case TBLOCK_IMPLICIT_INPROGRESS: - ereport(WARNING, - (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), - errmsg("there is no transaction in progress"))); + if (chain) + ereport(ERROR, + (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), + /* translator: %s represents an SQL statement name */ + errmsg("%s can only be used in transaction blocks", + "COMMIT AND CHAIN"))); + else + ereport(WARNING, + (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), + errmsg("there is no transaction in progress"))); s->blockState = TBLOCK_END; result = true; break; @@ -3789,15 +3797,26 @@ break; /* - * The user issued COMMIT when not inside a transaction. Issue a - * WARNING, staying in TBLOCK_STARTED state. The upcoming call to + * The user issued COMMIT when not inside a transaction. For + * COMMIT without transaction chaining, we just issue a WARNING, + * staying in TBLOCK_STARTED state. The upcoming call to * CommitTransactionCommand() will then close the transaction and * put us back into the default state. + * + * We disallow transaction chaining outside an explicit transaction + * block, so issue an ERROR if the user told us to do that. */ case TBLOCK_STARTED: - ereport(WARNING, - (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), - errmsg("there is no transaction in progress"))); + if (chain) + ereport(ERROR, + (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), + /* translator: %s represents an SQL statement name */ + errmsg("%s can only be used in transaction blocks", + "COMMIT AND CHAIN"))); + else + ereport(WARNING, + (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), + errmsg("there is no transaction in progress"))); result = true; break; @@ -3899,10 +3918,13 @@ break; /* - * The user issued ABORT when not inside a transaction. Issue a - * WARNING and go to abort state. The upcoming call to - * CommitTransactionCommand() will then put us back into the - * default state. + * The user issued ABORT when not inside a transaction. For + * ROLLBACK without transaction chaining, issue a WARNING and go + * to abort state. The upcoming call to CommitTransactionCommand() + * will then put us back into the default state. + * + * We disallow transaction chaining outside an explicit transaction + * block, so issue an ERROR if the user told us to do that. * * We do the same thing with ABORT inside an implicit transaction, * although in this case we might be rolling back actual database @@ -3911,9 +3933,16 @@ */ case TBLOCK_STARTED: case TBLOCK_IMPLICIT_INPROGRESS: - ereport(WARNING, - (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), - errmsg("there is no transaction in progress"))); + if (chain) + ereport(ERROR, + (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), + /* translator: %s represents an SQL statement name */ + errmsg("%s can only be used in transaction blocks", + "ROLLBACK AND CHAIN"))); + else + ereport(WARNING, + (errcode(ERRCODE_NO_ACTIVE_SQL_TRANSACTION), + errmsg("there is no transaction in progress"))); s->blockState = TBLOCK_ABORT_PENDING; break; --- a/src/test/regress/expected/transactions.out +++ b/src/test/regress/expected/transactions.out @@ -839,14 +839,87 @@ (1 row) ROLLBACK; +-- transaction chaining should not be used outside a transaction block +COMMIT AND CHAIN; -- error +ERROR: COMMIT AND CHAIN can only be used in transaction blocks +ROLLBACK AND CHAIN; -- error +ERROR: ROLLBACK AND CHAIN can only be used in transaction blocks +-- transaction chaining in an implicit transaction block should also not be used +SET TRANSACTION READ WRITE\; COMMIT AND CHAIN; -- error +ERROR: COMMIT AND CHAIN can only be used in transaction blocks +SHOW transaction_read_only; + transaction_read_only +----------------------- + on +(1 row) + +SET TRANSACTION READ WRITE\; ROLLBACK AND CHAIN; -- error +ERROR: ROLLBACK AND CHAIN can only be used in transaction blocks +SHOW transaction_read_only; + transaction_read_only +----------------------- + on +(1 row) + +-- a few more tests for implicit transaction chaining +SET default_transaction_read_only = off; +-- COMMIT/ROLLBACK ~ COMMIT/ROLLBACK AND CHAIN +INSERT INTO abc VALUES (7)\; COMMIT\; INSERT INTO abc VALUES (8)\; COMMIT AND CHAIN; -- 7 ok, 8 fail +WARNING: there is no transaction in progress +ERROR: COMMIT AND CHAIN can only be used in transaction blocks +INSERT INTO abc VALUES (9)\; ROLLBACK\; INSERT INTO abc VALUES (10)\; ROLLBACK AND CHAIN; -- 9 fail, 10 fail +WARNING: there is no transaction in progress +ERROR: ROLLBACK AND CHAIN can only be used in transaction blocks +-- COMMIT/ROLLBACK AND CHAIN ~ COMMIT/ROLLBACK +INSERT INTO abc VALUES (11)\; COMMIT AND CHAIN\; INSERT INTO abc VALUES (12)\; COMMIT; -- 11 fail, 12 fail +ERROR: COMMIT AND CHAIN can only be used in transaction blocks +INSERT INTO abc VALUES (13)\; ROLLBACK AND CHAIN\; INSERT INTO abc VALUES (14)\; ROLLBACK; -- 13 fail, 14 fail +ERROR: ROLLBACK AND CHAIN can only be used in transaction blocks +-- START TRANSACTION ~ COMMIT/ROLLBACK AND CHAIN +START TRANSACTION ISOLATION LEVEL REPEATABLE READ\; INSERT INTO abc VALUES (15)\; COMMIT AND CHAIN; -- 15 ok +SHOW transaction_isolation; -- transaction is active at this point + transaction_isolation +----------------------- + repeatable read +(1 row) + +COMMIT; +START TRANSACTION ISOLATION LEVEL REPEATABLE READ\; INSERT INTO abc VALUES (16)\; ROLLBACK AND CHAIN; -- 16 fail +SHOW transaction_isolation; -- transaction is active at this point + transaction_isolation +----------------------- + repeatable read +(1 row) + +ROLLBACK; +-- START TRANSACTION ~ COMMIT/ROLLBACK ~ COMMIT/ROLLBACK AND CHAIN +START TRANSACTION ISOLATION LEVEL REPEATABLE READ\; INSERT INTO abc VALUES (17)\; COMMIT\; INSERT INTO abc VALUES (18)\; COMMIT AND CHAIN; -- 17 ok, 18 fail +ERROR: COMMIT AND CHAIN can only be used in transaction blocks +SHOW transaction_isolation; -- out of transaction block + transaction_isolation +----------------------- + read committed +(1 row) + +START TRANSACTION ISOLATION LEVEL REPEATABLE READ\; INSERT INTO abc VALUES (19)\; ROLLBACK\; INSERT INTO abc VALUES (20)\; ROLLBACK AND CHAIN; -- 19 fail, 20 fail +ERROR: ROLLBACK AND CHAIN can only be used in transaction blocks +SHOW transaction_isolation; -- out of transaction block + transaction_isolation +----------------------- + read committed +(1 row) + SELECT * FROM abc ORDER BY 1; - a ---- - 1 - 2 - 4 - 5 -(4 rows) + a +---- + 1 + 2 + 4 + 5 + 7 + 15 + 17 +(7 rows) RESET default_transaction_read_only; DROP TABLE abc; --- a/src/test/regress/sql/transactions.sql +++ b/src/test/regress/sql/transactions.sql @@ -475,6 +475,44 @@ SHOW transaction_deferrable; ROLLBACK; +-- transaction chaining should not be used outside a transaction block +COMMIT AND CHAIN; -- error +ROLLBACK AND CHAIN; -- error + +-- transaction chaining in an implicit transaction block should also not be used +SET TRANSACTION READ WRITE\; COMMIT AND CHAIN; -- error +SHOW transaction_read_only; + +SET TRANSACTION READ WRITE\; ROLLBACK AND CHAIN; -- error +SHOW transaction_read_only; + +-- a few more tests for implicit transaction chaining +SET default_transaction_read_only = off; + +-- COMMIT/ROLLBACK ~ COMMIT/ROLLBACK AND CHAIN +INSERT INTO abc VALUES (7)\; COMMIT\; INSERT INTO abc VALUES (8)\; COMMIT AND CHAIN; -- 7 ok, 8 fail +INSERT INTO abc VALUES (9)\; ROLLBACK\; INSERT INTO abc VALUES (10)\; ROLLBACK AND CHAIN; -- 9 fail, 10 fail + +-- COMMIT/ROLLBACK AND CHAIN ~ COMMIT/ROLLBACK +INSERT INTO abc VALUES (11)\; COMMIT AND CHAIN\; INSERT INTO abc VALUES (12)\; COMMIT; -- 11 fail, 12 fail +INSERT INTO abc VALUES (13)\; ROLLBACK AND CHAIN\; INSERT INTO abc VALUES (14)\; ROLLBACK; -- 13 fail, 14 fail + +-- START TRANSACTION ~ COMMIT/ROLLBACK AND CHAIN +START TRANSACTION ISOLATION LEVEL REPEATABLE READ\; INSERT INTO abc VALUES (15)\; COMMIT AND CHAIN; -- 15 ok +SHOW transaction_isolation; -- transaction is active at this point +COMMIT; + +START TRANSACTION ISOLATION LEVEL REPEATABLE READ\; INSERT INTO abc VALUES (16)\; ROLLBACK AND CHAIN; -- 16 fail +SHOW transaction_isolation; -- transaction is active at this point +ROLLBACK; + +-- START TRANSACTION ~ COMMIT/ROLLBACK ~ COMMIT/ROLLBACK AND CHAIN +START TRANSACTION ISOLATION LEVEL REPEATABLE READ\; INSERT INTO abc VALUES (17)\; COMMIT\; INSERT INTO abc VALUES (18)\; COMMIT AND CHAIN; -- 17 ok, 18 fail +SHOW transaction_isolation; -- out of transaction block + +START TRANSACTION ISOLATION LEVEL REPEATABLE READ\; INSERT INTO abc VALUES (19)\; ROLLBACK\; INSERT INTO abc VALUES (20)\; ROLLBACK AND CHAIN; -- 19 fail, 20 fail +SHOW transaction_isolation; -- out of transaction block + SELECT * FROM abc ORDER BY 1; RESET default_transaction_read_only;
^ permalink raw reply [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-09-07 17:04  Fabien COELHO <coelho@cri.ensmp.fr>
  parent: fn ln <emuser20140816@gmail.com>
  1 sibling, 1 reply; 30+ messages in thread

From: Fabien COELHO @ 2019-09-07 17:04 UTC (permalink / raw)
  To: fn ln <emuser20140816@gmail.com>; +Cc: Michael Paquier <michael@paquier.xyz>; Andres Freund <andres@anarazel.de>; Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>


>> Now, I'd prefer error in all cases, no doubt about that, which might be
>> considered a regression. A way around that could be to have a GUC decide
>> between a strict behavior (error) and the old behavior (warning).
>
> I think it's more better to have a GUC to disable implicit transaction
> 'block' feature, because that's probably the root of all issues.

Hmmm… I'm not sure that erroring out on "SELECT 1" because there is no 
explicit "BEGIN" is sellable, even under some GUC.

-- 
Fabien.

^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-09-07 17:31  fn ln <emuser20140816@gmail.com>
  parent: Fabien COELHO <coelho@cri.ensmp.fr>
  0 siblings, 0 replies; 30+ messages in thread

From: fn ln @ 2019-09-07 17:31 UTC (permalink / raw)
  To: Fabien COELHO <coelho@cri.ensmp.fr>; +Cc: Michael Paquier <michael@paquier.xyz>; Andres Freund <andres@anarazel.de>; Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>

No, but instead always do an implicit COMMIT after each statement, like
SELECT 1; SELECT 2; (not \;) in psql.
The PostgreSQL document even states that 'Issuing COMMIT when not inside a
transaction does no harm, but it will provoke a warning message.' for a
long time,
but in fact it have side-effect when used in an implicit transactions.
If we can ensure that the COMMIT/ROLLBACK really does nothing, we don't
have to distinguish CHAIN and NO CHAIN errors anymore.

2019年9月8日(日) 2:04 Fabien COELHO <coelho@cri.ensmp.fr>:

>
> >> Now, I'd prefer error in all cases, no doubt about that, which might be
> >> considered a regression. A way around that could be to have a GUC decide
> >> between a strict behavior (error) and the old behavior (warning).
> >
> > I think it's more better to have a GUC to disable implicit transaction
> > 'block' feature, because that's probably the root of all issues.
>
> Hmmm… I'm not sure that erroring out on "SELECT 1" because there is no
> explicit "BEGIN" is sellable, even under some GUC.
>
> --
> Fabien.

^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-09-08 20:27  Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  parent: fn ln <emuser20140816@gmail.com>
  1 sibling, 1 reply; 30+ messages in thread

From: Peter Eisentraut @ 2019-09-08 20:27 UTC (permalink / raw)
  To: fn ln <emuser20140816@gmail.com>; Fabien COELHO <coelho@cri.ensmp.fr>; +Cc: Michael Paquier <michael@paquier.xyz>; Andres Freund <andres@anarazel.de>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>

On 2019-09-07 18:32, fn ln wrote:
>> Missed them somehow. But I don't think they're quite sufficient. I think
>> at least we also need tests that test things like multi-statement
>> exec_simple-query() *with* explicit transactions and chaining.
> Added a few more tests for that.

I committed this patch with some cosmetic changes and documentation updates.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-09-09 03:58  fn ln <emuser20140816@gmail.com>
  parent: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  0 siblings, 1 reply; 30+ messages in thread

From: fn ln @ 2019-09-09 03:58 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: Fabien COELHO <coelho@cri.ensmp.fr>; Michael Paquier <michael@paquier.xyz>; Andres Freund <andres@anarazel.de>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>

Confirmed. Thank you all for your help.

The only concern is that this test:

   SET TRANSACTION READ WRITE\; COMMIT AND CHAIN;  -- error
   SHOW transaction_read_only;

   SET TRANSACTION READ WRITE\; ROLLBACK AND CHAIN;  -- error
   SHOW transaction_read_only;

makes more sense with READ ONLY because default_transaction_read_only is
off at this point.

2019年9月9日(月) 5:27 Peter Eisentraut <peter.eisentraut@2ndquadrant.com>:

> On 2019-09-07 18:32, fn ln wrote:
> >> Missed them somehow. But I don't think they're quite sufficient. I think
> >> at least we also need tests that test things like multi-statement
> >> exec_simple-query() *with* explicit transactions and chaining.
> > Added a few more tests for that.
>
> I committed this patch with some cosmetic changes and documentation
> updates.
>
> --
> Peter Eisentraut              http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>

^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-09-09 08:42  Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  parent: fn ln <emuser20140816@gmail.com>
  0 siblings, 1 reply; 30+ messages in thread

From: Peter Eisentraut @ 2019-09-09 08:42 UTC (permalink / raw)
  To: fn ln <emuser20140816@gmail.com>; +Cc: Fabien COELHO <coelho@cri.ensmp.fr>; Michael Paquier <michael@paquier.xyz>; Andres Freund <andres@anarazel.de>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>

On 2019-09-09 05:58, fn ln wrote:
> Confirmed. Thank you all for your help.
> 
> The only concern is that this test:
> 
>    SET TRANSACTION READ WRITE\; COMMIT AND CHAIN;  -- error
>    SHOW transaction_read_only;
> 
>    SET TRANSACTION READ WRITE\; ROLLBACK AND CHAIN;  -- error
>    SHOW transaction_read_only;
> 
> makes more sense with READ ONLY because default_transaction_read_only is
> off at this point.

Oh you're right.  Fixed.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services





^ permalink  raw  reply  [nested|flat] 30+ messages in thread

* Re: BUG #15977: Inconsistent behavior in chained transactions
@ 2019-09-09 09:32  fn ln <emuser20140816@gmail.com>
  parent: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
  0 siblings, 0 replies; 30+ messages in thread

From: fn ln @ 2019-09-09 09:32 UTC (permalink / raw)
  To: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>; +Cc: Fabien COELHO <coelho@cri.ensmp.fr>; Michael Paquier <michael@paquier.xyz>; Andres Freund <andres@anarazel.de>; PostgreSQL Developers <pgsql-hackers@lists.postgresql.org>

It looks good now. Thank you again.

2019年9月9日(月) 17:43 Peter Eisentraut <peter.eisentraut@2ndquadrant.com>:

> On 2019-09-09 05:58, fn ln wrote:
> > Confirmed. Thank you all for your help.
> >
> > The only concern is that this test:
> >
> >    SET TRANSACTION READ WRITE\; COMMIT AND CHAIN;  -- error
> >    SHOW transaction_read_only;
> >
> >    SET TRANSACTION READ WRITE\; ROLLBACK AND CHAIN;  -- error
> >    SHOW transaction_read_only;
> >
> > makes more sense with READ ONLY because default_transaction_read_only is
> > off at this point.
>
> Oh you're right.  Fixed.
>
> --
> Peter Eisentraut              http://www.2ndQuadrant.com/
> PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
>

^ permalink  raw  reply  [nested|flat] 30+ messages in thread


end of thread, other threads:[~2019-09-09 09:32 UTC | newest]

Thread overview: 30+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-08-25 06:11 BUG #15977: Inconsistent behavior in chained transactions PG Bug reporting form <noreply@postgresql.org>
2019-08-25 09:11 ` Fabien COELHO <coelho@cri.ensmp.fr>
2019-08-28 19:29   ` fn ln <emuser20140816@gmail.com>
2019-08-29 06:30     ` Fabien COELHO <coelho@cri.ensmp.fr>
2019-08-29 11:39       ` fn ln <emuser20140816@gmail.com>
2019-08-29 12:10         ` Fabien COELHO <coelho@cri.ensmp.fr>
2019-08-29 12:35           ` fn ln <emuser20140816@gmail.com>
2019-08-29 13:01             ` Fabien COELHO <coelho@cri.ensmp.fr>
2019-08-29 13:55               ` fn ln <emuser20140816@gmail.com>
2019-08-29 14:58                 ` Fabien COELHO <coelho@cri.ensmp.fr>
2019-09-03 09:54                   ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2019-09-03 10:03                     ` Fabien COELHO <coelho@cri.ensmp.fr>
2019-09-03 13:27                     ` fn ln <emuser20140816@gmail.com>
2019-09-04 07:53                     ` Andres Freund <andres@anarazel.de>
2019-09-04 14:49                       ` fn ln <emuser20140816@gmail.com>
2019-09-05 12:16                         ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2019-09-05 21:11                           ` Andres Freund <andres@anarazel.de>
2019-09-06 07:54                             ` Michael Paquier <michael@paquier.xyz>
2019-09-07 06:54                               ` Fabien COELHO <coelho@cri.ensmp.fr>
2019-09-07 09:58                                 ` fn ln <emuser20140816@gmail.com>
2019-09-07 13:23                                   ` Fabien COELHO <coelho@cri.ensmp.fr>
2019-09-07 16:32                                     ` fn ln <emuser20140816@gmail.com>
2019-09-07 17:04                                       ` Fabien COELHO <coelho@cri.ensmp.fr>
2019-09-07 17:31                                         ` fn ln <emuser20140816@gmail.com>
2019-09-08 20:27                                       ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2019-09-09 03:58                                         ` fn ln <emuser20140816@gmail.com>
2019-09-09 08:42                                           ` Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
2019-09-09 09:32                                             ` fn ln <emuser20140816@gmail.com>
2019-09-07 10:16                               ` Andres Freund <andres@anarazel.de>
2019-08-29 07:24 Re: BUG #15977: Inconsistent behavior in chained transactions Fabien COELHO <coelho@cri.ensmp.fr>

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