polardbxengine/mysql-test/suite/xengine/t/instant_ddl_basic.test

220 lines
6.5 KiB
Plaintext

--source suite/xengine/include/have_xengine.inc
#
# instant ddl basic tests
#
# add columns
create table t1 (id int primary key, c1 int default 1) engine=xengine;
insert into t1(id) values (1);
select * from t1;
alter table t1 add column c2 int default 2, add column c3 char(100) default "c3c3c3c3c3c3", add column c4 varchar(100) default "c4c4c4c4c4c4c4c4c4",
add column c5 double default 5.5, add column c6 blob, add column c7 text, algorithm=instant;
select * from t1;
insert into t1(id) values(2);
select * from t1;
# not supported
--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter table t1 add column c8 int after c4, algorithm=instant;
--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter table t1 add column c9 ENUM('a', 'b') FIRST, algorithm=instant;
alter table t1 add column c8 ENUM('a', 'b'), algorithm=instant;
insert into t1 (id,c8) values (3,'a');
select * from t1;
# add PK is not supported
create table t2 (c1 int) engine=xengine;
insert into t2 values (1);
--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter table t2 add column id int primary key, algorithm=instant;
drop table t2;
#set/modify/drop default values
alter table t1 alter column c1 set default 2, algorithm=instant;
show create table t1;
alter table t1 alter column c2 set default 20, algorithm=instant;
select * from t1;
alter table t1 alter column c3 drop default, algorithm=instant;
insert into t1 (id) values (4);
insert into t1 (id,c3) values (5,"new c3");
select * from t1;
#not supoorted
--error ER_WRONG_USAGE
alter table t1 alter column c3 set default "newc3-1", algorithm=instant, LOCK=NONE;
--error ER_WRONG_USAGE
alter table t1 alter column c3 set default "newc3-2", algorithm=instant, LOCK=SHARED;
--error ER_WRONG_USAGE
alter table t1 alter column c3 set default "newc3-3", algorithm=instant, LOCK=EXCLUSIVE;
alter table t1 alter column c3 set default "newc3-4", algorithm=instant, LOCK=DEFAULT;
alter table t1 MODIFY COLUMN c8 ENUM('a', 'b', 'c', 'd', 'e'), ALGORITHM=INSTANT;
show create table t1;
insert into t1(id,c8) values(6,'e');
select * from t1;
ALTER TABLE t1 RENAME TO t2, ALGORITHM=INSTANT;
show create table t2;
ALTER TABLE t2 RENAME TO t1, ALGORITHM=INSTANT;
# not supoorted
--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter table t1 rename column c2 to c2_2, algorithm=instant;
drop table t1;
# "null_bytes" is changed from 1 to 2 after ddl
create table t1 (c1 int primary key, c2 int, c3 char(10), c4 varchar(200), c5 text, c6 datetime, c7 double, c8 blob, c9 varbinary(10), c10 int);
insert into t1(c1,c3,c10) values (1,"333",1);
select * from t1;
alter table t1 add column c11 int default '11',algorithm=instant;
select * from t1;
drop table t1;
# bug #21584085
CREATE TABLE IF NOT EXISTS t1(
id INT auto_increment,
col1 INT,
col2 INT,
col3 INT,
col4 TEXT,
primary key(`id`)
) engine=xengine;
insert into t1 values(1, 1, 1, 1, '1');
insert into t1 values(2, 2, 2, 2, '2');
insert into t1 values(3, 3, 3, 3, '3');
insert into t1 values(4, 4, 4, 4, '4');
select 0 from t1 where col1 > 1;
select col1 from t1 where col1 > 1;
alter table t1 add column col5 int default 0;
select 0 from t1 where col1 > 1;
select col1 from t1 where col1 > 1;
select * from t1;
insert into t1 values(5, 5, 5, 5, '5', 5);
alter table t1 add column col6 varchar(10) default "six";
select 0 from t1 where col1 > 1;
select col1, col3 from t1 where col1 > 1;
select col5 from t1 where col1 > 1;
select col5, col6 from t1 where col1 > 1;
select * from t1;
drop table t1;
# bug 21612195
create table t1 (id int primary key) engine=xengine;
insert into t1(id) values (1),(2);
alter table t1 add column c1 datetime not null default '2019-07-18', algorithm=instant;
select c1 from t1;
drop table t1;
# bug 22945802
create table test_0 (
pk bigint,
sk1 char(20),
sk2 varchar(20),
uk1 decimal(20,4),
uk2 bigint,
v1 timestamp(6) not null default now(6),
v2 timestamp(6) not null default now(6),
padding longblob,
primary key (pk),
key sk1 (sk1, sk2),
unique key uk1 (uk1, uk2)
) engine = xengine collate utf8mb4_general_ci;
insert into test_0 (pk, sk1, sk2, uk1, uk2, padding) values (1, '0', '1', 2, 3, REPEAT('MYSQLMYSQL', 6));
alter table test_0 add column a1 timestamp(6) not null default now(6);
insert into test_0 (pk, sk1, sk2, uk1, uk2, padding) values (4, '3', '4', 8, 9, REPEAT('MYSQLMYSQL', 6));
alter table test_0 drop column v1;
drop table test_0;--source suite/xengine/include/check_xengine_log_error.inc
# bug 29035163 run this on release mode
create table test_1 (
pk bigint,
c1 int not null default 0,
c2 int not null default 0,
primary key (pk)
) engine = xengine collate utf8mb4_general_ci;
insert into test_1 values (1,1,1);
alter table test_1 add column c3 int default 0;
insert into test_1 values (2,2,2,2);
alter table test_1 add column c4 int not null default 2;
insert into test_1 values (3,3,3,3,3);
select c1, c3, c4 from test_1;
drop table test_1;
# Create a small table and adding instant column between two columns should fail
CREATE TABLE t1 (a INT, b INT) engine = xengine;
INSERT INTO t1 VALUES(1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
# Try to add instant column after first column should fail
--error ER_ALTER_OPERATION_NOT_SUPPORTED
ALTER TABLE t1 ADD COLUMN c1 INT DEFAULT 5 AFTER a, ALGORITHM=INSTANT;
--error ER_ALTER_OPERATION_NOT_SUPPORTED
ALTER TABLE t1 ADD COLUMN c1 INT DEFAULT 5 FIRST, ALGORITHM=INSTANT;
# add instant column at the end of table
ALTER TABLE t1 ADD COLUMN c1 INT DEFAULT 5 AFTER b, ALGORITHM=INSTANT;
# INPLACE , not INSTANT
ALTER TABLE t1 ADD COLUMN c2 INT DEFAULT 6 AFTER c1, ALGORITHM=INPLACE;
SHOW CREATE TABLE t1;
DROP TABLE t1;
# add system variable xengine_disable_instant_ddl to disable instant ddl
show variables like "xengine_disable_instant_ddl";
CREATE TABLE t1 (a INT, b INT) engine = xengine;
INSERT INTO t1 VALUES(1, 1), (2, 2), (3, 3), (4, 4), (5, 5);
ALTER TABLE t1 ADD COLUMN c1 INT DEFAULT 5, ALGORITHM=INSTANT;
select b, c1 from t1 where c1 = 5;
set global xengine_disable_instant_ddl = ON;
--error ER_ALTER_OPERATION_NOT_SUPPORTED
ALTER TABLE t1 ADD COLUMN c2 INT DEFAULT 5, ALGORITHM=INSTANT;
ALTER TABLE t1 ADD COLUMN c2 INT DEFAULT 5;
--error ER_ALTER_OPERATION_NOT_SUPPORTED
alter table t1 alter column b set default 10, algorithm = instant;
alter table t1 alter column b set default 10;
select b, c1 from t1 where c1 = 5;
INSERT INTO t1 VALUES(6, 6, 10, 10);
set global xengine_disable_instant_ddl = OFF;
ALTER TABLE t1 ADD COLUMN c3 varchar(10) DEFAULT "xengine", ALGORITHM=INSTANT;
alter table t1 alter column b set default 8, algorithm = instant;
show create table t1;
select c2, a from t1;
DROP TABLE t1;