heap.result 37.6 KB
Newer Older
1
SET SESSION STORAGE_ENGINE = MEMORY;
unknown's avatar
unknown committed
2
drop table if exists t1,t3,t4,t5;
3
create table t1 (a int, b char(10), key a using btree (a), key b using btree (a,b));
unknown's avatar
unknown committed
4 5
insert into t1 values
(17,"ddd"),(18,"eee"),(19,"fff"),(19,"yyy"),
6
(14,"aaa"),(16,"ccc"),(16,"xxx"),
Michael Widenius's avatar
Michael Widenius committed
7
(20,"ggg"),(21,"hhh"),(22,"iii"),(23,"xxx"),(24,"xxx"),(25,"xxx");
unknown's avatar
unknown committed
8
handler t1 open as t2;
9
handler t2 read b first;
10 11
a	b
14	aaa
12
handler t2 read b next;
13 14
a	b
16	ccc
15
handler t2 read b next;
16
a	b
17 18
16	xxx
handler t2 read b prev;
19
a	b
20 21
16	ccc
handler t2 read b last;
22
a	b
Michael Widenius's avatar
Michael Widenius committed
23
25	xxx
24
handler t2 read b prev;
25
a	b
Michael Widenius's avatar
Michael Widenius committed
26
24	xxx
27 28
handler t2 read b prev;
a	b
Michael Widenius's avatar
Michael Widenius committed
29
23	xxx
30
handler t2 read b first;
31 32
a	b
14	aaa
33
handler t2 read b prev;
34
a	b
35
handler t2 read b last;
36
a	b
Michael Widenius's avatar
Michael Widenius committed
37
25	xxx
38
handler t2 read b prev;
39
a	b
Michael Widenius's avatar
Michael Widenius committed
40
24	xxx
41
handler t2 read b next;
42
a	b
Michael Widenius's avatar
Michael Widenius committed
43
25	xxx
44
handler t2 read b next;
45
a	b
unknown's avatar
unknown committed
46
handler t2 read a=(15);
47
a	b
48
handler t2 read a=(21);
unknown's avatar
unknown committed
49
a	b
50
21	hhh
unknown's avatar
unknown committed
51
handler t2 read a=(19,"fff");
52
ERROR 42000: Too many key parts specified; max 1 parts allowed
unknown's avatar
unknown committed
53
handler t2 read b=(19,"fff");
unknown's avatar
unknown committed
54 55
a	b
19	fff
unknown's avatar
unknown committed
56
handler t2 read b=(19,"yyy");
unknown's avatar
unknown committed
57 58
a	b
19	yyy
unknown's avatar
unknown committed
59
handler t2 read b=(19);
unknown's avatar
unknown committed
60 61
a	b
19	fff
unknown's avatar
unknown committed
62
handler t1 read a last;
63
ERROR 42S02: Unknown table 't1' in HANDLER
unknown's avatar
unknown committed
64
handler t2 read a=(11);
unknown's avatar
unknown committed
65
a	b
unknown's avatar
unknown committed
66
handler t2 read a>=(11);
unknown's avatar
unknown committed
67 68
a	b
14	aaa
69
handler t2 read b=(18);
unknown's avatar
unknown committed
70 71
a	b
18	eee
72
handler t2 read b>=(18);
unknown's avatar
unknown committed
73 74
a	b
18	eee
75
handler t2 read b>(18);
unknown's avatar
unknown committed
76 77
a	b
19	fff
78
handler t2 read b<=(18);
unknown's avatar
unknown committed
79 80
a	b
18	eee
81
handler t2 read b<(18);
unknown's avatar
unknown committed
82 83
a	b
17	ddd
84 85
handler t2 read a=(15);
a	b
86
handler t2 read a>=(15) limit 2;
87 88
a	b
16	ccc
89 90
16	xxx
handler t2 read a>(15) limit 2;
91 92
a	b
16	ccc
93
16	xxx
94 95 96 97 98 99 100 101 102 103 104 105 106 107
handler t2 read a<=(15);
a	b
14	aaa
handler t2 read a<(15);
a	b
14	aaa
handler t2 read a=(54);
a	b
handler t2 read a>=(54);
a	b
handler t2 read a>(54);
a	b
handler t2 read a<=(54);
a	b
Michael Widenius's avatar
Michael Widenius committed
108
25	xxx
109 110
handler t2 read a<(54);
a	b
Michael Widenius's avatar
Michael Widenius committed
111
25	xxx
112 113 114 115 116 117 118 119 120 121 122 123 124
handler t2 read a=(1);
a	b
handler t2 read a>=(1);
a	b
14	aaa
handler t2 read a>(1);
a	b
14	aaa
handler t2 read a<=(1);
a	b
handler t2 read a<(1);
a	b
handler t2 read b first limit 5;
unknown's avatar
unknown committed
125 126 127 128 129 130
a	b
14	aaa
16	ccc
16	xxx
17	ddd
18	eee
131 132
handler t2 read b next  limit 3;
a	b
unknown's avatar
unknown committed
133 134
19	fff
19	yyy
135 136
20	ggg
handler t2 read b prev  limit 10;
unknown's avatar
unknown committed
137
a	b
138
19	yyy
unknown's avatar
unknown committed
139 140 141 142 143 144
19	fff
18	eee
17	ddd
16	xxx
16	ccc
14	aaa
145
handler t2 read b>=(16) limit 4;
unknown's avatar
unknown committed
146 147 148 149 150
a	b
16	ccc
16	xxx
17	ddd
18	eee
151
handler t2 read b>=(16) limit 2,2;
152 153 154
a	b
17	ddd
18	eee
155
select * from t1 where a>=16 order by a,b limit 2,2;
unknown's avatar
unknown committed
156 157 158
a	b
17	ddd
18	eee
unknown's avatar
unknown committed
159
handler t2 read a last  limit 3;
unknown's avatar
unknown committed
160
a	b
Michael Widenius's avatar
Michael Widenius committed
161 162 163
25	xxx
24	xxx
23	xxx
164
handler t2 read b=(16) limit 1,3;
165 166 167
a	b
16	xxx
handler t2 read b=(19);
unknown's avatar
unknown committed
168 169
a	b
19	fff
170
handler t2 read b=(19) where b="yyy";
unknown's avatar
unknown committed
171 172
a	b
19	yyy
unknown's avatar
unknown committed
173
handler t2 read first;
unknown's avatar
unknown committed
174 175
a	b
17	ddd
unknown's avatar
unknown committed
176
handler t2 read next;
unknown's avatar
unknown committed
177 178
a	b
18	eee
unknown's avatar
unknown committed
179
handler t2 read next;
unknown's avatar
unknown committed
180 181
a	b
19	fff
unknown's avatar
unknown committed
182
handler t2 close;
unknown's avatar
unknown committed
183
handler t1 open;
184
handler t1 read b next;
unknown's avatar
unknown committed
185 186
a	b
14	aaa
187
handler t1 read b next;
unknown's avatar
unknown committed
188
a	b
189
16	ccc
unknown's avatar
unknown committed
190 191 192 193
handler t1 close;
handler t1 open;
handler t1 read a prev;
a	b
Michael Widenius's avatar
Michael Widenius committed
194
25	xxx
unknown's avatar
unknown committed
195 196
handler t1 read a prev;
a	b
Michael Widenius's avatar
Michael Widenius committed
197
24	xxx
unknown's avatar
unknown committed
198 199 200 201 202
handler t1 close;
handler t1 open as t2;
handler t2 read first;
a	b
17	ddd
203
alter table t1 engine = MEMORY;
unknown's avatar
unknown committed
204 205
handler t2 read first;
ERROR 42S02: Unknown table 't2' in HANDLER
206
handler t1 open;
Michael Widenius's avatar
Michael Widenius committed
207
handler t1 read a=(20) limit 1,3;
208 209
a	b
flush tables;
Michael Widenius's avatar
Michael Widenius committed
210
handler t1 read a=(20) limit 1,3;
211
a	b
Michael Widenius's avatar
Michael Widenius committed
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
handler t1 close;
handler t1 open;
handler t1 read a=(25);
a	b
25	xxx
handler t1 read a next;
a	b
handler t1 read a next;
a	b
handler t1 read a next;
a	b
handler t1 read a prev;
a	b
25	xxx
handler t1 read a=(1000);
a	b
handler t1 read a next;
a	b
handler t1 read a prev;
a	b
25	xxx
handler t1 read a=(1000);
a	b
handler t1 read a prev;
a	b
25	xxx
handler t1 read a=(14);
a	b
14	aaa
handler t1 read a prev;
a	b
handler t1 read a prev;
a	b
handler t1 read a next;
a	b
14	aaa
handler t1 read a=(1);
a	b
handler t1 read a prev;
a	b
handler t1 read a next;
a	b
14	aaa
handler t1 read a=(1);
a	b
handler t1 read a next;
a	b
14	aaa
260 261 262
handler t1 close;
handler t1 open;
prepare stmt from 'handler t1 read a=(?) limit ?,?';
Michael Widenius's avatar
Michael Widenius committed
263
set @a=20,@b=1,@c=100;
264 265
execute stmt using @a,@b,@c;
a	b
Michael Widenius's avatar
Michael Widenius committed
266
set @a=20,@b=2,@c=1;
267 268
execute stmt using @a,@b,@c;
a	b
Michael Widenius's avatar
Michael Widenius committed
269
set @a=20,@b=0,@c=2;
270 271
execute stmt using @a,@b,@c;
a	b
Michael Widenius's avatar
Michael Widenius committed
272
20	ggg
273 274
deallocate prepare stmt;
prepare stmt from 'handler t1 read a next limit ?';
Michael Widenius's avatar
Michael Widenius committed
275
handler t1 read a>=(21);
276
a	b
Michael Widenius's avatar
Michael Widenius committed
277
21	hhh
278 279 280
set @a=3;
execute stmt using @a;
a	b
Michael Widenius's avatar
Michael Widenius committed
281 282 283
22	iii
23	xxx
24	xxx
284 285
execute stmt using @a;
a	b
Michael Widenius's avatar
Michael Widenius committed
286
25	xxx
287 288 289 290 291 292
execute stmt using @a;
a	b
deallocate prepare stmt;
prepare stmt from 'handler t1 read b prev limit ?';
execute stmt using @a;
a	b
Michael Widenius's avatar
Michael Widenius committed
293 294 295 296 297
25	xxx
24	xxx
23	xxx
execute stmt using @a;
a	b
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
22	iii
21	hhh
20	ggg
execute stmt using @a;
a	b
19	yyy
19	fff
18	eee
execute stmt using @a;
a	b
17	ddd
16	xxx
16	ccc
deallocate prepare stmt;
prepare stmt from 'handler t1 read b=(?,?)';
set @a=14, @b='aaa';
execute stmt using @a,@b;
a	b
14	aaa
set @a=14, @b='not found';
execute stmt using @a,@b;
a	b
deallocate prepare stmt;
prepare stmt from 'handler t1 read b=(1+?) limit 10';
set @a=15;
execute stmt using @a;
a	b
16	ccc
16	xxx
execute stmt using @a;
a	b
16	ccc
16	xxx
deallocate prepare stmt;
Michael Widenius's avatar
Michael Widenius committed
332
prepare stmt from 'handler t1 read b>=(?) where a < ? limit 5';
Michael Widenius's avatar
Michael Widenius committed
333
set @a=17, @b=24;
334 335 336 337 338
execute stmt using @a,@b;
a	b
17	ddd
18	eee
19	fff
Michael Widenius's avatar
Michael Widenius committed
339 340
19	yyy
20	ggg
341 342 343 344 345
execute stmt using @a,@b;
a	b
17	ddd
18	eee
19	fff
Michael Widenius's avatar
Michael Widenius committed
346 347
19	yyy
20	ggg
348 349
deallocate prepare stmt;
prepare stmt from 'handler t1 read a=(?)';
Michael Widenius's avatar
Michael Widenius committed
350
set @a=17;
351 352
execute stmt using @a;
a	b
Michael Widenius's avatar
Michael Widenius committed
353
17	ddd
354 355 356 357 358 359 360 361 362
alter table t1 add c int;
execute stmt using @a;
ERROR 42S02: Unknown table 't1' in HANDLER
deallocate prepare stmt;
handler t1 close;
ERROR 42S02: Unknown table 't1' in HANDLER
handler t1 open;
prepare stmt from 'handler t1 read a=(?)';
flush tables;
Michael Widenius's avatar
Michael Widenius committed
363
set @a=17;
364
execute stmt using @a;
Sergei Golubchik's avatar
Sergei Golubchik committed
365 366
a	b	c
17	ddd	NULL
367 368
deallocate prepare stmt;
handler t1 close;
369 370
handler t1 open as t2;
drop table t1;
371
create table t1 (a int not null);
372 373
insert into t1 values (17);
handler t2 read first;
374
ERROR 42S02: Unknown table 't2' in HANDLER
unknown's avatar
unknown committed
375
handler t1 open as t2;
Sergei Golubchik's avatar
Sergei Golubchik committed
376
alter table t1 engine=csv;
unknown's avatar
unknown committed
377
handler t2 read first;
378
ERROR 42S02: Unknown table 't2' in HANDLER
379
drop table t1;
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
create table t1 (a int);
insert into t1 values (1),(2),(3),(4),(5),(6);
delete from t1 limit 2;
handler t1 open;
handler t1 read first;
a
3
handler t1 read first limit 1,1;
a
4
handler t1 read first limit 2,2;
a
5
6
delete from t1 limit 3;
handler t1 read first;
a
6
drop table t1;
399
create table t1(a int, index using btree (a));
unknown's avatar
unknown committed
400 401 402
insert into t1 values (1), (2), (3);
handler t1 open;
handler t1 read a=(W);
unknown's avatar
unknown committed
403
ERROR 42S22: Unknown column 'W' in 'field list'
404
handler t1 read a=(a);
405
ERROR HY000: Incorrect arguments to HANDLER ... READ
unknown's avatar
unknown committed
406
drop table t1;
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
create table t1 (a char(5));
insert into t1 values ("Ok");
handler t1 open as t;
handler t read first;
a
Ok
use mysql;
handler t read first;
a
Ok
handler t close;
handler test.t1 open as t;
handler t read first;
a
Ok
handler t close;
use test;
drop table t1;
425
create table t1 ( a int, b int, INDEX a using btree (a) );
unknown's avatar
unknown committed
426 427 428 429 430 431 432 433 434 435 436
insert into t1 values (1,2), (2,1);
handler t1 open;
handler t1 read a=(1) where b=2;
a	b
1	2
handler t1 read a=(1) where b=3;
a	b
handler t1 read a=(1) where b=1;
a	b
handler t1 close;
drop table t1;
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
create table t1 (c1 char(20));
insert into t1 values ("t1");
handler t1 open as h1;
handler h1 read first limit 9;
c1
t1
create table t2 (c1 char(20));
insert into t2 values ("t2");
handler t2 open as h2;
handler h2 read first limit 9;
c1
t2
create table t3 (c1 char(20));
insert into t3 values ("t3");
handler t3 open as h3;
handler h3 read first limit 9;
c1
t3
create table t4 (c1 char(20));
insert into t4 values ("t4");
handler t4 open as h4;
handler h4 read first limit 9;
c1
t4
create table t5 (c1 char(20));
insert into t5 values ("t5");
handler t5 open as h5;
handler h5 read first limit 9;
c1
t5
alter table t1 engine=MyISAM;
handler h1 read first limit 9;
unknown's avatar
unknown committed
469
ERROR 42S02: Unknown table 'h1' in HANDLER
470 471 472 473 474 475 476 477 478 479 480 481 482 483
handler h2 read first limit 9;
c1
t2
handler h3 read first limit 9;
c1
t3
handler h4 read first limit 9;
c1
t4
handler h5 read first limit 9;
c1
t5
alter table t5 engine=MyISAM;
handler h1 read first limit 9;
unknown's avatar
unknown committed
484
ERROR 42S02: Unknown table 'h1' in HANDLER
485 486 487 488 489 490 491 492 493 494
handler h2 read first limit 9;
c1
t2
handler h3 read first limit 9;
c1
t3
handler h4 read first limit 9;
c1
t4
handler h5 read first limit 9;
unknown's avatar
unknown committed
495
ERROR 42S02: Unknown table 'h5' in HANDLER
496 497
alter table t3 engine=MyISAM;
handler h1 read first limit 9;
unknown's avatar
unknown committed
498
ERROR 42S02: Unknown table 'h1' in HANDLER
499 500 501 502
handler h2 read first limit 9;
c1
t2
handler h3 read first limit 9;
unknown's avatar
unknown committed
503
ERROR 42S02: Unknown table 'h3' in HANDLER
504 505 506 507
handler h4 read first limit 9;
c1
t4
handler h5 read first limit 9;
unknown's avatar
unknown committed
508
ERROR 42S02: Unknown table 'h5' in HANDLER
509 510 511 512 513 514 515 516 517 518 519 520 521 522
handler h2 close;
handler h4 close;
handler t1 open as h1_1;
handler t1 open as h1_2;
handler t1 open as h1_3;
handler h1_1 read first limit 9;
c1
t1
handler h1_2 read first limit 9;
c1
t1
handler h1_3 read first limit 9;
c1
t1
523
alter table t1 engine=MEMORY;
524
handler h1_1 read first limit 9;
unknown's avatar
unknown committed
525
ERROR 42S02: Unknown table 'h1_1' in HANDLER
526
handler h1_2 read first limit 9;
unknown's avatar
unknown committed
527
ERROR 42S02: Unknown table 'h1_2' in HANDLER
528
handler h1_3 read first limit 9;
unknown's avatar
unknown committed
529
ERROR 42S02: Unknown table 'h1_3' in HANDLER
530 531 532 533 534
drop table t1;
drop table t2;
drop table t3;
drop table t4;
drop table t5;
535 536 537 538 539 540
create table t1 (c1 int);
insert into t1 values (1);
handler t1 open;
handler t1 read first;
c1
1
541 542
connect  con2,localhost,root,,;
connection con2;
543
send the below to another connection, do not wait for the result
544
optimize table t1;
545
connection default;
546 547 548
handler t1 read next;
c1
handler t1 close;
549
connection con2;
550
Table	Op	Msg_type	Msg_text
551
test.t1	optimize	note	The storage engine for the table doesn't support optimize
552
connection default;
553
drop table t1;
554
CREATE TABLE t1 (  no1 smallint(5) NOT NULL default '0',  no2 int(10) NOT NULL default '0',  PRIMARY KEY using btree (no1,no2));
unknown's avatar
unknown committed
555 556 557 558 559 560 561
INSERT INTO t1 VALUES (1,274),(1,275),(2,6),(2,8),(4,1),(4,2);
HANDLER t1 OPEN;
HANDLER t1 READ `primary` = (1, 1000);
no1	no2
HANDLER t1 READ `primary` PREV;
no1	no2
1	275
562 563 564 565 566
HANDLER t1 READ `primary` = (1, 1000);
no1	no2
HANDLER t1 READ `primary` NEXT;
no1	no2
2	6
unknown's avatar
unknown committed
567
DROP TABLE t1;
568 569 570 571 572
create table t1 (c1 int);
insert into t1 values (14397);
flush tables with read lock;
drop table t1;
ERROR HY000: Can't execute the query because you have a conflicting read lock
573
connection con2;
574
drop table t1;
575
connection default;
576 577 578 579
select * from t1;
c1
14397
unlock tables;
580
connection con2;
581
read the result from the other connection
582
connection default;
583 584 585 586
select * from t1;
ERROR 42S02: Table 'test.t1' doesn't exist
drop table if exists t1;
Warnings:
Sergei Golubchik's avatar
Sergei Golubchik committed
587
Note	1051	Unknown table 'test.t1'
Sergei Golubchik's avatar
Sergei Golubchik committed
588
create table t1 (a int not null) ENGINE=csv;
589
connection con2;
unknown's avatar
unknown committed
590
handler t1 open;
Sergei Golubchik's avatar
Sergei Golubchik committed
591
ERROR HY000: Storage engine CSV of the table `test`.`t1` doesn't have this option
592
connection default;
unknown's avatar
unknown committed
593
drop table t1;
594
disconnect con2;
unknown's avatar
unknown committed
595 596 597 598 599 600 601 602 603 604 605 606
create table t1 (a int);
handler t1 open as t1_alias;
handler t1_alias read a next;
ERROR 42000: Key 'a' doesn't exist in table 't1_alias'
handler t1_alias READ a next where inexistent > 0;
ERROR 42S22: Unknown column 'inexistent' in 'field list'
handler t1_alias read a next;
ERROR 42000: Key 'a' doesn't exist in table 't1_alias'
handler t1_alias READ a next where inexistent > 0;
ERROR 42S22: Unknown column 'inexistent' in 'field list'
handler t1_alias close;
drop table t1;
607
create temporary table t1 (a int, b char(1), key a using btree (a), key b using btree (a,b));
608
insert into t1 values (0,"a"),(1,"b"),(2,"c"),(3,"d"),(4,"e"),
609
(5,"f"),(6,"g"),(7,"h"),(8,"i"),(9,"j"),(9,'k');
610 611 612 613 614 615 616 617 618 619 620 621
select a,b from t1;
a	b
0	a
1	b
2	c
3	d
4	e
5	f
6	g
7	h
8	i
9	j
622
9	k
623
handler t1 open as a1;
624
handler a1 read a=(1);
625 626 627 628 629
a	b
1	b
handler a1 read a next;
a	b
2	c
630 631 632
handler a1 read a next;
a	b
3	d
633
select a,b from t1;
634 635 636 637 638 639 640 641 642 643 644 645
a	b
0	a
1	b
2	c
3	d
4	e
5	f
6	g
7	h
8	i
9	j
9	k
646 647
handler a1 read a prev;
a	b
648
2	c
649 650
handler a1 read a prev;
a	b
651
1	b
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
handler a1 read a=(6) where b="g";
a	b
6	g
handler a1 close;
select a,b from t1;
a	b
0	a
1	b
2	c
3	d
4	e
5	f
6	g
7	h
8	i
9	j
668
9	k
669
handler t1 open as a2;
670
handler a2 read b=(9);
671 672
a	b
9	j
673
handler a2 read b next;
674
a	b
675 676 677 678
9	k
handler a2 read b prev limit 2;
a	b
9	j
679
8	i
680 681 682 683 684 685
handler a2 read b last;
a	b
9	k
handler a2 read b prev;
a	b
9	j
686 687
handler a2 close;
drop table t1;
688
create table t1 (a int);
689
create temporary table t2 (a int, key using btree (a));
690 691 692 693 694 695 696 697 698
handler t1 open as a1;
handler t2 open as a2;
handler a2 read a first;
a
drop table t1, t2;
handler a2 read a next;
ERROR 42S02: Unknown table 'a2' in HANDLER
handler a1 close;
ERROR 42S02: Unknown table 'a1' in HANDLER
699
create table t1 (a int, key using btree (a));
700 701 702 703 704 705 706 707 708 709 710 711
create table t2 like t1;
handler t1 open as a1;
handler t2 open as a2;
handler a1 read a first;
a
handler a2 read a first;
a
alter table t1 add b int;
handler a1 close;
ERROR 42S02: Unknown table 'a1' in HANDLER
handler a2 close;
drop table t1, t2;
712
create table t1 (a int, key using btree (a));
713 714 715 716 717 718 719
handler t1 open as a1;
handler a1 read a first;
a
rename table t1 to t2;
handler a1 read a first;
ERROR 42S02: Unknown table 'a1' in HANDLER
drop table t2;
720
create table t1 (a int, key using btree (a));
721 722 723 724 725 726 727 728 729
create table t2 like t1;
handler t1 open as a1;
handler t2 open as a2;
handler a1 read a first;
a
handler a2 read a first;
a
optimize table t1;
Table	Op	Msg_type	Msg_text
730
test.t1	optimize	note	The storage engine for the table doesn't support optimize
731 732 733 734
handler a1 close;
ERROR 42S02: Unknown table 'a1' in HANDLER
handler a2 close;
drop table t1, t2;
735 736 737 738 739 740 741 742 743 744 745 746
#
# Add test coverage for HANDLER and LOCK TABLES, HANDLER and DDL.
#
drop table if exists t1, t2, t3;
create table t1 (a int, key a (a));
insert into t1 (a) values (1), (2), (3), (4), (5);
create table t2 (a int, key a (a)) select * from t1;
create temporary table t3 (a int, key a (a)) select * from t2;
handler t1 open;
handler t2 open;
handler t3 open;
#
747 748
# No HANDLER sql is allowed under LOCK TABLES.
# But it does not implicitly closes all handlers.
749
#
750
lock table t1 read;
751 752 753 754 755 756 757
handler t1 open;
ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction
handler t1 read next;
ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction
handler t2 close;
ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction
handler t3 open;
758
ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction
759 760
# After UNLOCK TABLES handlers should be around and
# we should be able to continue reading through them.
761 762
unlock tables;
handler t1 read next;
763 764 765 766 767 768
a
1
handler t1 close;
handler t2 read next;
a
1
769 770
handler t2 close;
handler t3 read next;
771 772 773 774
a
1
handler t3 close;
drop temporary table t3;
775
#
776
# Other operations that implicitly close handler:
777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810
#
# TRUNCATE
#
handler t1 open;
truncate table t1;
handler t1 read next;
ERROR 42S02: Unknown table 't1' in HANDLER
handler t1 open;
#
# CREATE TRIGGER
#
create trigger t1_ai after insert on t1 for each row set @a=1;
handler t1 read next;
ERROR 42S02: Unknown table 't1' in HANDLER
#
# DROP TRIGGER
#
handler t1 open;
drop trigger t1_ai;
handler t1 read next;
ERROR 42S02: Unknown table 't1' in HANDLER
#
# ALTER TABLE
# 
handler t1 open;
alter table t1 add column b int;
handler t1 read next;
ERROR 42S02: Unknown table 't1' in HANDLER
#
# ANALYZE TABLE
# 
handler t1 open;
analyze table t1;
Table	Op	Msg_type	Msg_text
Sergei Golubchik's avatar
Sergei Golubchik committed
811
test.t1	analyze	note	The storage engine for the table doesn't support analyze
812 813 814 815 816 817 818 819
handler t1 read next;
ERROR 42S02: Unknown table 't1' in HANDLER
#
# OPTIMIZE TABLE
# 
handler t1 open;
optimize table t1;
Table	Op	Msg_type	Msg_text
Sergei Golubchik's avatar
Sergei Golubchik committed
820
test.t1	optimize	note	The storage engine for the table doesn't support optimize
821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838
handler t1 read next;
ERROR 42S02: Unknown table 't1' in HANDLER
#
# REPAIR TABLE
# 
handler t1 open;
repair table t1;
Table	Op	Msg_type	Msg_text
test.t1	repair	note	The storage engine for the table doesn't support repair
handler t1 read next;
ERROR 42S02: Unknown table 't1' in HANDLER
#
# DROP TABLE, naturally.
# 
handler t1 open;
drop table t1;
handler t1 read next;
ERROR 42S02: Unknown table 't1' in HANDLER
Sergei Golubchik's avatar
Sergei Golubchik committed
839
create table t1 (a int, b int, key a using btree (a)) select a from t2;
840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884
#
# RENAME TABLE, naturally
# 
handler t1 open;
rename table t1 to t3;
handler t1 read next;
ERROR 42S02: Unknown table 't1' in HANDLER
#
# CREATE TABLE (even with IF NOT EXISTS clause,
# and the table exists).
# 
handler t2 open;
create table if not exists t2 (a int);
Warnings:
Note	1050	Table 't2' already exists
handler t2 read next;
ERROR 42S02: Unknown table 't2' in HANDLER
rename table t3 to t1;
drop table t2;
#
# FLUSH TABLE doesn't close the table but loses the position
# 
handler t1 open;
handler t1 read a prev;
b	a
NULL	5
flush table t1;
handler t1 read a prev;
b	a
NULL	5
handler t1 close;
#
# FLUSH TABLES WITH READ LOCK behaves like FLUSH TABLE.
# 
handler t1 open;
handler t1 read a prev;
b	a
NULL	5
flush tables with read lock;
handler t1 read a prev;
b	a
NULL	5
handler t1 close;
unlock tables;
#
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929
# Let us also check that these operations behave in similar
# way under LOCK TABLES.
#
# TRUNCATE under LOCK TABLES.
#
handler t1 open;
lock tables t1 write;
truncate table t1;
unlock tables;
handler t1 read next;
ERROR 42S02: Unknown table 't1' in HANDLER
handler t1 open;
#
# CREATE TRIGGER under LOCK TABLES.
#
lock tables t1 write;
create trigger t1_ai after insert on t1 for each row set @a=1;
unlock tables;
handler t1 read next;
ERROR 42S02: Unknown table 't1' in HANDLER
#
# DROP TRIGGER under LOCK TABLES.
#
handler t1 open;
lock tables t1 write;
drop trigger t1_ai;
unlock tables;
handler t1 read next;
ERROR 42S02: Unknown table 't1' in HANDLER
#
# ALTER TABLE under LOCK TABLES.
# 
handler t1 open;
lock tables t1 write;
alter table t1 drop column b;
unlock tables;
handler t1 read next;
ERROR 42S02: Unknown table 't1' in HANDLER
#
# ANALYZE TABLE under LOCK TABLES.
# 
handler t1 open;
lock tables t1 write;
analyze table t1;
Table	Op	Msg_type	Msg_text
Sergei Golubchik's avatar
Sergei Golubchik committed
930
test.t1	analyze	note	The storage engine for the table doesn't support analyze
931 932 933 934 935 936 937 938 939 940
unlock tables;
handler t1 read next;
ERROR 42S02: Unknown table 't1' in HANDLER
#
# OPTIMIZE TABLE under LOCK TABLES.
# 
handler t1 open;
lock tables t1 write;
optimize table t1;
Table	Op	Msg_type	Msg_text
Sergei Golubchik's avatar
Sergei Golubchik committed
941
test.t1	optimize	note	The storage engine for the table doesn't support optimize
942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964
unlock tables;
handler t1 read next;
ERROR 42S02: Unknown table 't1' in HANDLER
#
# REPAIR TABLE under LOCK TABLES.
# 
handler t1 open;
lock tables t1 write;
repair table t1;
Table	Op	Msg_type	Msg_text
test.t1	repair	note	The storage engine for the table doesn't support repair
unlock tables;
handler t1 read next;
ERROR 42S02: Unknown table 't1' in HANDLER
#
# DROP TABLE under LOCK TABLES, naturally.
# 
handler t1 open;
lock tables t1 write;
drop table t1;
unlock tables;
handler t1 read next;
ERROR 42S02: Unknown table 't1' in HANDLER
Sergei Golubchik's avatar
Sergei Golubchik committed
965
create table t1 (a int, b int, key a using btree (a));
966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981
insert into t1 (a) values (1), (2), (3), (4), (5);
#
# FLUSH TABLE doesn't close the table but loses the position
# 
handler t1 open;
handler t1 read a prev;
a	b
5	NULL
lock tables t1 write;
flush table t1;
unlock tables;
handler t1 read a prev;
a	b
5	NULL
handler t1 close;
#
982 983 984
# Explore the effect of HANDLER locks on concurrent DDL
#
handler t1 open;
985 986 987 988
connect con1, localhost, root,,;
connect con2, localhost, root,,;
connect con3, localhost, root,,;
connection con1;
989 990 991 992
# Sending:
drop table t1 ;
# We can't use connection 'default' as wait_condition will 
# autoclose handlers.
993
connection con2;
994
# Waitng for 'drop table t1' to get blocked...
995
connection default;
996
handler t1 read a prev;
997 998
a	b
5	NULL
999
handler t1 read a prev;
1000 1001
a	b
4	NULL
1002
handler t1 close;
1003
connection con1;
1004
# Reaping 'drop table t1'...
1005
connection default;
1006 1007 1008
#
# Explore the effect of HANDLER locks in parallel with SELECT 
#
Sergei Golubchik's avatar
Sergei Golubchik committed
1009
create table t1 (a int, key a using btree (a));
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
insert into t1 (a) values (1), (2), (3), (4), (5);
begin;
select * from t1;
a
1
2
3
4
5
handler t1 open;
handler t1 read a prev;
a
5
handler t1 read a prev;
a
4
handler t1 close;
1027
connection con1;
1028 1029
# Sending:
drop table t1 ;
1030
connection con2;
1031
# Waiting for 'drop table t1' to get blocked...
1032
connection default;
1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056
# We can still use the table, it's part of the transaction
select * from t1;
a
1
2
3
4
5
# Such are the circumstances that t1 is a part of transaction,
# thus we can reopen it in the handler
handler t1 open;
# We can commit the transaction, it doesn't close the handler
# and doesn't let DROP to proceed.
commit;
handler t1 read a prev;
a
5
handler t1 read a prev;
a
4
handler t1 read a prev;
a
3
handler t1 close;
1057
connection con1;
1058 1059
# Now drop can proceed
# Reaping 'drop table t1'...
1060
connection default;
1061 1062
#
# Demonstrate that HANDLER locks and transaction locks
1063
# reside in the same context.
1064 1065 1066
#
create table t1 (a int, key a (a));
insert into t1 (a) values (1), (2), (3), (4), (5);
Sergei Golubchik's avatar
Sergei Golubchik committed
1067
create table t0 (a int, key a using btree (a));
1068
insert into t0 (a) values (1), (2), (3), (4), (5);
1069 1070 1071 1072 1073 1074 1075 1076
begin;
select * from t1;
a
1
2
3
4
5
1077
connection con2;
1078
# Sending:
1079
rename table t0 to t3, t1 to t0, t3 to t1;
1080
connection con1;
1081
# Waiting for 'rename table ...' to get blocked...
1082
connection default;
1083
# We back-off on hitting deadlock condition.
1084
handler t0 open;
1085
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
1086
select * from t0;
1087 1088 1089 1090 1091 1092
a
1
2
3
4
5
1093 1094 1095
handler t1 open;
commit;
handler t1 close;
1096
connection con2;
1097
# Reaping 'rename table ...'...
1098
connection default;
1099 1100 1101 1102 1103
handler t1 open;
handler t1 read a prev;
a
5
handler t1 close;
1104
drop table t0;
1105
#
1106 1107 1108 1109 1110
# Originally there was a deadlock error in this test.
# With implementation of deadlock detector
# we no longer deadlock, but block and wait on a lock.
# The HANDLER is auto-closed as soon as the connection
# sees a pending conflicting lock against it.
1111 1112 1113
#
create table t2 (a int, key a (a));
handler t1 open;
1114
connection con1;
1115
lock tables t2 read;
1116
connection con2;
1117 1118
# Sending 'drop table t2'...
drop table t2;
1119
connection con1;
1120
# Waiting for 'drop table t2' to get blocked...
1121
connection default;
1122
# Sending 'select * from t2'
1123
select * from t2;
1124
connection con1;
1125
# Waiting for 'select * from t2' to get blocked...
1126
unlock tables;
1127
connection con2;
1128
# Reaping 'drop table t2'...
1129
connection default;
1130 1131
# Reaping 'select * from t2'
ERROR 42S02: Table 'test.t2' doesn't exist
1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152
handler t1 close;
#
# ROLLBACK TO SAVEPOINT releases transactional locks,
# but has no effect on open HANDLERs
#
create table t2 like t1;
create table t3 like t1;
begin;
# Have something before the savepoint
select * from t3;
a
savepoint sv;
handler t1 open;
handler t1 read a first;
a
1
handler t1 read a next;
a
2
select * from t2;
a
1153
connection con1;
1154 1155
# Sending:
drop table t1;
1156
connection con2;
1157 1158
# Sending:
drop table t2;
1159
connection default;
1160 1161 1162 1163
# Let DROP TABLE statements sync in. We must use
# a separate connection for that, because otherwise SELECT
# will auto-close the HANDLERs, becaues there are pending
# exclusive locks against them.
1164
connection con3;
1165 1166 1167 1168
# Waiting for 'drop table t1' to get blocked...
# Waiting for 'drop table t2' to get blocked...
# Demonstrate that t2 lock was released and t2 was dropped
# after ROLLBACK TO SAVEPOINT
1169
connection default;
1170
rollback to savepoint sv;
1171
connection con2;
1172 1173 1174
# Reaping 'drop table t2'...
# Demonstrate that ROLLBACK TO SAVEPOINT didn't release the handler
# lock.
1175
connection default;
1176 1177 1178 1179 1180 1181 1182 1183 1184
handler t1 read a next;
a
3
handler t1 read a next;
a
4
# Demonstrate that the drop will go through as soon as we close the 
# HANDLER
handler t1 close;
1185
connection con1;
1186
# Reaping 'drop table t1'...
1187
connection default;
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197
commit;
drop table t3;
#
# A few special cases when using SAVEPOINT/ROLLBACK TO
# SAVEPOINT and HANDLER.
#
# Show that rollback to the savepoint taken in the beginning
# of the transaction doesn't release mdl lock on
# the HANDLER that was opened later.
#
Sergei Golubchik's avatar
Sergei Golubchik committed
1198
create table t1 (a int, key using btree (a));
1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211
insert into t1 (a) values (1), (2), (3), (4), (5);
create table t2 like t1;
begin;
savepoint sv;
handler t1 open;
handler t1 read a first;
a
1
handler t1 read a next;
a
2
select * from t2;
a
1212
connection con1;
1213 1214
# Sending:
drop table t1;
1215
connection con2;
1216 1217
# Sending:
drop table t2;
1218
connection default;
1219 1220 1221 1222
# Let DROP TABLE statements sync in. We must use
# a separate connection for that, because otherwise SELECT
# will auto-close the HANDLERs, becaues there are pending
# exclusive locks against them.
1223
connection con3;
1224 1225 1226 1227
# Waiting for 'drop table t1' to get blocked...
# Waiting for 'drop table t2' to get blocked...
# Demonstrate that t2 lock was released and t2 was dropped
# after ROLLBACK TO SAVEPOINT
1228
connection default;
1229
rollback to savepoint sv;
1230
connection con2;
1231 1232 1233
# Reaping 'drop table t2'...
# Demonstrate that ROLLBACK TO SAVEPOINT didn't release the handler
# lock.
1234
connection default;
1235 1236 1237 1238 1239 1240 1241 1242 1243
handler t1 read a next;
a
3
handler t1 read a next;
a
4
# Demonstrate that the drop will go through as soon as we close the 
# HANDLER
handler t1 close;
1244
connection con1;
1245
# Reaping 'drop table t1'...
1246
connection default;
1247 1248 1249 1250 1251 1252 1253
commit;
#
# Show that rollback to the savepoint taken in the beginning
# of the transaction works properly (no valgrind warnins, etc),
# even though it's done after the HANDLER mdl lock that was there
# at the beginning is released and added again.
#
Sergei Golubchik's avatar
Sergei Golubchik committed
1254
create table t1 (a int, key using btree (a));
1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272
insert into t1 (a) values (1), (2), (3), (4), (5);
create table t2 like t1;
create table t3 like t1;
insert into t3 (a) select a from t1;
begin;
handler t1 open;
savepoint sv;
handler t1 read a first;
a
1
select * from t2;
a
handler t1 close;
handler t3 open;
handler t3 read a first;
a
1
rollback to savepoint sv;
1273
connection con1;
1274 1275 1276 1277
drop table t1, t2;
# Sending:
drop table t3;
# Let DROP TABLE statement sync in.
1278
connection con2;
1279 1280 1281
# Waiting for 'drop table t3' to get blocked...
# Demonstrate that ROLLBACK TO SAVEPOINT didn't release the handler
# lock.
1282
connection default;
1283 1284 1285 1286 1287 1288
handler t3 read a next;
a
2
# Demonstrate that the drop will go through as soon as we close the 
# HANDLER
handler t3 close;
1289
connection con1;
1290
# Reaping 'drop table t3'...
1291
connection default;
1292 1293 1294 1295 1296 1297 1298
commit;
# 
# If we have to wait on an exclusive locks while having
# an open HANDLER, ER_LOCK_DEADLOCK is reported.
#
create table t1 (a int, key a(a));
handler t1 open;
1299
connection con1;
1300 1301 1302
select get_lock('lock1', 10);
get_lock('lock1', 10)
1
1303
connection default;
1304
select get_lock('lock1', 10);
1305
connection con2;
1306
# Waiting for 'select get_lock('lock1', 10)' to get blocked...
1307
connection con1;
1308
drop table t1;
1309
ERROR 40001: Deadlock found when trying to get lock; try restarting transaction
1310 1311 1312
select release_lock('lock1');
release_lock('lock1')
1
1313
connection default;
1314 1315 1316 1317 1318
get_lock('lock1', 10)
1
select release_lock('lock1');
release_lock('lock1')
1
1319 1320
# Demonstrate that there is no deadlock with FLUSH TABLE,
# even though it is waiting for the other table to go away
1321
create table t2 like t1;
1322 1323
# Sending:
flush table t2;
1324
connection con2;
1325
drop table t1;
1326
connection con1;
1327
unlock tables;
1328
connection default;
1329 1330 1331 1332 1333 1334
# Reaping 'flush table t2'...
drop table t2;
# 
# Bug #46224 HANDLER statements within a transaction might 
#            lead to deadlocks
#
Sergei Golubchik's avatar
Sergei Golubchik committed
1335
create table t1 (a int, key using btree (a));
1336
insert into t1 values (1), (2);
1337
connection default;
1338 1339 1340
begin;
select * from t1;
a
1341 1342
1
2
1343
handler t1 open;
1344
connection con1;
1345
# Sending:
1346
lock tables t1 write;
1347
connection con2;
1348 1349
# Check that 'lock tables t1 write' waits until transaction which
# has read from the table commits.
1350
connection default;
1351 1352 1353 1354 1355 1356
# The below 'handler t1 read ...' should not be blocked as
# 'lock tables t1 write' has not succeeded yet.
handler t1 read a next;
a
1
# Unblock 'lock tables t1 write'.
1357 1358 1359 1360
select * from t1;
a
1
2
1361
commit;
1362
connection con1;
1363
# Reap 'lock tables t1 write'.
1364
connection default;
1365 1366
# Sending:
handler t1 read a next;
1367
connection con1;
1368
# Waiting for 'handler t1 read a next' to get blocked...
1369 1370
# The below 'drop table t1' should be able to proceed without
# waiting as it will force HANDLER to be closed.
1371
drop table t1;
1372
unlock tables;
1373
connection default;
1374
# Reaping 'handler t1 read a next'...
1375
ERROR 42S02: Table 'test.t1' doesn't exist
1376
handler t1 close;
1377 1378 1379 1380 1381 1382 1383
connection con1;
disconnect con1;
connection con2;
disconnect con2;
connection con3;
disconnect con3;
connection default;
1384 1385 1386 1387 1388
#
# A temporary table test.
# Check that we don't loose positions of HANDLER opened
# against a temporary table.
#
Sergei Golubchik's avatar
Sergei Golubchik committed
1389
create table t1 (a int, b int, key using btree (a));
1390
insert into t1 (a) values (1), (2), (3), (4), (5);
Sergei Golubchik's avatar
Sergei Golubchik committed
1391
create temporary table t2 (a int, b int, key using btree (a));
1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420
insert into t2 (a) select a from t1;
handler t1 open;
handler t1 read a next;
a	b
1	NULL
handler t2 open;
handler t2 read a next;
a	b
1	NULL
flush table t1;
handler t2 read a next;
a	b
2	NULL
# Sic: the position is lost
handler t1 read a next;
a	b
1	NULL
select * from t1;
a	b
1	NULL
2	NULL
3	NULL
4	NULL
5	NULL
# Sic: the position is not lost
handler t2 read a next;
a	b
3	NULL
select * from t2;
1421 1422 1423 1424 1425 1426
a	b
1	NULL
2	NULL
3	NULL
4	NULL
5	NULL
1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447
handler t2 read a next;
a	b
4	NULL
drop table t1;
drop temporary table t2;
#
# A test for lock_table_names()/unlock_table_names() function.
# It should work properly in presence of open HANDLER.
#
create table t1 (a int, b int, key a (a));
create table t2 like t1;
create table t3 like t1;
create table t4 like t1;
handler t1 open;
handler t2 open;
rename table t4 to t5, t3 to t4, t5 to t3;
handler t1 read first;
a	b
handler t2 read first;
a	b
drop table t1, t2, t3, t4;
1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514
#
# A test for FLUSH TABLES WITH READ LOCK and HANDLER statements.
#
set autocommit=0;
create table t1 (a int, b int, key a (a));
insert into t1 (a, b) values (1, 1), (2, 1), (3, 2), (4, 2), (5, 5);
create table t2 like t1;
insert into t2 (a, b) select a, b from t1;
create table t3 like t1;
insert into t3 (a, b) select a, b from t1;
commit;
flush tables with read lock;
handler t1 open;
lock table t1 read;
handler t1 read next;
ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction
# This implicitly leaves LOCK TABLES but doesn't drop the GLR
lock table not_exists_write read;
ERROR 42S02: Table 'test.not_exists_write' doesn't exist
# We still have the read lock.
drop table t1;
ERROR HY000: Can't execute the query because you have a conflicting read lock
handler t1 open;
select a from t2;
a
1
2
3
4
5
handler t1 read next;
a	b
1	1
flush tables with read lock;
handler t2 open;
flush tables with read lock;
handler t1 read next;
a	b
1	1
select a from t3;
a
1
2
3
4
5
handler t2 read next;
a	b
1	1
handler t1 close;
rollback;
handler t2 close;
drop table t1;
ERROR HY000: Can't execute the query because you have a conflicting read lock
commit;
flush tables;
drop table t1;
ERROR HY000: Can't execute the query because you have a conflicting read lock
unlock tables;
drop table t1;
set autocommit=default;
drop table t2, t3;
# 
# HANDLER statement and operation-type aware metadata locks.
# Check that when we clone a ticket for HANDLER we downrade
# the lock.
#
1515 1516
connect  con1,localhost,root,,;
connection default;
Sergei Golubchik's avatar
Sergei Golubchik committed
1517
create table t1 (a int, b int, key using btree (a));
1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529
insert into t1 (a, b) values (1, 1), (2, 1), (3, 2), (4, 2), (5, 5);
begin;
insert into t1 (a, b) values (6, 6);
handler t1 open;
handler t1 read a last;
a	b
6	6
insert into t1 (a, b) values (7, 7);
handler t1 read a last;
a	b
7	7
commit;
1530
connection default;
1531 1532 1533 1534 1535 1536
handler t1 read a prev;
a	b
6	6
handler t1 close;
# Cleanup.
drop table t1;
1537 1538 1539
connection con1;
disconnect con1;
connection default;
1540 1541 1542 1543 1544 1545 1546 1547
#
# A test for Bug#50555 "handler commands crash server in
# my_hash_first()". 
#
handler no_such_table read no_such_index first;
ERROR 42S02: Unknown table 'no_such_table' in HANDLER
handler no_such_table close;
ERROR 42S02: Unknown table 'no_such_table' in HANDLER
1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559
#
# Bug#50907 Assertion `hash_tables->table->next == __null' on 
#           HANDLER OPEN
#
DROP TABLE IF EXISTS t1, t2;
CREATE TEMPORARY TABLE t1 (i INT);
CREATE TEMPORARY TABLE t2 (i INT);
HANDLER t2 OPEN;
HANDLER t2 READ FIRST;
i
HANDLER t2 CLOSE;
DROP TABLE t1, t2;
1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572
#
# Bug#50912 Assertion `ticket->m_type >= mdl_request->type'
#           failed on HANDLER + I_S
#
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (id INT);
HANDLER t1 OPEN;
SELECT table_name, table_comment FROM information_schema.tables
WHERE table_schema= 'test' AND table_name= 't1';
table_name	table_comment
t1	
HANDLER t1 CLOSE;
DROP TABLE t1;
1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644
#
# Test for bug #50908 "Assertion `handler_tables_hash.records == 0'
#                      failed in enter_locked_tables_mode".
#
drop tables if exists t1, t2;
drop function if exists f1;
create table t1 (i int);
insert into t1 values (1), (2);
create table t2 (j int);
insert into t2 values (1);
create function f1() returns int return (select count(*) from t2);
# Check that open HANDLER survives statement executed in
# prelocked mode.
handler t1 open;
handler t1 read next;
i
1
# The below statement were aborted due to an assertion failure.
select f1() from t2;
f1()
1
handler t1 read next;
i
2
handler t1 close;
# Check that the same happens under GLOBAL READ LOCK.
flush tables with read lock;
handler t1 open;
handler t1 read next;
i
1
select f1() from t2;
f1()
1
handler t1 read next;
i
2
unlock tables;
handler t1 close;
# Now, check that the same happens if LOCK TABLES is executed.
handler t1 open;
handler t1 read next;
i
1
lock table t2 read;
select * from t2;
j
1
unlock tables;
handler t1 read next;
i
2
handler t1 close;
# Finally, check scenario with GRL and LOCK TABLES.
flush tables with read lock;
handler t1 open;
handler t1 read next;
i
1
lock table t2 read;
select * from t2;
j
1
# This unlocks both tables and GRL.
unlock tables;
handler t1 read next;
i
2
handler t1 close;
# Clean-up.
drop function f1;
drop tables t1, t2;
1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662
#
# Test for bug #51136 "Crash in pthread_rwlock_rdlock on TEMPORARY +
#                      HANDLER + LOCK + SP".
# Also see additional coverage for this bug in flush.test.
#
drop tables if exists t1, t2;
create table t1 (i int);
create temporary table t2 (j int);
handler t1 open;
lock table t2 read;
# This commit should not release any MDL locks.
commit;
unlock tables;
# The below statement crashed before the bug fix as it
# has attempted to release metadata lock which was
# already released by commit.
handler t1 close;
drop tables t1, t2;
1663 1664 1665 1666 1667
#
# Bug#51355 handler stmt cause assertion in
#           bool MDL_context::try_acquire_lock(MDL_request*)
#
DROP TABLE IF EXISTS t1;
1668 1669
connect con51355, localhost, root;
connection default;
1670 1671
CREATE TABLE t1(id INT, KEY id(id));
HANDLER t1 OPEN;
1672
connection con51355;
1673 1674
# Sending:
DROP TABLE t1;
1675
connection default;
1676 1677 1678
# This I_S query will cause the handler table to be closed and
# the metadata lock to be released. This will allow DROP TABLE
# to proceed. Waiting for the table to be removed.
1679
connection con51355;
1680
# Reaping: DROP TABLE t1
1681
connection default;
1682 1683 1684 1685 1686
HANDLER t1 READ id NEXT;
ERROR 42S02: Table 'test.t1' doesn't exist
HANDLER t1 READ id NEXT;
ERROR 42S02: Table 'test.t1' doesn't exist
HANDLER t1 CLOSE;
1687 1688 1689
connection con51355;
disconnect con51355;
connection default;
1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705
#
# Bug#54401 assert in Diagnostics_area::set_eof_status , HANDLER
#
DROP TABLE IF EXISTS t1, t2;
DROP FUNCTION IF EXISTS f1;
CREATE FUNCTION f1() RETURNS INTEGER
BEGIN
SELECT 1 FROM t2 INTO @a;
RETURN 1;
END|
SELECT f1();
ERROR 42S02: Table 'test.t2' doesn't exist
CREATE TABLE t1(a INT);
INSERT INTO t1 VALUES (1);
HANDLER t1 OPEN;
HANDLER t1 READ FIRST WHERE f1() = 1;
Sergei Golubchik's avatar
Sergei Golubchik committed
1706
ERROR 42000: This version of MariaDB doesn't yet support 'stored functions in HANDLER ... READ'
1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720
HANDLER t1 CLOSE;
DROP FUNCTION f1;
DROP TABLE t1;
#
# Bug#54920 Stored functions are allowed in HANDLER statements,
#           but broken.
#
DROP TABLE IF EXISTS t1;
DROP FUNCTION IF EXISTS f1;
CREATE TABLE t1 (a INT);
INSERT INTO t1 VALUES (1), (2);
CREATE FUNCTION f1() RETURNS INT RETURN 1;
HANDLER t1 OPEN;
HANDLER t1 READ FIRST WHERE f1() = 1;
Sergei Golubchik's avatar
Sergei Golubchik committed
1721
ERROR 42000: This version of MariaDB doesn't yet support 'stored functions in HANDLER ... READ'
1722 1723 1724
HANDLER t1 CLOSE;
DROP FUNCTION f1;
DROP TABLE t1;
Sergei Golubchik's avatar
Sergei Golubchik committed
1725
#
1726 1727 1728 1729 1730 1731 1732 1733 1734 1735
# BUG#51877 - HANDLER interface causes invalid memory read
#
CREATE TABLE t1(a INT, KEY using btree (a));
HANDLER t1 OPEN;
HANDLER t1 READ a FIRST;
a
INSERT INTO t1 VALUES(1);
HANDLER t1 READ a NEXT;
HANDLER t1 CLOSE;
DROP TABLE t1;
1736 1737
connect  con1,localhost,root,,;
connection default;
1738
CREATE TABLE t1(a INT, b INT, KEY(a), KEY b using btree (b), KEY ab using btree(a, b)) engine=memory;
1739 1740
INSERT INTO t1 VALUES (2, 20), (2,20), (1, 10), (4, 40), (3, 30), (5,50), (6,50);
HANDLER t1 OPEN;
1741
HANDLER t1 READ a=(2) limit 3;
1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773
a	b
2	20
2	20
HANDLER t1 READ a PREV;
a	b
2	20
HANDLER t1 READ a PREV;
a	b
2	20
HANDLER t1 READ a PREV;
a	b
HANDLER t1 READ b>=(20) limit 3;
a	b
2	20
2	20
3	30
HANDLER t1 READ b PREV;
a	b
2	20
HANDLER t1 READ b PREV LIMIT 2;
a	b
2	20
1	10
HANDLER t1 READ ab=(3,30) limit 3;
a	b
3	30
HANDLER t1 READ ab>=(3,30) limit 3;
a	b
3	30
4	40
5	50
HANDLER t1 READ a FIRST;
Sergei Golubchik's avatar
Sergei Golubchik committed
1774
ERROR HY000: Storage engine MEMORY of the table `test`.`t1` doesn't have this option
1775
HANDLER t1 READ a LAST;
Sergei Golubchik's avatar
Sergei Golubchik committed
1776
ERROR HY000: Storage engine MEMORY of the table `test`.`t1` doesn't have this option
1777 1778 1779 1780
HANDLER t1 READ b FIRST LIMIT 2;
a	b
1	10
2	20
1781
HANDLER t1 READ ab LAST LIMIT 2;
1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802
a	b
6	50
5	50
HANDLER t1 READ FIRST LIMIT 10;
a	b
2	20
2	20
1	10
4	40
3	30
5	50
6	50
HANDLER t1 READ b FIRST;
a	b
1	10
insert into t1 values (7,50);
HANDLER t1 READ b NEXT;
ERROR HY000: Record has changed since last read in table 't1'
HANDLER t1 READ b FIRST;
a	b
1	10
1803
connection con1;
1804
insert into t1 values (7,50);
1805
connection default;
1806 1807 1808 1809 1810
HANDLER t1 READ b NEXT;
ERROR HY000: Record has changed since last read in table 't1'
HANDLER t1 READ FIRST;
a	b
2	20
1811
connection con1;
1812
insert into t1 values (8,50);
1813
connection default;
1814 1815 1816
HANDLER t1 READ NEXT;
a	b
2	20
1817
connection con1;
1818
delete from t1 where a=3;
1819
connection default;
1820 1821 1822 1823
HANDLER t1 READ NEXT LIMIT 2;
a	b
1	10
4	40
1824
connection con1;
1825
delete from t1;
1826
connection default;
1827 1828 1829 1830
HANDLER t1 READ NEXT LIMIT 2;
ERROR HY000: Record has changed since last read in table 't1'
HANDLER t1 CLOSE;
DROP TABLE t1;
1831
disconnect con1;
1832 1833 1834 1835
create table t1 (f1 integer not null, key (f1)) engine=Memory;
insert into t1 values (1);
HANDLER t1 OPEN;
HANDLER t1 READ f1 NEXT;
Sergei Golubchik's avatar
Sergei Golubchik committed
1836
ERROR HY000: Storage engine MEMORY of the table `test`.`t1` doesn't have this option
1837
HANDLER t1 READ f1 NEXT;
Sergei Golubchik's avatar
Sergei Golubchik committed
1838
ERROR HY000: Storage engine MEMORY of the table `test`.`t1` doesn't have this option
1839
HANDLER t1 READ f1 NEXT;
Sergei Golubchik's avatar
Sergei Golubchik committed
1840
ERROR HY000: Storage engine MEMORY of the table `test`.`t1` doesn't have this option
1841 1842 1843
HANDLER t1 CLOSE;
DROP TABLE t1;
End of 5.3 tests
1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862
#
# MDEV-15813 ASAN use-after-poison in hp_hashnr upon
#            HANDLER READ on a versioned HEAP table
#
CREATE TABLE t1 (a INT NOT NULL, b INT NOT NULL, CONSTRAINT PRIMARY KEY (a, b), UNIQUE ba(b, a) USING HASH) ENGINE=HEAP;
INSERT INTO t1 VALUES (1, 10), (2, 20), (3,30), (4,40);
HANDLER t1 OPEN AS m;
HANDLER m READ `PRIMARY`= (3,30);
a	b
3	30
HANDLER m READ `PRIMARY`> (3,30);
ERROR HY000: HASH index `PRIMARY` does not support this operation
HANDLER m READ `ba`= (30,3);
a	b
3	30
HANDLER m READ `ba`= (30);
ERROR HY000: HASH index `ba` does not support this operation
HANDLER m CLOSE;
DROP TABLE t1;