1 drop temporary table if exists t1, t2, t3;
2 drop table if exists t1, t2, t3;
3 drop procedure if exists p_verify_reprepare_count;
4 drop procedure if exists p1;
5 drop function if exists f1;
6 drop view if exists v1, v2;
7 create procedure p_verify_reprepare_count(expected int)
9 declare old_reprepare_count int default @reprepare_count;
10 select variable_value from
11 information_schema.session_status where
12 variable_name='com_stmt_reprepare'
13 into @reprepare_count;
14 if old_reprepare_count + expected <> @reprepare_count then
15 select concat("Expected: ", expected,
16 ", actual: ", @reprepare_count - old_reprepare_count)
19 select '' as "SUCCESS";
22 set @reprepare_count= 0;
24 =====================================================================
25 Part 1: NOTHING -> TABLE transitions
26 =====================================================================
27 prepare stmt from "select * from t1";
28 ERROR 42S02: Table 'test.t1' doesn't exist
29 =====================================================================
30 Part 2: NOTHING -> TEMPORARY TABLE transitions
31 =====================================================================
32 =====================================================================
33 Part 3: NOTHING -> VIEW transitions
34 =====================================================================
35 =====================================================================
36 Part 4: TABLE -> NOTHING transitions
37 =====================================================================
38 # Test 4-a: select ... from <table>
39 create table t1 (a int);
40 prepare stmt from "select * from t1";
43 call p_verify_reprepare_count(0);
48 call p_verify_reprepare_count(0);
53 ERROR 42S02: Table 'test.t1' doesn't exist
54 call p_verify_reprepare_count(0);
58 ERROR 42S02: Table 'test.t1' doesn't exist
59 call p_verify_reprepare_count(0);
62 deallocate prepare stmt;
63 # Test 4-b: TABLE -> NOTHING by renaming the table
64 create table t1 (a int);
65 prepare stmt from "select * from t1";
68 call p_verify_reprepare_count(0);
73 call p_verify_reprepare_count(0);
76 rename table t1 to t2;
78 ERROR 42S02: Table 'test.t1' doesn't exist
79 call p_verify_reprepare_count(0);
83 ERROR 42S02: Table 'test.t1' doesn't exist
84 call p_verify_reprepare_count(0);
87 deallocate prepare stmt;
89 =====================================================================
90 Part 5: TABLE -> TABLE (DDL) transitions
91 =====================================================================
92 create table t1 (a int);
93 prepare stmt from "select a from t1";
96 call p_verify_reprepare_count(0);
101 call p_verify_reprepare_count(0);
104 alter table t1 add column (b int);
107 call p_verify_reprepare_count(1);
112 call p_verify_reprepare_count(0);
116 deallocate prepare stmt;
117 =====================================================================
118 Part 6: TABLE -> TABLE (TRIGGER) transitions
119 =====================================================================
120 # Test 6-a: adding a relevant trigger
121 create table t1 (a int);
122 prepare stmt from "insert into t1 (a) value (?)";
124 execute stmt using @val;
125 call p_verify_reprepare_count(0);
128 create trigger t1_bi before insert on t1 for each row
131 execute stmt using @val;
132 call p_verify_reprepare_count(1);
139 execute stmt using @val;
140 call p_verify_reprepare_count(0);
146 prepare stmt from "insert into t1 (a) value (?)";
148 execute stmt using @val;
149 call p_verify_reprepare_count(0);
155 # Test 6-b: adding an irrelevant trigger
156 create trigger t1_bd before delete on t1 for each row
159 execute stmt using @val;
160 call p_verify_reprepare_count(1);
167 execute stmt using @val;
168 call p_verify_reprepare_count(0);
174 prepare stmt from "insert into t1 (a) value (?)";
176 execute stmt using @val;
177 call p_verify_reprepare_count(0);
183 # Test 6-c: changing a relevant trigger
185 create trigger t1_bi before insert on t1 for each row
186 set @message= concat("new trigger: ", new.a);
188 execute stmt using @val;
189 call p_verify_reprepare_count(1);
196 execute stmt using @val;
197 call p_verify_reprepare_count(0);
203 prepare stmt from "insert into t1 (a) value (?)";
205 execute stmt using @val;
206 call p_verify_reprepare_count(0);
212 # Test 6-d: changing an irrelevant trigger
215 execute stmt using @val;
216 call p_verify_reprepare_count(1);
222 Test 6-e: removing a relevant trigger
225 execute stmt using @val;
226 call p_verify_reprepare_count(1);
233 execute stmt using @val;
234 call p_verify_reprepare_count(0);
240 prepare stmt from "insert into t1 (a) value (?)";
242 execute stmt using @val;
243 call p_verify_reprepare_count(0);
249 select * from t1 order by a;
266 deallocate prepare stmt;
267 =====================================================================
268 Part 7: TABLE -> TABLE (TRIGGER dependencies) transitions
269 =====================================================================
270 # Test 7-a: dependent PROCEDURE has changed
272 # Note, this scenario is not supported, subject of Bug#12093
274 create table t1 (a int);
275 create trigger t1_ai after insert on t1 for each row
277 create procedure p1(a int) begin end;
278 prepare stmt from "insert into t1 (a) values (?)";
280 execute stmt using @var;
282 create procedure p1 (a int) begin end;
284 execute stmt using @var;
285 ERROR 42000: PROCEDURE test.p1 does not exist
288 call p_verify_reprepare_count(0);
291 # Test 7-b: dependent FUNCTION has changed
293 # Note, this scenario is supported, subject of Bug#12093
296 create trigger t1_ai after insert on t1 for each row
297 select f1(new.a+1) into @var;
298 create function f1 (a int) returns int return a;
299 prepare stmt from "insert into t1(a) values (?)";
301 execute stmt using @var;
306 create function f1 (a int) returns int return 0;
307 execute stmt using @var;
308 call p_verify_reprepare_count(1);
312 deallocate prepare stmt;
313 # Test 7-c: dependent VIEW has changed
315 # Note, this scenario is not functioning correctly, see
316 # Bug#33255 Trigger using views and view ddl : corrupted triggers
317 # and Bug #33000 Triggers do not detect changes in meta-data.
320 create table t2 (a int unique);
321 create table t3 (a int unique);
322 create view v1 as select a from t2;
323 create trigger t1_ai after insert on t1 for each row
324 insert into v1 (a) values (new.a);
325 # Demonstrate that the same bug is present
326 # without prepared statements
327 insert into t1 (a) values (5);
334 create view v1 as select a from t3;
335 insert into t1 (a) values (6);
336 ERROR 42S02: Table 'test.t2' doesn't exist
338 insert into t1 (a) values (6);
345 prepare stmt from "insert into t1 (a) values (?)";
347 execute stmt using @var;
348 call p_verify_reprepare_count(0);
359 create view v1 as select a from t2;
361 # XXX: bug, the SQL statement in the trigger is still
362 # pointing at table 't3', since the view was expanded
363 # at first statement execution.
364 # Repreparation of the main statement doesn't cause repreparation
365 # of trigger statements.
366 execute stmt using @var;
367 ERROR 42S02: Table 'test.t3' doesn't exist
368 call p_verify_reprepare_count(1);
372 # Sic: the insert went into t3, even though the view now
373 # points at t2. This is because neither the merged view
374 # nor its prelocking list are affected by view DDL
375 # The binary log is of course wrong, since it is not
376 # using prepared statements
387 execute stmt using @var;
388 call p_verify_reprepare_count(1);
401 # Test 7-d: dependent TABLE has changed
402 create table t1 (a int);
403 create trigger t1_ai after insert on t1 for each row
404 insert into t2 (a) values (new.a);
405 create table t2 (a int);
406 prepare stmt from "insert into t1 (a) values (?)";
408 execute stmt using @var;
409 alter table t2 add column comment varchar(255);
411 # Since the dependent table is tracked in the prelocked
412 # list of the prepared statement, invalidation happens
413 # and the statement is re-prepared. This is an unnecessary
414 # side effect, since the statement that *is* dependent
415 # on t2 definition is inside the trigger, and it is currently
416 # not reprepared (see the previous test case).
417 execute stmt using @var;
418 call p_verify_reprepare_count(1);
430 # Test 7-e: dependent TABLE TRIGGER has changed
431 create table t1 (a int);
432 create trigger t1_ai after insert on t1 for each row
433 insert into t2 (a) values (new.a);
434 create table t2 (a int unique);
435 create trigger t2_ai after insert on t2 for each row
436 insert into t3 (a) values (new.a);
437 create table t3 (a int unique);
438 create table t4 (a int unique);
439 insert into t1 (a) values (1);
440 select * from t1 join t2 on (t1.a=t2.a) join t3 on (t2.a=t3.a);
444 create trigger t2_ai after insert on t2 for each row
445 insert into t4 (a) values (new.a);
446 insert into t1 (a) values (2);
447 select * from t1 join t2 on (t1.a=t2.a) join t4 on (t2.a=t4.a);
450 prepare stmt from "insert into t1 (a) values (?)";
452 execute stmt using @var;
453 select * from t1 join t2 on (t1.a=t2.a) join t4 on (t2.a=t4.a);
458 create trigger t2_ai after insert on t2 for each row
459 insert into t3 (a) values (new.a);
461 execute stmt using @var;
462 call p_verify_reprepare_count(1);
465 select * from t1 join t2 on (t1.a=t2.a) join t3 on (t2.a=t3.a);
469 select * from t1 join t2 on (t1.a=t2.a) join t4 on (t2.a=t4.a);
473 drop table t1, t2, t3, t4;
474 deallocate prepare stmt;
475 =====================================================================
476 Part 8: TABLE -> TEMPORARY TABLE transitions
477 =====================================================================
478 # Test 8-a: base table used recreated as temporary table
479 create table t1 (a int);
480 prepare stmt from "select * from t1";
484 create temporary table t1 (a int);
487 call p_verify_reprepare_count(1);
492 call p_verify_reprepare_count(0);
496 deallocate prepare stmt;
497 # Test 8-b: temporary table has precedence over base table with same name
498 create table t1 (a int);
499 prepare stmt from 'select count(*) from t1';
503 call p_verify_reprepare_count(0);
509 call p_verify_reprepare_count(0);
512 create temporary table t1 AS SELECT 1;
516 call p_verify_reprepare_count(1);
522 call p_verify_reprepare_count(0);
525 deallocate prepare stmt;
526 drop temporary table t1;
528 =====================================================================
529 Part 9: TABLE -> VIEW transitions
530 =====================================================================
531 create table t1 (a int);
532 prepare stmt from "select * from t1";
535 call p_verify_reprepare_count(0);
539 create table t2 (a int);
540 create view t1 as select * from t2;
543 call p_verify_reprepare_count(1);
548 deallocate prepare stmt;
549 =====================================================================
550 Part 10: TEMPORARY TABLE -> NOTHING transitions
551 =====================================================================
552 create temporary table t1 (a int);
553 prepare stmt from "select * from t1";
556 call p_verify_reprepare_count(0);
559 drop temporary table t1;
561 ERROR 42S02: Table 'test.t1' doesn't exist
562 call p_verify_reprepare_count(0);
565 deallocate prepare stmt;
566 =====================================================================
567 Part 11: TEMPORARY TABLE -> TABLE transitions
568 =====================================================================
569 # Test 11-a: temporary table replaced by base table
570 create table t1 (a int);
571 insert into t1 (a) value (1);
572 create temporary table t1 (a int);
573 prepare stmt from "select * from t1";
576 call p_verify_reprepare_count(0);
579 drop temporary table t1;
583 call p_verify_reprepare_count(1);
590 deallocate prepare stmt;
591 # Test 11-b: temporary table has precedence over base table with same name
592 # temporary table disappears
593 create table t1 (a int);
594 create temporary table t1 as select 1 as a;
595 prepare stmt from "select count(*) from t1";
599 call p_verify_reprepare_count(0);
605 call p_verify_reprepare_count(0);
608 drop temporary table t1;
612 call p_verify_reprepare_count(1);
618 call p_verify_reprepare_count(0);
621 deallocate prepare stmt;
623 =====================================================================
624 Part 12: TEMPORARY TABLE -> TEMPORARY TABLE (DDL) transitions
625 =====================================================================
626 create temporary table t1 (a int);
627 prepare stmt from "select a from t1";
630 call p_verify_reprepare_count(0);
633 drop temporary table t1;
634 create temporary table t1 (a int, b int);
637 call p_verify_reprepare_count(1);
642 drop temporary table t1;
643 deallocate prepare stmt;
644 =====================================================================
645 Part 13: TEMPORARY TABLE -> VIEW transitions
646 =====================================================================
647 create temporary table t1 (a int);
648 create table t2 (a int);
649 prepare stmt from "select * from t1";
652 call p_verify_reprepare_count(0);
655 drop temporary table t1;
656 create view t1 as select * from t2;
659 call p_verify_reprepare_count(1);
664 deallocate prepare stmt;
665 =====================================================================
666 Part 14: VIEW -> NOTHING transitions
667 =====================================================================
668 create table t2 (a int);
669 create view t1 as select * from t2;
670 prepare stmt from "select * from t1";
675 ERROR 42S02: Table 'test.t1' doesn't exist
676 call p_verify_reprepare_count(0);
680 ERROR 42S02: Table 'test.t1' doesn't exist
681 call p_verify_reprepare_count(0);
685 deallocate prepare stmt;
686 =====================================================================
687 Part 15: VIEW -> TABLE transitions
688 =====================================================================
689 create table t2 (a int);
690 create view t1 as select * from t2;
691 prepare stmt from "select * from t1";
694 call p_verify_reprepare_count(0);
698 create table t1 (a int);
701 call p_verify_reprepare_count(1);
706 deallocate prepare stmt;
707 =====================================================================
708 Part 16: VIEW -> TEMPORARY TABLE transitions
709 =====================================================================
710 create table t2 (a int);
711 insert into t2 (a) values (1);
712 create view t1 as select * from t2;
713 prepare stmt from "select * from t1";
717 call p_verify_reprepare_count(0);
720 create temporary table t1 (a int);
723 call p_verify_reprepare_count(1);
729 call p_verify_reprepare_count(0);
733 drop temporary table t1;
734 deallocate prepare stmt;
735 =====================================================================
736 Part 17: VIEW -> VIEW (DDL) transitions
737 =====================================================================
738 create table t2 (a int);
739 insert into t2 values (10), (20), (30);
740 create view t1 as select a, 2*a as b, 3*a as c from t2;
746 prepare stmt from "select * from t1";
753 create view t1 as select a, 2*a as b, 5*a as c from t2;
759 # Currently a different result from conventional statements.
760 # A view is inlined once at prepare, later on view DDL
761 # does not affect prepared statement and it is not re-prepared.
762 # This is reported in Bug#36002 Prepared statements: if a view
763 # used in a statement is replaced, bad data
769 call p_verify_reprepare_count(0);
778 call p_verify_reprepare_count(1);
783 deallocate prepare stmt;
784 =====================================================================
785 Part 18: VIEW -> VIEW (VIEW dependencies) transitions
786 =====================================================================
787 # Part 18a: dependent function has changed
788 create table t1 (a int);
789 insert into t1 (a) values (1), (2), (3);
790 create function f1() returns int return (select max(a) from t1);
791 create view v1 as select f1();
792 prepare stmt from "select * from v1";
799 call p_verify_reprepare_count(0);
803 create function f1() returns int return 2;
804 # XXX: Used to be another manifestation of Bug#12093.
805 # We only used to get a different error
806 # message because the non-existing procedure error is masked
814 call p_verify_reprepare_count(1);
817 # Part 18b: dependent procedure has changed (referred to via a function)
818 create table t2 (a int);
819 insert into t2 (a) values (4), (5), (6);
821 create function f1() returns int
827 create procedure p1(out x int) select max(a) from t1 into x;
828 prepare stmt from "select * from v1";
835 call p_verify_reprepare_count(0);
839 create procedure p1(out x int) select max(a) from t2 into x;
840 # XXX: used to be a bug. The prelocked list was not invalidated
841 # and we kept opening table t1, whereas the procedure
842 # is now referring to table t2
846 call p_verify_reprepare_count(1);
853 call p_verify_reprepare_count(0);
859 # Test 18-c: dependent VIEW has changed
861 create view v2 as select a from t1;
862 create view v1 as select * from v2;
863 prepare stmt from "select * from v1";
874 call p_verify_reprepare_count(0);
878 create view v2 as select a from t2;
889 call p_verify_reprepare_count(0);
898 call p_verify_reprepare_count(1);
906 # Test 18-d: dependent TABLE has changed
908 create table v2 as select * from t1;
914 call p_verify_reprepare_count(1);
922 call p_verify_reprepare_count(0);
926 create table v2 (a int unique) as select * from t2;
932 call p_verify_reprepare_count(1);
940 call p_verify_reprepare_count(0);
943 # Test 18-e: dependent TABLE trigger has changed
944 prepare stmt from "insert into v1 (a) values (?)";
946 execute stmt using @var;
947 call p_verify_reprepare_count(0);
950 create trigger v2_bi before insert on v2 for each row set @message="v2_bi";
952 execute stmt using @var;
953 call p_verify_reprepare_count(1);
962 execute stmt using @var;
963 call p_verify_reprepare_count(1);
969 create trigger v2_bi after insert on v2 for each row set @message="v2_ai";
971 execute stmt using @var;
972 call p_verify_reprepare_count(1);
988 drop table if exists t1, t2, v1, v2;
989 drop view if exists v1, v2;
992 deallocate prepare stmt;
993 =====================================================================
994 Part 19: Special tables (INFORMATION_SCHEMA)
995 =====================================================================
997 "select ROUTINE_SCHEMA, ROUTINE_NAME, ROUTINE_TYPE
998 from INFORMATION_SCHEMA.ROUTINES where
1000 create procedure p1() select "hi there";
1002 ROUTINE_SCHEMA ROUTINE_NAME ROUTINE_TYPE
1005 ROUTINE_SCHEMA ROUTINE_NAME ROUTINE_TYPE
1008 create procedure p1() select "hi there, again";
1010 ROUTINE_SCHEMA ROUTINE_NAME ROUTINE_TYPE
1013 ROUTINE_SCHEMA ROUTINE_NAME ROUTINE_TYPE
1015 call p_verify_reprepare_count(0);
1019 deallocate prepare stmt;
1020 =====================================================================
1021 Part 20: Special tables (log tables)
1022 =====================================================================
1024 "select * from mysql.general_log where argument='IMPOSSIBLE QUERY STRING'";
1029 call p_verify_reprepare_count(0);
1032 deallocate prepare stmt;
1033 =====================================================================
1034 Part 21: Special tables (system tables)
1035 =====================================================================
1037 "select type, db, name from mysql.proc where name='p1'";
1038 create procedure p1() select "hi there";
1046 create procedure p1() select "hi there, again";
1053 call p_verify_reprepare_count(0);
1057 deallocate prepare stmt;
1058 =====================================================================
1059 Part 22: Special tables (views temp tables)
1060 =====================================================================
1061 create table t1 (a int);
1062 create algorithm=temptable view v1 as select a*a as a2 from t1;
1063 # Using a temporary table internally should not confuse the prepared
1064 # statement code, and should not raise ER_PS_INVALIDATED errors
1065 show create view v1;
1066 View Create View character_set_client collation_connection
1067 v1 CREATE ALGORITHM=TEMPTABLE DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select (`t1`.`a` * `t1`.`a`) AS `a2` from `t1` latin1 latin1_swedish_ci
1068 prepare stmt from "select * from v1";
1069 insert into t1 values (1), (2), (3);
1080 insert into t1 values (4), (5), (6);
1097 call p_verify_reprepare_count(0);
1102 =====================================================================
1103 Part 23: Special statements
1104 =====================================================================
1105 # SQLCOM_ALTER_TABLE:
1106 create table t1 (a int);
1107 prepare stmt from "alter table t1 add column b int";
1110 create table t1 (a1 int, a2 int);
1111 # t1 has changed, and it's does not lead to reprepare
1113 alter table t1 drop column b;
1115 alter table t1 drop column b;
1117 call p_verify_reprepare_count(0);
1122 create table t1 (a int);
1123 insert into t1 values (1), (2), (3);
1124 prepare stmt from "repair table t1";
1126 Table Op Msg_type Msg_text
1127 test.t1 repair status OK
1129 Table Op Msg_type Msg_text
1130 test.t1 repair status OK
1132 create table t1 (a1 int, a2 int);
1133 insert into t1 values (1, 10), (2, 20), (3, 30);
1134 # t1 has changed, and it's does not lead to reprepare
1136 Table Op Msg_type Msg_text
1137 test.t1 repair status OK
1138 alter table t1 add column b varchar(50) default NULL;
1140 Table Op Msg_type Msg_text
1141 test.t1 repair status OK
1142 call p_verify_reprepare_count(0);
1145 alter table t1 drop column b;
1147 Table Op Msg_type Msg_text
1148 test.t1 repair status OK
1149 call p_verify_reprepare_count(0);
1153 prepare stmt from "analyze table t1";
1155 Table Op Msg_type Msg_text
1156 test.t1 analyze status OK
1158 create table t1 (a1 int, a2 int);
1159 insert into t1 values (1, 10), (2, 20), (3, 30);
1160 # t1 has changed, and it's not a problem
1162 Table Op Msg_type Msg_text
1163 test.t1 analyze status OK
1164 alter table t1 add column b varchar(50) default NULL;
1166 Table Op Msg_type Msg_text
1167 test.t1 analyze status OK
1168 alter table t1 drop column b;
1170 Table Op Msg_type Msg_text
1171 test.t1 analyze status OK
1172 call p_verify_reprepare_count(0);
1176 prepare stmt from "optimize table t1";
1178 Table Op Msg_type Msg_text
1179 test.t1 optimize status Table is already up to date
1181 create table t1 (a1 int, a2 int);
1182 insert into t1 values (1, 10), (2, 20), (3, 30);
1183 # t1 has changed, and it's not a problem
1185 Table Op Msg_type Msg_text
1186 test.t1 optimize status OK
1187 alter table t1 add column b varchar(50) default NULL;
1189 Table Op Msg_type Msg_text
1190 test.t1 optimize status OK
1191 alter table t1 drop column b;
1193 Table Op Msg_type Msg_text
1194 test.t1 optimize status OK
1195 call p_verify_reprepare_count(0);
1199 # SQLCOM_SHOW_CREATE_PROC:
1200 prepare stmt from "show create procedure p1";
1202 ERROR 42000: PROCEDURE p1 does not exist
1204 ERROR 42000: PROCEDURE p1 does not exist
1205 create procedure p1() begin end;
1209 create procedure p1(x int, y int) begin end;
1214 ERROR 42000: PROCEDURE p1 does not exist
1216 ERROR 42000: PROCEDURE p1 does not exist
1217 call p_verify_reprepare_count(0);
1220 # SQLCOM_SHOW_CREATE_FUNC:
1221 prepare stmt from "show create function f1";
1223 ERROR 42000: FUNCTION f1 does not exist
1225 ERROR 42000: FUNCTION f1 does not exist
1226 create function f1() returns int return 0;
1230 create function f1(x int, y int) returns int return x+y;
1235 ERROR 42000: FUNCTION f1 does not exist
1237 ERROR 42000: FUNCTION f1 does not exist
1238 call p_verify_reprepare_count(0);
1241 # SQLCOM_SHOW_CREATE_TRIGGER:
1242 create table t1 (a int);
1243 prepare stmt from "show create trigger t1_bi";
1245 ERROR HY000: Trigger does not exist
1247 ERROR HY000: Trigger does not exist
1248 create trigger t1_bi before insert on t1 for each row set @message= "t1_bi";
1252 create trigger t1_bi before insert on t1 for each row set @message= "t1_bi (2)";
1257 ERROR HY000: Trigger does not exist
1259 ERROR HY000: Trigger does not exist
1260 call p_verify_reprepare_count(0);
1264 deallocate prepare stmt;
1265 =====================================================================
1266 Part 24: Testing the strength of TABLE_SHARE version
1267 =====================================================================
1268 # Test 24-a: number of columns
1269 create table t1 (a int);
1270 prepare stmt from "select a from t1";
1273 call p_verify_reprepare_count(0);
1276 alter table t1 add column b varchar(50) default NULL;
1279 call p_verify_reprepare_count(1);
1284 call p_verify_reprepare_count(0);
1287 # Test 24-b: column name
1288 alter table t1 change b c int;
1291 call p_verify_reprepare_count(1);
1296 call p_verify_reprepare_count(0);
1299 # Test 24-c: column type
1300 alter table t1 change a a varchar(10);
1303 call p_verify_reprepare_count(1);
1308 call p_verify_reprepare_count(0);
1311 # Test 24-d: column type length
1312 alter table t1 change a a varchar(20);
1315 call p_verify_reprepare_count(1);
1320 call p_verify_reprepare_count(0);
1323 # Test 24-e: column NULL property
1324 alter table t1 change a a varchar(20) NOT NULL;
1327 call p_verify_reprepare_count(1);
1332 call p_verify_reprepare_count(0);
1335 # Test 24-f: column DEFAULT
1336 alter table t1 change c c int DEFAULT 20;
1339 call p_verify_reprepare_count(1);
1344 call p_verify_reprepare_count(0);
1347 # Test 24-g: number of keys
1348 create unique index t1_a_idx on t1 (a);
1351 call p_verify_reprepare_count(1);
1356 call p_verify_reprepare_count(0);
1359 # Test 24-h: changing index uniqueness
1360 drop index t1_a_idx on t1;
1361 create index t1_a_idx on t1 (a);
1364 call p_verify_reprepare_count(1);
1369 call p_verify_reprepare_count(0);
1374 deallocate prepare stmt;
1375 =====================================================================
1376 Testing reported bugs
1377 =====================================================================
1379 # Bug#27420 A combination of PS and view operations cause
1380 # error + assertion on shutdown
1382 drop table if exists t_27420_100;
1383 drop table if exists t_27420_101;
1384 drop view if exists v_27420;
1385 create table t_27420_100(a int);
1386 insert into t_27420_100 values (1), (2);
1387 create table t_27420_101(a int);
1388 insert into t_27420_101 values (1), (2);
1389 create view v_27420 as select t_27420_100.a X, t_27420_101.a Y
1390 from t_27420_100, t_27420_101
1391 where t_27420_100.a=t_27420_101.a;
1392 prepare stmt from "select * from v_27420";
1397 call p_verify_reprepare_count(0);
1401 create table v_27420(X int, Y int);
1404 call p_verify_reprepare_count(1);
1408 create table v_27420 (a int, b int, filler char(200));
1411 call p_verify_reprepare_count(1);
1414 drop table t_27420_100;
1415 drop table t_27420_101;
1417 deallocate prepare stmt;
1419 # Bug#27430 Crash in subquery code when in PS and table DDL changed
1422 drop table if exists t_27430_1;
1423 drop table if exists t_27430_2;
1424 create table t_27430_1 (a int not null, oref int not null, key(a));
1425 insert into t_27430_1 values
1431 create table t_27430_2 (a int not null, oref int not null);
1432 insert into t_27430_2 values
1438 "select oref, a, a in (select a from t_27430_1 where oref=t_27430_2.oref) Z from t_27430_2";
1445 call p_verify_reprepare_count(0);
1448 drop table t_27430_1, t_27430_2;
1449 create table t_27430_1 (a int, oref int, key(a));
1450 insert into t_27430_1 values
1456 create table t_27430_2 (a int, oref int);
1457 insert into t_27430_2 values
1468 call p_verify_reprepare_count(1);
1471 drop table t_27430_1;
1472 drop table t_27430_2;
1473 deallocate prepare stmt;
1475 # Bug#27690 Re-execution of prepared statement after table
1476 # was replaced with a view crashes
1478 drop table if exists t_27690_1;
1479 drop view if exists v_27690_1;
1480 drop table if exists v_27690_2;
1481 create table t_27690_1 (a int, b int);
1482 insert into t_27690_1 values (1,1),(2,2);
1483 create table v_27690_1 as select * from t_27690_1;
1484 create table v_27690_2 as select * from t_27690_1;
1485 prepare stmt from "select * from v_27690_1, v_27690_2";
1498 drop table v_27690_1;
1500 ERROR 42S02: Table 'test.v_27690_1' doesn't exist
1502 ERROR 42S02: Table 'test.v_27690_1' doesn't exist
1503 call p_verify_reprepare_count(0);
1506 create view v_27690_1 as select A.a, A.b from t_27690_1 A, t_27690_1 B;
1517 call p_verify_reprepare_count(1);
1530 call p_verify_reprepare_count(0);
1533 drop table t_27690_1;
1534 drop view v_27690_1;
1535 drop table v_27690_2;
1536 deallocate prepare stmt;
1537 #=====================================================================
1539 # Bug#21294 Executing a prepared statement that executes
1540 # a stored function which was recreat
1542 create function f1() returns int return 10;
1543 prepare stmt from "select f1()";
1548 create function f1() returns int return 10;
1553 create function f1() returns int return 20;
1557 call p_verify_reprepare_count(2);
1561 deallocate prepare stmt;
1563 # Bug#12093 SP not found on second PS execution if another thread drops
1564 # other SP in between
1566 drop table if exists t_12093;
1567 drop function if exists f_12093;
1568 drop function if exists f_12093_unrelated;
1569 drop procedure if exists p_12093;
1570 drop view if exists v_12093_unrelated;
1571 create table t_12093 (a int);
1572 create function f_12093() returns int return (select count(*) from t_12093);
1573 create procedure p_12093(a int) select * from t_12093;
1574 create function f_12093_unrelated() returns int return 2;
1575 create procedure p_12093_unrelated() begin end;
1576 create view v_12093_unrelated as select * from t_12093;
1577 prepare stmt_sf from 'select f_12093();';
1578 prepare stmt_sp from 'call p_12093(f_12093())';
1584 drop function f_12093_unrelated;
1585 # XXX: used to be a bug
1589 # XXX: used to be a bug
1592 # XXX: used to be a bug
1596 # XXX: used to be a bug
1599 prepare stmt_sf from 'select f_12093();';
1600 prepare stmt_sp from 'call p_12093(f_12093())';
1606 drop procedure p_12093_unrelated;
1607 # XXX: used to be a bug
1611 # XXX: used to be a bug
1614 # XXX: used to be a bug
1618 # XXX: used to be a bug
1621 prepare stmt_sf from 'select f_12093();';
1622 prepare stmt_sp from 'call p_12093(f_12093())';
1628 drop view v_12093_unrelated;
1629 # XXX: used to be a bug
1633 # XXX: used to be a bug
1636 # XXX: used to be a bug
1640 # XXX: used to be a bug
1643 call p_verify_reprepare_count(6);
1647 drop function f_12093;
1648 drop procedure p_12093;
1649 deallocate prepare stmt_sf;
1650 deallocate prepare stmt_sp;
1651 =====================================================================
1652 Ensure that metadata validation is performed for every type of
1653 SQL statement where it is needed.
1654 =====================================================================
1658 drop table if exists t1;
1659 create table t1 (a int);
1660 prepare stmt from "select 1 as res from dual where (1) in (select * from t1)";
1662 create table t1 (x int);
1666 deallocate prepare stmt;
1667 call p_verify_reprepare_count(1);
1671 # SQLCOM_CREATE_TABLE
1673 drop table if exists t1;
1674 drop table if exists t2;
1675 create table t1 (a int);
1676 prepare stmt from 'create table t2 as select * from t1';
1682 call p_verify_reprepare_count(0);
1686 ERROR 42S01: Table 't2' already exists
1687 call p_verify_reprepare_count(1);
1691 ERROR 42S01: Table 't2' already exists
1692 call p_verify_reprepare_count(0);
1696 create temporary table t2 (a int);
1698 call p_verify_reprepare_count(1);
1702 ERROR 42S01: Table 't2' already exists
1703 call p_verify_reprepare_count(1);
1706 drop temporary table t2;
1708 ERROR 42S01: Table 't2' already exists
1709 call p_verify_reprepare_count(0);
1714 call p_verify_reprepare_count(1);
1718 create view t2 as select 1;
1720 Got one of the listed errors
1721 call p_verify_reprepare_count(1);
1725 Got one of the listed errors
1726 call p_verify_reprepare_count(0);
1731 create table t1 (x varchar(20));
1733 call p_verify_reprepare_count(1);
1740 call p_verify_reprepare_count(0);
1744 alter table t1 add column y decimal(10,3);
1746 call p_verify_reprepare_count(1);
1753 call p_verify_reprepare_count(0);
1757 deallocate prepare stmt;
1758 # XXX: no validation of the first table in case of
1759 # CREATE TEMPORARY TABLE. This is a shortcoming of the current code,
1760 # but since validation is not strictly necessary, nothing is done
1762 # Will be fixed as part of work on Bug#21431 "Incomplete support of
1764 create table t1 (a int);
1765 insert into t1 (a) values (1);
1766 prepare stmt from "create temporary table if not exists t2 as select * from t1";
1772 Note 1050 Table 't2' already exists
1779 Note 1050 Table 't2' already exists
1786 create temporary table t2 (a varchar(10));
1789 Note 1050 Table 't2' already exists
1793 call p_verify_reprepare_count(0);
1797 create table t1 (x int);
1800 Note 1050 Table 't2' already exists
1801 call p_verify_reprepare_count(1);
1806 Note 1050 Table 't2' already exists
1807 call p_verify_reprepare_count(0);
1811 drop temporary table t2;
1813 deallocate prepare stmt;
1814 create table t1 (a int);
1815 prepare stmt from "create table t2 like t1";
1817 call p_verify_reprepare_count(0);
1822 call p_verify_reprepare_count(0);
1828 ERROR 42S02: Table 'test.t1' doesn't exist
1829 call p_verify_reprepare_count(0);
1833 ERROR 42S02: Table 'test.t1' doesn't exist
1834 call p_verify_reprepare_count(0);
1837 create table t1 (x char(17));
1839 call p_verify_reprepare_count(1);
1844 call p_verify_reprepare_count(0);
1848 alter table t1 add column y time;
1850 call p_verify_reprepare_count(1);
1857 call p_verify_reprepare_count(0);
1862 deallocate prepare stmt;
1866 drop table if exists t1, t2;
1867 create table t1 (a int);
1868 create table t2 (a int);
1869 prepare stmt from "update t2 set a=a+1 where (1) in (select * from t1)";
1872 create table t1 (x int);
1875 deallocate prepare stmt;
1879 drop table if exists t1, t2;
1880 create table t1 (a int);
1881 create table t2 (a int);
1882 prepare stmt from "insert into t2 set a=((1) in (select * from t1))";
1885 create table t1 (x int);
1888 deallocate prepare stmt;
1890 # SQLCOM_INSERT_SELECT
1892 drop table if exists t1, t2;
1893 create table t1 (a int);
1894 create table t2 (a int);
1895 prepare stmt from "insert into t2 select * from t1";
1898 create table t1 (x int);
1901 deallocate prepare stmt;
1905 drop table if exists t1, t2;
1906 create table t1 (a int);
1907 create table t2 (a int);
1908 prepare stmt from "replace t2 set a=((1) in (select * from t1))";
1911 create table t1 (x int);
1914 deallocate prepare stmt;
1916 # SQLCOM_REPLACE_SELECT
1918 drop table if exists t1, t2;
1919 create table t1 (a int);
1920 create table t2 (a int);
1921 prepare stmt from "replace t2 select * from t1";
1924 create table t1 (x int);
1927 deallocate prepare stmt;
1931 drop table if exists t1, t2;
1932 create table t1 (a int);
1933 create table t2 (a int);
1934 prepare stmt from "delete from t2 where (1) in (select * from t1)";
1937 create table t1 (x int);
1940 deallocate prepare stmt;
1942 # SQLCOM_DELETE_MULTI
1944 drop table if exists t1, t2, t3;
1945 create table t1 (a int);
1946 create table t2 (a int);
1947 create table t3 (a int);
1948 prepare stmt from "delete t2, t3 from t2, t3 where (1) in (select * from t1)";
1951 create table t1 (x int);
1953 drop table t1, t2, t3;
1954 deallocate prepare stmt;
1956 # SQLCOM_UPDATE_MULTI
1958 drop table if exists t1, t2, t3;
1959 create table t1 (a int);
1960 create table t2 (a int);
1961 create table t3 (a int);
1962 prepare stmt from "update t2, t3 set t3.a=t2.a, t2.a=null where (1) in (select * from t1)";
1964 create table t1 (x int);
1966 drop table t1, t2, t3;
1967 deallocate prepare stmt;
1968 # Intermediate results: 8 SQLCOMs tested, 8 automatic reprepares
1969 call p_verify_reprepare_count(8);
1975 drop table if exists t1;
1976 create table t1 (a varchar(20));
1977 prepare stmt from "load data infile '../std_data_ln/words.dat' into table t1";
1978 ERROR HY000: This command is not supported in the prepared statement protocol yet
1981 # SQLCOM_SHOW_DATABASES
1983 drop table if exists t1;
1984 create table t1 (a int);
1985 prepare stmt from "show databases where (1) in (select * from t1)";
1989 create table t1 (x int);
1993 deallocate prepare stmt;
1995 # SQLCOM_SHOW_TABLES
1997 drop table if exists t1;
1998 create table t1 (a int);
1999 prepare stmt from "show tables where (1) in (select * from t1)";
2003 create table t1 (x int);
2007 deallocate prepare stmt;
2009 # SQLCOM_SHOW_FIELDS
2011 drop table if exists t1;
2012 create table t1 (a int);
2013 prepare stmt from "show fields from t1 where (1) in (select * from t1)";
2015 Field Type Null Key Default Extra
2017 create table t1 (x int);
2019 Field Type Null Key Default Extra
2021 deallocate prepare stmt;
2025 drop table if exists t1;
2026 create table t1 (a int);
2027 prepare stmt from "show keys from t1 where (1) in (select * from t1)";
2029 Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
2031 create table t1 (x int);
2033 Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment
2035 deallocate prepare stmt;
2037 # SQLCOM_SHOW_VARIABLES
2039 drop table if exists t1;
2040 create table t1 (a int);
2041 prepare stmt from "show variables where (1) in (select * from t1)";
2045 create table t1 (x int);
2049 deallocate prepare stmt;
2051 # SQLCOM_SHOW_STATUS
2053 drop table if exists t1;
2054 create table t1 (a int);
2055 prepare stmt from "show status where (1) in (select * from t1)";
2059 create table t1 (x int);
2063 deallocate prepare stmt;
2065 # SQLCOM_SHOW_ENGINE_STATUS, SQLCOM_SHOW_ENGINE_LOGS,
2066 # SQLCOM_SHOW_ENGINE_MUTEX, SQLCOM_SHOW_PROCESSLIST
2068 # Currently can not have a where clause, need to be covered
2070 drop table if exists t1;
2071 create table t1 (a int);
2072 prepare stmt from "show engine all status where (1) in (select * from t1)";
2073 ERROR 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 'where (1) in (select * from t1)' at line 1
2074 prepare stmt from "show engine all logs where (1) in (select * from t1)";
2075 ERROR 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 'where (1) in (select * from t1)' at line 1
2076 prepare stmt from "show engine all mutex where (1) in (select * from t1)";
2077 ERROR 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 'where (1) in (select * from t1)' at line 1
2078 prepare stmt from "show processlist where (1) in (select * from t1)";
2079 ERROR 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 'where (1) in (select * from t1)' at line 1
2082 # SQLCOM_SHOW_CHARSETS
2084 drop table if exists t1;
2085 create table t1 (a int);
2086 prepare stmt from "show charset where (1) in (select * from t1)";
2088 Charset Description Default collation Maxlen
2090 create table t1 (x int);
2092 Charset Description Default collation Maxlen
2094 deallocate prepare stmt;
2096 # SQLCOM_SHOW_COLLATIONS
2098 drop table if exists t1;
2099 create table t1 (a int);
2100 prepare stmt from "show collation where (1) in (select * from t1)";
2102 Collation Charset Id Default Compiled Sortlen
2104 create table t1 (x int);
2106 Collation Charset Id Default Compiled Sortlen
2108 deallocate prepare stmt;
2110 # SQLCOM_SHOW_TABLE_STATUS
2112 drop table if exists t1;
2113 create table t1 (a int);
2114 prepare stmt from "show table status where (1) in (select * from t1)";
2116 Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
2118 create table t1 (x int);
2120 Name Engine Version Row_format Rows Avg_row_length Data_length Max_data_length Index_length Data_free Auto_increment Create_time Update_time Check_time Collation Checksum Create_options Comment
2122 deallocate prepare stmt;
2124 # SQLCOM_SHOW_TRIGGERS
2126 drop table if exists t1;
2127 create table t1 (a int);
2128 prepare stmt from "show triggers where (1) in (select * from t1)";
2130 Trigger Event Table Statement Timing Created sql_mode Definer character_set_client collation_connection Database Collation
2132 create table t1 (x int);
2134 Trigger Event Table Statement Timing Created sql_mode Definer character_set_client collation_connection Database Collation
2136 deallocate prepare stmt;
2138 # SQLCOM_SHOW_OPEN_TABLES
2140 drop table if exists t1;
2141 create table t1 (a int);
2142 prepare stmt from "show open tables where (1) in (select * from t1)";
2144 Database Table In_use Name_locked
2146 create table t1 (x int);
2148 Database Table In_use Name_locked
2150 deallocate prepare stmt;
2152 # SQLCOM_SHOW_STATUS_PROC
2154 drop table if exists t1;
2155 create table t1 (a int);
2156 prepare stmt from "show procedure status where (1) in (select * from t1)";
2158 Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation
2160 create table t1 (x int);
2162 Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation
2164 deallocate prepare stmt;
2166 # SQLCOM_SHOW_STATUS_FUNC
2168 drop table if exists t1;
2169 create table t1 (a int);
2170 prepare stmt from "show function status where (1) in (select * from t1)";
2172 Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation
2174 create table t1 (x int);
2176 Db Name Type Definer Modified Created Security_type Comment character_set_client collation_connection Database Collation
2178 deallocate prepare stmt;
2180 # SQLCOM_SHOW_EVENTS
2183 # Please see this test in ps.test, it requires not_embedded.inc
2188 drop table if exists t1;
2189 create table t1 (a int);
2190 prepare stmt from "set @a=((1) in (select * from t1))";
2193 create table t1 (x int);
2196 deallocate prepare stmt;
2200 drop table if exists t1;
2201 create table t1 (a int);
2202 prepare stmt from "do ((1) in (select * from t1))";
2205 create table t1 (x int);
2208 deallocate prepare stmt;
2212 drop table if exists t1;
2213 drop procedure if exists p1;
2214 create procedure p1(a int) begin end;
2215 create table t1 (a int);
2216 prepare stmt from "call p1((1) in (select * from t1))";
2219 create table t1 (x int);
2223 deallocate prepare stmt;
2225 # SQLCOM_CREATE_VIEW
2227 drop table if exists t1;
2228 drop view if exists v1;
2229 create table t1 (a int);
2230 prepare stmt from "create view v1 as select * from t1";
2234 create table t1 (x int);
2238 deallocate prepare stmt;
2239 # Intermediate result: number of reprepares matches the number
2241 call p_verify_reprepare_count(17);
2247 drop view if exists v1;
2248 create view v1 as select 1;
2249 prepare stmt from "alter view v1 as select 2";
2250 ERROR HY000: This command is not supported in the prepared statement protocol yet
2254 drop temporary table if exists t1, t2, t3;
2255 drop table if exists t1, t2, t3, v1, v2;
2256 drop procedure if exists p_verify_reprepare_count;
2257 drop procedure if exists p1;
2258 drop function if exists f1;
2259 drop view if exists v1, v2;