summaryrefslogtreecommitdiff
path: root/mysql-test/t/ps_ddl.test
blob: c824d17063badd8811384441743b1911cd61bf95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
#
# Testing the behavior of 'PREPARE', 'DDL', 'EXECUTE' scenarios
#
# Background:
# In a statement like "select * from t1", t1 can be:
# - nothing (the table does not exist)
# - a real table
# - a temporary table
# - a view
#
# Changing the nature of "t1" between a PREPARE and an EXECUTE
# can invalidate the internal state of a prepared statement, so that,
# during the execute, the server should:
# - detect state changes and fail to execute a statement,
#   instead of crashing the server or returning wrong results
# - "RE-PREPARE" the statement to restore a valid internal state.
#
# Also, changing the physical structure of "t1", by:
# - changing the definition of t1 itself (DDL on tables, views)
# - changing TRIGGERs associated with a table
# - changing PROCEDURE, FUNCTION referenced by a TRIGGER body,
# - changing PROCEDURE, FUNCTION referenced by a VIEW body,
# impacts the internal structure of a prepared statement, and should
# cause the same verifications at execute time to be performed.
#
# This test provided in this file cover the different state transitions
# between a PREPARE and an EXECUTE, and are organized as follows:
# - Part  1: NOTHING -> TABLE
# - Part  2: NOTHING -> TEMPORARY TABLE
# - Part  3: NOTHING -> VIEW
# - Part  4: TABLE -> NOTHING
# - Part  5: TABLE -> TABLE (DDL)
# - Part  6: TABLE -> TABLE (TRIGGER)
# - Part  7: TABLE -> TABLE (TRIGGER dependencies)
# - Part  8: TABLE -> TEMPORARY TABLE
# - Part  9: TABLE -> VIEW
# - Part 10: TEMPORARY TABLE -> NOTHING
# - Part 11: TEMPORARY TABLE -> TABLE
# - Part 12: TEMPORARY TABLE -> TEMPORARY TABLE (DDL)
# - Part 13: TEMPORARY TABLE -> VIEW
# - Part 14: VIEW -> NOTHING
# - Part 15: VIEW -> TABLE
# - Part 16: VIEW -> TEMPORARY TABLE
# - Part 17: VIEW -> VIEW (DDL)
# - Part 18: VIEW -> VIEW (VIEW dependencies)
# - Part 19: Special tables (INFORMATION_SCHEMA)
# - Part 20: Special tables (log tables)
# - Part 21: Special tables (system tables)
# - Part 22: Special tables (views temp tables)
# - Part 23: Special tables (internal join tables)
# - Part 24: Special statements
# - Part 25: Testing the strength of TABLE_SHARE version

let $base_count = SELECT VARIABLE_VALUE from
INFORMATION_SCHEMA.SESSION_STATUS where variable_name='COM_STMT_REPREPARE'
into @base_count ;

let $check = SELECT CASE (VARIABLE_VALUE - @base_count - @expected)
  WHEN 0 THEN "PASSED"
  ELSE "FAILED"
  END
 AS `CHECK`, 
 (VARIABLE_VALUE - @base_count - @expected) AS `OFFSET`
 from INFORMATION_SCHEMA.SESSION_STATUS
 where variable_name='COM_STMT_REPREPARE' ;

eval $base_count;
set @expected = 0;

# Maintainer:
# When not expecting a re-prepare, write the test like this:
#   execute stmt;
#   eval $check;
#
# When expecting a re-prepare, write the test like this:
#   set @expected = @expected + 1;
#   execute stmt;
#   eval $check;
#

--echo =====================================================================
--echo Testing 1: NOTHING -> TABLE transitions
--echo =====================================================================

--disable_warnings
drop table if exists t1;
--enable_warnings

# can not be tested since prepare failed
--error ER_NO_SUCH_TABLE
prepare stmt from 'select * from t1';

--echo =====================================================================
--echo Testing 2: NOTHING -> TEMPORARY TABLE transitions
--echo =====================================================================

# can not be tested

--echo =====================================================================
--echo Testing 3: NOTHING -> VIEW transitions
--echo =====================================================================

# can not be tested

--echo =====================================================================
--echo Testing 4: TABLE -> NOTHING transitions
--echo =====================================================================

--disable_warnings
drop table if exists t4;
--enable_warnings

create table t4(a int);

prepare stmt from 'select * from t4';
execute stmt;
eval $check;
execute stmt;
eval $check;

drop table t4;
--error ER_NO_SUCH_TABLE
execute stmt;
eval $check;
--error ER_NO_SUCH_TABLE
execute stmt;
eval $check;

--echo =====================================================================
--echo Testing 5: TABLE -> TABLE (DDL) transitions
--echo =====================================================================

--disable_warnings
drop table if exists t5;
--enable_warnings

create table t5(a int);

prepare stmt from 'select a from t5';
execute stmt;
eval $check;
execute stmt;
eval $check;

alter table t5 add column (b int);

set @expected = @expected + 1;
execute stmt;
eval $check;
execute stmt;
eval $check;

drop table t5;

--echo =====================================================================
--echo Testing 6: TABLE -> TABLE (TRIGGER) transitions
--echo =====================================================================

#
# Test 6-a: adding a relevant trigger
# Test 6-b: adding an irrelevant trigger
# Test 6-c: changing a relevant trigger
# Test 6-d: changing an irrelevant trigger
# Test 6-e: removing a relevant trigger
# Test 6-f: removing an irrelevant trigger
#

--disable_warnings
drop table if exists t6;
--enable_warnings

create table t6(a int);

prepare stmt from 'insert into t6(a) value (?)';
set @val=1;
execute stmt using @val;
eval $check;
set @val=2;
execute stmt using @val;
eval $check;

# Relevant trigger: execute should reprepare
delimiter $$;
create trigger t6_bi before insert on t6 for each row
  begin
    set @message= "t6_bi";
  end
$$
delimiter ;$$

set @message="none";
set @val=3;
set @expected = @expected + 1;
execute stmt using @val;
eval $check;
select @message;
set @val=4;
execute stmt using @val;
eval $check;
select @message;

prepare stmt from 'insert into t6(a) value (?)';
set @message="none";
set @val=5;
execute stmt using @val;
eval $check;
select @message;
set @message="none";
set @val=6;
execute stmt using @val;
eval $check;
select @message;

# Unrelated trigger: execute can pass of fail, implementation dependent
delimiter $$;
create trigger t6_bd before delete on t6 for each row
  begin
    set @message= "t6_bd";
  end
$$
delimiter ;$$

set @message="none";
set @val=7;
set @expected = @expected + 1;
execute stmt using @val;
eval $check;
select @message;
set @message="none";
set @val=8;
execute stmt using @val;
eval $check;
select @message;

prepare stmt from 'insert into t6(a) value (?)';
set @message="none";
set @val=9;
execute stmt using @val;
eval $check;
select @message;
set @message="none";
set @val=10;
execute stmt using @val;
eval $check;
select @message;

# Relevant trigger: execute should reprepare
drop trigger t6_bi;
delimiter $$;
create trigger t6_bi before insert on t6 for each row
  begin
    set @message= "t6_bi (2)";
  end
$$
delimiter ;$$

set @message="none";
set @val=11;
set @expected = @expected + 1;
execute stmt using @val;
eval $check;
select @message;
set @val=12;
execute stmt using @val;
eval $check;
select @message;

prepare stmt from 'insert into t6(a) value (?)';
set @message="none";
set @val=13;
execute stmt using @val;
eval $check;
select @message;
set @message="none";
set @val=14;
execute stmt using @val;
eval $check;
select @message;

# Unrelated trigger: execute can pass of fail, implementation dependent
drop trigger t6_bd;
delimiter $$;
create trigger t6_bd before delete on t6 for each row
  begin
    set @message= "t6_bd (2)";
  end
$$
delimiter ;$$

set @message="none";
set @val=15;
set @expected = @expected + 1;
execute stmt using @val;
eval $check;
select @message;
set @message="none";
set @val=16;
execute stmt using @val;
eval $check;
select @message;

prepare stmt from 'insert into t6(a) value (?)';
set @message="none";
set @val=17;
execute stmt using @val;
eval $check;
select @message;
set @message="none";
set @val=18;
execute stmt using @val;
eval $check;
select @message;

drop trigger t6_bi;

set @message="none";
set @val=19;
set @expected = @expected + 1;
execute stmt using @val;
eval $check;
select @message;
set @val=20;
execute stmt using @val;
eval $check;
select @message;

prepare stmt from 'insert into t6(a) value (?)';
set @message="none";
set @val=21;
execute stmt using @val;
eval $check;
select @message;
set @val=22;
execute stmt using @val;
eval $check;
select @message;

drop trigger t6_bd;

set @val=23;
set @expected = @expected + 1;
execute stmt using @val;
eval $check;
select @message;
set @val=24;
execute stmt using @val;
eval $check;
select @message;

select * from t6 order by a;
drop table t6;

--echo =====================================================================
--echo Testing 7: TABLE -> TABLE (TRIGGER dependencies) transitions
--echo =====================================================================

#
# Test 7-a: dependent PROCEDURE has changed
# Test 7-b: dependent FUNCTION has changed
# Test 7-c: dependent VIEW has changed
# Test 7-d: dependent TABLE has changed
# Test 7-e: dependent TABLE TRIGGER has changed
#

--disable_warnings
drop table if exists t7_proc;
drop table if exists t7_func;
drop table if exists t7_view;
drop table if exists t7_table;
drop table if exists t7_dependent_table;
drop table if exists t7_table_trigger;
drop table if exists t7_audit;
drop procedure if exists audit_proc;
drop function if exists audit_func;
drop view if exists audit_view;
--enable_warnings

create table t7_proc(a int);
create table t7_func(a int);
create table t7_view(a int);
create table t7_table(a int);
create table t7_table_trigger(a int);

create table t7_audit(old_a int, new_a int, reason varchar(50));
create table t7_dependent_table(old_a int, new_a int, reason varchar(50));

create procedure audit_proc(a int)
  insert into t7_audit values (NULL, a, "proc v1");

create function audit_func() returns varchar(50)
  return "func v1";

