diff --git a/src/common/backend/utils/misc/guc/guc_storage.cpp b/src/common/backend/utils/misc/guc/guc_storage.cpp index 521a9523f..bccbd50e3 100755 --- a/src/common/backend/utils/misc/guc/guc_storage.cpp +++ b/src/common/backend/utils/misc/guc/guc_storage.cpp @@ -4672,7 +4672,7 @@ static void assign_phony_autocommit(bool newval, void* extra) { /* change autocommit from false to on */ if (newval && u_sess->attr.attr_storage.phony_autocommit != newval) { - if (!IsTransactionDefaultState() && !EndTransactionBlock()) { + if (IsTransactionInProgressState() && !EndTransactionBlock()) { ereport(ERROR, (errmsg("end transaction failed"))); } } diff --git a/src/gausskernel/storage/access/transam/xact.cpp b/src/gausskernel/storage/access/transam/xact.cpp index 9c2d596e7..b5ab6235c 100755 --- a/src/gausskernel/storage/access/transam/xact.cpp +++ b/src/gausskernel/storage/access/transam/xact.cpp @@ -8483,16 +8483,10 @@ static void AtEOXact_Proceed_PatchSeq() } } -bool IsTransactionDefaultState() -{ - TransactionState s = CurrentTransactionState; - return s->blockState == TBLOCK_DEFAULT; -} - bool IsTransactionInProgressState() { TransactionState s = CurrentTransactionState; - return s->blockState == TBLOCK_INPROGRESS; + return (s->blockState == TBLOCK_INPROGRESS) || (s->blockState == TBLOCK_SUBINPROGRESS); } void BeginTxnForAutoCommitOff() diff --git a/src/include/access/xact.h b/src/include/access/xact.h index 637eedac3..98d0dedf9 100644 --- a/src/include/access/xact.h +++ b/src/include/access/xact.h @@ -468,5 +468,4 @@ extern char* GetCurrentTransactionName(); extern List* GetTransactionList(List *head); extern void BeginTxnForAutoCommitOff(); extern bool IsTransactionInProgressState(); -extern bool IsTransactionDefaultState(); #endif /* XACT_H */ diff --git a/src/test/regress/expected/autocommit_test.out b/src/test/regress/expected/autocommit_test.out index 05ac4ec7f..5fdc53300 100644 --- a/src/test/regress/expected/autocommit_test.out +++ b/src/test/regress/expected/autocommit_test.out @@ -85,7 +85,7 @@ SELECT * FROM test_a; ROLLBACK; SELECT * FROM test_a; -ERROR: relation "test_a" does not exist on datanode1 +--?ERROR: relation "test_a" does not exist on .* LINE 1: SELECT * FROM test_a; ^ COMMIT; @@ -238,6 +238,23 @@ SELECT * FROM test_table; aaaaa (1 row) +-- set autocommit = 0 and rollback +BEGIN; +INSERT INTO test_table values('ccccc'); +SET autocommit = 0; +ROLLBACK; +SELECT * FROM test_table; + a +------- + aaaaa +(1 row) + +SHOW autocommit; + autocommit +------------ + on +(1 row) + \c regression DROP DATABASE test_db; DROP DATABASE test_drop; diff --git a/src/test/regress/sql/autocommit_test.sql b/src/test/regress/sql/autocommit_test.sql index 1d4d6e172..98d9cad05 100644 --- a/src/test/regress/sql/autocommit_test.sql +++ b/src/test/regress/sql/autocommit_test.sql @@ -116,6 +116,14 @@ SET autocommit = 1; ROLLBACK; SELECT * FROM test_table; +-- set autocommit = 0 and rollback +BEGIN; +INSERT INTO test_table values('ccccc'); +SET autocommit = 0; +ROLLBACK; +SELECT * FROM test_table; +SHOW autocommit; + \c regression DROP DATABASE test_db; DROP DATABASE test_drop;