github.com/matrixorigin/matrixone@v1.2.0/test/distributed/cases/optimistic/isolation_2.sql (about) 1 --env prepare statement 2 drop table if exists dis_table_01; 3 drop table if exists dis_table_02; 4 drop table if exists dis_table_03; 5 drop table if exists dis_table_04; 6 drop table if exists dis_table_05; 7 drop table if exists dis_table_06; 8 drop table if exists dis_table_07; 9 drop table if exists dis_view_01; 10 drop table if exists dis_view_02; 11 drop table if exists dis_temp_01; 12 drop table if exists iso_table_0001; 13 14 create table dis_table_01(a int,b varchar(25)); 15 insert into dis_table_01 select 20,'apple'; 16 insert into dis_table_01 select 21,'orange'; 17 start transaction; 18 create view dis_view_01 as select * from dis_table_01; 19 -- @session:id=1{ 20 use isolation_2; 21 begin; 22 insert into dis_table_01 values (22,'pear'); 23 select * from dis_table_01; 24 update dis_table_01 set b='bens' where a=20; 25 select * from dis_table_01; 26 rollback ; 27 -- @session} 28 select * from dis_view_01; 29 -- @session:id=2{ 30 use isolation_2; 31 select * from dis_table_01; 32 update dis_table_01 set a=19 where b='apple'; 33 select * from dis_table_01; 34 -- @session} 35 commit; 36 select * from dis_view_01; 37 select * from dis_table_01; 38 39 ------------------------- 40 create table dis_table_02(a int not null auto_increment,b varchar(25) not null,c datetime,primary key(a),key bstr (b),key cdate (c) ); 41 insert into dis_table_02(b,c) values ('aaaa','2020-09-08'); 42 insert into dis_table_02(b,c) values ('aaaa','2020-09-08'); 43 create table dis_table_03(b varchar(25) primary key,c datetime); 44 begin ; 45 insert into dis_table_03 select b,c from dis_table_02; 46 select * from dis_table_03; 47 -- @session:id=1{ 48 insert into dis_table_03 select 'bbb','2012-09-30'; 49 update dis_table_03 set b='aaa'; 50 select * from dis_table_03; 51 -- @session} 52 -- @session:id=2{ 53 select * from dis_table_03; 54 truncate table dis_table_03; 55 -- @session} 56 insert into dis_table_03 select 'bbb','2012-09-30'; 57 select * from dis_table_03; 58 commit; 59 select * from dis_table_03; 60 61 begin ; 62 insert into dis_table_02 values (null,'ccc',null); 63 select * from dis_table_02; 64 -- @session:id=1{ 65 start transaction ; 66 insert into dis_table_02 values (5,null,'1345-09-23'); 67 select * from dis_table_02; 68 commit; 69 -- @session} 70 -- @pattern 71 update dis_table_02 set a=90; 72 commit; 73 select * from dis_table_02; 74 75 --------------------------------------- 76 start transaction ; 77 create database dis_db_01; 78 use dis_db_01; 79 begin; 80 create table dis_table_04(a int); 81 insert into dis_table_04 values (4); 82 -- @session:id=1{ 83 create table dis_table_04(a int); 84 insert into dis_table_04 values (4); 85 drop database dis_db_01; 86 -- @session} 87 delete from dis_table_04 where a=4; 88 select * from dis_table_04; 89 rollback ; 90 select * from dis_db_01.dis_table_04; 91 drop database dis_db_01; 92 drop table isolation_2.dis_table_04; 93 --------------------------------------- 94 begin; 95 use isolation_2; 96 create external table ex_table_dis(num_col1 tinyint,num_col2 smallint,num_col3 int,num_col4 bigint,num_col5 tinyint unsigned,num_col6 smallint unsigned,num_col7 int unsigned,num_col8 bigint unsigned ,num_col9 float(5,3),num_col10 double(6,5),num_col11 decimal(38,19)) infile{"filepath"='$resources/external_table_file/ex_table_number.csv'} fields terminated by ',' enclosed by '\"' lines terminated by '\n'; 97 select num_col1,num_col2 from ex_table_dis; 98 -- @session:id=1{ 99 select * from ex_table_dis; 100 -- @session} 101 update ex_table_dis set num_col1=1000; 102 select num_col1,num_col2 from ex_table_dis; 103 commit; 104 select num_col1,num_col2 from ex_table_dis; 105 -- @session:id=1{ 106 insert into dis_table_01 select num_col1,'fffff' from ex_table_dis; 107 select * from dis_table_01; 108 select num_col1,num_col2 from ex_table_dis; 109 drop table ex_table_dis; 110 -- @session} 111 select * from dis_table_01; 112 113 begin; 114 create view aaa as select * from dis_table_02; 115 show create table aaa ; 116 -- @session:id=1{ 117 insert into dis_table_02(b,c) values ('vvv','2000-09-08'); 118 -- @session} 119 -- @session:id=2{ 120 begin ; 121 select b, c from dis_table_02; 122 delete from dis_table_02 where a=1; 123 rollback ; 124 -- @session} 125 commit ; 126 select b, c from aaa; 127 -- @session:id=1{ 128 select b, c from aaa; 129 -- @session} 130 drop view aaa ; 131 132 start transaction ; 133 insert into dis_table_02(b,c) values ('','1999-06-04'); 134 -- @session:id=1{ 135 prepare stmt1 from "update dis_table_02 set c='2222-07-12' where a=2"; 136 execute stmt1; 137 select b, c from dis_table_02; 138 -- @session} 139 update dis_table_02 set c='2000-09-02' where a=2; 140 select b, c from dis_table_02; 141 -- @session:id=2{ 142 begin ; 143 create database dis_db_02; 144 rollback ; 145 -- @session} 146 commit; 147 select b, c from dis_table_02; 148 149 begin ; 150 prepare stmt1 from "insert into dis_table_02(b,c) values('oppo','1009-11-11')"; 151 execute stmt1; 152 select b, c from dis_table_02; 153 -- @session:id=1{ 154 select b, c from dis_table_02; 155 -- @session} 156 prepare stmt2 from "update dis_table_02 set a=null"; 157 execute stmt2; 158 commit; 159 deallocate prepare stmt1; 160 deallocate prepare stmt2; 161 select b, c from dis_table_02; 162 use dis_db_02; 163 select b, c from dis_table_02; 164 insert into dis_table_02(b,c) values ('','1999-06-04'); 165 166 ------------------------------ 167 -- @bvt:issue#9124 168 create temporary table dis_temp_01(a int,b varchar(100),primary key(a)); 169 begin ; 170 insert into dis_temp_01 values (233,'uuuu'); 171 -- @session:id=1{ 172 select * from dis_temp_01; 173 -- @session} 174 select * from dis_temp_01; 175 -- @session:id=1{ 176 truncate table dis_temp_01; 177 -- @session} 178 rollback ; 179 select * from dis_temp_01; 180 drop table dis_temp_01; 181 -- @bvt:issue 182 183 start transaction; 184 load data infile '$resources/external_table_file/isolation_01.csv' into table dis_table_02 fields terminated by ','; 185 -- @session:id=1{ 186 update dis_table_02 set b='pppp'; 187 select b, c from dis_table_02; 188 -- @session} 189 select b, c from dis_table_02; 190 -- @session:id=2{ 191 begin ; 192 create view dis_view_02 as select * from dis_table_02; 193 insert into dis_table_02 values (2,'oooo','1802-03-20'); 194 select b, c from dis_table_02; 195 -- @session} 196 -- @session:id=1{ 197 use isolation_2; 198 select * from dis_view_02; 199 -- @session} 200 select * from dis_view_02; 201 -- @session:id=2{ 202 insert into dis_table_02 values (2,'oooo','1802-03-20'); 203 -- @session} 204 commit; 205 -- @session:id=1{ 206 select b, c from dis_table_02; 207 -- @session} 208 select * from dis_view_02; 209 drop table dis_view_02; 210 211 begin ; 212 select * from dis_table_01; 213 -- @session:id=1{ 214 truncate table dis_table_01; 215 -- @session} 216 -- @bvt:issue#9095 217 insert into dis_table_01 select 9999,'abcdefg'; 218 -- @bvt:issue 219 -- @session:id=1{ 220 select * from dis_table_01; 221 -- @session} 222 explain select * from dis_table_01; 223 commit ; 224 -- @session:id=1{ 225 select * from dis_table_01; 226 -- @session} 227 228 begin ; 229 delete from dis_table_02 where a>1; 230 select b, c from dis_table_02; 231 -- @session:id=1{ 232 select b, c from dis_table_02; 233 update dis_table_02 set b='tittttt' where a>1; 234 select b, c from dis_table_02; 235 -- @session} 236 select b, c from dis_table_02; 237 -- @session:id=2{ 238 rollback; 239 start transaction ; 240 update dis_table_02 set b='catttteee' where a>1; 241 select b, c from dis_table_02; 242 commit; 243 -- @session} 244 commit; 245 select b, c from dis_table_02; 246 -- @session:id=1{ 247 select b, c from dis_table_02; 248 -- @session} 249 250 -------------------------------- 251 create database if not exists iso_db_02; 252 start transaction ; 253 use iso_db_02; 254 show tables; 255 -- @session:id=1{ 256 begin ; 257 use iso_db_02; 258 create table iso_table_0001(a int); 259 -- @session} 260 insert into iso_table_0001 values (2); 261 -- @session:id=2{ 262 use iso_db_02; 263 create table iso_table_0001(a int); 264 drop database iso_db_02; 265 -- @session} 266 -- @session:id=1{ 267 commit; 268 -- @session} 269 create table iso_table_0001(a int); 270 commit; 271 use iso_db_02; 272 select * from iso_table_0001; 273 274 use isolation_2; 275 create table dis_table_04(a int,b varchar(25) not null,c datetime,primary key(a),unique key bstr (b),key cdate (c)); 276 insert into dis_table_04 values (6666,'kkkk','2010-11-25'); 277 insert into dis_table_04 values (879,'oopp','2011-11-26'); 278 select * from dis_table_01; 279 start transaction ; 280 use isolation_2; 281 update dis_table_04 set b=(select 'ccccool' from dis_table_01 limit 1) where a=879; 282 select * from dis_table_04 ; 283 -- @session:id=1{ 284 begin ; 285 use isolation_2; 286 update dis_table_04 set b='uuyyy' where a=879; 287 select * from dis_table_04; 288 commit; 289 -- @session} 290 commit; 291 update dis_table_04 set b=(select 'kkkk') where a=879; 292 -- @session:id=1{ 293 select * from dis_table_04; 294 -- @session} 295 ---------------------------- 296 -- @bvt:issue#9124 297 begin ; 298 use isolation_2; 299 create temporary table dis_table_05(a int,b varchar(25) not null,c datetime,primary key(a),unique key bstr (b),key cdate (c)); 300 load data infile 'fff.csv' to dis_table_05 fields terminated by ','; 301 -- @session:id=1{ 302 use isolation_2; 303 select * from dis_table_05; 304 -- @session} 305 insert into dis_table_05 values (8900,'kkkk77','1772-04-20'); 306 commit; 307 select * from dis_table_05; 308 -- @session:id=1{ 309 select * from dis_table_05; 310 -- @session} 311 drop table dis_table_05; 312 -- @bvt:issue 313 314 -- auto_increment 主键冲突 315 use isolation_2; 316 create table dis_table_06(a int auto_increment primary key,b varchar(25),c double default 0.0); 317 insert into dis_table_06(a,b) values(2,'moon'); 318 insert into dis_table_06(b) values('sun'); 319 begin; 320 use isolation_2; 321 insert into dis_table_06(a,b) values (3,'llllp'); 322 select * from dis_table_06; 323 -- @session:id=1{ 324 use isolation_2; 325 insert into dis_table_06 values (3,'uuubbb',12.02); 326 select * from dis_table_06; 327 -- @session} 328 insert into dis_table_06(a,b) values (4,'cookie'); 329 commit; 330 select * from dis_table_06; 331 332 begin; 333 use isolation_2; 334 insert into dis_table_06(a,b) values (5,'leetio'); 335 select * from dis_table_06; 336 -- @session:id=1{ 337 update dis_table_06 set a=5 where b='sun'; 338 select * from dis_table_06; 339 -- @session} 340 commit; 341 select * from dis_table_06; 342 drop table dis_table_06; 343 344 --compk 冲突 345 create table dis_table_07(a int,b varchar(25),c double,d datetime,primary key(a,b,d)); 346 insert into dis_table_07 values (1,'yellow',20.09,'2020-09-27'); 347 begin; 348 insert into dis_table_07 values (2,'blue',10.00,'2021-01-20'); 349 -- @session:id=1{ 350 use isolation_2; 351 insert into dis_table_07 values (2,'blue',11.00,'2021-01-20'); 352 select * from dis_table_07; 353 -- @session} 354 select * from dis_table_07; 355 commit; 356 select * from dis_table_07; 357 -- @session:id=1{ 358 insert into dis_table_07 values (2,'blue',12.00,'2024-01-20'); 359 -- @session} 360 begin; 361 update dis_table_07 set d='2024-01-20' where a=2 and b='blue'; 362 -- @session:id=1{ 363 select * from dis_table_07; 364 -- @session} 365 select * from dis_table_07; 366 commit; 367 select * from dis_table_07; 368 drop table dis_table_07;