1SET SESSION DEFAULT_STORAGE_ENGINE = InnoDB; 2drop table if exists t1,t3,t4,t5; 3create table t1 (a int, b char(10), key a(a), key b(a,b)); 4insert into t1 values 5(17,"ddd"),(18,"eee"),(19,"fff"),(19,"yyy"), 6(14,"aaa"),(15,"bbb"),(16,"ccc"),(16,"xxx"), 7(20,"ggg"),(21,"hhh"),(22,"iii"); 8handler t1 open as t2; 9handler t2 read a=(SELECT 1); 10ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT 1)' at line 1 11handler t2 read a first; 12a b 1314 aaa 14handler t2 read a next; 15a b 1615 bbb 17handler t2 read a next; 18a b 1916 ccc 20handler t2 read a prev; 21a b 2215 bbb 23handler t2 read a last; 24a b 2522 iii 26handler t2 read a prev; 27a b 2821 hhh 29handler t2 read a prev; 30a b 3120 ggg 32handler t2 read a first; 33a b 3414 aaa 35handler t2 read a prev; 36a b 37handler t2 read a last; 38a b 3922 iii 40handler t2 read a prev; 41a b 4221 hhh 43handler t2 read a next; 44a b 4522 iii 46handler t2 read a next; 47a b 48handler t2 read a=(15); 49a b 5015 bbb 51handler t2 read a=(16); 52a b 5316 ccc 54handler t2 read a=(19,"fff"); 55ERROR 42000: Too many key parts specified; max 1 parts allowed 56handler t2 read b=(19,"fff"); 57a b 5819 fff 59handler t2 read b=(19,"yyy"); 60a b 6119 yyy 62handler t2 read b=(19); 63a b 6419 fff 65handler t1 read a last; 66ERROR 42S02: Unknown table 't1' in HANDLER 67handler t2 read a=(11); 68a b 69handler t2 read a>=(11); 70a b 7114 aaa 72handler t2 read a=(18); 73a b 7418 eee 75handler t2 read a>=(18); 76a b 7718 eee 78handler t2 read a>(18); 79a b 8019 fff 81handler t2 read a<=(18); 82a b 8318 eee 84handler t2 read a<(18); 85a b 8617 ddd 87handler t2 read a first limit 5; 88a b 8914 aaa 9015 bbb 9116 ccc 9216 xxx 9317 ddd 94handler t2 read a next limit 3; 95a b 9618 eee 9719 fff 9819 yyy 99handler t2 read a prev limit 10; 100a b 10119 fff 10218 eee 10317 ddd 10416 xxx 10516 ccc 10615 bbb 10714 aaa 108handler t2 read a>=(16) limit 4; 109a b 11016 ccc 11116 xxx 11217 ddd 11318 eee 114handler t2 read a>=(16) limit 2,2; 115a b 11617 ddd 11718 eee 118handler t2 read a last limit 3; 119a b 12022 iii 12121 hhh 12220 ggg 123handler t2 read a=(19); 124a b 12519 fff 126handler t2 read a=(19) where b="yyy"; 127a b 12819 yyy 129handler t2 read first; 130a b 13117 ddd 132handler t2 read next; 133a b 13418 eee 135handler t2 read next; 136a b 13719 fff 138handler t2 read last; 139ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 140handler t2 close; 141handler t1 open; 142handler t1 read a next; 143a b 14414 aaa 145handler t1 read a next; 146a b 14715 bbb 148handler t1 close; 149handler t1 open; 150handler t1 read a prev; 151a b 15222 iii 153handler t1 read a prev; 154a b 15521 hhh 156handler t1 close; 157handler t1 open as t2; 158handler t2 read first; 159a b 16017 ddd 161alter table t1 engine = InnoDB; 162handler t2 read first; 163ERROR 42S02: Unknown table 't2' in HANDLER 164handler t1 open as t2; 165drop table t1; 166create table t1 (a int); 167insert into t1 values (17); 168handler t2 read first; 169ERROR 42S02: Unknown table 't2' in HANDLER 170handler t1 open as t2; 171alter table t1 engine=MEMORY; 172handler t2 read first; 173ERROR 42S02: Unknown table 't2' in HANDLER 174drop table t1; 175create table t1 (a int); 176insert into t1 values (1),(2),(3),(4),(5),(6); 177delete from t1 limit 2; 178handler t1 open; 179handler t1 read first; 180a 1813 182handler t1 read first limit 1,1; 183a 1844 185handler t1 read first limit 2,2; 186a 1875 1886 189delete from t1 limit 3; 190handler t1 read first; 191a 1926 193drop table t1; 194create table t1(a int, index(a)); 195insert into t1 values (1), (2), (3); 196handler t1 open; 197handler t1 read a=(W); 198ERROR 42S22: Unknown column 'W' in 'field list' 199handler t1 read a=(a); 200ERROR HY000: Incorrect arguments to HANDLER ... READ 201drop table t1; 202create table t1 (a char(5)); 203insert into t1 values ("Ok"); 204handler t1 open as t; 205handler t read first; 206a 207Ok 208use mysql; 209handler t read first; 210a 211Ok 212handler t close; 213handler test.t1 open as t; 214handler t read first; 215a 216Ok 217handler t close; 218use test; 219drop table t1; 220create table t1 ( a int, b int, INDEX a (a) ); 221insert into t1 values (1,2), (2,1); 222handler t1 open; 223handler t1 read a=(1) where b=2; 224a b 2251 2 226handler t1 read a=(1) where b=3; 227a b 228handler t1 read a=(1) where b=1; 229a b 230handler t1 close; 231drop table t1; 232drop database if exists test_test; 233create database test_test; 234use test_test; 235create table t1(table_id char(20) primary key); 236insert into t1 values ('test_test.t1'); 237insert into t1 values (''); 238handler t1 open; 239handler t1 read first limit 9; 240table_id 241 242test_test.t1 243create table t2(table_id char(20) primary key); 244insert into t2 values ('test_test.t2'); 245insert into t2 values (''); 246handler t2 open; 247handler t2 read first limit 9; 248table_id 249 250test_test.t2 251use test; 252drop table if exists t1; 253create table t1(table_id char(20) primary key); 254insert into t1 values ('test.t1'); 255insert into t1 values (''); 256handler t1 open; 257ERROR 42000: Not unique table/alias: 't1' 258use test; 259handler test.t1 read first limit 9; 260ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read first limit 9' at line 1 261handler test_test.t1 read first limit 9; 262ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read first limit 9' at line 1 263handler t1 read first limit 9; 264table_id 265 266test_test.t1 267handler test_test.t2 read first limit 9; 268ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read first limit 9' at line 1 269handler t2 read first limit 9; 270table_id 271 272test_test.t2 273handler test_test.t1 close; 274ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'close' at line 1 275handler t1 close; 276drop table test_test.t1; 277handler test_test.t2 close; 278ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'close' at line 1 279handler t2 close; 280drop table test_test.t2; 281drop database test_test; 282use test; 283handler test.t1 close; 284ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'close' at line 1 285handler t1 close; 286ERROR 42S02: Unknown table 't1' in HANDLER 287drop table test.t1; 288drop database if exists test_test; 289drop table if exists t1; 290drop table if exists t2; 291drop table if exists t3; 292create database test_test; 293use test_test; 294create table t1 (c1 char(20)); 295insert into t1 values ('test_test.t1'); 296create table t3 (c1 char(20)); 297insert into t3 values ('test_test.t3'); 298handler t1 open; 299handler t1 read first limit 9; 300c1 301test_test.t1 302handler t1 open h1; 303handler h1 read first limit 9; 304c1 305test_test.t1 306use test; 307create table t1 (c1 char(20)); 308create table t2 (c1 char(20)); 309create table t3 (c1 char(20)); 310insert into t1 values ('t1'); 311insert into t2 values ('t2'); 312insert into t3 values ('t3'); 313handler t1 open; 314ERROR 42000: Not unique table/alias: 't1' 315handler t2 open t1; 316ERROR 42000: Not unique table/alias: 't1' 317handler t3 open t1; 318ERROR 42000: Not unique table/alias: 't1' 319handler t1 read first limit 9; 320c1 321test_test.t1 322handler test.t1 close; 323ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'close' at line 1 324handler test.t1 open h1; 325ERROR 42000: Not unique table/alias: 'h1' 326handler test_test.t1 open h1; 327ERROR 42000: Not unique table/alias: 'h1' 328handler test_test.t3 open h3; 329handler test.t1 open h2; 330handler t1 read first limit 9; 331c1 332test_test.t1 333handler h1 read first limit 9; 334c1 335test_test.t1 336handler h2 read first limit 9; 337c1 338t1 339handler h3 read first limit 9; 340c1 341test_test.t3 342handler h2 read first limit 9; 343c1 344t1 345handler test.h1 close; 346ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'close' at line 1 347handler t1 close; 348handler h1 close; 349handler h2 close; 350handler t1 read first limit 9; 351ERROR 42S02: Unknown table 't1' in HANDLER 352handler h1 read first limit 9; 353ERROR 42S02: Unknown table 'h1' in HANDLER 354handler h2 read first limit 9; 355ERROR 42S02: Unknown table 'h2' in HANDLER 356handler h3 read first limit 9; 357c1 358test_test.t3 359handler h3 read first limit 9; 360c1 361test_test.t3 362use test_test; 363handler h3 read first limit 9; 364c1 365test_test.t3 366handler test.h3 read first limit 9; 367ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read first limit 9' at line 1 368handler h3 close; 369use test; 370drop table t3; 371drop table t2; 372drop table t1; 373drop database test_test; 374create table t1 (c1 char(20)); 375insert into t1 values ("t1"); 376handler t1 open as h1; 377handler h1 read first limit 9; 378c1 379t1 380create table t2 (c1 char(20)); 381insert into t2 values ("t2"); 382handler t2 open as h2; 383handler h2 read first limit 9; 384c1 385t2 386create table t3 (c1 char(20)); 387insert into t3 values ("t3"); 388handler t3 open as h3; 389handler h3 read first limit 9; 390c1 391t3 392create table t4 (c1 char(20)); 393insert into t4 values ("t4"); 394handler t4 open as h4; 395handler h4 read first limit 9; 396c1 397t4 398create table t5 (c1 char(20)); 399insert into t5 values ("t5"); 400handler t5 open as h5; 401handler h5 read first limit 9; 402c1 403t5 404alter table t1 engine=MyISAM; 405handler h1 read first limit 9; 406ERROR 42S02: Unknown table 'h1' in HANDLER 407handler h2 read first limit 9; 408c1 409t2 410handler h3 read first limit 9; 411c1 412t3 413handler h4 read first limit 9; 414c1 415t4 416handler h5 read first limit 9; 417c1 418t5 419alter table t5 engine=MyISAM; 420handler h1 read first limit 9; 421ERROR 42S02: Unknown table 'h1' in HANDLER 422handler h2 read first limit 9; 423c1 424t2 425handler h3 read first limit 9; 426c1 427t3 428handler h4 read first limit 9; 429c1 430t4 431handler h5 read first limit 9; 432ERROR 42S02: Unknown table 'h5' in HANDLER 433alter table t3 engine=MyISAM; 434handler h1 read first limit 9; 435ERROR 42S02: Unknown table 'h1' in HANDLER 436handler h2 read first limit 9; 437c1 438t2 439handler h3 read first limit 9; 440ERROR 42S02: Unknown table 'h3' in HANDLER 441handler h4 read first limit 9; 442c1 443t4 444handler h5 read first limit 9; 445ERROR 42S02: Unknown table 'h5' in HANDLER 446handler h2 close; 447handler h4 close; 448handler t1 open as h1_1; 449handler t1 open as h1_2; 450handler t1 open as h1_3; 451handler h1_1 read first limit 9; 452c1 453t1 454handler h1_2 read first limit 9; 455c1 456t1 457handler h1_3 read first limit 9; 458c1 459t1 460alter table t1 engine=InnoDB; 461handler h1_1 read first limit 9; 462ERROR 42S02: Unknown table 'h1_1' in HANDLER 463handler h1_2 read first limit 9; 464ERROR 42S02: Unknown table 'h1_2' in HANDLER 465handler h1_3 read first limit 9; 466ERROR 42S02: Unknown table 'h1_3' in HANDLER 467drop table t1; 468drop table t2; 469drop table t3; 470drop table t4; 471drop table t5; 472create table t1 (c1 int); 473insert into t1 values (1); 474handler t1 open; 475handler t1 read first; 476c1 4771 478send the below to another connection, do not wait for the result 479optimize table t1; 480proceed with the normal connection 481handler t1 read next; 482c1 4831 484handler t1 close; 485read the result from the other connection 486Table Op Msg_type Msg_text 487test.t1 optimize note Table does not support optimize, doing recreate + analyze instead 488test.t1 optimize status OK 489proceed with the normal connection 490drop table t1; 491CREATE TABLE t1 ( no1 smallint(5) NOT NULL default '0', no2 int(10) NOT NULL default '0', PRIMARY KEY (no1,no2)); 492INSERT INTO t1 VALUES (1,274),(1,275),(2,6),(2,8),(4,1),(4,2); 493HANDLER t1 OPEN; 494HANDLER t1 READ `primary` = (1, 1000); 495no1 no2 496HANDLER t1 READ `primary` PREV; 497no1 no2 4981 275 499DROP TABLE t1; 500create table t1 (c1 int); 501insert into t1 values (14397); 502flush tables with read lock; 503drop table t1; 504ERROR HY000: Can't execute the query because you have a conflicting read lock 505send the below to another connection, do not wait for the result 506drop table t1; 507proceed with the normal connection 508select * from t1; 509c1 51014397 511unlock tables; 512read the result from the other connection 513proceed with the normal connection 514select * from t1; 515ERROR 42S02: Table 'test.t1' doesn't exist 516drop table if exists t1; 517Warnings: 518Note 1051 Unknown table 'test.t1' 519drop table if exists t1; 520create table t1 (a int) ENGINE=MEMORY; 521--> client 2 522handler t1 open; 523ERROR HY000: Table storage engine for 't1' doesn't have this option 524--> client 1 525drop table t1; 526drop table if exists t1; 527create table t1 (a int); 528handler t1 open as t1_alias; 529handler t1_alias read a next; 530ERROR 42000: Key 'a' doesn't exist in table 't1_alias' 531handler t1_alias READ a next where inexistent > 0; 532ERROR 42S22: Unknown column 'inexistent' in 'field list' 533handler t1_alias read a next; 534ERROR 42000: Key 'a' doesn't exist in table 't1_alias' 535handler t1_alias READ a next where inexistent > 0; 536ERROR 42S22: Unknown column 'inexistent' in 'field list' 537handler t1_alias close; 538drop table t1; 539drop table if exists t1,t2; 540create table t1 (c1 int); 541create table t2 (c1 int); 542insert into t1 values (1); 543insert into t2 values (2); 544connection: default 545handler t1 open; 546handler t1 read first; 547c1 5481 549connection: flush 550flush tables;; 551connection: waiter 552connection: default 553handler t2 open; 554handler t2 read first; 555c1 5562 557handler t1 read next; 558c1 5591 560handler t1 close; 561handler t2 close; 562drop table t1,t2; 563drop table if exists t1, t0; 564create table t1 (c1 int); 565connection: default 566handler t1 open; 567handler t1 read first; 568c1 569connection: flush 570rename table t1 to t0;; 571connection: waiter 572connection: default 573# 574# RENAME placed two pending locks and waits. 575# When HANDLER t0 OPEN does open_tables(), it calls 576# mysql_ha_flush(), which in turn closes the open HANDLER for t1. 577# RENAME TABLE gets unblocked. If it gets scheduled quickly 578# and manages to complete before open_tables() 579# of HANDLER t0 OPEN, open_tables() and therefore the whole 580# HANDLER t0 OPEN succeeds. Otherwise open_tables() 581# notices a pending or active exclusive metadata lock on t2 582# and the whole HANDLER t0 OPEN fails with ER_LOCK_DEADLOCK 583# error. 584# 585handler t0 open; 586handler t0 close; 587connection: flush 588handler t1 read next; 589ERROR 42S02: Unknown table 't1' in HANDLER 590handler t1 close; 591ERROR 42S02: Unknown table 't1' in HANDLER 592drop table t0; 593drop table if exists t1; 594create temporary table t1 (a int, b char(1), key a(a), key b(a,b)); 595insert into t1 values (0,"a"),(1,"b"),(2,"c"),(3,"d"),(4,"e"), 596(5,"f"),(6,"g"),(7,"h"),(8,"i"),(9,"j"); 597select a,b from t1; 598a b 5990 a 6001 b 6012 c 6023 d 6034 e 6045 f 6056 g 6067 h 6078 i 6089 j 609handler t1 open as a1; 610handler a1 read a first; 611a b 6120 a 613handler a1 read a next; 614a b 6151 b 616handler a1 read a next; 617a b 6182 c 619select a,b from t1; 620ERROR HY000: Can't reopen table: 'a1' 621handler a1 read a prev; 622a b 6231 b 624handler a1 read a prev; 625a b 6260 a 627handler a1 read a=(6) where b="g"; 628a b 6296 g 630handler a1 close; 631select a,b from t1; 632a b 6330 a 6341 b 6352 c 6363 d 6374 e 6385 f 6396 g 6407 h 6418 i 6429 j 643handler t1 open as a2; 644handler a2 read a first; 645a b 6460 a 647handler a2 read a last; 648a b 6499 j 650handler a2 read a prev; 651a b 6528 i 653handler a2 close; 654drop table t1; 655drop table if exists t1,t2; 656create table t1 (a int); 657handler t1 open as t1_alias; 658drop table t1; 659create table t1 (a int); 660handler t1 open as t1_alias; 661flush tables; 662drop table t1; 663create table t1 (a int); 664handler t1 open as t1_alias; 665handler t1_alias close; 666drop table t1; 667create table t1 (a int); 668handler t1 open as t1_alias; 669handler t1_alias read first; 670a 671drop table t1; 672handler t1_alias read next; 673ERROR 42S02: Unknown table 't1_alias' in HANDLER 674create table t1 (a int); 675create temporary table t2 (a int, key(a)); 676handler t1 open as a1; 677handler t2 open as a2; 678handler a2 read a first; 679a 680drop table t1, t2; 681handler a2 read a next; 682ERROR 42S02: Unknown table 'a2' in HANDLER 683handler a1 close; 684ERROR 42S02: Unknown table 'a1' in HANDLER 685create table t1 (a int, key(a)); 686create table t2 like t1; 687handler t1 open as a1; 688handler t2 open as a2; 689handler a1 read a first; 690a 691handler a2 read a first; 692a 693alter table t1 add b int; 694handler a1 close; 695ERROR 42S02: Unknown table 'a1' in HANDLER 696handler a2 close; 697drop table t1, t2; 698create table t1 (a int, key(a)); 699handler t1 open as a1; 700handler a1 read a first; 701a 702rename table t1 to t2; 703handler a1 read a first; 704ERROR 42S02: Unknown table 'a1' in HANDLER 705drop table t2; 706create table t1 (a int, key(a)); 707create table t2 like t1; 708handler t1 open as a1; 709handler t2 open as a2; 710handler a1 read a first; 711a 712handler a2 read a first; 713a 714optimize table t1; 715Table Op Msg_type Msg_text 716test.t1 optimize note Table does not support optimize, doing recreate + analyze instead 717test.t1 optimize status OK 718handler a1 close; 719ERROR 42S02: Unknown table 'a1' in HANDLER 720handler a2 close; 721drop table t1, t2; 722create table t1 (a int, b char(1), key a(a), key b(a,b)); 723insert into t1 values (0,"a"),(1,"b"),(2,"c"),(3,"d"),(4,"e"), 724(5,"f"),(6,"g"),(7,"h"),(8,"i"),(9,"j"); 725handler t1 open; 726handler t1 read a first; 727a b 7280 a 729handler t1 read a next; 730a b 7311 b 732flush tables; 733handler t1 read a next; 734a b 7350 a 736handler t1 read a next; 737a b 7381 b 739flush tables with read lock; 740handler t1 read a next; 741a b 7420 a 743unlock tables; 744drop table t1; 745handler t1 read a next; 746ERROR 42S02: Unknown table 't1' in HANDLER 747drop table if exists t1; 748# First test case which is supposed trigger the execution 749# path on which problem was discovered. 750create table t1 (a int); 751insert into t1 values (1); 752handler t1 open; 753lock table t1 write; 754alter table t1 engine=memory; 755handler t1 read a next; 756ERROR HY000: Table storage engine for 't1' doesn't have this option 757handler t1 close; 758unlock tables; 759drop table t1; 760# Now test case which was reported originally but which no longer 761# triggers execution path which has caused the problem. 762create table t1 (a int, key(a)); 763insert into t1 values (1); 764handler t1 open; 765alter table t1 engine=memory; 766# Since S metadata lock was already acquired at HANDLER OPEN time 767# and TL_READ lock requested by HANDLER READ is compatible with 768# ALTER's TL_WRITE_ALLOW_READ the below statement should succeed 769# without waiting. The old version of table should be used in it. 770handler t1 read a next; 771a 7721 773handler t1 close; 774drop table t1; 775USE information_schema; 776HANDLER COLUMNS OPEN; 777ERROR HY000: Incorrect usage of HANDLER OPEN and information_schema 778USE test; 779# 780# Add test coverage for HANDLER and LOCK TABLES, HANDLER and DDL. 781# 782drop table if exists t1, t2, t3; 783create table t1 (a int, key a (a)); 784insert into t1 (a) values (1), (2), (3), (4), (5); 785create table t2 (a int, key a (a)) select * from t1; 786create temporary table t3 (a int, key a (a)) select * from t2; 787create temporary table t4 like t3; 788handler t1 open; 789handler t2 open; 790handler t3 open; 791# 792# No HANDLER sql is allowed under LOCK TABLES. 793# But it does not implicitly closes all handlers. 794# 795lock table t1 read; 796handler t1 open; 797ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 798handler t1 read next; 799ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 800handler t2 close; 801ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 802handler t3 open; 803ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 804handler t4 open; 805ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 806# After UNLOCK TABLES handlers should be around and 807# we should be able to continue reading through them. 808unlock tables; 809handler t1 read next; 810a 8111 812handler t1 close; 813handler t2 read next; 814a 8151 816handler t2 close; 817handler t3 read next; 818a 8191 820handler t3 close; 821drop temporary tables t3, t4; 822# 823# Other operations that implicitly close handler: 824# 825# TRUNCATE 826# 827handler t1 open; 828truncate table t1; 829handler t1 read next; 830ERROR 42S02: Unknown table 't1' in HANDLER 831handler t1 open; 832# 833# CREATE TRIGGER 834# 835create trigger t1_ai after insert on t1 for each row set @a=1; 836handler t1 read next; 837ERROR 42S02: Unknown table 't1' in HANDLER 838# 839# DROP TRIGGER 840# 841handler t1 open; 842drop trigger t1_ai; 843handler t1 read next; 844ERROR 42S02: Unknown table 't1' in HANDLER 845# 846# ALTER TABLE 847# 848handler t1 open; 849alter table t1 add column b int; 850handler t1 read next; 851ERROR 42S02: Unknown table 't1' in HANDLER 852# 853# ANALYZE TABLE 854# 855handler t1 open; 856analyze table t1; 857Table Op Msg_type Msg_text 858test.t1 analyze status OK 859handler t1 read next; 860ERROR 42S02: Unknown table 't1' in HANDLER 861# 862# OPTIMIZE TABLE 863# 864handler t1 open; 865optimize table t1; 866Table Op Msg_type Msg_text 867test.t1 optimize note Table does not support optimize, doing recreate + analyze instead 868test.t1 optimize status OK 869handler t1 read next; 870ERROR 42S02: Unknown table 't1' in HANDLER 871# 872# REPAIR TABLE 873# 874handler t1 open; 875repair table t1; 876Table Op Msg_type Msg_text 877test.t1 repair note The storage engine for the table doesn't support repair 878handler t1 read next; 879ERROR 42S02: Unknown table 't1' in HANDLER 880# 881# DROP TABLE, naturally. 882# 883handler t1 open; 884drop table t1; 885handler t1 read next; 886ERROR 42S02: Unknown table 't1' in HANDLER 887create table t1 (a int, b int, key a (a)) select a from t2; 888# 889# RENAME TABLE, naturally 890# 891handler t1 open; 892rename table t1 to t3; 893handler t1 read next; 894ERROR 42S02: Unknown table 't1' in HANDLER 895# 896# CREATE TABLE (even with IF NOT EXISTS clause, 897# and the table exists). 898# 899handler t2 open; 900create table if not exists t2 (a int); 901Warnings: 902Note 1050 Table 't2' already exists 903handler t2 read next; 904ERROR 42S02: Unknown table 't2' in HANDLER 905rename table t3 to t1; 906drop table t2; 907# 908# FLUSH TABLE doesn't close the table but loses the position 909# 910handler t1 open; 911handler t1 read a prev; 912b a 913NULL 5 914flush table t1; 915handler t1 read a prev; 916b a 917NULL 5 918handler t1 close; 919# 920# FLUSH TABLES WITH READ LOCK behaves like FLUSH TABLE. 921# 922handler t1 open; 923handler t1 read a prev; 924b a 925NULL 5 926flush tables with read lock; 927handler t1 read a prev; 928b a 929NULL 5 930handler t1 close; 931unlock tables; 932# 933# Let us also check that these operations behave in similar 934# way under LOCK TABLES. 935# 936# TRUNCATE under LOCK TABLES. 937# 938handler t1 open; 939lock tables t1 write; 940truncate table t1; 941unlock tables; 942handler t1 read next; 943ERROR 42S02: Unknown table 't1' in HANDLER 944handler t1 open; 945# 946# CREATE TRIGGER under LOCK TABLES. 947# 948lock tables t1 write; 949create trigger t1_ai after insert on t1 for each row set @a=1; 950unlock tables; 951handler t1 read next; 952ERROR 42S02: Unknown table 't1' in HANDLER 953# 954# DROP TRIGGER under LOCK TABLES. 955# 956handler t1 open; 957lock tables t1 write; 958drop trigger t1_ai; 959unlock tables; 960handler t1 read next; 961ERROR 42S02: Unknown table 't1' in HANDLER 962# 963# ALTER TABLE under LOCK TABLES. 964# 965handler t1 open; 966lock tables t1 write; 967alter table t1 drop column b; 968unlock tables; 969handler t1 read next; 970ERROR 42S02: Unknown table 't1' in HANDLER 971# 972# ANALYZE TABLE under LOCK TABLES. 973# 974handler t1 open; 975lock tables t1 write; 976analyze table t1; 977Table Op Msg_type Msg_text 978test.t1 analyze status OK 979unlock tables; 980handler t1 read next; 981ERROR 42S02: Unknown table 't1' in HANDLER 982# 983# OPTIMIZE TABLE under LOCK TABLES. 984# 985handler t1 open; 986lock tables t1 write; 987optimize table t1; 988Table Op Msg_type Msg_text 989test.t1 optimize note Table does not support optimize, doing recreate + analyze instead 990test.t1 optimize status OK 991unlock tables; 992handler t1 read next; 993ERROR 42S02: Unknown table 't1' in HANDLER 994# 995# REPAIR TABLE under LOCK TABLES. 996# 997handler t1 open; 998lock tables t1 write; 999repair table t1; 1000Table Op Msg_type Msg_text 1001test.t1 repair note The storage engine for the table doesn't support repair 1002unlock tables; 1003handler t1 read next; 1004ERROR 42S02: Unknown table 't1' in HANDLER 1005# 1006# DROP TABLE under LOCK TABLES, naturally. 1007# 1008handler t1 open; 1009lock tables t1 write; 1010drop table t1; 1011unlock tables; 1012handler t1 read next; 1013ERROR 42S02: Unknown table 't1' in HANDLER 1014create table t1 (a int, b int, key a (a)); 1015insert into t1 (a) values (1), (2), (3), (4), (5); 1016# 1017# FLUSH TABLE doesn't close the table but loses the position 1018# 1019handler t1 open; 1020handler t1 read a prev; 1021a b 10225 NULL 1023lock tables t1 write; 1024flush table t1; 1025unlock tables; 1026handler t1 read a prev; 1027a b 10285 NULL 1029handler t1 close; 1030# 1031# Explore the effect of HANDLER locks on concurrent DDL 1032# 1033handler t1 open; 1034# Establishing auxiliary connections con1, con2, con3 1035# --> connection con1; 1036# Sending: 1037drop table t1 ; 1038# We can't use connection 'default' as wait_condition will 1039# autoclose handlers. 1040# --> connection con2 1041# Waitng for 'drop table t1' to get blocked... 1042# --> connection default 1043handler t1 read a prev; 1044a b 10455 NULL 1046handler t1 read a prev; 1047a b 10484 NULL 1049handler t1 close; 1050# --> connection con1 1051# Reaping 'drop table t1'... 1052# --> connection default 1053# 1054# Explore the effect of HANDLER locks in parallel with SELECT 1055# 1056create table t1 (a int, key a (a)); 1057insert into t1 (a) values (1), (2), (3), (4), (5); 1058begin; 1059select * from t1; 1060a 10611 10622 10633 10644 10655 1066handler t1 open; 1067handler t1 read a prev; 1068a 10695 1070handler t1 read a prev; 1071a 10724 1073handler t1 close; 1074# --> connection con1; 1075# Sending: 1076drop table t1 ; 1077# --> connection con2 1078# Waiting for 'drop table t1' to get blocked... 1079# --> connection default 1080# We can still use the table, it's part of the transaction 1081select * from t1; 1082a 10831 10842 10853 10864 10875 1088# Such are the circumstances that t1 is a part of transaction, 1089# thus we can reopen it in the handler 1090handler t1 open; 1091# We can commit the transaction, it doesn't close the handler 1092# and doesn't let DROP to proceed. 1093commit; 1094handler t1 read a prev; 1095a 10965 1097handler t1 read a prev; 1098a 10994 1100handler t1 read a prev; 1101a 11023 1103handler t1 close; 1104# --> connection con1 1105# Now drop can proceed 1106# Reaping 'drop table t1'... 1107# --> connection default 1108# 1109# Demonstrate that HANDLER locks and transaction locks 1110# reside in the same context. 1111# 1112create table t1 (a int, key a (a)); 1113insert into t1 (a) values (1), (2), (3), (4), (5); 1114create table t0 (a int, key a (a)); 1115insert into t0 (a) values (1), (2), (3), (4), (5); 1116begin; 1117select * from t1; 1118a 11191 11202 11213 11224 11235 1124# --> connection con2 1125# Sending: 1126rename table t0 to t3, t1 to t0, t3 to t1; 1127# --> connection con1 1128# Waiting for 'rename table ...' to get blocked... 1129# --> connection default 1130# We back-off on hitting deadlock condition. 1131handler t0 open; 1132ERROR 40001: Deadlock found when trying to get lock; try restarting transaction 1133select * from t0; 1134a 11351 11362 11373 11384 11395 1140handler t1 open; 1141commit; 1142handler t1 close; 1143# --> connection con2 1144# Reaping 'rename table ...'... 1145# --> connection default 1146handler t1 open; 1147handler t1 read a prev; 1148a 11495 1150handler t1 close; 1151drop table t0; 1152# 1153# Originally there was a deadlock error in this test. 1154# With implementation of deadlock detector 1155# we no longer deadlock, but block and wait on a lock. 1156# The HANDLER is auto-closed as soon as the connection 1157# sees a pending conflicting lock against it. 1158# 1159create table t2 (a int, key a (a)); 1160handler t1 open; 1161# --> connection con1 1162lock tables t2 read; 1163# --> connection con2 1164# Sending 'drop table t2'... 1165drop table t2; 1166# --> connection con1 1167# Waiting for 'drop table t2' to get blocked... 1168# --> connection default 1169# Sending 'select * from t2' 1170select * from t2; 1171# --> connection con1 1172# Waiting for 'select * from t2' to get blocked... 1173unlock tables; 1174# --> connection con2 1175# Reaping 'drop table t2'... 1176# --> connection default 1177# Reaping 'select * from t2' 1178ERROR 42S02: Table 'test.t2' doesn't exist 1179handler t1 close; 1180# 1181# ROLLBACK TO SAVEPOINT releases transactional locks, 1182# but has no effect on open HANDLERs 1183# 1184create table t2 like t1; 1185create table t3 like t1; 1186begin; 1187# Have something before the savepoint 1188select * from t3; 1189a 1190savepoint sv; 1191handler t1 open; 1192handler t1 read a first; 1193a 11941 1195handler t1 read a next; 1196a 11972 1198select * from t2; 1199a 1200# --> connection con1 1201# Sending: 1202drop table t1; 1203# --> connection con2 1204# Sending: 1205drop table t2; 1206# --> connection default 1207# Let DROP TABLE statements sync in. We must use 1208# a separate connection for that, because otherwise SELECT 1209# will auto-close the HANDLERs, becaues there are pending 1210# exclusive locks against them. 1211# --> connection con3 1212# Waiting for 'drop table t1' to get blocked... 1213# Waiting for 'drop table t2' to get blocked... 1214# Demonstrate that t2 lock was released and t2 was dropped 1215# after ROLLBACK TO SAVEPOINT 1216# --> connection default 1217rollback to savepoint sv; 1218# --> connection con2 1219# Reaping 'drop table t2'... 1220# Demonstrate that ROLLBACK TO SAVEPOINT didn't release the handler 1221# lock. 1222# --> connection default 1223handler t1 read a next; 1224a 12253 1226handler t1 read a next; 1227a 12284 1229# Demonstrate that the drop will go through as soon as we close the 1230# HANDLER 1231handler t1 close; 1232# connection con1 1233# Reaping 'drop table t1'... 1234# --> connection default 1235commit; 1236drop table t3; 1237# 1238# A few special cases when using SAVEPOINT/ROLLBACK TO 1239# SAVEPOINT and HANDLER. 1240# 1241# Show that rollback to the savepoint taken in the beginning 1242# of the transaction doesn't release mdl lock on 1243# the HANDLER that was opened later. 1244# 1245create table t1 (a int, key a(a)); 1246insert into t1 (a) values (1), (2), (3), (4), (5); 1247create table t2 like t1; 1248begin; 1249savepoint sv; 1250handler t1 open; 1251handler t1 read a first; 1252a 12531 1254handler t1 read a next; 1255a 12562 1257select * from t2; 1258a 1259# --> connection con1 1260# Sending: 1261drop table t1; 1262# --> connection con2 1263# Sending: 1264drop table t2; 1265# --> connection default 1266# Let DROP TABLE statements sync in. We must use 1267# a separate connection for that, because otherwise SELECT 1268# will auto-close the HANDLERs, becaues there are pending 1269# exclusive locks against them. 1270# --> connection con3 1271# Waiting for 'drop table t1' to get blocked... 1272# Waiting for 'drop table t2' to get blocked... 1273# Demonstrate that t2 lock was released and t2 was dropped 1274# after ROLLBACK TO SAVEPOINT 1275# --> connection default 1276rollback to savepoint sv; 1277# --> connection con2 1278# Reaping 'drop table t2'... 1279# Demonstrate that ROLLBACK TO SAVEPOINT didn't release the handler 1280# lock. 1281# --> connection default 1282handler t1 read a next; 1283a 12843 1285handler t1 read a next; 1286a 12874 1288# Demonstrate that the drop will go through as soon as we close the 1289# HANDLER 1290handler t1 close; 1291# connection con1 1292# Reaping 'drop table t1'... 1293# --> connection default 1294commit; 1295# 1296# Show that rollback to the savepoint taken in the beginning 1297# of the transaction works properly (no valgrind warnins, etc), 1298# even though it's done after the HANDLER mdl lock that was there 1299# at the beginning is released and added again. 1300# 1301create table t1 (a int, key a(a)); 1302insert into t1 (a) values (1), (2), (3), (4), (5); 1303create table t2 like t1; 1304create table t3 like t1; 1305insert into t3 (a) select a from t1; 1306begin; 1307handler t1 open; 1308savepoint sv; 1309handler t1 read a first; 1310a 13111 1312select * from t2; 1313a 1314handler t1 close; 1315handler t3 open; 1316handler t3 read a first; 1317a 13181 1319rollback to savepoint sv; 1320# --> connection con1 1321drop table t1, t2; 1322# Sending: 1323drop table t3; 1324# Let DROP TABLE statement sync in. 1325# --> connection con2 1326# Waiting for 'drop table t3' to get blocked... 1327# Demonstrate that ROLLBACK TO SAVEPOINT didn't release the handler 1328# lock. 1329# --> connection default 1330handler t3 read a next; 1331a 13322 1333# Demonstrate that the drop will go through as soon as we close the 1334# HANDLER 1335handler t3 close; 1336# connection con1 1337# Reaping 'drop table t3'... 1338# --> connection default 1339commit; 1340# 1341# If we have to wait on an exclusive locks while having 1342# an open HANDLER, ER_LOCK_DEADLOCK is reported. 1343# 1344create table t1 (a int, key a(a)); 1345create table t2 like t1; 1346handler t1 open; 1347# --> connection con1 1348lock table t1 write, t2 write; 1349# --> connection default 1350drop table t2; 1351# --> connection con2 1352# Waiting for 'drop table t2' to get blocked... 1353# --> connection con1 1354drop table t1; 1355ERROR 40001: Deadlock found when trying to get lock; try restarting transaction 1356unlock tables; 1357# --> connection default 1358# Demonstrate that there is no deadlock with FLUSH TABLE, 1359# even though it is waiting for the other table to go away 1360create table t2 like t1; 1361# Sending: 1362flush table t2; 1363# --> connection con2 1364drop table t1; 1365# --> connection con1 1366unlock tables; 1367# --> connection default 1368# Reaping 'flush table t2'... 1369drop table t2; 1370# 1371# Bug #46224 HANDLER statements within a transaction might 1372# lead to deadlocks 1373# 1374create table t1 (a int, key a(a)); 1375insert into t1 values (1), (2); 1376# --> connection default 1377begin; 1378select * from t1; 1379a 13801 13812 1382handler t1 open; 1383# --> connection con1 1384# Sending: 1385lock tables t1 write; 1386# --> connection con2 1387# Check that 'lock tables t1 write' waits until transaction which 1388# has read from the table commits. 1389# --> connection default 1390# The below 'handler t1 read ...' should not be blocked as 1391# 'lock tables t1 write' has not succeeded yet. 1392handler t1 read a next; 1393a 13941 1395# Unblock 'lock tables t1 write'. 1396commit; 1397# --> connection con1 1398# Reap 'lock tables t1 write'. 1399# --> connection default 1400# Sending: 1401handler t1 read a next; 1402# --> connection con1 1403# Waiting for 'handler t1 read a next' to get blocked... 1404# The below 'drop table t1' should be able to proceed without 1405# waiting as it will force HANDLER to be closed. 1406drop table t1; 1407unlock tables; 1408# --> connection default 1409# Reaping 'handler t1 read a next'... 1410ERROR 42S02: Table 'test.t1' doesn't exist 1411handler t1 close; 1412# --> connection con1 1413# --> connection con2 1414# --> connection con3 1415# 1416# A temporary table test. 1417# Check that we don't loose positions of HANDLER opened 1418# against a temporary table. 1419# 1420create table t1 (a int, b int, key a (a)); 1421insert into t1 (a) values (1), (2), (3), (4), (5); 1422create temporary table t2 (a int, b int, key a (a)); 1423insert into t2 (a) select a from t1; 1424handler t1 open; 1425handler t1 read a next; 1426a b 14271 NULL 1428handler t2 open; 1429handler t2 read a next; 1430a b 14311 NULL 1432flush table t1; 1433handler t2 read a next; 1434a b 14352 NULL 1436# Sic: the position is lost 1437handler t1 read a next; 1438a b 14391 NULL 1440select * from t1; 1441a b 14421 NULL 14432 NULL 14443 NULL 14454 NULL 14465 NULL 1447# Sic: the position is not lost 1448handler t2 read a next; 1449a b 14503 NULL 1451select * from t2; 1452ERROR HY000: Can't reopen table: 't2' 1453handler t2 read a next; 1454a b 14554 NULL 1456drop table t1; 1457drop temporary table t2; 1458# 1459# A test for lock_table_names()/unlock_table_names() function. 1460# It should work properly in presence of open HANDLER. 1461# 1462create table t1 (a int, b int, key a (a)); 1463create table t2 like t1; 1464create table t3 like t1; 1465create table t4 like t1; 1466handler t1 open; 1467handler t2 open; 1468rename table t4 to t5, t3 to t4, t5 to t3; 1469handler t1 read first; 1470a b 1471handler t2 read first; 1472a b 1473drop table t1, t2, t3, t4; 1474# 1475# A test for FLUSH TABLES WITH READ LOCK and HANDLER statements. 1476# 1477set autocommit=0; 1478create table t1 (a int, b int, key a (a)); 1479insert into t1 (a, b) values (1, 1), (2, 1), (3, 2), (4, 2), (5, 5); 1480create table t2 like t1; 1481insert into t2 (a, b) select a, b from t1; 1482create table t3 like t1; 1483insert into t3 (a, b) select a, b from t1; 1484commit; 1485flush tables with read lock; 1486handler t1 open; 1487lock table t1 read; 1488handler t1 read next; 1489ERROR HY000: Can't execute the given command because you have active locked tables or an active transaction 1490# This implicitly leaves LOCK TABLES but doesn't drop the GLR 1491lock table not_exists_write read; 1492ERROR 42S02: Table 'test.not_exists_write' doesn't exist 1493# We still have the read lock. 1494drop table t1; 1495ERROR HY000: Can't execute the query because you have a conflicting read lock 1496handler t1 open; 1497select a from t2; 1498a 14991 15002 15013 15024 15035 1504handler t1 read next; 1505a b 15061 1 1507flush tables with read lock; 1508handler t2 open; 1509flush tables with read lock; 1510handler t1 read next; 1511a b 15121 1 1513select a from t3; 1514a 15151 15162 15173 15184 15195 1520handler t2 read next; 1521a b 15221 1 1523handler t1 close; 1524rollback; 1525handler t2 close; 1526drop table t1; 1527ERROR HY000: Can't execute the query because you have a conflicting read lock 1528commit; 1529flush tables; 1530drop table t1; 1531ERROR HY000: Can't execute the query because you have a conflicting read lock 1532unlock tables; 1533drop table t1; 1534set autocommit=default; 1535drop table t2, t3; 1536# 1537# HANDLER statement and operation-type aware metadata locks. 1538# Check that when we clone a ticket for HANDLER we downrade 1539# the lock. 1540# 1541# Establish an auxiliary connection con1. 1542# -> connection default 1543create table t1 (a int, b int, key a (a)); 1544insert into t1 (a, b) values (1, 1), (2, 1), (3, 2), (4, 2), (5, 5); 1545begin; 1546insert into t1 (a, b) values (6, 6); 1547handler t1 open; 1548handler t1 read a last; 1549a b 15506 6 1551insert into t1 (a, b) values (7, 7); 1552handler t1 read a last; 1553a b 15547 7 1555commit; 1556# -> connection con1 1557# Demonstrate that the HANDLER doesn't hold MDL_SHARED_WRITE. 1558lock table t1 write; 1559unlock tables; 1560# -> connection default 1561handler t1 read a prev; 1562a b 15636 6 1564handler t1 close; 1565# Cleanup. 1566drop table t1; 1567# -> connection con1 1568# -> connection default 1569# 1570# A test for Bug#50555 "handler commands crash server in 1571# my_hash_first()". 1572# 1573handler no_such_table read no_such_index first; 1574ERROR 42S02: Unknown table 'no_such_table' in HANDLER 1575handler no_such_table close; 1576ERROR 42S02: Unknown table 'no_such_table' in HANDLER 1577# 1578# Bug#50907 Assertion `hash_tables->table->next == __null' on 1579# HANDLER OPEN 1580# 1581DROP TABLE IF EXISTS t1, t2; 1582CREATE TEMPORARY TABLE t1 (i INT); 1583CREATE TEMPORARY TABLE t2 (i INT); 1584HANDLER t2 OPEN; 1585HANDLER t2 READ FIRST; 1586i 1587HANDLER t2 CLOSE; 1588DROP TABLE t1, t2; 1589# 1590# Bug#50912 Assertion `ticket->m_type >= mdl_request->type' 1591# failed on HANDLER + I_S 1592# 1593DROP TABLE IF EXISTS t1; 1594CREATE TABLE t1 (id INT); 1595HANDLER t1 OPEN; 1596SELECT table_name, table_comment FROM information_schema.tables 1597WHERE table_schema= 'test' AND table_name= 't1'; 1598table_name table_comment 1599t1 1600HANDLER t1 CLOSE; 1601DROP TABLE t1; 1602# 1603# Test for bug #50908 "Assertion `handler_tables_hash.records == 0' 1604# failed in enter_locked_tables_mode". 1605# 1606drop tables if exists t1, t2; 1607drop function if exists f1; 1608create table t1 (i int); 1609insert into t1 values (1), (2); 1610create table t2 (j int); 1611insert into t2 values (1); 1612create function f1() returns int return (select count(*) from t2); 1613# Check that open HANDLER survives statement executed in 1614# prelocked mode. 1615handler t1 open; 1616handler t1 read next; 1617i 16181 1619# The below statement were aborted due to an assertion failure. 1620select f1() from t2; 1621f1() 16221 1623handler t1 read next; 1624i 16252 1626handler t1 close; 1627# Check that the same happens under GLOBAL READ LOCK. 1628flush tables with read lock; 1629handler t1 open; 1630handler t1 read next; 1631i 16321 1633select f1() from t2; 1634f1() 16351 1636handler t1 read next; 1637i 16382 1639unlock tables; 1640handler t1 close; 1641# Now, check that the same happens if LOCK TABLES is executed. 1642handler t1 open; 1643handler t1 read next; 1644i 16451 1646lock table t2 read; 1647select * from t2; 1648j 16491 1650unlock tables; 1651handler t1 read next; 1652i 16532 1654handler t1 close; 1655# Finally, check scenario with GRL and LOCK TABLES. 1656flush tables with read lock; 1657handler t1 open; 1658handler t1 read next; 1659i 16601 1661lock table t2 read; 1662select * from t2; 1663j 16641 1665# This unlocks both tables and GRL. 1666unlock tables; 1667handler t1 read next; 1668i 16692 1670handler t1 close; 1671# Clean-up. 1672drop function f1; 1673drop tables t1, t2; 1674# 1675# Test for bug #51136 "Crash in pthread_rwlock_rdlock on TEMPORARY + 1676# HANDLER + LOCK + SP". 1677# Also see additional coverage for this bug in flush.test. 1678# 1679drop tables if exists t1, t2; 1680create table t1 (i int); 1681create temporary table t2 (j int); 1682handler t1 open; 1683lock table t2 read; 1684# This commit should not release any MDL locks. 1685commit; 1686unlock tables; 1687# The below statement crashed before the bug fix as it 1688# has attempted to release metadata lock which was 1689# already released by commit. 1690handler t1 close; 1691drop tables t1, t2; 1692# 1693# Bug#51355 handler stmt cause assertion in 1694# bool MDL_context::try_acquire_lock(MDL_request*) 1695# 1696DROP TABLE IF EXISTS t1; 1697# Connection default 1698CREATE TABLE t1(id INT, KEY id(id)); 1699HANDLER t1 OPEN; 1700# Connection con51355 1701# Sending: 1702DROP TABLE t1; 1703# Connection default 1704# This I_S query will cause the handler table to be closed and 1705# the metadata lock to be released. This will allow DROP TABLE 1706# to proceed. Waiting for the table to be removed. 1707# Connection con51355 1708# Reaping: DROP TABLE t1 1709# Connection default 1710HANDLER t1 READ id NEXT; 1711ERROR 42S02: Table 'test.t1' doesn't exist 1712HANDLER t1 READ id NEXT; 1713ERROR 42S02: Table 'test.t1' doesn't exist 1714HANDLER t1 CLOSE; 1715# Connection con51355 1716# Connection default 1717# 1718# Bug#54401 assert in Diagnostics_area::set_eof_status , HANDLER 1719# 1720DROP TABLE IF EXISTS t1, t2; 1721DROP FUNCTION IF EXISTS f1; 1722CREATE FUNCTION f1() RETURNS INTEGER 1723BEGIN 1724SELECT 1 FROM t2 INTO @a; 1725RETURN 1; 1726END| 1727SELECT f1(); 1728ERROR 42S02: Table 'test.t2' doesn't exist 1729CREATE TABLE t1(a INT); 1730INSERT INTO t1 VALUES (1); 1731HANDLER t1 OPEN; 1732HANDLER t1 READ FIRST WHERE f1() = 1; 1733ERROR 42000: This version of MySQL doesn't yet support 'stored functions in HANDLER ... READ' 1734HANDLER t1 CLOSE; 1735DROP FUNCTION f1; 1736DROP TABLE t1; 1737# 1738# Bug#54920 Stored functions are allowed in HANDLER statements, 1739# but broken. 1740# 1741DROP TABLE IF EXISTS t1; 1742DROP FUNCTION IF EXISTS f1; 1743CREATE TABLE t1 (a INT); 1744INSERT INTO t1 VALUES (1), (2); 1745CREATE FUNCTION f1() RETURNS INT RETURN 1; 1746HANDLER t1 OPEN; 1747HANDLER t1 READ FIRST WHERE f1() = 1; 1748ERROR 42000: This version of MySQL doesn't yet support 'stored functions in HANDLER ... READ' 1749HANDLER t1 CLOSE; 1750DROP FUNCTION f1; 1751DROP TABLE t1; 1752# 1753# Bug#13008220 HANDLER SQL STATEMENT CAN MISS TO INITIALIZE 1754# FOR RANDOM READ 1755# 1756# A handler can only have one active 'cursor' at a time, 1757# so switching between index and/or random should restart the cursor. 1758CREATE TABLE t1(a INT, b INT, KEY b(b), KEY ab(a, b)); 1759INSERT INTO t1 VALUES (2, 20), (1, 10), (4, 40), (3, 30); 1760HANDLER t1 OPEN; 1761HANDLER t1 READ b FIRST; 1762a b 17631 10 1764HANDLER t1 READ NEXT; 1765a b 17662 20 1767HANDLER t1 READ NEXT; 1768a b 17691 10 1770HANDLER t1 READ b FIRST; 1771a b 17721 10 1773HANDLER t1 READ b NEXT; 1774a b 17752 20 1776HANDLER t1 READ b NEXT; 1777a b 17783 30 1779HANDLER t1 READ FIRST; 1780a b 17812 20 1782HANDLER t1 READ b FIRST; 1783a b 17841 10 1785HANDLER t1 READ NEXT; 1786a b 17872 20 1788HANDLER t1 READ NEXT; 1789a b 17901 10 1791HANDLER t1 READ NEXT; 1792a b 17934 40 1794HANDLER t1 READ NEXT; 1795a b 17963 30 1797HANDLER t1 READ NEXT; 1798a b 1799HANDLER t1 READ b NEXT; 1800a b 18011 10 1802HANDLER t1 READ b NEXT; 1803a b 18042 20 1805HANDLER t1 READ b NEXT; 1806a b 18073 30 1808HANDLER t1 READ b NEXT; 1809a b 18104 40 1811HANDLER t1 READ b NEXT; 1812a b 1813HANDLER t1 READ NEXT; 1814a b 18152 20 1816HANDLER t1 READ b NEXT; 1817a b 18181 10 1819HANDLER t1 READ FIRST; 1820a b 18212 20 1822HANDLER t1 READ b PREV; 1823a b 18244 40 1825HANDLER t1 READ b LAST; 1826a b 18274 40 1828HANDLER t1 READ NEXT; 1829a b 18302 20 1831HANDLER t1 READ ab FIRST; 1832a b 18331 10 1834HANDLER t1 READ b NEXT; 1835a b 18361 10 1837HANDLER t1 READ ab LAST; 1838a b 18394 40 1840HANDLER t1 READ b PREV; 1841a b 18424 40 1843HANDLER t1 CLOSE; 1844DROP TABLE t1; 1845