create view audit_view as select "view v1" as reason from dual;

create trigger t7_proc_bi before insert on t7_proc for each row
  call audit_proc(NEW.a);

create trigger t7_func_bi before insert on t7_func for each row
  insert into t7_audit values (NULL, NEW.a, audit_func());

create trigger t7_view_bi before insert on t7_view for each row
  insert into t7_audit values (NULL, NEW.a, (select reason from audit_view));

create trigger t7_table_bi before insert on t7_table for each row
  insert into t7_dependent_table values (NULL, NEW.a, "dependent table");

create trigger t7_table_trigger_bi before insert on t7_dependent_table
  for each row set NEW.reason="trigger v1";

prepare stmt_proc from 'insert into t7_proc(a) value (?)';
set @val=101;
execute stmt_proc using @val;
eval $check;
set @val=102;
execute stmt_proc using @val;
eval $check;

drop procedure audit_proc;

create procedure audit_proc(a int)
  insert into t7_audit values (NULL, a, "proc v2");

set @val=103;
set @expected = @expected + 1;
execute stmt_proc using @val;
eval $check;
set @val=104;
execute stmt_proc using @val;
eval $check;


prepare stmt_func from 'insert into t7_func(a) value (?)';
set @val=201;
execute stmt_func using @val;
eval $check;
set @val=202;
execute stmt_func using @val;
eval $check;

drop function audit_func;

create function audit_func() returns varchar(50)
  return "func v2";

set @val=203;
set @expected = @expected + 1;
execute stmt_func using @val;
eval $check;
set @val=204;
execute stmt_func using @val;
eval $check;

prepare stmt_view from 'insert into t7_view(a) value (?)';
set @val=301;
execute stmt_view using @val;
eval $check;
set @val=302;
execute stmt_view using @val;
eval $check;

drop view audit_view;

create view audit_view as select "view v2" as reason from dual;

# Because of Bug#33255, the wrong result is still produced for cases
# 303 and 304, even after re-preparing the statement.
# This is because the table trigger is cached and is not invalidated.

set @val=303;
set @expected = @expected + 1;
execute stmt_view using @val;
eval $check;
set @val=304;
execute stmt_view using @val;
eval $check;


prepare stmt_table from 'insert into t7_table(a) value (?)';
set @val=401;
execute stmt_table using @val;
eval $check;
set @val=402;
execute stmt_table using @val;
eval $check;

alter table t7_dependent_table add column comments varchar(100) default NULL;

set @val=403;
set @expected = @expected + 1;
--error ER_WRONG_VALUE_COUNT_ON_ROW
execute stmt_table using @val;
eval $check;
set @val=404;
set @expected = @expected + 1;
--error ER_WRONG_VALUE_COUNT_ON_ROW
execute stmt_table using @val;
eval $check;

alter table t7_dependent_table drop column comments;

set @val=405;
set @expected = @expected + 1;
execute stmt_table using @val;
eval $check;
set @val=406;
execute stmt_table using @val;
eval $check;


prepare stmt_table_trigger from 'insert into t7_table(a) value (?)';
set @val=501;
execute stmt_table_trigger using @val;
eval $check;
set @val=502;
execute stmt_table_trigger using @val;
eval $check;

drop trigger t7_table_trigger_bi;

create trigger t7_table_trigger_bi before insert on t7_dependent_table
  for each row set NEW.reason="trigger v2";

set @val=503;
set @expected = @expected + 1;
execute stmt_table_trigger using @val;
eval $check;
set @val=504;
execute stmt_table_trigger using @val;
eval $check;

select * from t7_audit order by new_a;

select * from t7_dependent_table order by new_a;

drop table t7_proc;
drop table t7_func;
drop table t7_view;
drop table t7_table;
drop table t7_dependent_table;
drop table t7_table_trigger;
drop table t7_audit;
drop procedure audit_proc;
drop function audit_func;
drop view audit_view;

--echo =====================================================================
--echo Testing 8: TABLE -> TEMPORARY TABLE transitions
--echo =====================================================================

--disable_warnings
drop table if exists t8;
--enable_warnings

create table t8(a int);

prepare stmt from 'select * from t8';
execute stmt;
eval $check;
execute stmt;
eval $check;

drop table t8;
create temporary table t8(a int);

set @expected = @expected + 1;
execute stmt;
eval $check;
execute stmt;
eval $check;

drop table t8;

--echo =====================================================================
--echo Testing 9: TABLE -> VIEW transitions
--echo =====================================================================

--disable_warnings
drop table if exists t9;
drop table if exists t9_b;
--enable_warnings

create table t9(a int);
create table t9_b(a int);

prepare stmt from 'select * from t9';
execute stmt;
eval $check;
execute stmt;
eval $check;

drop table t9;
create view t9 as select * from t9_b;

set @expected = @expected + 1;
execute stmt;
eval $check;
execute stmt;
eval $check;

drop view t9;
drop table t9_b;

--echo =====================================================================
--echo Testing 10: TEMPORARY TABLE -> NOTHING transitions
--echo =====================================================================

--disable_warnings
drop temporary table if exists t10;
--enable_warnings

create temporary table t10(a int);

