Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7cabb20

Browse files
committed
Fix COMMIT/ROLLBACK AND CHAIN in the presence of subtransactions.
In older branches, COMMIT/ROLLBACK AND CHAIN failed to propagatethe current transaction's properties to the new transaction ifthere was any open subtransaction (unreleased savepoint).Instead, some previous transaction's properties would be restored.This is because the "if (s->chain)" check in CommitTransactionCommandexamined the wrong instance of the "chain" flag and falselyconcluded that it didn't need to save transaction properties.Our regression tests would have noticed this, except they usedidentical transaction properties for multiple tests in a row,so that the faulty behavior was not distinguishable from correctbehavior.Commit12d768e fixed the problem in v15 and later, but only ratheraccidentally, because I removed the "if (s->chain)" test to avoid acompiler warning, while not realizing that the warning was flagging areal bug.In v14 and before, remove the if-test and save transaction propertiesunconditionally; just as in the newer branches, that's not expensiveenough to justify thinking harder.Add the comment and extra regression test to v15 and later toforestall any future recurrence, but there's no live bug in thosebranches.Patch by me, per bug #18118 from Liu Xiang. Back-patch to v12 wherethe AND CHAIN feature was added.Discussion:https://postgr.es/m/18118-4b72fcbb903aace6@postgresql.org
1 parentc50ad79 commit7cabb20

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

‎src/backend/access/transam/xact.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2913,8 +2913,8 @@ CommitTransactionCommand(void)
29132913
{
29142914
TransactionStates=CurrentTransactionState;
29152915

2916-
if (s->chain)
2917-
SaveTransactionCharacteristics();
2916+
/* Must save in case we need to restore below */
2917+
SaveTransactionCharacteristics();
29182918

29192919
switch (s->blockState)
29202920
{

‎src/test/regress/expected/transactions.out

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,46 @@ SHOW transaction_deferrable;
814814
on
815815
(1 row)
816816

817+
COMMIT;
818+
START TRANSACTION ISOLATION LEVEL READ COMMITTED, READ WRITE, DEFERRABLE;
819+
SHOW transaction_isolation;
820+
transaction_isolation
821+
-----------------------
822+
read committed
823+
(1 row)
824+
825+
SHOW transaction_read_only;
826+
transaction_read_only
827+
-----------------------
828+
off
829+
(1 row)
830+
831+
SHOW transaction_deferrable;
832+
transaction_deferrable
833+
------------------------
834+
on
835+
(1 row)
836+
837+
SAVEPOINT x;
838+
COMMIT AND CHAIN; -- TBLOCK_SUBCOMMIT
839+
SHOW transaction_isolation;
840+
transaction_isolation
841+
-----------------------
842+
read committed
843+
(1 row)
844+
845+
SHOW transaction_read_only;
846+
transaction_read_only
847+
-----------------------
848+
off
849+
(1 row)
850+
851+
SHOW transaction_deferrable;
852+
transaction_deferrable
853+
------------------------
854+
on
855+
(1 row)
856+
817857
COMMIT;
818858
-- different mix of options just for fun
819859
START TRANSACTION ISOLATION LEVEL SERIALIZABLE, READ WRITE, NOT DEFERRABLE;

‎src/test/regress/sql/transactions.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,17 @@ SHOW transaction_read_only;
469469
SHOW transaction_deferrable;
470470
COMMIT;
471471

472+
START TRANSACTION ISOLATION LEVEL READ COMMITTED, READ WRITE, DEFERRABLE;
473+
SHOW transaction_isolation;
474+
SHOW transaction_read_only;
475+
SHOW transaction_deferrable;
476+
SAVEPOINT x;
477+
COMMITAND CHAIN;-- TBLOCK_SUBCOMMIT
478+
SHOW transaction_isolation;
479+
SHOW transaction_read_only;
480+
SHOW transaction_deferrable;
481+
COMMIT;
482+
472483
-- different mix of options just for fun
473484
START TRANSACTION ISOLATION LEVEL SERIALIZABLE, READ WRITE, NOT DEFERRABLE;
474485
SHOW transaction_isolation;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp