!1729 修复设置事务读写模式失效的问题

Merge pull request !1729 from pengjiong/transaction
This commit is contained in:
opengauss-bot
2022-06-21 11:03:38 +00:00
committed by Gitee
4 changed files with 39 additions and 2 deletions

View File

@ -2260,8 +2260,11 @@ static void set_item_arg_according_to_def_name(DefElem* item)
if (strcmp(item->defname, "transaction_isolation") == 0) {
SetPGVariable("transaction_isolation", list_make1(item->arg), true);
} else if (strcmp(item->defname, "transaction_read_only") == 0) {
#ifdef ENABLE_MULTIPLE_NODES
/* Set read only state from CN when this DN is not read only. */
if (u_sess->attr.attr_storage.DefaultXactReadOnly == false) {
if (u_sess->attr.attr_storage.DefaultXactReadOnly == false)
#endif
{
SetPGVariable("transaction_read_only", list_make1(item->arg), true);
}
} else if (strcmp(item->defname, "transaction_deferrable") == 0) {

View File

@ -0,0 +1,20 @@
SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY;
START TRANSACTION READ WRITE;
CREATE TABLE transaction_test_table(a int);
insert into transaction_test_table values(1);
update transaction_test_table set a=2 where a=1;
select * from transaction_test_table;
a
---
2
(1 row)
commit;
-- error
delete from transaction_test_table;
ERROR: cannot execute DELETE in a read-only transaction
drop table transaction_test_table;
ERROR: cannot execute DROP TABLE in a read-only transaction
START TRANSACTION READ WRITE;
drop table transaction_test_table;
commit;

View File

@ -154,7 +154,7 @@ test: single_node_select_implicit single_node_select_having
test: single_node_union
#test: single_node_case single_node_join single_node_aggregates
#test: single_node_transactions
test: single_node_random
test: single_node_random transactions_test
#test: single_node_portals
#test: single_node_arrays
#test: single_node_btree_index single_node_hash_index single_node_update

View File

@ -0,0 +1,14 @@
SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY;
START TRANSACTION READ WRITE;
CREATE TABLE transaction_test_table(a int);
insert into transaction_test_table values(1);
update transaction_test_table set a=2 where a=1;
select * from transaction_test_table;
commit;
-- error
delete from transaction_test_table;
drop table transaction_test_table;
START TRANSACTION READ WRITE;
drop table transaction_test_table;
commit;