1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
|
SET sql_mode = 'NO_ENGINE_SUBSTITUTION';
create procedure populate_tables()
begin
declare n int default 20;
declare inner_loop int default 100;
create temporary table t1(c1 int not null,
c2 int not null,
c3 char(255) not null,
c4 text(6000) not null,
c5 blob(6000) not null,
c6 varchar(2000) not null,
c7 varchar(2000) not null,
c8 datetime,
c9 decimal(6,3),
primary key (c1),
index (c3,c4(50),c5(50)),
index (c2))
engine=innodb row_format=redundant charset latin1;
create temporary table t2(c1 int not null,
c2 int not null,
c3 char(255) not null,
c4 text(6000) not null,
c5 blob(6000) not null,
c6 varchar(2000) not null,
c7 varchar(2000) not null,
c8 datetime,
c9 decimal(6,3),
primary key (c1),
index (c3,c4(50),c5(50)),
index (c2))
engine=innodb row_format=compact charset latin1;
create temporary table t4(c1 int not null,
c2 int not null,
c3 char(255) not null,
c4 text(6000) not null,
c5 blob(6000) not null,
c6 varchar(2000) not null,
c7 varchar(2000) not null,
c8 datetime,
c9 decimal(6,3),
primary key (c1),
index (c3,c4(50),c5(50)),
index (c2))
engine=innodb row_format=dynamic charset latin1;
create temporary table t5(c1 int not null,
c2 int not null,
c3 char(255) not null,
c4 text(6000) not null,
c5 blob(6000) not null,
c6 varchar(2000) not null,
c7 varchar(2000) not null,
c8 datetime,
c9 decimal(6,3),
primary key (c1),
index (c3,c4(50),c5(50)),
index (c2))
engine=innodb charset latin1;
create temporary table t6 ( a int ) engine = innodb;
insert into t6 values (50),(100),(150),(190);
while (n > 0) do
start transaction;
insert into t1 values(n,n,repeat(concat(' tc3_',n),30),
repeat(concat(' tc4_',n),800),repeat(concat(' tc_',n),800),
repeat(concat(' tc6_',n),800),repeat(concat(' tc7_',n),800),
now(),(100.55+n));
insert into t2 values(n,n,repeat(concat(' tc3_',n),30),
repeat(concat(' tc4_',n),800),repeat(concat(' tc_',n),800),
repeat(concat(' tc6_',n),800),repeat(concat(' tc7_',n),800),
now(),(100.55+n));
insert into t4 values(n,n,repeat(concat(' tc3_',n),30),
repeat(concat(' tc4_',n),800),repeat(concat(' tc_',n),800),
repeat(concat(' tc6_',n),800),repeat(concat(' tc7_',n),800),
now(),(100.55+n));
insert into t5 values(n,n,repeat(concat(' tc3_',n),30),
repeat(concat(' tc4_',n),800),repeat(concat(' tc_',n),800),
repeat(concat(' tc6_',n),800),repeat(concat(' tc7_',n),800),
now(),(100.55+n));
if (n > 10) then
commit;
else
delete from t1 where c1 > 10 ;
delete from t2 where c1 > 10 ;
delete from t4 where c1 > 10 ;
delete from t5 where c1 > 10 ;
rollback;
start transaction;
update t1 set c1 = c1 + 1000 where c1 > 10;
update t2 set c1 = c1 + 1000 where c1 > 10;
update t4 set c1 = c1 + 1000 where c1 > 10;
update t5 set c1 = c1 + 1000 where c1 > 10;
rollback;
end if;
start transaction;
insert into t1 values(n+inner_loop,n+inner_loop,repeat(concat(' tc3_',n+inner_loop),30),
repeat(concat(' tc4_',n+inner_loop),800),repeat(concat(' tc_',n+inner_loop),800),
repeat(concat(' tc6_',n+inner_loop),245),repeat(concat(' tc7_',n+inner_loop),245),
now(),(100.55+n+inner_loop));
insert into t2 values(n+inner_loop,n+inner_loop,repeat(concat(' tc3_',n+inner_loop),30),
repeat(concat(' tc4_',n+inner_loop),800),repeat(concat(' tc_',n+inner_loop),800),
repeat(concat(' tc6_',n+inner_loop),245),repeat(concat(' tc7_',n+inner_loop),245),
now(),(100.55+n+inner_loop));
insert into t4 values(n+inner_loop,n+inner_loop,repeat(concat(' tc3_',n+inner_loop),30),
repeat(concat(' tc4_',n+inner_loop),800),repeat(concat(' tc_',n+inner_loop),800),
repeat(concat(' tc6_',n+inner_loop),245),repeat(concat(' tc7_',n+inner_loop),245),
now(),(100.55+n+inner_loop));
insert into t5 values(n+inner_loop,n+inner_loop,repeat(concat(' tc3_',n+inner_loop),30),
repeat(concat(' tc4_',n+inner_loop),800),repeat(concat(' tc_',n+inner_loop),800),
repeat(concat(' tc6_',n+inner_loop),245),repeat(concat(' tc7_',n+inner_loop),245),
now(),(100.55+n+inner_loop));
delete from t1 where c1 between 100 and 110;
delete from t2 where c1 between 100 and 110;
delete from t4 where c1 between 100 and 110;
delete from t5 where c1 between 100 and 110;
update t1 set c1 = c1+1 where c1>110;
update t2 set c1 = c1+1 where c1>110;
update t4 set c1 = c1+1 where c1>110;
update t5 set c1 = c1+1 where c1>110;
savepoint a;
insert into t1 values(300+n+inner_loop,n+inner_loop,repeat(concat(' tc3_',n+inner_loop),30),
repeat(concat(' tc4_',n+inner_loop),800),repeat(concat(' tc_',n+inner_loop),800),
repeat(concat(' tc6_',n+inner_loop),245),repeat(concat(' tc7_',n+inner_loop),245),
now(),(100.55+n+inner_loop));
insert into t2 values(300+n+inner_loop,n+inner_loop,repeat(concat(' tc3_',n+inner_loop),30),
repeat(concat(' tc4_',n+inner_loop),800),repeat(concat(' tc_',n+inner_loop),800),
repeat(concat(' tc6_',n+inner_loop),245),repeat(concat(' tc7_',n+inner_loop),245),
now(),(100.55+n+inner_loop));
insert into t4 values(300+n+inner_loop,n+inner_loop,repeat(concat(' tc3_',n+inner_loop),30),
repeat(concat(' tc4_',n+inner_loop),800),repeat(concat(' tc_',n+inner_loop),800),
repeat(concat(' tc6_',n+inner_loop),245),repeat(concat(' tc7_',n+inner_loop),245),
now(),(100.55+n+inner_loop));
insert into t5 values(300+n+inner_loop,n+inner_loop,repeat(concat(' tc3_',n+inner_loop),30),
repeat(concat(' tc4_',n+inner_loop),800),repeat(concat(' tc_',n+inner_loop),800),
repeat(concat(' tc6_',n+inner_loop),245),repeat(concat(' tc7_',n+inner_loop),245),
now(),(100.55+n+inner_loop));
savepoint b;
insert into t1 values(400+n+inner_loop,n+inner_loop,repeat(concat(' tc3_',n+inner_loop),30),
repeat(concat(' tc4_',n+inner_loop),800),repeat(concat(' tc_',n+inner_loop),800),
repeat(concat(' tc6_',n+inner_loop),245),repeat(concat(' tc7_',n+inner_loop),245),
now(),(100.55+n+inner_loop));
insert into t2 values(400+n+inner_loop,n+inner_loop,repeat(concat(' tc3_',n+inner_loop),30),
repeat(concat(' tc4_',n+inner_loop),800),repeat(concat(' tc_',n+inner_loop),800),
repeat(concat(' tc6_',n+inner_loop),245),repeat(concat(' tc7_',n+inner_loop),245),
now(),(100.55+n+inner_loop));
insert into t4 values(400+n+inner_loop,n+inner_loop,repeat(concat(' tc3_',n+inner_loop),30),
repeat(concat(' tc4_',n+inner_loop),800),repeat(concat(' tc_',n+inner_loop),800),
repeat(concat(' tc6_',n+inner_loop),245),repeat(concat(' tc7_',n+inner_loop),245),
now(),(100.55+n+inner_loop));
insert into t5 values(400+n+inner_loop,n+inner_loop,repeat(concat(' tc3_',n+inner_loop),30),
repeat(concat(' tc4_',n+inner_loop),800),repeat(concat(' tc_',n+inner_loop),800),
repeat(concat(' tc6_',n+inner_loop),245),repeat(concat(' tc7_',n+inner_loop),245),
now(),(100.55+n+inner_loop));
savepoint c;
rollback to b;
rollback to a;
commit;
commit;
rollback;
set n = n - 1;
end while;
end|
#---client 1 : dml operation ---"
#---client 2 : dml operation ---"
# In connection 1
select count(*) from t1;
count(*)
20
select count(*) from t2;
count(*)
20
select count(*) from t4;
count(*)
20
select count(*) from t5;
count(*)
20
select c1 from t1;
c1
11
12
13
14
15
16
17
18
19
20
122
124
126
128
130
132
134
136
138
140
select c1 from t2;
c1
11
12
13
14
15
16
17
18
19
20
122
124
126
128
130
132
134
136
138
140
select c1 from t4;
c1
11
12
13
14
15
16
17
18
19
20
122
124
126
128
130
132
134
136
138
140
select c1 from t5;
c1
11
12
13
14
15
16
17
18
19
20
122
124
126
128
130
132
134
136
138
140
# In connection 2
select count(*) from t1;
count(*)
20
select count(*) from t2;
count(*)
20
select count(*) from t4;
count(*)
20
select count(*) from t5;
count(*)
20
select c1 from t1;
c1
11
12
13
14
15
16
17
18
19
20
122
124
126
128
130
132
134
136
138
140
select c1 from t2;
c1
11
12
13
14
15
16
17
18
19
20
122
124
126
128
130
132
134
136
138
140
select c1 from t4;
c1
11
12
13
14
15
16
17
18
19
20
122
124
126
128
130
132
134
136
138
140
select c1 from t5;
c1
11
12
13
14
15
16
17
18
19
20
122
124
126
128
130
132
134
136
138
140
# In connection 1
set autocommit = 0;
insert into t1 values (20,1,'a','a','a','a','a',now(),100.55);
ERROR 23000: Duplicate entry '20' for key 't1.PRIMARY'
insert ignore into t1 values (20,1,'a','a','a','a','a',now(),100.55);
Warnings:
Warning 1062 Duplicate entry '20' for key 't1.PRIMARY'
insert into t2 values (20,1,'a','a','a','a','a',now(),100.55);
ERROR 23000: Duplicate entry '20' for key 't2.PRIMARY'
insert ignore into t2 values (20,1,'a','a','a','a','a',now(),100.55);
Warnings:
Warning 1062 Duplicate entry '20' for key 't2.PRIMARY'
insert into t4 values (20,1,'a','a','a','a','a',now(),100.55);
ERROR 23000: Duplicate entry '20' for key 't4.PRIMARY'
insert ignore into t4 values (20,1,'a','a','a','a','a',now(),100.55);
Warnings:
Warning 1062 Duplicate entry '20' for key 't4.PRIMARY'
insert into t5 values (20,1,'a','a','a','a','a',now(),100.55);
ERROR 23000: Duplicate entry '20' for key 't5.PRIMARY'
insert ignore into t5 values (20,1,'a','a','a','a','a',now(),100.55);
Warnings:
Warning 1062 Duplicate entry '20' for key 't5.PRIMARY'
insert into t1 values (1,1,'a','a','a','a','a',now(),100.55),
(20,1,'a','a','a','a','a',now(),100.55);
ERROR 23000: Duplicate entry '20' for key 't1.PRIMARY'
insert into t2 values (1,1,'a','a','a','a','a',now(),100.55),
(20,1,'a','a','a','a','a',now(),100.55);
ERROR 23000: Duplicate entry '20' for key 't2.PRIMARY'
insert into t4 values (1,1,'a','a','a','a','a',now(),100.55),
(20,1,'a','a','a','a','a',now(),100.55);
ERROR 23000: Duplicate entry '20' for key 't4.PRIMARY'
insert into t5 values (1,1,'a','a','a','a','a',now(),100.55),
(20,1,'a','a','a','a','a',now(),100.55);
ERROR 23000: Duplicate entry '20' for key 't5.PRIMARY'
set autocommit = 1;
select c1,c2 from t1 where c1 in (20,1);
c1 c2
20 20
select c1,c2 from t2 where c1 in (20,1);
c1 c2
20 20
select c1,c2 from t4 where c1 in (20,1);
c1 c2
20 20
select c1,c2 from t5 where c1 in (20,1);
c1 c2
20 20
replace into t1 values (20,1,'a','a','a','a','a',now(),100.55);
replace into t2 values (20,1,'a','a','a','a','a',now(),100.55);
replace into t4 values (20,1,'a','a','a','a','a',now(),100.55);
replace into t5 values (20,1,'a','a','a','a','a',now(),100.55);
select c1,c2,c3,c4,c5,c6,c7,c9 from t1 where c1 = 20;
c1 c2 c3 c4 c5 c6 c7 c9
20 1 a a a a a 100.550
select c1,c2,c3,c4,c5,c6,c7,c9 from t2 where c1 = 20;
c1 c2 c3 c4 c5 c6 c7 c9
20 1 a a a a a 100.550
select c1,c2,c3,c4,c5,c6,c7,c9 from t4 where c1 = 20;
c1 c2 c3 c4 c5 c6 c7 c9
20 1 a a a a a 100.550
select c1,c2,c3,c4,c5,c6,c7,c9 from t5 where c1 = 20;
c1 c2 c3 c4 c5 c6 c7 c9
20 1 a a a a a 100.550
update ignore t1 set c1 = 20 where c1 = 140 ;
Warnings:
Warning 1062 Duplicate entry '20' for key 't1.PRIMARY'
update ignore t2 set c1 = 20 where c1 = 140 ;
Warnings:
Warning 1062 Duplicate entry '20' for key 't2.PRIMARY'
update ignore t4 set c1 = 20 where c1 = 140 ;
Warnings:
Warning 1062 Duplicate entry '20' for key 't4.PRIMARY'
update ignore t5 set c1 = 20 where c1 = 140 ;
Warnings:
Warning 1062 Duplicate entry '20' for key 't5.PRIMARY'
select count(*) from t1 where c1 = 140;
count(*)
1
select count(*) from t2 where c1 = 140;
count(*)
1
select count(*) from t4 where c1 = 140;
count(*)
1
select count(*) from t5 where c1 = 140;
count(*)
1
"running select * into outfile <file> from t1 ;
create temporary table temp_1 engine = innodb as select * from t1 where 1=2;
select count(*) from temp_1;
count(*)
0
"running load data infile <file> into temp_1 ;
select count(*) from temp_1;
count(*)
20
alter table temp_1 add column c10 int default 99 ,
add column c11 varchar(100) default 'test';
alter table temp_1 add primary key (c1);
insert into temp_1 (c1,c2,c3,c4,c5,c6,c7,c8,c9) values (-1,-1,'a','a','a','a','a',now(),100.55);
select c1,c2,c3,c4,c5,c6,c7,c9,c10,c11 from temp_1 where c1 < 0;
c1 c2 c3 c4 c5 c6 c7 c9 c10 c11
-1 -1 a a a a a 100.550 99 test
select count(*) from temp_1 where c10 = 99 and c11 like 'test';
count(*)
21
insert into temp_1 (c1,c2,c3,c4,c5,c6,c7,c8,c9) values (-1,-1,'a','a','a','a','a',now(),100.55)
on duplicate key update c1=-2,c2=-2;
select c1,c2,c3,c4,c5,c6,c7,c9,c10,c11 from temp_1 where c1 < 0;
c1 c2 c3 c4 c5 c6 c7 c9 c10 c11
-2 -2 a a a a a 100.550 99 test
drop table t1,t2,t4,t5,t6,temp_1;
drop table t1 ,t2,t4,t5,t6;
drop procedure populate_tables;
create temporary table prep_1(c1 int not null,
c2 int not null,
c3 char(255) not null,
c4 text(6000) not null,
c5 blob(6000) not null,
c6 varchar(2000) not null,
c7 varchar(2000) not null,
c8 datetime,
c9 decimal(6,3),
index (c3,c4(50),c5(50)),
index (c2))
engine=innodb;
PREPARE stm FROM "insert into prep_1 values(?,?,repeat(concat(' tc3_',?),30),repeat(concat(' tc4_',?),800),repeat(concat(' tc_',?),800),repeat(concat(' tc6_',?),245),repeat(concat(' tc7_',?),245),now(),(100.55+?))";
set @var = 5;
set @var_static = 5;
EXECUTE stm USING @var,@var,@var,@var,@var,@var,@var,@var;
EXECUTE stm USING @var_static,@var_static,@var_static,@var_static,@var_static,@var_static,@var_static,@var_static;
set @var = @var - 1;
EXECUTE stm USING @var,@var,@var,@var,@var,@var,@var,@var;
EXECUTE stm USING @var_static,@var_static,@var_static,@var_static,@var_static,@var_static,@var_static,@var_static;
set @var = @var - 1;
EXECUTE stm USING @var,@var,@var,@var,@var,@var,@var,@var;
EXECUTE stm USING @var_static,@var_static,@var_static,@var_static,@var_static,@var_static,@var_static,@var_static;
set @var = @var - 1;
EXECUTE stm USING @var,@var,@var,@var,@var,@var,@var,@var;
EXECUTE stm USING @var_static,@var_static,@var_static,@var_static,@var_static,@var_static,@var_static,@var_static;
set @var = @var - 1;
EXECUTE stm USING @var,@var,@var,@var,@var,@var,@var,@var;
EXECUTE stm USING @var_static,@var_static,@var_static,@var_static,@var_static,@var_static,@var_static,@var_static;
set @var = @var - 1;
select c1,left(c3,15) from prep_1 order by c1 ;
c1 left(c3,15)
1 tc3_1 tc3_1 tc
2 tc3_2 tc3_2 tc
3 tc3_3 tc3_3 tc
4 tc3_4 tc3_4 tc
5 tc3_5 tc3_5 tc
5 tc3_5 tc3_5 tc
5 tc3_5 tc3_5 tc
5 tc3_5 tc3_5 tc
5 tc3_5 tc3_5 tc
5 tc3_5 tc3_5 tc
select count(*) from prep_1;
count(*)
10
PREPARE stm_1 FROM "UPDATE prep_1 SET c1 = c1 + 1";
EXECUTE stm_1;
EXECUTE stm_1;
select c1,left(c3,15) from prep_1 order by c1 ;
c1 left(c3,15)
3 tc3_1 tc3_1 tc
4 tc3_2 tc3_2 tc
5 tc3_3 tc3_3 tc
6 tc3_4 tc3_4 tc
7 tc3_5 tc3_5 tc
7 tc3_5 tc3_5 tc
7 tc3_5 tc3_5 tc
7 tc3_5 tc3_5 tc
7 tc3_5 tc3_5 tc
7 tc3_5 tc3_5 tc
select count(*) from prep_1;
count(*)
10
PREPARE stm_2 FROM "DELETE FROM prep_1 ORDER BY c1 LIMIT 1";
EXECUTE stm_2;
EXECUTE stm_2;
select c1,left(c3,15) from prep_1 order by c1 ;
c1 left(c3,15)
5 tc3_3 tc3_3 tc
6 tc3_4 tc3_4 tc
7 tc3_5 tc3_5 tc
7 tc3_5 tc3_5 tc
7 tc3_5 tc3_5 tc
7 tc3_5 tc3_5 tc
7 tc3_5 tc3_5 tc
7 tc3_5 tc3_5 tc
select count(*) from prep_1;
count(*)
8
drop prepare stm;
drop prepare stm_1;
drop prepare stm_2;
drop table prep_1;
|