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

Commit77dc816

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 parentda42121 commit77dc816

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3024,6 +3024,7 @@ CommitTransactionCommand(void)
30243024
TransactionStates=CurrentTransactionState;
30253025
SavedTransactionCharacteristicssavetc;
30263026

3027+
/* Must save in case we need to restore below */
30273028
SaveTransactionCharacteristics(&savetc);
30283029

30293030
switch (s->blockState)

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,46 @@ SHOW transaction_deferrable;
818818
on
819819
(1 row)
820820

821+
COMMIT;
822+
START TRANSACTION ISOLATION LEVEL READ COMMITTED, READ WRITE, DEFERRABLE;
823+
SHOW transaction_isolation;
824+
transaction_isolation
825+
-----------------------
826+
read committed
827+
(1 row)
828+
829+
SHOW transaction_read_only;
830+
transaction_read_only
831+
-----------------------
832+
off
833+
(1 row)
834+
835+
SHOW transaction_deferrable;
836+
transaction_deferrable
837+
------------------------
838+
on
839+
(1 row)
840+
841+
SAVEPOINT x;
842+
COMMIT AND CHAIN; -- TBLOCK_SUBCOMMIT
843+
SHOW transaction_isolation;
844+
transaction_isolation
845+
-----------------------
846+
read committed
847+
(1 row)
848+
849+
SHOW transaction_read_only;
850+
transaction_read_only
851+
-----------------------
852+
off
853+
(1 row)
854+
855+
SHOW transaction_deferrable;
856+
transaction_deferrable
857+
------------------------
858+
on
859+
(1 row)
860+
821861
COMMIT;
822862
-- different mix of options just for fun
823863
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
@@ -471,6 +471,17 @@ SHOW transaction_read_only;
471471
SHOW transaction_deferrable;
472472
COMMIT;
473473

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp