!2532 修复在事务块中set autocommit = 0再rollback时引发fatal错误的bug
Merge pull request !2532 from Cross-罗/autocommit
This commit is contained in:
@ -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")));
|
||||
}
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -468,5 +468,4 @@ extern char* GetCurrentTransactionName();
|
||||
extern List* GetTransactionList(List *head);
|
||||
extern void BeginTxnForAutoCommitOff();
|
||||
extern bool IsTransactionInProgressState();
|
||||
extern bool IsTransactionDefaultState();
|
||||
#endif /* XACT_H */
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user