prepare stmt from 'select * from t10';
execute stmt;
eval $check;
execute stmt;
eval $check;

drop temporary table t10;
--error ER_NO_SUCH_TABLE
execute stmt;
eval $check;
--error ER_NO_SUCH_TABLE
execute stmt;
eval $check;

--echo =====================================================================
--echo Testing 11: TEMPORARY TABLE -> TABLE transitions
--echo =====================================================================

--disable_warnings
drop table if exists t11;
drop temporary table if exists t11;
--enable_warnings

create table t11(a int);
insert into t11(a) value (1);
create temporary table t11(a int);

prepare stmt from 'select * from t11';
execute stmt;
eval $check;
execute stmt;
eval $check;

drop temporary table t11;

set @expected = @expected + 1;
execute stmt;
eval $check;
execute stmt;
eval $check;

select * from t11;
drop table t11;

--echo =====================================================================
--echo Testing 12: TEMPORARY TABLE -> TEMPORARY TABLE (DDL) transitions
--echo =====================================================================

--disable_warnings
drop temporary table if exists t12;
--enable_warnings

create temporary table t12(a int);

prepare stmt from 'select a from t12';
execute stmt;
eval $check;
execute stmt;
eval $check;

drop temporary table t12;
create temporary table t12(a int, b int);

set @expected = @expected + 1;
execute stmt;
eval $check;
execute stmt;
eval $check;

select * from t12;
drop table t12;

--echo =====================================================================
--echo Testing 13: TEMPORARY TABLE -> VIEW transitions
--echo =====================================================================

--disable_warnings
drop temporary table if exists t13;
drop table if exists t13_b;
--enable_warnings

create temporary table t13(a int);
create table t13_b(a int);

prepare stmt from 'select * from t13';
execute stmt;
eval $check;
execute stmt;
eval $check;

drop temporary table t13;
create view t13 as select * from t13_b;

set @expected = @expected + 1;
execute stmt;
eval $check;
execute stmt;
eval $check;

drop view t13;
drop table t13_b;

--echo =====================================================================
--echo Testing 14: VIEW -> NOTHING transitions
--echo =====================================================================

--disable_warnings
drop view if exists t14;
drop table if exists t14_b;
--enable_warnings

create table t14_b(a int);
create view t14 as select * from t14_b;

prepare stmt from 'select * from t14';
execute stmt;
eval $check;
execute stmt;
eval $check;

drop view t14;

set @expected = @expected + 1;
--error ER_NO_SUCH_TABLE
execute stmt;
eval $check;
set @expected = @expected + 1;
--error ER_NO_SUCH_TABLE
execute stmt;
eval $check;

drop table t14_b;

--echo =====================================================================
--echo Testing 15: VIEW -> TABLE transitions
--echo =====================================================================

--disable_warnings
drop view if exists t15;
drop table if exists t15_b;
--enable_warnings

create table t15_b(a int);
create view t15 as select * from t15_b;

prepare stmt from 'select * from t15';
execute stmt;
eval $check;
execute stmt;
eval $check;

drop view t15;
create table t15(a int);

set @expected = @expected + 1;
execute stmt;
eval $check;
execute stmt;
eval $check;

drop table t15_b;
drop table t15;

--echo =====================================================================
--echo Testing 16: VIEW -> TEMPORARY TABLE transitions
--echo =====================================================================

--disable_warnings
drop view if exists t16;
drop table if exists t16_b;
--enable_warnings

create table t16_b(a int);
create view t16 as select * from t16_b;

prepare stmt from 'select * from t16';
execute stmt;
eval $check;
execute stmt;
eval $check;

drop view t16;
create temporary table t16(a int);

set @expected = @expected + 1;
execute stmt;
eval $check;
execute stmt;
eval $check;

drop table t16_b;
drop temporary table t16;

--echo =====================================================================
--echo Testing 17: VIEW -> VIEW (DDL) transitions
--echo =====================================================================

--disable_warnings
drop view if exists t17;
drop table if exists t17_b;
--enable_warnings

create table t17_b(a int);
insert into t17_b values (10), (20), (30);

create view t17 as select a, 2*a as b, 3*a as c from t17_b;
select * from t17;

prepare stmt from 'select * from t17';
execute stmt;
eval $check;
execute stmt;
eval $check;

drop view t17;
create view t17 as select a, 2*a as b, 5*a as c from t17_b;
select * from t17;

set @expected = @expected + 1;
execute stmt;
eval $check;
execute stmt;
eval $check;

drop table t17_b;
drop view t17;

--echo =====================================================================
--echo Testing 18: VIEW -> VIEW (VIEW dependencies) transitions
--echo =====================================================================

#
# Test 18-a: dependent PROCEDURE has changed (via a trigger)
# Test 18-b: dependent FUNCTION has changed
# Test 18-c: dependent VIEW has changed
# Test 18-d: dependent TABLE has changed
# Test 18-e: dependent TABLE TRIGGER has changed
#

--disable_warnings
drop table if exists t18;
drop table if exists t18_dependent_table;
drop view if exists t18_func;
drop view if exists t18_view;
drop view if exists t18_table;
drop function if exists view_func;
drop view if exists view_view;
--enable_warnings

# TODO: insertable view -> trigger
# TODO: insertable view -> trigger -> proc ?

create table t18(a int);
insert into t18 values (1), (2), (3);

create function view_func(x int) returns int
  return x+1;

create view view_view as select "view v1" as reason from dual;

create table t18_dependent_table(a int);

create view t18_func as select a, view_func(a) as b from t18;
create view t18_view as select a, reason as b from t18, view_view;
create view t18_table as select * from t18;

prepare stmt_func from 'select * from t18_func';
execute stmt_func;
eval $check;
execute stmt_func;
eval $check;

drop function view_func;
create function view_func(x int) returns int
  return x*x;

set @expected = @expected + 1;
execute stmt_func;
eval $check;
execute stmt_func;
eval $check;

prepare stmt_view from 'select * from t18_view';
execute stmt_view;
eval $check;
execute stmt_view;
eval $check;

drop view view_view;
create view view_view as select "view v2" as reason from dual;

set @expected = @expected + 1;
execute stmt_view;
eval $check;
execute stmt_view;
eval $check;

prepare stmt_table from 'select * from t18_table';
execute stmt_table;
eval $check;
execute stmt_table;
eval $check;

alter table t18 add column comments varchar(50) default NULL;

set @expected = @expected + 1;
execute stmt_table;
eval $check;
execute stmt_table;
eval $check;

drop table t18;
drop table t18_dependent_table;
drop view t18_func;
drop view t18_view;
drop view t18_table;
drop function view_func;
drop view view_view;

--echo =====================================================================
--echo Testing 19: Special tables (INFORMATION_SCHEMA)
--echo =====================================================================

--disable_warnings
drop procedure if exists proc_19;
--enable_warnings

# Using a temporary table internally should not confuse the prepared
# statement code, and should not raise ER_PS_INVALIDATED errors
prepare stmt from
 'select ROUTINE_SCHEMA, ROUTINE_NAME, ROUTINE_TYPE
 from INFORMATION_SCHEMA.ROUTINES where
 routine_name=\'proc_19\'';

create procedure proc_19() select "hi there";

execute stmt;
eval $check;
execute stmt;
eval $check;

drop procedure proc_19;
create procedure proc_19() select "hi there, again";

execute stmt;
eval $check;
execute stmt;
eval $check;

drop procedure proc_19;

--echo =====================================================================
--echo Testing 20: Special tables (log tables)
--echo =====================================================================

prepare stmt from
 'select * from mysql.general_log where argument=\'IMPOSSIBLE QUERY STRING\'';

execute stmt;
eval $check;
execute stmt;
eval $check;
execute stmt;
eval $check;
execute stmt;
eval $check;

--echo =====================================================================
--echo Testing 21: Special tables (system tables)
--echo =====================================================================

--disable_warnings
drop procedure if exists proc_21;
--enable_warnings

prepare stmt from
 'select type, db, name from mysql.proc where name=\'proc_21\'';

create procedure proc_21() select "hi there";

execute stmt;
eval $check;
execute stmt;
eval $check;

drop procedure proc_21;
create procedure proc_21() select "hi there, again";

execute stmt;
eval $check;
execute stmt;
eval $check;

drop procedure proc_21;

--echo =====================================================================
--echo Testing 22: Special tables (views temp tables)
--echo =====================================================================

--disable_warnings
drop table if exists t22_b;
drop view if exists t22;
--enable_warnings

create table t22_b(a int);

create algorithm=temptable view t22 as select a*a as a2 from t22_b;

# Using a temporary table internally should not confuse the prepared
# statement code, and should not raise ER_PS_INVALIDATED errors
show create view t22;

prepare stmt from 'select * from t22';

insert into t22_b values (1), (2), (3);
execute stmt;
eval $check;
execute stmt;
eval $check;

insert into t22_b values (4), (5), (6);
execute stmt;
eval $check;
execute stmt;
eval $check;

drop table t22_b;
drop view t22;

--echo =====================================================================
--echo Testing 23: Special tables (internal join tables)
--echo =====================================================================

--disable_warnings
drop table if exists t23_a;
drop table if exists t23_b;
--enable_warnings

create table t23_a(a int);
create table t23_b(b int);

# Using a temporary table internally should not confuse the prepared
# statement code, and should not raise ER_PS_INVALIDATED errors
prepare stmt from 'select * from t23_a join t23_b';

insert into t23_a values (1), (2), (3);
insert into t23_b values (10), (20), (30);
execute stmt;
eval $check;
execute stmt;
eval $check;

insert into t23_a values (4);
insert into t23_b values (40);
execute stmt;
eval $check;
execute stmt;
eval $check;

drop table t23_a;
drop table t23_b;

--echo =====================================================================
--echo Testing 24: Special statements
--echo =====================================================================

# SQLCOM_ALTER_TABLE:

--disable_warnings
drop table if exists t24_alter;
--enable_warnings

create table t24_alter(a int);

prepare stmt from 'alter table t24_alter add column b int';
execute stmt;
eval $check;

drop table t24_alter;
create table t24_alter(a1 int, a2 int);

# t24_alter has changed, and it's not a problem
execute stmt;
eval $check;

