1# Save the initial number of concurrent sessions
2--source include/count_sessions.inc
3
4connect (con1,localhost,root,,);
5connect (con2,localhost,root,,);
6connection con1;
7--disable_warnings
8drop table if exists t1,t2;
9drop view if exists v1;
10--enable_warnings
11
12# Add a lot of keys to slow down check
13create table t1(n int not null, key(n), key(n), key(n), key(n));
14let $1=10000;
15--disable_query_log
16begin;
17while ($1)
18{
19 eval insert into t1 values ($1);
20 dec $1;
21}
22commit;
23--enable_query_log
24send check table t1 extended;
25connection con2;
26insert into t1 values (200000);
27connection con1;
28reap;
29connection default;
30disconnect con1;
31disconnect con2;
32drop table t1;
33
34
35# End of 4.1 tests
36
37#
38# Bug#9897 Views: 'Check Table' crashes MySQL, with a view and a table
39#          in the statement
40#
41Create table t1(f1 int);
42Create table t2(f1 int);
43Create view v1 as Select * from t1;
44Check Table v1,t2;
45drop view v1;
46drop table t1, t2;
47
48
49#
50# Bug#26325 TEMPORARY TABLE "corrupt" after first read, according to CHECK TABLE
51#
52CREATE TEMPORARY TABLE t1(a INT);
53CHECK TABLE t1;
54REPAIR TABLE t1;
55DROP TABLE t1;
56
57
58--echo #
59--echo # Bug#56422 CHECK TABLE run when the table is locked reports corruption
60--echo #           along with timeout
61--echo #
62
63--disable_warnings
64DROP TABLE IF EXISTS t1;
65--enable_warnings
66
67CREATE TABLE t1(a INT);
68LOCK TABLE t1 WRITE;
69
70connect(con1, localhost, root);
71SET lock_wait_timeout= 1;
72CHECK TABLE t1;
73
74connection default;
75UNLOCK TABLES;
76DROP TABLE t1;
77disconnect con1;
78
79
80# Wait till we reached the initial number of concurrent sessions
81--source include/wait_until_count_sessions.inc
82
83--echo #
84--echo # MDEV-15338
85--echo # Assertion `!table || (!table->read_set ||
86--echo # bitmap_is_set(table->read_set, field_index))'
87--echo # failed on dropping column with CHECK
88--echo #
89
90CREATE TABLE t1 (a INT, b INT, CHECK (a>0)) ENGINE=MyISAM;
91INSERT INTO t1 VALUES (1,2),(3,4);
92ALTER TABLE t1 DROP COLUMN a;
93CREATE OR REPLACE TABLE t1 (a INT, b INT, CHECK (a>0)) ENGINE=MyISAM;
94ALTER TABLE t1 DROP COLUMN b;
95CREATE OR REPLACE TABLE t1 (a INT, b INT, c INT, CHECK (a+b>0)) ENGINE=MyISAM;
96--error ER_BAD_FIELD_ERROR
97ALTER TABLE t1 DROP COLUMN b;
98ALTER TABLE t1 DROP COLUMN a, DROP COLUMN b;
99CREATE OR REPLACE TABLE t1 (a INT, b INT, c INT, CHECK (a+b>0)) ENGINE=MyISAM;
100ALTER TABLE t1 DROP CONSTRAINT `CONSTRAINT_1`;
101SHOW CREATE TABLE t1;
102CREATE OR REPLACE TABLE t1 (a INT, b INT, c INT, CHECK (a+b>0)) ENGINE=MyISAM;
103ALTER TABLE t1 DROP COLUMN b, DROP CONSTRAINT `CONSTRAINT_1`;
104SHOW CREATE TABLE t1;
105DROP TABLE t1;
106
107#
108# MDEV-16903 Assertion `!auto_increment_field_not_null' failed in TABLE::init after unsuccessful attempt to add CHECK constraint on temporary table
109#
110create temporary table t1 (
111  id int not null auto_increment primary key,
112  f int not null default 0
113);
114insert into t1 () values ();
115alter ignore table t1 add constraint check (f > 0);
116alter table t1;
117drop table t1;
118
119#
120# MDEV-16905 ASAN heap-use-after-free in __interceptor_strnlen / ... / TABLE::verify_constraints upon INSERT into temporary table with CHECK constraint
121#
122create temporary table t1 (a int default 0, check (a > 0));
123alter table t1 drop constraint if exists non_existing_constraint;
124--error ER_CONSTRAINT_FAILED
125insert into t1 () values ();
126drop table t1;
127