From cf8217da76957b791a3a4d188fcd0943c427de72 Mon Sep 17 00:00:00 2001 From: Narek Galstyan Date: Thu, 5 Nov 2026 18:32:36 -0500 Subject: [PATCH 1/2] Add tests for AND CHAIN after an error in a non-chained transaction The existing tests for COMMIT/ROLLBACK AND CHAIN of a failed transaction block (TBLOCK_ABORT_END) only test failures of transactions that were started via AND CHAIN. Since they come after AND CHAIN, their characteristics are set via RestoreTransactionCharacteristics() and not through the GUC stack, so the characteristics correctly survive the abort. The commit adds cases where the failed transaction got its characteristics from START TRANSACTION or SET TRANSACTION. The expected output is the correct behavior, so regression test fails until the next commit. --- src/test/regress/expected/transactions.out | 53 ++++++++++++++++++++++ src/test/regress/sql/transactions.sql | 19 ++++++++ 2 files changed, 72 insertions(+) diff --git a/src/test/regress/expected/transactions.out b/src/test/regress/expected/transactions.out index 7f5757e89c4..f9bdc54675c 100644 --- a/src/test/regress/expected/transactions.out +++ b/src/test/regress/expected/transactions.out @@ -956,6 +956,59 @@ SHOW transaction_deferrable; off (1 row) +ROLLBACK; +-- failed transaction with characteristics set by START TRANSACTION or +-- SET TRANSACTION, and not through AND CHAIN +START TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ WRITE, DEFERRABLE; +INSERT INTO trans_abc VALUES ('error'); +ERROR: invalid input syntax for type integer: "error" +LINE 1: INSERT INTO trans_abc VALUES ('error'); + ^ +COMMIT AND CHAIN; -- TBLOCK_ABORT_END +SHOW transaction_isolation; + transaction_isolation +----------------------- + repeatable read +(1 row) + +SHOW transaction_read_only; + transaction_read_only +----------------------- + off +(1 row) + +SHOW transaction_deferrable; + transaction_deferrable +------------------------ + on +(1 row) + +ROLLBACK; +START TRANSACTION; +SET TRANSACTION ISOLATION LEVEL SERIALIZABLE, READ WRITE, DEFERRABLE; +INSERT INTO trans_abc VALUES ('error'); +ERROR: invalid input syntax for type integer: "error" +LINE 1: INSERT INTO trans_abc VALUES ('error'); + ^ +ROLLBACK AND CHAIN; -- TBLOCK_ABORT_END +SHOW transaction_isolation; + transaction_isolation +----------------------- + serializable +(1 row) + +SHOW transaction_read_only; + transaction_read_only +----------------------- + off +(1 row) + +SHOW transaction_deferrable; + transaction_deferrable +------------------------ + on +(1 row) + ROLLBACK; -- not allowed outside a transaction block COMMIT AND CHAIN; -- error diff --git a/src/test/regress/sql/transactions.sql b/src/test/regress/sql/transactions.sql index 51ae1b31b30..ff9a3048933 100644 --- a/src/test/regress/sql/transactions.sql +++ b/src/test/regress/sql/transactions.sql @@ -517,6 +517,25 @@ SHOW transaction_read_only; SHOW transaction_deferrable; ROLLBACK; +-- failed transaction with characteristics set by START TRANSACTION or +-- SET TRANSACTION, and not through AND CHAIN +START TRANSACTION ISOLATION LEVEL REPEATABLE READ, READ WRITE, DEFERRABLE; +INSERT INTO trans_abc VALUES ('error'); +COMMIT AND CHAIN; -- TBLOCK_ABORT_END +SHOW transaction_isolation; +SHOW transaction_read_only; +SHOW transaction_deferrable; +ROLLBACK; + +START TRANSACTION; +SET TRANSACTION ISOLATION LEVEL SERIALIZABLE, READ WRITE, DEFERRABLE; +INSERT INTO trans_abc VALUES ('error'); +ROLLBACK AND CHAIN; -- TBLOCK_ABORT_END +SHOW transaction_isolation; +SHOW transaction_read_only; +SHOW transaction_deferrable; +ROLLBACK; + -- not allowed outside a transaction block COMMIT AND CHAIN; -- error ROLLBACK AND CHAIN; -- error -- 2.50.1 (Apple Git-155)