alter table t24_alter drop column b;
execute stmt;
eval $check;

alter table t24_alter drop column b;
execute stmt;
eval $check;

drop table t24_alter;

# SQLCOM_REPAIR:

--disable_warnings
drop table if exists t24_repair;
--enable_warnings

create table t24_repair(a int);
insert into t24_repair values (1), (2), (3);

prepare stmt from 'repair table t24_repair';
execute stmt;
eval $check;

drop table t24_repair;
create table t24_repair(a1 int, a2 int);
insert into t24_repair values (1, 10), (2, 20), (3, 30);

# t24_repair has changed, and it's not a problem
execute stmt;
eval $check;

alter table t24_repair add column b varchar(50) default NULL;
execute stmt;
eval $check;

alter table t24_repair drop column b;
execute stmt;
eval $check;

drop table t24_repair;

# SQLCOM_ANALYZE:

--disable_warnings
drop table if exists t24_analyze;
--enable_warnings

create table t24_analyze(a int);
insert into t24_analyze values (1), (2), (3);

prepare stmt from 'analyze table t24_analyze';
execute stmt;
eval $check;

drop table t24_analyze;
create table t24_analyze(a1 int, a2 int);
insert into t24_analyze values (1, 10), (2, 20), (3, 30);

# t24_analyze has changed, and it's not a problem
execute stmt;
eval $check;

alter table t24_analyze add column b varchar(50) default NULL;
execute stmt;
eval $check;

alter table t24_analyze drop column b;
execute stmt;
eval $check;

drop table t24_analyze;

# SQLCOM_OPTIMIZE:

--disable_warnings
drop table if exists t24_optimize;
--enable_warnings

create table t24_optimize(a int);
insert into t24_optimize values (1), (2), (3);

prepare stmt from 'optimize table t24_optimize';
execute stmt;
eval $check;

drop table t24_optimize;
create table t24_optimize(a1 int, a2 int);
insert into t24_optimize values (1, 10), (2, 20), (3, 30);

# t24_optimize has changed, and it's not a problem
execute stmt;
eval $check;

alter table t24_optimize add column b varchar(50) default NULL;
execute stmt;
eval $check;

alter table t24_optimize drop column b;
execute stmt;
eval $check;

drop table t24_optimize;

# SQLCOM_SHOW_CREATE_PROC:

--disable_warnings
drop procedure if exists changing_proc;
--enable_warnings

prepare stmt from 'show create procedure changing_proc';
--error ER_SP_DOES_NOT_EXIST
execute stmt;
eval $check;
--error ER_SP_DOES_NOT_EXIST
execute stmt;
eval $check;

create procedure changing_proc() begin end;

# changing_proc has changed, and it's not a problem
execute stmt;
eval $check;
execute stmt;
eval $check;

drop procedure changing_proc;
create procedure changing_proc(x int, y int) begin end;

execute stmt;
eval $check;
execute stmt;
eval $check;

drop procedure changing_proc;

--error ER_SP_DOES_NOT_EXIST
execute stmt;
eval $check;
--error ER_SP_DOES_NOT_EXIST
execute stmt;
eval $check;

# SQLCOM_SHOW_CREATE_FUNC:

--disable_warnings
drop function if exists changing_func;
--enable_warnings

prepare stmt from 'show create function changing_func';
--error ER_SP_DOES_NOT_EXIST
execute stmt;
eval $check;
--error ER_SP_DOES_NOT_EXIST
execute stmt;
eval $check;

create function changing_func() returns int return 0;

# changing_proc has changed, and it's not a problem
execute stmt;
eval $check;
execute stmt;
eval $check;

drop function changing_func;
create function changing_func(x int, y int) returns int return x+y;

execute stmt;
eval $check;
execute stmt;
eval $check;

drop function changing_func;

--error ER_SP_DOES_NOT_EXIST
execute stmt;
eval $check;
--error ER_SP_DOES_NOT_EXIST
execute stmt;
eval $check;

# SQLCOM_SHOW_CREATE_TRIGGER:

--disable_warnings
drop table if exists t24_trigger;
--enable_warnings

create table t24_trigger(a int);

prepare stmt from 'show create trigger t24_bi;';
--error ER_TRG_DOES_NOT_EXIST
execute stmt;
eval $check;
--error ER_TRG_DOES_NOT_EXIST
execute stmt;
eval $check;

delimiter $$;
create trigger t24_bi before insert on t24_trigger for each row
  begin
    set @message= "t24_bi";
  end
$$
delimiter ;$$

# t24_bi has changed, and it's not a problem
execute stmt;
eval $check;
execute stmt;
eval $check;

drop trigger t24_bi;
delimiter $$;
create trigger t24_bi before insert on t24_trigger for each row
  begin
    set @message= "t24_bi (2)";
  end
$$
delimiter ;$$

# t24_bi has changed, and it's not a problem
set @expected = @expected + 1;
execute stmt;
eval $check;
execute stmt;
eval $check;

drop trigger t24_bi;

--error ER_TRG_DOES_NOT_EXIST
execute stmt;
eval $check;
--error ER_TRG_DOES_NOT_EXIST
execute stmt;
eval $check;

