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

Appearance settings

Commit 8a55cb5

Browse filesBrowse files
committed
Fix bug in COMMIT AND CHAIN command.
This commit fixes COMMIT AND CHAIN command so that it starts new transaction immediately even if savepoints are defined within the transaction to commit. Previously COMMIT AND CHAIN command did not in that case because commit 280a408 forgot to make CommitTransactionCommand() handle a transaction chaining when the transaction state was TBLOCK_SUBCOMMIT. Also this commit adds the regression test for COMMIT AND CHAIN command when savepoints are defined. Back-patch to v12 where transaction chaining was added. Reported-by: Arthur Nascimento Author: Fujii Masao Reviewed-by: Arthur Nascimento, Vik Fearing Discussion: https://postgr.es/m/16867-3475744069228158@postgresql.org
1 parent 678d0e2 commit 8a55cb5
Copy full SHA for 8a55cb5

File tree

Expand file treeCollapse file tree

3 files changed

+58
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+58
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/backend/access/transam/xact.c
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3105,6 +3105,13 @@ CommitTransactionCommand(void)
31053105
Assert(s->parent == NULL);
31063106
CommitTransaction();
31073107
s->blockState = TBLOCK_DEFAULT;
3108+
if (s->chain)
3109+
{
3110+
StartTransaction();
3111+
s->blockState = TBLOCK_INPROGRESS;
3112+
s->chain = false;
3113+
RestoreTransactionCharacteristics();
3114+
}
31083115
}
31093116
else if (s->blockState == TBLOCK_PREPARE)
31103117
{

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

Copy file name to clipboardExpand all lines: src/test/regress/expected/transactions.out
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,46 @@ SHOW transaction_deferrable;
774774
(1 row)
775775

776776
INSERT INTO abc VALUES (5);
777+
COMMIT;
778+
START TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ WRITE, DEFERRABLE;
779+
SHOW transaction_isolation;
780+
transaction_isolation
781+
-----------------------
782+
repeatable read
783+
(1 row)
784+
785+
SHOW transaction_read_only;
786+
transaction_read_only
787+
-----------------------
788+
off
789+
(1 row)
790+
791+
SHOW transaction_deferrable;
792+
transaction_deferrable
793+
------------------------
794+
on
795+
(1 row)
796+
797+
SAVEPOINT x;
798+
COMMIT AND CHAIN; -- TBLOCK_SUBCOMMIT
799+
SHOW transaction_isolation;
800+
transaction_isolation
801+
-----------------------
802+
repeatable read
803+
(1 row)
804+
805+
SHOW transaction_read_only;
806+
transaction_read_only
807+
-----------------------
808+
off
809+
(1 row)
810+
811+
SHOW transaction_deferrable;
812+
transaction_deferrable
813+
------------------------
814+
on
815+
(1 row)
816+
777817
COMMIT;
778818
-- different mix of options just for fun
779819
START TRANSACTION ISOLATION LEVEL SERIALIZABLE, READ WRITE, NOT DEFERRABLE;

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

Copy file name to clipboardExpand all lines: src/test/regress/sql/transactions.sql
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,17 @@ SHOW transaction_deferrable;
458458
INSERT INTO abc VALUES (5);
459459
COMMIT;
460460

461+
START TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ WRITE, DEFERRABLE;
462+
SHOW transaction_isolation;
463+
SHOW transaction_read_only;
464+
SHOW transaction_deferrable;
465+
SAVEPOINT x;
466+
COMMIT AND CHAIN; -- TBLOCK_SUBCOMMIT
467+
SHOW transaction_isolation;
468+
SHOW transaction_read_only;
469+
SHOW transaction_deferrable;
470+
COMMIT;
471+
461472
-- different mix of options just for fun
462473
START TRANSACTION ISOLATION LEVEL SERIALIZABLE, READ WRITE, NOT DEFERRABLE;
463474
SHOW transaction_isolation;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.