github.com/matrixorigin/matrixone@v1.2.0/test/distributed/cases/snapshot/sys_restore_to_nonsys_account.sql (about) 1 drop account if exists acc01; 2 create account acc01 admin_name = 'test_account' identified by '111'; 3 4 -- under account, single db, single table 5 -- @session:id=1&user=acc01:test_account&password=111 6 drop database if exists acc_test01; 7 create database acc_test01; 8 use acc_test01; 9 drop table if exists s3t; 10 create table s3t (col1 int, col2 int, col3 int, primary key(col1, col2)); 11 insert into s3t select result, 2, 12 from generate_series(1, 30000, 1) g; 12 select count(*) from s3t; 13 select sum(col1) from s3t; 14 select avg(col1) from s3t; 15 select count(col3) from s3t where col1 > 1000; 16 alter table s3t add column col4 int after col2; 17 -- @session 18 19 drop snapshot if exists sp01; 20 create snapshot sp01 for account acc01; 21 -- @ignore:1 22 show snapshots; 23 24 -- @session:id=1&user=acc01:test_account&password=111 25 show snapshots; 26 insert into s3t values (300001, 34, 23, 1); 27 select count(*) from s3t; 28 select * from s3t where col1 = 23; 29 -- @session 30 31 restore account acc01 from snapshot sp01 to account acc01; 32 33 -- @session:id=1&user=acc01:test_account&password=111 34 show databases; 35 use acc_test01; 36 show tables; 37 select sum(col1) from s3t; 38 select avg(col1) from s3t; 39 select count(col3) from s3t where col1 > 1000; 40 select count(*) from s3t; 41 alter table s3t drop column col4; 42 -- @session 43 44 drop snapshot if exists sp02; 45 create snapshot sp02 for account acc01; 46 47 -- @session:id=1&user=acc01:test_account&password=111 48 insert into s3t select result, 2, 12 from generate_series(30002, 60000, 1) g; 49 select count(*) from s3t where col1 > 2000; 50 select sum(col1) from s3t; 51 select avg(col1) from s3t; 52 delete from s3t where col1 > 30000; 53 -- @session 54 55 restore account acc01 from snapshot sp02 to account acc01; 56 57 -- @session:id=1&user=acc01:test_account&password=111 58 select count(*) from s3t where col1 > 2000; 59 select sum(col1) from s3t; 60 select avg(col1) from s3t; 61 show create table s3t; 62 -- @session 63 64 restore account acc01 from snapshot sp01 to account acc01; 65 66 -- @session:id=1&user=acc01:test_account&password=111 67 show databases; 68 use acc_test01; 69 show tables; 70 select sum(col1) from s3t; 71 select avg(col1) from s3t; 72 select count(col3) from s3t where col1 > 1000; 73 select count(*) from s3t; 74 show create table s3t; 75 -- @session 76 drop snapshot sp01; 77 drop snapshot sp02; 78 -- @session:id=1&user=acc01:test_account&password=111 79 drop database acc_test01; 80 -- @session 81 82 83 84 -- under account, multi db, multi table 85 -- @session:id=1&user=acc01:test_account&password=111 86 drop database if exists acc_test02; 87 create database acc_test02; 88 use acc_test02; 89 drop table if exists pri01; 90 create table pri01( 91 deptno int unsigned comment '部门编号', 92 dname varchar(15) comment '部门名称', 93 loc varchar(50) comment '部门所在位置', 94 primary key(deptno) 95 ) comment='部门表'; 96 97 insert into pri01 values (10,'ACCOUNTING','NEW YORK'); 98 insert into pri01 values (20,'RESEARCH','DALLAS'); 99 insert into pri01 values (30,'SALES','CHICAGO'); 100 insert into pri01 values (40,'OPERATIONS','BOSTON'); 101 102 drop table if exists aff01; 103 create table aff01( 104 empno int unsigned auto_increment COMMENT '雇员编号', 105 ename varchar(15) comment '雇员姓名', 106 job varchar(10) comment '雇员职位', 107 mgr int unsigned comment '雇员对应的领导的编号', 108 hiredate date comment '雇员的雇佣日期', 109 sal decimal(7,2) comment '雇员的基本工资', 110 comm decimal(7,2) comment '奖金', 111 deptno int unsigned comment '所在部门', 112 primary key(empno), 113 constraint `c1` foreign key (deptno) references pri01 (deptno) 114 ); 115 116 insert into aff01 values (7369,'SMITH','CLERK',7902,'1980-12-17',800,NULL,20); 117 insert into aff01 values (7499,'ALLEN','SALESMAN',7698,'1981-02-20',1600,300,30); 118 insert into aff01 values (7521,'WARD','SALESMAN',7698,'1981-02-22',1250,500,30); 119 insert into aff01 values (7566,'JONES','MANAGER',7839,'1981-04-02',2975,NULL,20); 120 insert into aff01 values (7654,'MARTIN','SALESMAN',7698,'1981-09-28',1250,1400,30); 121 insert into aff01 values (7698,'BLAKE','MANAGER',7839,'1981-05-01',2850,NULL,30); 122 insert into aff01 values (7782,'CLARK','MANAGER',7839,'1981-06-09',2450,NULL,10); 123 insert into aff01 values (7788,'SCOTT','ANALYST',7566,'0087-07-13',3000,NULL,20); 124 insert into aff01 values (7839,'KING','PRESIDENT',NULL,'1981-11-17',5000,NULL,10); 125 insert into aff01 values (7844,'TURNER','SALESMAN',7698,'1981-09-08',1500,0,30); 126 insert into aff01 values (7876,'ADAMS','CLERK',7788,'0087-07-13',1100,NULL,20); 127 insert into aff01 values (7900,'JAMES','CLERK',7698,'1981-12-03',950,NULL,30); 128 insert into aff01 values (7902,'FORD','ANALYST',7566,'1981-12-03',3000,NULL,20); 129 insert into aff01 values (7934,'MILLER','CLERK',7782,'1982-01-23',1300,NULL,10); 130 131 drop database if exists acc_test03; 132 create database acc_test03; 133 use acc_test03; 134 drop table if exists table01; 135 create table table01(col1 int primary key , col2 decimal, col3 char, col4 varchar(20), col5 text, col6 double); 136 insert into table01 values (1, 2, 'a', '23eiojf', 'r23v324r23rer', 3923.324); 137 insert into table01 values (2, 3, 'b', '32r32r', 'database', 1111111); 138 create table table02 (col1 int unique key, col2 varchar(20)); 139 insert into table02 (col1, col2) values (133, 'database'); 140 create table table03(a INT primary key AUTO_INCREMENT, b INT, c INT); 141 create table table04(a INT primary key AUTO_INCREMENT, b INT, c INT); 142 insert into table03 values (1,1,1), (2,2,2); 143 insert into table04 values (0,1,2), (2,3,4); 144 145 drop database if exists acc_test04; 146 create database acc_test04; 147 use acc_test04; 148 drop table if exists index03; 149 create table index03 ( 150 emp_no int not null, 151 birth_date date not null, 152 first_name varchar(14) not null, 153 last_name varchar(16) not null, 154 gender varchar(5) not null, 155 hire_date date not null, 156 primary key (emp_no) 157 ) partition by range columns (emp_no)( 158 partition p01 values less than (100001), 159 partition p02 values less than (200001), 160 partition p03 values less than (300001), 161 partition p04 values less than (400001) 162 ); 163 164 insert into index03 values (9001,'1980-12-17', 'SMITH', 'CLERK', 'F', '2008-12-17'), 165 (9002,'1981-02-20', 'ALLEN', 'SALESMAN', 'F', '2008-02-20'); 166 167 168 select count(*) from acc_test02.pri01; 169 select count(*) from acc_test02.aff01; 170 select * from acc_test02.pri01; 171 show create table acc_test02.pri01; 172 show create table acc_test02.aff01; 173 select count(*) from acc_test03.table01; 174 select count(*) from acc_test03.table02; 175 select count(*) from acc_test03.table03; 176 select count(*) from acc_test03.table04; 177 show create table acc_test03.table01; 178 show create table acc_test03.table02; 179 show create table acc_test03.table03; 180 show create table acc_test03.table04; 181 select count(*) from acc_test04.index03; 182 show create table acc_test04.index03; 183 -- @session 184 185 drop snapshot if exists sp04; 186 create snapshot sp04 for account acc01; 187 188 -- @session:id=1&user=acc01:test_account&password=111 189 insert into acc_test02.pri01 values (50,'ACCOUNTING','NEW YORK'); 190 insert into acc_test02.aff01 values (7900,'MILLER','CLERK',7782,'1982-01-23',1300,NULL,50); 191 truncate table acc_test03.table01; 192 drop table acc_test03.table02; 193 delete from acc_test03.table03 where col1 = 1; 194 update acc_test03.table04 set col1 = 1000; 195 alter table acc_test04.index03 drop primary key; 196 select count(*) from acc_test02.pri01; 197 select count(*) from acc_test02.aff01; 198 select * from acc_test03.table01; 199 select count(*) from acc_test03.table03; 200 select * from acc_test03.table04; 201 show create table acc_test04.index03; 202 -- @session 203 204 restore account acc01 from snapshot sp04 to account acc01; 205 206 -- @session:id=1&user=acc01:test_account&password=111 207 show databases; 208 select count(*) from acc_test02.pri01; 209 select count(*) from acc_test02.aff01; 210 select count(*) from acc_test03.table01; 211 select count(*) from acc_test03.table02; 212 select count(*) from acc_test03.table03; 213 select count(*) from acc_test03.table04; 214 select count(*) from acc_test03.table04; 215 drop database acc_test03; 216 -- @session 217 drop snapshot sp04; 218 219 220 221 -- acc01 create sp01,sp02, restore sp02, restore sp01 222 -- @session:id=1&user=acc01:test_account&password=111 223 drop database if exists test01; 224 create database test01; 225 use test01; 226 drop table if exists table01; 227 create table table01(col1 int primary key , col2 decimal, col3 char, col4 varchar(20), col5 text, col6 double); 228 insert into table01 values (1, 2, 'a', '23eiojf', 'r23v324r23rer', 3923.324); 229 insert into table01 values (2, 3, 'b', '32r32r', 'database', 1111111); 230 drop table if exists table02; 231 create table table02 (col1 int unique key, col2 varchar(20)); 232 insert into table02 (col1, col2) values (133, 'database'); 233 -- @session 234 235 drop snapshot if exists sp07; 236 create snapshot sp07 for account acc01; 237 238 -- @session:id=1&user=acc01:test_account&password=111 239 use test01; 240 drop table table01; 241 insert into table02 values(134, 'database'); 242 -- @session 243 244 drop snapshot if exists sp08; 245 create snapshot sp08 for account acc01; 246 -- @ignore:1 247 show snapshots; 248 249 -- @session:id=1&user=acc01:test_account&password=111 250 use test01; 251 create table table03 (col1 int); 252 insert into table03 values (1),(2); 253 -- @session 254 255 restore account acc01 from snapshot sp07 to account acc01; 256 257 -- @session:id=1&user=acc01:test_account&password=111 258 use test01; 259 show tables; 260 select * from table01; 261 select * from table02; 262 -- @session 263 264 restore account acc01 from snapshot sp08 to account acc01; 265 266 -- @session:id=1&user=acc01:test_account&password=111 267 use test01; 268 show tables; 269 select * from table01; 270 select * from table02; 271 show create table table02; 272 drop database test01; 273 -- @session 274 drop snapshot sp07; 275 drop snapshot sp08; 276 277 278 279 280 -- sys create sp01,sp02, restore sp02, restore sp01 281 -- @session:id=1&user=acc01:test_account&password=111 282 drop database if exists test02; 283 create database test02; 284 use test02; 285 drop table if exists table01; 286 create table table01(col1 int primary key , col2 decimal, col3 char, col4 varchar(20), col5 text, col6 double); 287 insert into table01 values (1, 2, 'a', '23eiojf', 'r23v324r23rer', 3923.324); 288 insert into table01 values (2, 3, 'b', '32r32r', 'database', 1111111); 289 drop table if exists table02; 290 create table table02 (col1 int unique key, col2 varchar(20)); 291 insert into table02 (col1, col2) values (133, 'database'); 292 -- @session 293 294 drop snapshot if exists sp09; 295 create snapshot sp09 for account acc01; 296 297 -- @session:id=1&user=acc01:test_account&password=111 298 use test02; 299 drop table table01; 300 insert into table02 values(134, 'database'); 301 alter table table02 add column new decimal after col2; 302 -- @session 303 304 drop snapshot if exists sp10; 305 create snapshot sp10 for account acc01; 306 307 -- @session:id=1&user=acc01:test_account&password=111 308 use test02; 309 show create table table01; 310 show create table table02; 311 insert into table02 values(139, 'database', null); 312 alter table table02 drop column new; 313 -- @session 314 315 restore account acc01 from snapshot sp10 to account acc01; 316 317 -- @session:id=1&user=acc01:test_account&password=111 318 use test02; 319 show create table table01; 320 show create table table02; 321 select * from table02; 322 select * from table01; 323 -- @session 324 325 -- @session:id=2&user=acc01:test_account&password=111 326 drop database test02; 327 -- @session 328 329 drop snapshot sp09; 330 drop snapshot sp10; 331 332 333 334 335 -- abnormal test: sys restore non-sys account:acc01 to sys 336 -- @session:id=1&user=acc01:test_account&password=111 337 drop database if exists test01; 338 create database test01; 339 use test01; 340 341 drop table if exists rs01; 342 create table rs01 (col1 int, col2 decimal(6), col3 varchar(30)); 343 insert into rs01 values (1, null, 'database'); 344 insert into rs01 values (2, 38291.32132, 'database'); 345 insert into rs01 values (3, null, 'database management system'); 346 insert into rs01 values (4, 10, null); 347 insert into rs01 values (1, -321.321, null); 348 insert into rs01 values (2, -1, null); 349 select count(*) from rs01; 350 -- @session 351 352 drop snapshot if exists sp03; 353 create snapshot sp03 for account acc01; 354 355 -- @session:id=1&user=acc01:test_account&password=111 356 use test01; 357 delete from rs01 where col1 = 4; 358 insert into rs01 values (10, -1, null); 359 select count(*) from rs01; 360 -- @session 361 362 restore account acc01 from snapshot sp03 to account sys; 363 drop snapshot sp03; 364 365 -- @session:id=1&user=acc01:test_account&password=111 366 drop database test01; 367 -- @session 368 369 drop account acc01;