drop table t24_trigger;

--echo =====================================================================
--echo Testing 25: Testing the strength of TABLE_SHARE version
--echo =====================================================================

# Test 25-a: number of columns

--disable_warnings
drop table if exists t25_num_col;
--enable_warnings

create table t25_num_col(a int);

prepare stmt from 'select a from t25_num_col';
execute stmt;
eval $check;
execute stmt;
eval $check;

alter table t25_num_col add column b varchar(50) default NULL;

set @expected = @expected + 1;
execute stmt;
eval $check;
execute stmt;
eval $check;

drop table t25_num_col;

# Test 25-b: column name

--disable_warnings
drop table if exists t25_col_name;
--enable_warnings

create table t25_col_name(a int);

prepare stmt from 'select * from t25_col_name';
execute stmt;
eval $check;
execute stmt;
eval $check;

alter table t25_col_name change a b int;

set @expected = @expected + 1;
--error ER_PS_REBIND
execute stmt;
eval $check;
set @expected = @expected + 1;
--error ER_PS_REBIND
execute stmt;
eval $check;

drop table t25_col_name;

# Test 25-c: column type

--disable_warnings
drop table if exists t25_col_type;
--enable_warnings

create table t25_col_type(a int);

prepare stmt from 'select * from t25_col_type';
execute stmt;
eval $check;
execute stmt;
eval $check;

alter table t25_col_type change a a varchar(10);

set @expected = @expected + 1;
--error ER_PS_REBIND
execute stmt;
eval $check;
set @expected = @expected + 1;
--error ER_PS_REBIND
execute stmt;
eval $check;

drop table t25_col_type;

# Test 25-d: column type length

--disable_warnings
drop table if exists t25_col_type_length;
--enable_warnings

create table t25_col_type_length(a varchar(10));

prepare stmt from 'select * from t25_col_type_length';
execute stmt;
eval $check;
execute stmt;
eval $check;

alter table t25_col_type_length change a a varchar(20);

set @expected = @expected + 1;
--error ER_PS_REBIND
execute stmt;
eval $check;
set @expected = @expected + 1;
--error ER_PS_REBIND
execute stmt;
eval $check;

drop table t25_col_type_length;

# Test 25-e: column NULL property

--disable_warnings
drop table if exists t25_col_null;
--enable_warnings

create table t25_col_null(a varchar(10));

prepare stmt from 'select * from t25_col_null';
execute stmt;
eval $check;
execute stmt;
eval $check;

alter table t25_col_null change a a varchar(10) NOT NULL;

set @expected = @expected + 1;
--error ER_PS_REBIND
execute stmt;
eval $check;
set @expected = @expected + 1;
--error ER_PS_REBIND
execute stmt;
eval $check;

drop table t25_col_null;

# Test 25-f: column DEFAULT

--disable_warnings
drop table if exists t25_col_default;
--enable_warnings

create table t25_col_default(a int, b int DEFAULT 10);

prepare stmt from 'insert into t25_col_default(a) values (?)';
set @val=1;
execute stmt using @val;
eval $check;
set @val=2;
execute stmt using @val;
eval $check;

alter table t25_col_default change b b int DEFAULT 20;

set @val=3;
# Must insert the correct default value for b
set @expected = @expected + 1;
execute stmt using @val;
eval $check;

set @val=4;
# Must insert the correct default value for b
execute stmt using @val;
eval $check;

select * from t25_col_default;

drop table t25_col_default;

# Test 25-g: number of keys

--disable_warnings
drop table if exists t25_index;
--enable_warnings

create table t25_index(a varchar(10));

prepare stmt from 'select * from t25_index';
execute stmt;
eval $check;
execute stmt;
eval $check;

create index i1 on t25_index(a);

set @expected = @expected + 1;
execute stmt;
eval $check;
execute stmt;
eval $check;

drop table t25_index;

# Test 25-h: changing index uniqueness

--disable_warnings
drop table if exists t25_index_unique;
--enable_warnings

create table t25_index_unique(a varchar(10), b varchar(10));
create index i1 on t25_index_unique(a, b);

show create table t25_index_unique;

prepare stmt from 'select * from t25_index_unique';
execute stmt;
eval $check;
execute stmt;
eval $check;

alter table t25_index_unique drop index i1;
create unique index i1 on t25_index_unique(a, b);

show create table t25_index_unique;

set @expected = @expected + 1;
execute stmt;
eval $check;
execute stmt;
eval $check;

drop table t25_index_unique;

--echo =====================================================================
--echo Testing reported bugs
--echo =====================================================================

#
# Bug#12093 (SP not found on second PS execution if another thread drops
# other SP in between)
#

--disable_warnings
drop table if exists table_12093;
drop function if exists func_12093;
drop function if exists func_12093_unrelated;
drop procedure if exists proc_12093;
--enable_warnings

connect (con1,localhost,root,,);

connection default;

create table table_12093(a int);

delimiter //;

create function func_12093()
returns int
begin
  return (select count(*) from table_12093);
end//

create procedure proc_12093(a int)
begin
  select * from table_12093;
end//

delimiter ;//

create function func_12093_unrelated() returns int return 2;
create procedure proc_12093_unrelated() begin end;

