4 # $engine_type -- storage engine to be tested
5 # $other_engine_type -- storage engine <> $engine_type
6 # $other_handler_engine_type -- storage engine <> $engine_type, if possible
7 # 1. $other_handler_engine_type must support handler
8 # 2. $other_handler_engine_type must point to an all
9 # time available storage engine
10 # 2006-08 MySQL 5.1 MyISAM and MEMORY only
11 # have to be set before sourcing this script.
12 -- source include/not_embedded.inc
17 # 2006-07-31 ML test refactored (MySQL 5.1)
18 # code of t/handler.test and t/innodb_handler.test united
19 # main testing code put into include/handler.inc
22 eval SET SESSION DEFAULT_STORAGE_ENGINE = $engine_type;
25 drop
table if exists t1,t3,t4,t5;
28 create
table t1 (a
int, b
char(10), key a(a), key b(a,b));
30 (17,
"ddd"),(18,
"eee"),(19,
"fff"),(19,
"yyy"),
31 (14,
"aaa"),(15,
"bbb"),(16,
"ccc"),(16,
"xxx"),
32 (20,
"ggg"),(21,
"hhh"),(22,
"iii");
76 handler t2 read a prev limit 10;
78 handler t2 read a>=(16) limit 4;
79 handler t2 read a>=(16) limit 2,2;
83 handler t2 read a=(19) where b=
"yyy";
93 handler t1 read a next; #
this used
to crash as a bug#5373
98 handler t1 read a prev; #
this used
to crash as a bug#5373
104 eval alter
table t1 engine = $engine_type;
109 # DROP TABLE / ALTER TABLE
113 create
table t1 (a
int);
114 insert into t1 values (17);
118 eval alter
table t1 engine=$other_engine_type;
124 # Test case for the bug #787
126 create
table t1 (a
int);
127 insert into t1 values (1),(2),(3),(4),(5),(6);
128 delete from t1 limit 2;
131 handler t1 read first limit 1,1;
132 handler t1 read first limit 2,2;
133 delete from t1 limit 3;
141 insert into t1 values (1), (2), (3);
151 create
table t1 (a
char(5));
152 insert into t1 values (
"Ok");
167 create
table t1 ( a
int, b
int, INDEX a (a) );
168 insert into t1 values (1,2), (2,1);
170 handler t1 read a=(1) where b=2;
171 handler t1 read a=(1) where b=3;
172 handler t1 read a=(1) where b=1;
177 # Check if two database names beginning the same are seen as different.
179 # This database begins like the usual 'test' database.
182 drop database
if exists test_test;
184 create database test_test;
186 create
table t1(table_id
char(20) primary key);
187 insert into t1 values (
'test_test.t1');
188 insert into t1 values (
'');
191 create
table t2(table_id
char(20) primary key);
192 insert into t2 values (
'test_test.t2');
193 insert into t2 values (
'');
197 # This is the usual 'test' database.
201 drop
table if exists t1;
203 create
table t1(table_id
char(20) primary key);
204 insert into t1 values (
'test.t1');
205 insert into t1 values (
'');
209 # Check accesibility of all the tables.
213 handler test.t1 read first limit 9;
215 handler test_test.t1 read first limit 9;
218 handler test_test.t2 read first limit 9;
228 drop
table test_test.t1;
232 drop
table test_test.t2;
233 drop database test_test;
247 drop database
if exists test_test;
248 drop
table if exists t1;
249 drop
table if exists t2;
250 drop
table if exists t3;
252 create database test_test;
254 create
table t1 (c1
char(20));
255 insert into t1 values (
'test_test.t1');
256 create
table t3 (c1
char(20));
257 insert into t3 values (
'test_test.t3');
263 create
table t1 (c1
char(20));
264 create
table t2 (c1
char(20));
265 create
table t3 (c1
char(20));
266 insert into t1 values (
't1');
267 insert into t2 values (
't2');
268 insert into t3 values (
't3');
305 handler test.h3 read first limit 9;
311 drop database test_test;
314 # Test if fix for BUG#4286 correctly closes handler tables.
316 create
table t1 (c1
char(20));
317 insert into t1 values (
"t1");
320 create
table t2 (c1
char(20));
321 insert into t2 values (
"t2");
324 create
table t3 (c1
char(20));
325 insert into t3 values (
"t3");
328 create
table t4 (c1
char(20));
329 insert into t4 values (
"t4");
332 create
table t5 (c1
char(20));
333 insert into t5 values (
"t5");
337 eval alter
table t1 engine=$other_handler_engine_type;
345 eval alter
table t5 engine=$other_handler_engine_type;
354 eval alter
table t3 engine=$other_handler_engine_type;
365 # close all depending handler tables
369 handler h1_1 read first limit 9;
370 handler h1_2 read first limit 9;
371 handler h1_3 read first limit 9;
372 eval alter
table t1 engine=$engine_type;
374 handler h1_1 read first limit 9;
376 handler h1_2 read first limit 9;
378 handler h1_3 read first limit 9;
386 # Bug#14397 - OPTIMIZE TABLE with an open HANDLER causes a crash
388 create
table t1 (c1
int);
389 insert into t1 values (1);
394 connect (con2,localhost,root,,);
396 --exec echo send the below
to another connection,
do not wait
for the result
397 send optimize
table t1;
400 --exec echo proceed with the normal connection
405 --exec echo read the result from the other connection
409 --exec echo proceed with the normal connection
413 CREATE
TABLE t1 ( no1 smallint(5) NOT NULL
default '0', no2
int(10) NOT NULL
default '0', PRIMARY
KEY (no1,no2));
414 INSERT INTO t1 VALUES (1,274),(1,275),(2,6),(2,8),(4,1),(4,2);
416 HANDLER t1 READ `primary` = (1, 1000);
417 HANDLER t1 READ `primary` PREV;
423 # Addendum to Bug#14397 - OPTIMIZE TABLE with an open HANDLER causes a crash
424 # Show that DROP TABLE can no longer deadlock against
425 # FLUSH TABLES WITH READ LOCK. This is a 5.0 issue.
427 create
table t1 (c1
int);
428 insert into t1 values (14397);
429 flush tables with read lock;
430 # The thread with the global read lock cannot drop the table itself:
435 # We need a second connection to try the drop.
436 # The drop waits for the global read lock to go away.
437 # Without the addendum fix it locked LOCK_open before entering the wait loop.
439 --exec echo send the below
to another connection,
do not wait
for the result
444 # Now we need something that wants LOCK_open. A simple table access which
445 # opens the table does the trick.
446 --exec echo proceed with the normal connection
448 # This would hang on LOCK_open without the 5.0 addendum fix.
450 # Release the read lock. This should make the DROP go through.
454 # Read the result of the drop command.
456 --exec echo read the result from the other connection
460 # Now back to normal operation. The table should not exist any more.
461 --exec echo proceed with the normal connection
465 # Just to be sure and not confuse the next test case writer.
466 drop
table if exists t1;
469 # Bug#25856 - HANDLER table OPEN in one connection lock DROP TABLE in another one
472 drop
table if exists t1;
474 eval create
table t1 (a
int) ENGINE=$other_engine_type;
485 # Bug#30632 HANDLER read failure causes hang
488 drop
table if exists t1;
490 create
table t1 (a
int);
495 handler t1_alias READ a next where inexistent > 0;
499 handler t1_alias READ a next where inexistent > 0;
504 # Bug#21587 FLUSH TABLES causes server crash when used with HANDLER statements
508 drop
table if exists t1,t2;
510 create
table t1 (c1
int);
511 create
table t2 (c1
int);
512 insert into t1 values (1);
513 insert into t2 values (2);
514 --echo connection:
default
517 connect (flush,localhost,root,,);
519 --echo connection: flush
521 connect (waiter,localhost,root,,);
523 --echo connection: waiter
525 select count(*) = 1 from information_schema.processlist
526 where state =
"Waiting for table flush";
527 --source include/wait_condition.inc
529 --echo connection:
default
542 # Bug#31409 RENAME TABLE causes server crash or deadlock when used with HANDLER statements
546 drop
table if exists t1, t0;
548 create
table t1 (c1
int);
549 --echo connection:
default
552 connect (flush,localhost,root,,);
554 --echo connection: flush
557 --echo connection: waiter
559 select count(*) = 1 from information_schema.processlist
560 where state =
"Waiting for table metadata lock" and
561 info =
"rename table t1 to t0";
562 --source include/wait_condition.inc
564 --echo connection:
default
566 --echo # RENAME placed two pending locks and waits.
567 --echo # When HANDLER t0 OPEN does
open_tables(), it calls
568 --echo # mysql_ha_flush(), which in turn closes the open HANDLER
for t1.
569 --echo # RENAME
TABLE gets unblocked. If it gets scheduled quickly
571 --echo # of HANDLER t0 OPEN,
open_tables() and therefore the whole
572 --echo
# HANDLER t0 OPEN succeeds. Otherwise open_tables()
573 --echo # notices a pending or active exclusive metadata lock on t2
574 --echo # and the whole HANDLER t0 OPEN fails with ER_LOCK_DEADLOCK
577 --error 0, ER_LOCK_DEADLOCK
579 --error 0, ER_UNKNOWN_TABLE
581 --echo connection: flush
584 --error ER_UNKNOWN_TABLE
586 --error ER_UNKNOWN_TABLE
592 --source include/wait_until_disconnected.inc
595 --source include/wait_until_disconnected.inc
599 # Bug#30882 Dropping a temporary table inside a stored function may cause a server crash
601 # Test HANDLER statements in conjunction with temporary tables. While the temporary table
602 # is open by a HANDLER, no other statement can access it.
606 drop
table if exists t1;
608 create temporary
table t1 (a
int, b
char(1), key a(a), key b(a,b));
609 insert into t1 values (0,
"a"),(1,
"b"),(2,
"c"),(3,
"d"),(4,
"e"),
610 (5,
"f"),(6,
"g"),(7,
"h"),(8,
"i"),(9,
"j");
616 --error ER_CANT_REOPEN_TABLE
620 handler a1 read a=(6) where b=
"g";
631 # Bug#31397 Inconsistent drop table behavior of handler tables.
635 drop
table if exists t1,t2;
637 create
table t1 (a
int);
640 create
table t1 (a
int);
644 create
table t1 (a
int);
648 create
table t1 (a
int);
652 --error ER_UNKNOWN_TABLE
655 # Test that temporary tables associated with handlers are properly dropped.
657 create
table t1 (a
int);
658 create temporary
table t2 (a
int, key(a));
663 --error ER_UNKNOWN_TABLE
665 --error ER_UNKNOWN_TABLE
668 # Alter table drop handlers
670 create
table t1 (a
int, key(a));
671 create
table t2 like t1;
676 alter
table t1 add b int;
677 --error ER_UNKNOWN_TABLE
682 # Rename table drop handlers
684 create
table t1 (a
int, key(a));
688 --error ER_UNKNOWN_TABLE
692 # Optimize table drop handlers
694 create
table t1 (a
int, key(a));
695 create
table t2 like t1;
701 --error ER_UNKNOWN_TABLE
706 # Flush tables causes handlers reopen
708 create
table t1 (a
int, b
char(1), key a(a), key b(a,b));
709 insert into t1 values (0,
"a"),(1,
"b"),(2,
"c"),(3,
"d"),(4,
"e"),
710 (5,
"f"),(6,
"g"),(7,
"h"),(8,
"i"),(9,
"j");
717 flush tables with read lock;
721 --error ER_UNKNOWN_TABLE
725 # Bug#41110: crash with handler command when used concurrently with alter table
726 # Bug#41112: crash in mysql_ha_close_table/get_lock_data with alter table
729 connect(con1,localhost,root,,);
730 connect(con2,localhost,root,,);
734 drop
table if exists t1;
736 --echo # First test
case which is supposed trigger the execution
737 --echo # path on which problem was discovered.
738 create
table t1 (a
int);
739 insert into t1 values (1);
743 send alter
table t1 engine=memory;
746 select count(*) = 1 from information_schema.processlist
747 where state =
"Waiting for table metadata lock" and
748 info =
"alter table t1 engine=memory";
749 --source include/wait_condition.inc
751 --error ER_ILLEGAL_HA
758 --echo # Now test
case which was reported originally but which no longer
759 --echo # triggers execution path which has caused the problem.
761 create
table t1 (a
int, key(a));
762 insert into t1 values (1);
765 send alter
table t1 engine=memory;
768 select count(*) = 1 from information_schema.processlist
769 where state =
"Waiting for table metadata lock" and
770 info =
"alter table t1 engine=memory";
771 --source include/wait_condition.inc
773 --echo # Since S metadata lock was already acquired at HANDLER OPEN time
774 --echo # and TL_READ lock requested by HANDLER READ is compatible with
775 --echo # ALTER
's TL_WRITE_ALLOW_READ the below statement should succeed
776 --echo # without waiting. The old version of table should be used in it.
777 handler t1 read a next;
780 --reap # Since last in this connection was a send
783 --source include/wait_until_disconnected.inc
786 --source include/wait_until_disconnected.inc
790 # Bug#44151 using handler commands on information_schema tables crashes server
792 USE information_schema;
793 --error ER_WRONG_USAGE
794 HANDLER COLUMNS OPEN;
798 --echo # Add test coverage for HANDLER and LOCK TABLES, HANDLER and DDL.
801 drop table if exists t1, t2, t3;
803 create table t1 (a int, key a (a));
804 insert into t1 (a) values (1), (2), (3), (4), (5);
805 create table t2 (a int, key a (a)) select * from t1;
806 create temporary table t3 (a int, key a (a)) select * from t2;
807 create temporary table t4 like t3;
812 --echo # No HANDLER sql is allowed under LOCK TABLES.
813 --echo # But it does not implicitly closes all handlers.
816 --error ER_LOCK_OR_ACTIVE_TRANSACTION
818 --error ER_LOCK_OR_ACTIVE_TRANSACTION
819 handler t1 read next;
820 --error ER_LOCK_OR_ACTIVE_TRANSACTION
822 --error ER_LOCK_OR_ACTIVE_TRANSACTION
824 --error ER_LOCK_OR_ACTIVE_TRANSACTION
826 --echo # After UNLOCK TABLES handlers should be around and
827 --echo # we should be able to continue reading through them.
829 handler t1 read next;
831 handler t2 read next;
833 handler t3 read next;
835 drop temporary tables t3, t4;
837 --echo # Other operations that implicitly close handler:
843 --error ER_UNKNOWN_TABLE
844 handler t1 read next;
847 --echo # CREATE TRIGGER
849 create trigger t1_ai after insert on t1 for each row set @a=1;
850 --error ER_UNKNOWN_TABLE
851 handler t1 read next;
853 --echo # DROP TRIGGER
857 --error ER_UNKNOWN_TABLE
858 handler t1 read next;
863 alter table t1 add column b int;
864 --error ER_UNKNOWN_TABLE
865 handler t1 read next;
867 --echo # ANALYZE TABLE
871 --error ER_UNKNOWN_TABLE
872 handler t1 read next;
874 --echo # OPTIMIZE TABLE
878 --error ER_UNKNOWN_TABLE
879 handler t1 read next;
881 --echo # REPAIR TABLE
885 --error ER_UNKNOWN_TABLE
886 handler t1 read next;
888 --echo # DROP TABLE, naturally.
892 --error ER_UNKNOWN_TABLE
893 handler t1 read next;
894 create table t1 (a int, b int, key a (a)) select a from t2;
896 --echo # RENAME TABLE, naturally
899 rename table t1 to t3;
900 --error ER_UNKNOWN_TABLE
901 handler t1 read next;
903 --echo # CREATE TABLE (even with IF NOT EXISTS clause,
904 --echo # and the table exists).
907 create table if not exists t2 (a int);
908 --error ER_UNKNOWN_TABLE
909 handler t2 read next;
910 rename table t3 to t1;
913 --echo # FLUSH TABLE doesn't close the
table but loses the position
921 --echo # FLUSH TABLES WITH READ LOCK behaves like FLUSH
TABLE.
925 flush tables with read lock;
930 --echo # Let us also check that these operations behave in similar
931 --echo # way under LOCK TABLES.
933 --echo # TRUNCATE under LOCK TABLES.
936 lock tables t1 write;
939 --error ER_UNKNOWN_TABLE
943 --echo # CREATE TRIGGER under LOCK TABLES.
945 lock tables t1 write;
946 create trigger t1_ai after insert on t1
for each row
set @a=1;
948 --error ER_UNKNOWN_TABLE
951 --echo # DROP TRIGGER under LOCK TABLES.
954 lock tables t1 write;
957 --error ER_UNKNOWN_TABLE
960 --echo # ALTER
TABLE under LOCK TABLES.
963 lock tables t1 write;
964 alter
table t1 drop column b;
966 --error ER_UNKNOWN_TABLE
969 --echo # ANALYZE
TABLE under LOCK TABLES.
972 lock tables t1 write;
975 --error ER_UNKNOWN_TABLE
978 --echo # OPTIMIZE
TABLE under LOCK TABLES.
981 lock tables t1 write;
984 --error ER_UNKNOWN_TABLE
987 --echo # REPAIR
TABLE under LOCK TABLES.
990 lock tables t1 write;
993 --error ER_UNKNOWN_TABLE
996 --echo # DROP
TABLE under LOCK TABLES, naturally.
999 lock tables t1 write;
1002 --error ER_UNKNOWN_TABLE
1004 create
table t1 (a
int, b
int, key a (a));
1005 insert into t1 (a) values (1), (2), (3), (4), (5);
1007 --echo # FLUSH
TABLE doesn
't close the table but loses the position
1010 handler t1 read a prev;
1011 lock tables t1 write;
1014 handler t1 read a prev;
1017 --echo # Explore the effect of HANDLER locks on concurrent DDL
1020 --echo # Establishing auxiliary connections con1, con2, con3
1021 connect(con1, localhost, root,,);
1022 connect(con2, localhost, root,,);
1023 connect(con3, localhost, root,,);
1024 --echo # --> connection con1;
1027 --send drop table t1
1028 --echo # We can't use connection
'default' as wait_condition will
1029 --echo # autoclose handlers.
1030 --echo # --> connection con2
1032 --echo # Waitng
for 'drop table t1' to get blocked...
1033 let $wait_condition=select count(*)=1 from information_schema.processlist
1034 where state=
'Waiting for table metadata lock' and
1035 info=
'drop table t1';
1036 --source include/wait_condition.inc
1037 --echo # --> connection
default
1042 --echo # --> connection con1
1044 --echo # Reaping
'drop table t1'...
1046 --echo # --> connection
default
1049 --echo # Explore the effect of HANDLER locks in parallel with SELECT
1051 create
table t1 (a
int, key a (a));
1052 insert into t1 (a) values (1), (2), (3), (4), (5);
1059 --echo
# --> connection con1;
1062 --send drop
table t1
1063 --echo # --> connection con2
1065 --echo # Waiting
for 'drop table t1' to get blocked...
1066 let $wait_condition=select count(*)=1 from information_schema.processlist
1067 where state=
'Waiting for table metadata lock' and
1068 info=
'drop table t1';
1069 --source include/wait_condition.inc
1070 --echo # --> connection
default
1072 --echo # We can still use the
table, it
's part of the transaction
1074 --echo # Such are the circumstances that t1 is a part of transaction,
1075 --echo # thus we can reopen it in the handler
1077 --echo # We can commit the transaction, it doesn't close the
handler
1078 --echo # and doesn
't let DROP to proceed.
1080 handler t1 read a prev;
1081 handler t1 read a prev;
1082 handler t1 read a prev;
1084 --echo # --> connection con1
1086 --echo # Now drop can proceed
1087 --echo # Reaping 'drop table t1
'...
1089 --echo # --> connection default
1092 --echo # Demonstrate that HANDLER locks and transaction locks
1093 --echo # reside in the same context.
1095 create table t1 (a int, key a (a));
1096 insert into t1 (a) values (1), (2), (3), (4), (5);
1097 create table t0 (a int, key a (a));
1098 insert into t0 (a) values (1), (2), (3), (4), (5);
1101 --echo # --> connection con2
1104 send rename table t0 to t3, t1 to t0, t3 to t1;
1105 --echo # --> connection con1
1107 --echo # Waiting for 'rename table ...
' to get blocked...
1108 let $wait_condition=select count(*)=1 from information_schema.processlist
1109 where state='Waiting
for table metadata lock
' and
1110 info='rename table t0
to t3, t1
to t0, t3
to t1
';
1111 --source include/wait_condition.inc
1112 --echo # --> connection default
1114 --echo # We back-off on hitting deadlock condition.
1115 --error ER_LOCK_DEADLOCK
1121 --echo # --> connection con2
1123 --echo # Reaping 'rename table ...
'...
1125 --echo # --> connection default
1128 handler t1 read a prev;
1132 --echo # Originally there was a deadlock error in this test.
1133 --echo # With implementation of deadlock detector
1134 --echo # we no longer deadlock, but block and wait on a lock.
1135 --echo # The HANDLER is auto-closed as soon as the connection
1136 --echo # sees a pending conflicting lock against it.
1138 create table t2 (a int, key a (a));
1140 --echo # --> connection con1
1142 lock tables t2 read;
1143 --echo # --> connection con2
1145 --echo # Sending 'drop table t2
'...
1146 --send drop table t2
1147 --echo # --> connection con1
1149 --echo # Waiting for 'drop table t2
' to get blocked...
1150 let $wait_condition=select count(*)=1 from information_schema.processlist
1151 where state='Waiting
for table metadata lock
' and
1152 info='drop table t2
';
1153 --source include/wait_condition.inc
1154 --echo # --> connection default
1156 --echo # Sending 'select * from t2
'
1157 send select * from t2;
1158 --echo # --> connection con1
1160 --echo # Waiting for 'select * from t2
' to get blocked...
1161 let $wait_condition=select count(*)=1 from information_schema.processlist
1162 where state='Waiting
for table metadata lock
' and
1163 info='select * from t2
';
1165 --echo # --> connection con2
1167 --echo # Reaping 'drop table t2
'...
1169 --echo # --> connection default
1171 --echo # Reaping 'select * from t2
'
1172 --error ER_NO_SUCH_TABLE
1177 --echo # ROLLBACK TO SAVEPOINT releases transactional locks,
1178 --echo # but has no effect on open HANDLERs
1180 create table t2 like t1;
1181 create table t3 like t1;
1183 --echo # Have something before the savepoint
1187 handler t1 read a first;
1188 handler t1 read a next;
1190 --echo # --> connection con1
1193 --send drop table t1
1194 --echo # --> connection con2
1197 --send drop table t2
1198 --echo # --> connection default
1200 --echo # Let DROP TABLE statements sync in. We must use
1201 --echo # a separate connection for that, because otherwise SELECT
1202 --echo # will auto-close the HANDLERs, becaues there are pending
1203 --echo # exclusive locks against them.
1204 --echo # --> connection con3
1206 --echo # Waiting for 'drop table t1
' to get blocked...
1207 let $wait_condition=select count(*)=1 from information_schema.processlist
1208 where state='Waiting
for table metadata lock
' and
1209 info='drop table t1
';
1210 --source include/wait_condition.inc
1211 --echo # Waiting for 'drop table t2
' to get blocked...
1212 let $wait_condition=select count(*)=1 from information_schema.processlist
1213 where state='Waiting
for table metadata lock
' and
1214 info='drop table t2
';
1215 --source include/wait_condition.inc
1216 --echo # Demonstrate that t2 lock was released and t2 was dropped
1217 --echo # after ROLLBACK TO SAVEPOINT
1218 --echo # --> connection default
1220 rollback to savepoint sv;
1221 --echo # --> connection con2
1223 --echo # Reaping 'drop table t2
'...
1225 --echo # Demonstrate that ROLLBACK TO SAVEPOINT didn't release the
handler
1227 --echo # --> connection
default
1231 --echo # Demonstrate that the drop will go through as soon as we close the
1234 --echo # connection con1
1236 --echo # Reaping
'drop table t1'...
1238 --echo # --> connection
default
1243 --echo #
A few special cases when
using SAVEPOINT/ROLLBACK TO
1244 --echo # SAVEPOINT and HANDLER.
1246 --echo # Show that rollback
to the savepoint taken in the beginning
1247 --echo # of the transaction doesn
't release mdl lock on
1248 --echo # the HANDLER that was opened later.
1250 create table t1 (a int, key a(a));
1251 insert into t1 (a) values (1), (2), (3), (4), (5);
1252 create table t2 like t1;
1256 handler t1 read a first;
1257 handler t1 read a next;
1259 --echo # --> connection con1
1262 --send drop table t1
1263 --echo # --> connection con2
1266 --send drop table t2
1267 --echo # --> connection default
1269 --echo # Let DROP TABLE statements sync in. We must use
1270 --echo # a separate connection for that, because otherwise SELECT
1271 --echo # will auto-close the HANDLERs, becaues there are pending
1272 --echo # exclusive locks against them.
1273 --echo # --> connection con3
1275 --echo # Waiting for 'drop table t1
' to get blocked...
1276 let $wait_condition=select count(*)=1 from information_schema.processlist
1277 where state='Waiting
for table metadata lock
' and
1278 info='drop table t1
';
1279 --source include/wait_condition.inc
1280 --echo # Waiting for 'drop table t2
' to get blocked...
1281 let $wait_condition=select count(*)=1 from information_schema.processlist
1282 where state='Waiting
for table metadata lock
' and
1283 info='drop table t2
';
1284 --source include/wait_condition.inc
1285 --echo # Demonstrate that t2 lock was released and t2 was dropped
1286 --echo # after ROLLBACK TO SAVEPOINT
1287 --echo # --> connection default
1289 rollback to savepoint sv;
1290 --echo # --> connection con2
1292 --echo # Reaping 'drop table t2
'...
1294 --echo # Demonstrate that ROLLBACK TO SAVEPOINT didn't release the
handler
1296 --echo # --> connection
default
1300 --echo # Demonstrate that the drop will go through as soon as we close the
1303 --echo # connection con1
1305 --echo # Reaping
'drop table t1'...
1307 --echo # --> connection
default
1311 --echo # Show that rollback
to the savepoint taken in the beginning
1312 --echo # of the transaction works properly (no valgrind warnins, etc),
1313 --echo # even though it
's done after the HANDLER mdl lock that was there
1314 --echo # at the beginning is released and added again.
1316 create table t1 (a int, key a(a));
1317 insert into t1 (a) values (1), (2), (3), (4), (5);
1318 create table t2 like t1;
1319 create table t3 like t1;
1320 insert into t3 (a) select a from t1;
1324 handler t1 read a first;
1328 handler t3 read a first;
1329 rollback to savepoint sv;
1330 --echo # --> connection con1
1334 --send drop table t3
1335 --echo # Let DROP TABLE statement sync in.
1336 --echo # --> connection con2
1338 --echo # Waiting for 'drop table t3
' to get blocked...
1339 let $wait_condition=select count(*)=1 from information_schema.processlist
1340 where state='Waiting
for table metadata lock
' and
1341 info='drop table t3
';
1342 --source include/wait_condition.inc
1343 --echo # Demonstrate that ROLLBACK TO SAVEPOINT didn't release the
handler
1345 --echo # --> connection
default
1348 --echo # Demonstrate that the drop will go through as soon as we close the
1351 --echo # connection con1
1353 --echo # Reaping
'drop table t3'...
1355 --echo # --> connection
default
1360 --echo # If we have
to wait on an exclusive locks
while having
1361 --echo # an open HANDLER, ER_LOCK_DEADLOCK is reported.
1363 create table t1 (a
int, key a(a));
1364 create table t2 like t1;
1366 --echo # --> connection con1
1368 lock table t1 write, t2 write;
1369 --echo # --> connection
default
1372 --echo # --> connection con2
1374 --echo # Waiting
for 'drop table t2' to get blocked...
1375 let $wait_condition=select count(*)=1 from information_schema.processlist
1376 where state=
'Waiting for table metadata lock' and
1377 info=
'drop table t2';
1378 --source include/wait_condition.inc
1379 --echo # --> connection con1
1381 --error ER_LOCK_DEADLOCK
1384 --echo # --> connection
default
1388 --echo # Demonstrate that there is no deadlock with FLUSH
TABLE,
1389 --echo # even though it is waiting
for the other table
to go away
1390 create table t2 like t1;
1392 --send flush table t2
1393 --echo # --> connection con2
1396 --echo # --> connection con1
1399 --echo # --> connection
default
1401 --echo # Reaping
'flush table t2'...
1406 --echo # Bug #46224 HANDLER statements within a transaction might
1407 --echo # lead
to deadlocks
1409 create table t1 (a
int, key a(a));
1410 insert into t1 values (1), (2);
1412 --echo # --> connection
default
1418 --echo # --> connection con1
1421 --send lock tables t1 write
1423 --echo # --> connection con2
1425 --echo #
Check that
'lock tables t1 write' waits until transaction which
1426 --echo # has read from the table commits.
1427 let $wait_condition=
1428 select count(*) = 1 from information_schema.processlist
1429 where state =
"Waiting for table metadata lock" and
1430 info =
"lock tables t1 write";
1431 --source include/wait_condition.inc
1433 --echo # --> connection
default
1435 --echo # The below
'handler t1 read ...' should not be blocked as
1436 --echo #
'lock tables t1 write' has not succeeded yet.
1437 handler t1 read a next;
1439 --echo # Unblock
'lock tables t1 write'.
1442 --echo # --> connection con1
1444 --echo # Reap
'lock tables t1 write'.
1447 --echo # --> connection
default
1452 --echo # --> connection con1
1454 --echo # Waiting
for 'handler t1 read a next' to get blocked...
1455 let $wait_condition=
1456 select count(*) = 1 from information_schema.processlist
1457 where state =
"Waiting for table level lock" and
1458 info =
"handler t1 read a next";
1459 --source include/wait_condition.inc
1461 --echo # The below
'drop table t1' should be able
to proceed without
1462 --echo # waiting as it will force HANDLER
to be closed.
1466 --echo # --> connection
default
1468 --echo # Reaping
'handler t1 read a next'...
1469 --error ER_NO_SUCH_TABLE
1473 --echo # --> connection con1
1476 --source include/wait_until_disconnected.inc
1477 --echo # --> connection con2
1480 --source include/wait_until_disconnected.inc
1481 --echo # --> connection con3
1484 --source include/wait_until_disconnected.inc
1488 --echo #
A temporary table test.
1489 --echo #
Check that we don
't loose positions of HANDLER opened
1490 --echo # against a temporary table.
1492 create table t1 (a int, b int, key a (a));
1493 insert into t1 (a) values (1), (2), (3), (4), (5);
1494 create temporary table t2 (a int, b int, key a (a));
1495 insert into t2 (a) select a from t1;
1497 handler t1 read a next;
1499 handler t2 read a next;
1501 handler t2 read a next;
1502 --echo # Sic: the position is lost
1503 handler t1 read a next;
1505 --echo # Sic: the position is not lost
1506 handler t2 read a next;
1507 --error ER_CANT_REOPEN_TABLE
1509 handler t2 read a next;
1511 drop temporary table t2;
1514 --echo # A test for lock_table_names()/unlock_table_names() function.
1515 --echo # It should work properly in presence of open HANDLER.
1517 create table t1 (a int, b int, key a (a));
1518 create table t2 like t1;
1519 create table t3 like t1;
1520 create table t4 like t1;
1523 rename table t4 to t5, t3 to t4, t5 to t3;
1524 handler t1 read first;
1525 handler t2 read first;
1526 drop table t1, t2, t3, t4;
1529 --echo # A test for FLUSH TABLES WITH READ LOCK and HANDLER statements.
1532 create table t1 (a int, b int, key a (a));
1533 insert into t1 (a, b) values (1, 1), (2, 1), (3, 2), (4, 2), (5, 5);
1534 create table t2 like t1;
1535 insert into t2 (a, b) select a, b from t1;
1536 create table t3 like t1;
1537 insert into t3 (a, b) select a, b from t1;
1539 flush tables with read lock;
1542 --error ER_LOCK_OR_ACTIVE_TRANSACTION
1543 handler t1 read next;
1544 --echo # This implicitly leaves LOCK TABLES but doesn't drop the GLR
1545 --error ER_NO_SUCH_TABLE
1546 lock table not_exists_write read;
1547 --echo # We still have the read lock.
1548 --error ER_CANT_UPDATE_WITH_READLOCK
1553 flush tables with read lock;
1555 flush tables with read lock;
1562 --error ER_CANT_UPDATE_WITH_READLOCK
1566 --error ER_CANT_UPDATE_WITH_READLOCK
1570 set autocommit=
default;
1574 --echo # HANDLER
statement and operation-
type aware metadata locks.
1575 --echo #
Check that when we clone a ticket
for HANDLER we downrade
1578 --echo # Establish an auxiliary connection con1.
1579 connect (con1,localhost,root,,);
1580 --echo # -> connection
default
1582 create table t1 (a
int, b
int, key a (a));
1583 insert into t1 (a, b) values (1, 1), (2, 1), (3, 2), (4, 2), (5, 5);
1585 insert into t1 (a, b) values (6, 6);
1588 insert into t1 (a, b) values (7, 7);
1591 --echo
# -> connection con1
1593 --echo # Demonstrate that the HANDLER doesn
't hold MDL_SHARED_WRITE.
1594 lock table t1 write;
1596 --echo # -> connection default
1598 handler t1 read a prev;
1602 --echo # -> connection con1
1605 --source include/wait_until_disconnected.inc
1606 --echo # -> connection default
1610 --echo # A test for Bug#50555 "handler commands crash server in
1611 --echo # my_hash_first()".
1613 --error ER_UNKNOWN_TABLE
1614 handler no_such_table read no_such_index first;
1615 --error ER_UNKNOWN_TABLE
1616 handler no_such_table close;
1620 --echo # Bug#50907 Assertion `hash_tables->table->next == __null' on
1621 --echo # HANDLER OPEN
1625 DROP TABLE IF EXISTS t1, t2;
1628 CREATE TEMPORARY TABLE t1 (
i INT);
1629 CREATE TEMPORARY TABLE t2 (
i INT);
1631 # This used to trigger the assert
1634 # This also used to trigger the assert
1635 HANDLER t2 READ FIRST;
1642 --echo # Bug#50912 Assertion `ticket->m_type >= mdl_request->type
'
1643 --echo # failed on HANDLER + I_S
1647 DROP TABLE IF EXISTS t1;
1650 CREATE TABLE t1 (id INT);
1653 # This used to trigger the assert.
1654 SELECT table_name, table_comment FROM information_schema.tables
1655 WHERE table_schema= 'test
' AND table_name= 't1
';
1662 --echo # Test for bug #50908 "Assertion `handler_tables_hash.records == 0'
1663 --echo # failed in enter_locked_tables_mode
".
1666 drop tables if exists t1, t2;
1667 drop function if exists f1;
1669 create table t1 (i int);
1670 insert into t1 values (1), (2);
1671 create table t2 (j int);
1672 insert into t2 values (1);
1673 create function f1() returns int return (select count(*) from t2);
1674 --echo # Check that open HANDLER survives statement executed in
1675 --echo # prelocked mode.
1677 handler t1 read next;
1678 --echo # The below statement were aborted due to an assertion failure.
1679 select f1() from t2;
1680 handler t1 read next;
1682 --echo # Check that the same happens under GLOBAL READ LOCK.
1683 flush tables with read lock;
1685 handler t1 read next;
1686 select f1() from t2;
1687 handler t1 read next;
1690 --echo # Now, check that the same happens if LOCK TABLES is executed.
1692 handler t1 read next;
1696 handler t1 read next;
1698 --echo # Finally, check scenario with GRL and LOCK TABLES.
1699 flush tables with read lock;
1701 handler t1 read next;
1704 --echo # This unlocks both tables and GRL.
1706 handler t1 read next;
1714 --echo # Test for bug #51136 "Crash in pthread_rwlock_rdlock on TEMPORARY +
1715 --echo # HANDLER + LOCK + SP
".
1716 --echo # Also see additional coverage for this bug in flush.test.
1719 drop tables if exists t1, t2;
1721 create table t1 (i int);
1722 create temporary table t2 (j int);
1725 --echo # This commit should not release any MDL locks.
1728 --echo # The below statement crashed before the bug fix as it
1729 --echo # has attempted to release metadata lock which was
1730 --echo # already released by commit.
1736 --echo # Bug#51355 handler stmt cause assertion in
1737 --echo # bool MDL_context::try_acquire_lock(MDL_request*)
1741 DROP TABLE IF EXISTS t1;
1744 connect(con51355, localhost, root);
1746 --echo # Connection default
1748 CREATE TABLE t1(id INT, KEY id(id));
1751 --echo # Connection con51355
1752 connection con51355;
1754 --send DROP TABLE t1
1756 --echo # Connection default
1758 --echo # This I_S query will cause the handler table to be closed and
1759 --echo # the metadata lock to be released. This will allow DROP TABLE
1760 --echo # to proceed. Waiting for the table to be removed.
1761 let $wait_condition=
1762 SELECT COUNT(*) = 0 FROM information_schema.tables WHERE table_name = "t1
";
1763 --source include/wait_condition.inc
1765 --echo # Connection con51355
1766 connection con51355;
1767 --echo # Reaping: DROP TABLE t1
1770 --echo # Connection default
1772 --error ER_NO_SUCH_TABLE
1773 HANDLER t1 READ id NEXT;
1774 # This caused an assertion
1775 --error ER_NO_SUCH_TABLE
1776 HANDLER t1 READ id NEXT;
1779 --echo # Connection con51355
1780 connection con51355;
1781 disconnect con51355;
1782 --source include/wait_until_disconnected.inc
1783 --echo # Connection default
1788 --echo # Bug#54401 assert in Diagnostics_area::set_eof_status , HANDLER
1792 DROP TABLE IF EXISTS t1, t2;
1793 DROP FUNCTION IF EXISTS f1;
1797 CREATE FUNCTION f1() RETURNS INTEGER
1799 SELECT 1 FROM t2 INTO @a;
1804 # Get f1() parsed and cached
1805 --error ER_NO_SUCH_TABLE
1808 CREATE TABLE t1(a INT);
1809 INSERT INTO t1 VALUES (1);
1811 # This used to cause the assert
1812 --error ER_NOT_SUPPORTED_YET
1813 HANDLER t1 READ FIRST WHERE f1() = 1;
1821 --echo # Bug#54920 Stored functions are allowed in HANDLER statements,
1822 --echo # but broken.
1826 DROP TABLE IF EXISTS t1;
1827 DROP FUNCTION IF EXISTS f1;
1830 CREATE TABLE t1 (a INT);
1831 INSERT INTO t1 VALUES (1), (2);
1832 CREATE FUNCTION f1() RETURNS INT RETURN 1;
1835 --error ER_NOT_SUPPORTED_YET
1836 HANDLER t1 READ FIRST WHERE f1() = 1;
1843 --echo # Bug#13008220 HANDLER SQL STATEMENT CAN MISS TO INITIALIZE
1844 --echo # FOR RANDOM READ
1846 --echo # A handler can only have one active 'cursor' at a time,
1847 --echo # so switching between index and/or random should restart the cursor.
1849 CREATE TABLE t1(a INT, b INT, KEY b(b), KEY ab(a, b));
1850 INSERT INTO t1 VALUES (2, 20), (1, 10), (4, 40), (3, 30);
1852 HANDLER t1 READ b FIRST;
1853 HANDLER t1 READ NEXT;
1854 HANDLER t1 READ NEXT;
1855 HANDLER t1 READ b FIRST;
1856 HANDLER t1 READ b NEXT;
1857 HANDLER t1 READ b NEXT;
1858 HANDLER t1 READ FIRST;
1859 HANDLER t1 READ b FIRST;
1860 HANDLER t1 READ NEXT;
1861 HANDLER t1 READ NEXT;
1862 HANDLER t1 READ NEXT;
1863 HANDLER t1 READ NEXT;
1864 HANDLER t1 READ NEXT;
1865 HANDLER t1 READ b NEXT;
1866 HANDLER t1 READ b NEXT;
1867 HANDLER t1 READ b NEXT;
1868 HANDLER t1 READ b NEXT;
1869 HANDLER t1 READ b NEXT;
1870 HANDLER t1 READ NEXT;
1871 HANDLER t1 READ b NEXT;
1872 HANDLER t1 READ FIRST;
1873 HANDLER t1 READ b PREV;
1874 HANDLER t1 READ b LAST;
1875 HANDLER t1 READ NEXT;
1876 HANDLER t1 READ ab FIRST;
1877 HANDLER t1 READ b NEXT;
1878 HANDLER t1 READ ab LAST;
1879 HANDLER t1 READ b PREV;