Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 422012c

Browse 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 bf9d3a5 commit 422012c

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

src/backend/access/transam/xact.c

+7
Original file line numberDiff line numberDiff line change
@@ -3084,6 +3084,13 @@ CommitTransactionCommand(void)
30843084
Assert(s->parent == NULL);
30853085
CommitTransaction();
30863086
s->blockState = TBLOCK_DEFAULT;
3087+
if (s->chain)
3088+
{
3089+
StartTransaction();
3090+
s->blockState = TBLOCK_INPROGRESS;
3091+
s->chain = false;
3092+
RestoreTransactionCharacteristics();
3093+
}
30873094
}
30883095
else if (s->blockState == TBLOCK_PREPARE)
30893096
{

src/test/regress/expected/transactions.out

+40
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

+11
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)