ndb_alter_table.test 2.71 KB
Newer Older
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
-- source include/have_ndb.inc

--disable_warnings
DROP TABLE IF EXISTS t1;
--enable_warnings

#
# Basic test to show that the ALTER TABLE
#  is working
#
CREATE TABLE t1 (
  a INT NOT NULL,
  b INT NOT NULL
) ENGINE=ndbcluster;

INSERT INTO t1 VALUES (9410,9412);
  
ALTER TABLE t1 ADD COLUMN c int not null;
SELECT * FROM t1;

DROP TABLE t1;

#
# More advanced test
#
create table t1 (
col1 int not null auto_increment primary key,
col2 varchar(30) not null,
col3 varchar (20) not null,
col4 varchar(4) not null,
col5 enum('PENDING', 'ACTIVE', 'DISABLED') not null,
mskold@mysql.com's avatar
mskold@mysql.com committed
32
col6 int not null, to_be_deleted int)  ENGINE=ndbcluster;
33
show table status;
34
SET SQL_MODE=NO_AUTO_VALUE_ON_ZERO;
mskold@mysql.com's avatar
mskold@mysql.com committed
35 36
insert into t1 values
(0,4,3,5,"PENDING",1,7),(NULL,4,3,5,"PENDING",1,7),(31,4,3,5,"PENDING",1,7), (7,4,3,5,"PENDING",1,7), (NULL,4,3,5,"PENDING",1,7), (100,4,3,5,"PENDING",1,7), (99,4,3,5,"PENDING",1,7), (8,4,3,5,"PENDING",1,7), (NULL,4,3,5,"PENDING",1,7);
37
show table status;
38
select * from t1 order by col1;
39 40 41 42 43 44
alter table t1
add column col4_5 varchar(20) not null after col4,
add column col7 varchar(30) not null after col5,
add column col8 datetime not null, drop column to_be_deleted,
change column col2 fourth varchar(30) not null after col3,
modify column col6 int not null first;
45
show table status;
46 47
select * from t1 order by col1;
insert into t1 values (2, NULL,4,3,5,99,"PENDING","EXTRA",'2004-01-01 00:00:00');
48
show table status;
49
select * from t1 order by col1;
50 51 52 53 54 55 56 57
delete from t1;
insert into t1 values (0,0,4,3,5,99,"PENDING","EXTRA",'2004-01-01 00:00:00');
SET SQL_MODE='';
insert into t1 values (1,0,4,3,5,99,"PENDING","EXTRA",'2004-01-01 00:00:00');
select * from t1 order by col1;
alter table t1 drop column col4_5;
insert into t1 values (2,0,4,3,5,"PENDING","EXTRA",'2004-01-01 00:00:00');
select * from t1 order by col1;
58
drop table t1;
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

#
# Check that invalidating dictionary cache works
#

CREATE TABLE t1 (
  a INT NOT NULL,
  b INT NOT NULL
) ENGINE=ndbcluster;

INSERT INTO t1 VALUES (9410,9412);

connect (con1,localhost,,,test);
connect (con2,localhost,,,test);

connection con1;
ALTER TABLE t1 ADD COLUMN c int not null;
select * from t1;

connection con2;
select * from t1;
alter table t1 drop c;

connection con1;
select * from t1;
drop table t1;

connection con2;
--error 1146
select * from t1;

91 92 93
#--disable_warnings
#DROP TABLE IF EXISTS t2;
#--enable_warnings
94

95 96 97 98 99 100 101 102 103 104 105 106 107
#create table t2 (a int NOT NULL PRIMARY KEY) engine=myisam;
#let $1=12001;
#disable_query_log;
#while ($1)
#{
# eval insert into t2 values($1);
# dec $1;
#}
#enable_query_log;
#alter table t2 engine=ndbcluster;
#alter table t2 add c int;
#--error 1297
#delete from t2;
108
#to make sure we do a full table scan
109 110 111 112
#select count(*) from t2 where a+0 > 0;
#truncate table t2;
#select count(*) from t2;
#drop table t2;