Files
tidb/tests/integrationtest/t/ddl/db_table.test

91 lines
3.3 KiB
Plaintext

# TestTableForeignKey
drop table if exists t1,t2,t3,t4;
create table t1 (a int, b int, index(a), index(b));
-- error 1072
create table t2 (c int, foreign key (a) references t1(a));
create table t3 (a int, b int);
-- error 1072
alter table t1 add foreign key (c) REFERENCES t3(a);
-- error 1239
alter table t1 add foreign key (a) REFERENCES t3(a, b);
create table t4 (c int,d int,foreign key (d) references t1 (b));
-- error 1828
alter table t4 drop column d;
-- error 3780
alter table t4 change column d e bigint;
-- error 3780
alter table t4 modify column d bigint;
--disable_result_log
select count(*) from information_schema.KEY_COLUMN_USAGE;
--enable_result_log
alter table t4 drop foreign key fk_1;
alter table t4 modify column d bigint;
drop table if exists t1,t2,t3,t4;
# TestCharacterSetInColumns
drop table if exists t;
create table t (c1 int, s1 varchar(10), s2 text);
select count(*) from information_schema.columns where table_schema = 'ddl__db_table' and table_name = 't' and character_set_name != 'utf8mb4';
select count(*) from information_schema.columns where table_schema = 'ddl__db_table' and table_name = 't' and character_set_name = 'utf8mb4';
create table t1(id int) charset=UTF8;
create table t2(id int) charset=BINARY;
create table t3(id int) charset=LATIN1;
create table t4(id int) charset=ASCII;
create table t5(id int) charset=UTF8MB4;
create table t11(id int) charset=utf8;
create table t12(id int) charset=binary;
create table t13(id int) charset=latin1;
create table t14(id int) charset=ascii;
create table t15(id int) charset=utf8mb4;
# TestAlterTableWithValidation
drop table if exists t1;
create table t1 (c1 int, c2 int as (c1 + 1));
alter table t1 with validation;
show warnings;
alter table t1 without validation;
show warnings;
drop table if exists t1;
# TestLock
# port from MySQL
# https://github.com/mysql/mysql-server/blob/124c7ab1d6f914637521fd4463a993aa73403513/mysql-test/t/lock.test
DROP TABLE IF EXISTS t1;
CREATE TABLE t1 ( `id` int(11) NOT NULL default '0', `id2` int(11) NOT NULL default '0', `id3` int(11) NOT NULL default '0', `dummy1` char(30) default NULL, PRIMARY KEY (`id`,`id2`), KEY `index_id3` (`id3`));
insert into t1 (id,id2) values (1,1),(1,2),(1,3);
LOCK TABLE t1 WRITE;
select dummy1,count(distinct id) from t1 group by dummy1;
update t1 set id=-1 where id=1;
LOCK TABLE t1 READ;
-- error 1099
update t1 set id=1 where id=1;
unlock tables;
update t1 set id=1 where id=-1;
drop table t1;
# TestDDLWithInvalidTableInfo
drop table if exists t;
-- error 1064
CREATE TABLE t (
c0 int(11),
c1 int(11),
c2 decimal(16,4) GENERATED ALWAYS AS ((case when (c0 = 0) then 0when (c0 > 0) then (c1 / c0) end))
);
create table t (a bigint, b int, c int generated always as (b+1)) partition by hash(a) partitions 4;
-- error 3855
alter table t drop column a;
-- error 1064
alter table t modify column c int GENERATED ALWAYS AS ((case when (a = 0) then 0when (a > 0) then (b / a) end));
-- error 1064
alter table t add column d int GENERATED ALWAYS AS ((case when (a = 0) then 0when (a > 0) then (b / a) end));
drop table if exists t;
# TestUnsupportedEngineAttribute
drop table if exists t;
-- error 3981
create table t (a int) ENGINE_ATTRIBUTE = '{"key": "value"}';
create table t (a int);
-- error 3981
alter table t ENGINE_ATTRIBUTE = '{"key": "value"}';
drop table if exists t;