github.com/matrixorigin/matrixone@v1.2.0/test/distributed/cases/optimistic/autocommit_1.sql (about)

     1  -- @suit
     2  
     3  -- @case
     4  -- @desc:Test echo autocommit
     5  -- @label:bvt
     6  
     7  
     8  SELECT @@session.autocommit;
     9  
    10  
    11  SET @@session.autocommit=1;
    12  SELECT @@session.autocommit;
    13  
    14  SET @@session.autocommit= 0;
    15  SELECT @@session.autocommit;
    16  -- select has started a txn
    17  rollback;
    18  
    19  SET @@session.autocommit=OFF;
    20  SELECT @@session.autocommit;
    21  -- select has started a txn
    22  rollback;
    23  
    24  SET @@session.autocommit=ON;
    25  SELECT @@session.autocommit;
    26  
    27  --error You have an error in your SQL syntax;
    28  SET @@session.autocommit=foo;
    29  SELECT @@session.autocommit;
    30  commit;
    31  
    32  SET @@session.autocommit=OFF;
    33  SELECT @@session.autocommit;
    34  commit;
    35  
    36  SET @@session.autocommit=ON;
    37  SELECT @@session.autocommit;
    38  commit;
    39  
    40  -- convert to the system variable bool type failed
    41  SET @@session.autocommit=foo;
    42  SELECT @@session.autocommit;
    43  commit;
    44  
    45  
    46  -- @case
    47  -- @desc:Test implicit transaction commit (commit;,rollback;)
    48  -- @label:bvt
    49  
    50  set autocommit=0;
    51  select @@autocommit;
    52  commit;
    53  
    54  -- Test implicit transaction rollback
    55  drop database if exists db;
    56  create database db;
    57  show databases like 'db';
    58  use db;
    59  create table tab1(a int, b int);
    60  create view view_tab1 as select * from tab1;
    61  insert into tab1 values (2000, 3000);
    62  rollback;
    63  select * from tab1;
    64  commit;
    65  
    66  
    67  -- Test implicit transaction commit
    68  drop database if exists db;
    69  create database db;
    70  show databases like 'db';
    71  use db;
    72  create table tab1(a int, b int);
    73  
    74  -- test table tab1 DML and commit; rollback;
    75  insert into tab1 values (2000, 3000);
    76  insert into tab1 values (10, 10);
    77  commit;
    78  select * from tab1;
    79  update tab1 set a=100000 where b=3000;
    80  select * from tab1;
    81  rollback;
    82  select * from tab1;
    83  update tab1 set a=100000 where b=3000;
    84  commit;
    85  select * from tab1;
    86  delete from tab1 where a=10;
    87  rollback;
    88  select * from tab1;
    89  delete from tab1 where a=10;
    90  commit;
    91  select * from tab1;
    92  
    93  
    94  -- test view view_tab1 DML and commit; rollback;(view nonsupport insert/delete/update)
    95  create view view_tab1 as select * from tab1;
    96  select * from view_tab1;
    97  commit;
    98  
    99  insert into view_tab1 values (200, 300);
   100  commit;
   101  
   102  drop database db;
   103  
   104  use autocommit_1;
   105  commit;
   106  
   107  -- test rollback
   108  drop table if exists t1;
   109  create table t1(col1 varchar(255));
   110  insert into t1 values ('helloworld');
   111  rollback;
   112  -- echo error
   113  select * from t1;
   114  commit;
   115  
   116  -- test commit
   117  drop table if exists t2;
   118  create table t2 (a varchar(255));
   119  insert into t2 values ('hello');
   120  commit;
   121  select * from t2;
   122  commit;
   123  drop table t2;
   124  
   125  
   126  -- @case
   127  -- @desc:Test implicit transaction uncommitted, modify AUTOCOMMIT value, mo throw exception
   128  -- @label:bvt
   129  
   130  drop table if exists t3;
   131  create table t3(a int);
   132  insert into t3 values (10),(20),(30);
   133  
   134  -- no error. autocommit from OFF to ON. Commit the transaction.
   135  set @@autocommit=ON;
   136  select @@autocommit;
   137  
   138  -- no error. autocommit from ON to OFF.
   139  set @@autocommit=OFF;
   140  select @@autocommit;
   141  
   142  -- no error. autocommit from OFF to ON. Commit the transaction.
   143  set @@autocommit=1;
   144  select @@autocommit;
   145  
   146  -- no error. autocommit from ON to OFF.
   147  set @@autocommit=0;
   148  select @@autocommit;
   149  
   150  rollback;
   151  
   152  
   153  drop table if exists tab3;
   154  create table tab3 (a int, b varchar(25));
   155  insert into tab3 values (10, 'aa'),(20, 'bb'),(30, 'cc');
   156  -- no error. autocommit from OFF to ON. Commit the transaction.
   157  set @@autocommit=ON;
   158  select @@autocommit;
   159  
   160  -- no error. autocommit from ON to OFF.
   161  set @@autocommit=OFF;
   162  select @@autocommit;
   163  
   164  -- no error. autocommit from OFF to ON. Commit the transaction.
   165  set @@autocommit=1;
   166  select @@autocommit;
   167  
   168  -- no error. autocommit from ON to OFF.
   169  set @@autocommit=0;
   170  commit;
   171  
   172  select * from tab3;
   173  update tab3 set a=1000 where b='aa';
   174  select * from tab3;
   175  rollback;
   176  delete from tab3 where b='cc';
   177  select * from tab3;
   178  commit;
   179  select * from tab3;
   180  commit;
   181  
   182  drop table tab3;
   183  
   184  -- test An implicit transaction has uncommitted content.
   185  -- Turning on an explicit transaction forces the previously uncommitted content to be committed
   186  
   187  drop table if exists t4;
   188  create table t4(a varchar(225), b int);
   189  insert into t4 values ('aa', 1000),('bb', 2000);
   190  
   191  begin;
   192  select * from t4;
   193  update t4 set a='xxxx' where b=1000;
   194  select * from t4;
   195  rollback;
   196  
   197  select * from t4;
   198  update t4 set a='xxxx' where b=1000;
   199  select * from t4;
   200  commit;
   201  select * from t4;
   202  
   203  create view view_t4 as select * from t4;
   204  
   205  begin;
   206  select * from view_t4;
   207  delete from t4 where a='bb';
   208  rollback;
   209  
   210  select * from t4;
   211  select * from view_t4;
   212  commit;
   213  
   214  
   215  -- @case
   216  -- @desc:Test explicit transaction commit (commit;rollback;)
   217  -- @label:bvt
   218  
   219  set autocommit=1;
   220  select @@autocommit;
   221  
   222  drop database if exists test_xx;
   223  begin;
   224  create database test_xx;
   225  
   226  -- no error. autocommit from ON to ON.
   227  SET @@session.autocommit=1;
   228  SELECT @@session.autocommit;
   229  
   230  -- no error. autocommit from ON to OFF.
   231  SET @@session.autocommit= 0;
   232  SELECT @@session.autocommit;
   233  
   234  -- no error. autocommit from OFF to OFF.
   235  SET @@session.autocommit=OFF;
   236  SELECT @@session.autocommit;
   237  
   238  -- no error. autocommit from OFF to ON. Commit the transaction.
   239  SET @@session.autocommit=ON;
   240  SELECT @@session.autocommit;
   241  commit;
   242  
   243  show databases like 'test_xx';
   244  commit;
   245  drop database test_xx;
   246  
   247  
   248  -- Test explicit transaction rollback;
   249  drop database if exists db;
   250  begin;
   251  create database db;
   252  show databases like 'db';
   253  use db;
   254  
   255  begin;
   256  create table table3(a int, b int);
   257  insert into table3 values (2000, 3000);
   258  create view view_table3 as select * from table3;
   259  select * from table3;
   260  select * from view_table3;
   261  rollback;
   262  
   263  -- echo error
   264  select * from table3;
   265  select * from view_table3;
   266  
   267  
   268  -- Test explicit transaction commit;
   269  
   270  drop database if exists db;
   271  begin;
   272  create database db;
   273  show databases like 'db';
   274  use db;
   275  create table table3(a int, b int);
   276  
   277  
   278  -- test table table3 DML and commit; rollback;
   279  insert into table3 values (2000, 3000);
   280  insert into table3 values (10, 10);
   281  commit;
   282  select * from table3;
   283  
   284  begin;
   285  update table3 set a=100000 where b=3000;
   286  select * from table3;
   287  rollback;
   288  select * from table3;
   289  
   290  begin;
   291  update table3 set a=100000 where b=3000;
   292  commit;
   293  select * from table3;
   294  
   295  begin;
   296  delete from table3 where a=10;
   297  rollback;
   298  select * from table3;
   299  
   300  begin;
   301  delete from table3 where a=10;
   302  commit;
   303  select * from table3;
   304  
   305  -- Test start transaction;rollback;commit;
   306  
   307  drop table if exists t3;
   308  start transaction;
   309  create table t3 (b varchar(255));
   310  insert into t3 values ('helloworld');
   311  rollback ;
   312  select * from t3;
   313  
   314  drop table if exists t4;
   315  start transaction;
   316  create table t4 (a int);
   317  insert into t4 values (10),(20);
   318  commit;
   319  select * from t4;
   320  drop table t4;
   321  
   322  
   323  -- Test explicit transactions are nested, Uncommitted content is forced to be submitted
   324  drop table if exists t5;
   325  start transaction;
   326  
   327  create table t5(a int);
   328  insert into t5 values(10),(20),(30);
   329  -- execute success
   330  drop table t5;
   331  
   332  start transaction;
   333  -- t5 is dropped. error and rollback.
   334  insert into t5 values(100),(2000),(3000);
   335  -- execute success due to last txn rollback.
   336  set @autocommit=0;
   337  begin;
   338  -- error. t5 is dropped. txn rollback.
   339  select * from t5;
   340  
   341  insert into t5 values(1),(2),(3);
   342  rollback;
   343  
   344  -- error. t5 is dropped. txn rollback.
   345  select * from t5;
   346  
   347  begin;
   348  -- error. t5 is dropped. txn rollback.
   349  select * from t5;
   350  insert into t5 values(100),(2000),(3000);
   351  delete from t5;
   352  
   353  begin;
   354  select * from t5;
   355  rollback;
   356  
   357  select * from t5;
   358  
   359  drop table t5
   360  
   361  
   362  
   363  -- Test explicit transactions  include set command;
   364      start transaction;
   365  -- execute error
   366  set @@a=0;
   367  rollback;
   368  
   369  set @@b=0;
   370  -- execute error
   371  commit;
   372  -- execute error
   373  select @@b;
   374  
   375  
   376  -- Test AUTOCOMMIT=1 Each DML statement is a separate transaction
   377  
   378  drop database if exists db;
   379  create database db;
   380  show databases like 'db';
   381  use db;
   382  create table t6(a int, b int);
   383  
   384  -- test table t6 DML and commit; rollback;
   385  insert into t6 values (2000, 3000);
   386  insert into t6 values (10, 10);
   387  
   388  select * from t6;
   389  update t6 set a=100000 where b=3000;
   390  select * from t6;
   391  delete from t6 where a=10;
   392  
   393  select * from t6;
   394  
   395  
   396  -- test view view_t6 DML and commit; rollback;
   397  create view view_t6 as select * from t6;
   398  select * from view_t6;
   399  
   400  insert into view_t6 values (200, 300);
   401  insert into view_t6 values (10, 10);
   402  
   403  
   404  select * from view_t6;
   405  update view_t6 set a=100000 where b=3000;
   406  select * from view_t6;
   407  delete from view_t6 where a=10;
   408  select * from view_t6;
   409  
   410  drop database db;
   411  
   412  use autocommit_1;
   413  
   414  
   415  
   416  -- @case
   417  -- @desc:Test Nested explicit transactions within implicit transactions
   418  -- @label:bvt
   419  
   420  set @@autocommit=0;
   421  select @@autocommit;
   422  
   423  create table t7(a int);
   424  insert into t7 values (500);
   425  commit;
   426  
   427  
   428  begin;
   429  insert into t7 values (1000);
   430  commit;
   431  insert into t7 values (2000);
   432  rollback;
   433  select * from t7;
   434  drop table t7;
   435  commit;
   436  drop table t7;
   437  
   438  create table t8(a int);
   439  insert into t8 values (500);
   440  rollback;
   441  
   442  
   443  begin;
   444  insert into t8 values (1000);
   445  create table t9 (a char(25));
   446  commit;
   447  
   448  insert into t9 values ('hello');
   449  rollback;
   450  select * from t9;
   451  commit;
   452  drop table t9;
   453  rollback;
   454  set @@autocommit=on;
   455