prepare stmt_sf from 'select func_12093();';
prepare stmt_sp from 'call proc_12093(func_12093())';

execute stmt_sf;
eval $check;
execute stmt_sp;
eval $check;

connection con1;

drop function func_12093_unrelated;
drop procedure proc_12093_unrelated;

connection default;

# previously, failed with --error 1305
execute stmt_sf;
eval $check;
# previously, failed with --error 1305
execute stmt_sp;
eval $check;

# previously, failed with --error 1305
execute stmt_sf;
eval $check;
# previously, failed with --error 1305
execute stmt_sp;
eval $check;

deallocate prepare stmt_sf;
deallocate prepare stmt_sp;

disconnect con1;

drop table table_12093;
drop function func_12093;
drop procedure proc_12093;

#
# Bug#21294 (executing a prepared statement that executes a stored function
# which was recreat)
#

--disable_warnings
drop function if exists func_21294;
--enable_warnings

create function func_21294() returns int return 10;

prepare stmt from "select func_21294()";
execute stmt;
eval $check;

drop function func_21294;
create function func_21294() returns int return 10;

# might pass or fail, implementation dependent
execute stmt;
eval $check;

drop function func_21294;
create function func_21294() returns int return 20;

set @expected = @expected + 1;
execute stmt;
eval $check;

deallocate prepare stmt;
drop function func_21294;

#
# Bug#27420 (A combination of PS and view operations cause error + assertion
# on shutdown)
#

--disable_warnings
drop table if exists t_27420_100;
drop table if exists t_27420_101;
drop view if exists v_27420;
--enable_warnings

connect (con1,localhost,root,,);

connection default;

create table t_27420_100(a int);
insert into t_27420_100 values (1), (2);

create table t_27420_101(a int);
insert into t_27420_101 values (1), (2);

create view v_27420 as select t_27420_100.a X, t_27420_101.a Y
  from t_27420_100, t_27420_101
  where t_27420_100.a=t_27420_101.a;

prepare stmt from 'select * from v_27420';

execute stmt;
eval $check;

connection con1;

drop view v_27420;
create table v_27420(X int, Y int);

connection default;

set @expected = @expected + 1;
execute stmt;
eval $check;

connection con1;

drop table v_27420;
# passes in 5.0, fails in 5.1, should pass
create table v_27420 (a int, b int, filler char(200));

connection default;

set @expected = @expected + 1;
--error ER_PS_REBIND
execute stmt;
eval $check;

disconnect con1;

deallocate prepare stmt;
drop table t_27420_100;
drop table t_27420_101;
drop table v_27420;

#
# Bug#27430 (Crash in subquery code when in PS and table DDL changed after
# PREPARE)
#

--disable_warnings
drop table if exists t_27430_1;
drop table if exists t_27430_2;
--enable_warnings

create table t_27430_1 (a int not null, oref int not null, key(a));
insert into t_27430_1 values
  (1, 1),
  (1, 1234),
  (2, 3),
  (2, 1234),
  (3, 1234);

create table t_27430_2 (a int not null, oref int not null);
insert into t_27430_2 values
  (1, 1),
  (2, 2),
  (1234, 3),
  (1234, 4);

prepare stmt from 
 'select oref, a, a in (select a from t_27430_1 where oref=t_27430_2.oref) Z from t_27430_2';

execute stmt; 
eval $check;
execute stmt; 
eval $check;

drop table t_27430_1, t_27430_2;

create table t_27430_1 (a int, oref int, key(a));
insert into t_27430_1 values 
  (1, 1),
  (1, NULL),
  (2, 3),
  (2, NULL),
  (3, NULL);

create table t_27430_2 (a int, oref int);
insert into t_27430_2 values
  (1, 1),
  (2,2),
  (NULL, 3),
  (NULL, 4);

set @expected = @expected + 1;
--error ER_PS_REBIND
execute stmt;
eval $check;
set @expected = @expected + 1;
--error ER_PS_REBIND
execute stmt;
eval $check;

deallocate prepare stmt;
drop table t_27430_1;
drop table t_27430_2;

#
# Bug#27690 (Re-execution of prepared statement after table was replaced
# with a view crashes)
#

--disable_warnings
drop table if exists t_27690_1;
drop view if exists v_27690_1;
drop table if exists v_27690_2;
--enable_warnings

create table t_27690_1 (a int, b int);
insert into t_27690_1 values (1,1),(2,2);

create table v_27690_1 as select * from t_27690_1;
create table v_27690_2 as select * from t_27690_1;

prepare stmt from 'select * from v_27690_1, v_27690_2'; 

execute stmt;
eval $check;
execute stmt;
eval $check;

drop table v_27690_1;

--error ER_NO_SUCH_TABLE
execute stmt;
eval $check;

--error ER_NO_SUCH_TABLE
execute stmt;
eval $check;

create view v_27690_1 as select A.a, A.b from t_27690_1 A, t_27690_1 B;

set @expected = @expected + 1;
execute stmt;
eval $check;
execute stmt;
eval $check;

deallocate prepare stmt;
drop table t_27690_1;
drop view v_27690_1;
drop table v_27690_2;