1# 2# Testing indexing with ALTER on inward table (in-place) 3# 4CREATE TABLE t1 (c INT NOT NULL, d CHAR(10) NOT NULL) ENGINE=CONNECT; 5Warnings: 6Warning 1105 No table_type. Will be set to DOS 7Warning 1105 No file name. Table will use t1.dos 8INSERT INTO t1 VALUES (1,'One'), (2,'Two'), (3,'Three'); 9SELECT * FROM t1; 10c d 111 One 122 Two 133 Three 14CREATE INDEX xc ON t1(c); 15DESCRIBE SELECT * FROM t1 WHERE c = 2; 16id select_type table type possible_keys key key_len ref rows Extra 171 SIMPLE t1 ref xc xc 4 const 1 18DROP INDEX xc ON t1; 19CREATE INDEX xd ON t1(d); 20DROP INDEX xd ON t1; 21ALTER TABLE t1 ADD INDEX xc (c), ADD INDEX xd (d); 22SHOW INDEX FROM t1; 23Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment 24t1 1 xc 1 c A NULL NULL NULL XINDEX 25t1 1 xd 1 d A NULL NULL NULL XINDEX 26ALTER TABLE t1 DROP INDEX xc, DROP INDEX xd; 27SHOW INDEX FROM t1; 28Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment 29# 30# Testing modifying columns inward table (not in-place) 31# 32ALTER TABLE t1 MODIFY COLUMN c CHAR(5) NOT NULL; 33SHOW CREATE TABLE t1; 34Table Create Table 35t1 CREATE TABLE `t1` ( 36 `c` char(5) NOT NULL, 37 `d` char(10) NOT NULL 38) ENGINE=CONNECT DEFAULT CHARSET=latin1 39SELECT * FROM t1; 40c d 411 One 422 Two 433 Three 44ALTER TABLE t1 MODIFY COLUMN c INT NOT NULL; 45# 46# Fails because indexing must be in-place 47# 48ALTER TABLE t1 MODIFY COLUMN c CHAR(10) NOT NULL, ADD INDEX xd (d); 49ERROR 0A000: Alter operations not supported together by CONNECT 50# 51# Testing changing table type (not in-place) 52# 53ALTER TABLE t1 TABLE_TYPE=CSV HEADER=1 QUOTED=1; 54SELECT * FROM t1; 55c d 561 One 572 Two 583 Three 59SHOW CREATE TABLE t1; 60Table Create Table 61t1 CREATE TABLE `t1` ( 62 `c` int(11) NOT NULL, 63 `d` char(10) NOT NULL 64) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`=CSV `HEADER`=1 `QUOTED`=1 65# create an outward table used to see the t1 file 66CREATE TABLE t2 (line VARCHAR(100) NOT NULL) ENGINE=CONNECT FILE_NAME='t1.csv'; 67Warnings: 68Warning 1105 No table_type. Will be set to DOS 69SELECT * FROM t2; 70line 71"c","d" 721,"One" 732,"Two" 743,"Three" 75# 76# Testing changing engine 77# 78DROP TABLE t1; 79CREATE TABLE t1 (c INT NOT NULL, d CHAR(10) NOT NULL) ENGINE=CONNECT; 80Warnings: 81Warning 1105 No table_type. Will be set to DOS 82Warning 1105 No file name. Table will use t1.dos 83INSERT INTO t1 VALUES (1,'One'), (2,'Two'), (3,'Three'); 84ALTER TABLE t1 ADD INDEX xc (c), ADD INDEX xd (d); 85ALTER TABLE t1 ENGINE = MYISAM; 86SHOW CREATE TABLE t1; 87Table Create Table 88t1 CREATE TABLE `t1` ( 89 `c` int(11) NOT NULL, 90 `d` char(10) NOT NULL, 91 KEY `xc` (`c`), 92 KEY `xd` (`d`) 93) ENGINE=MyISAM DEFAULT CHARSET=latin1 94SHOW INDEX FROM t1; 95Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment 96t1 1 xc 1 c A NULL NULL NULL BTREE 97t1 1 xd 1 d A NULL NULL NULL BTREE 98SELECT * FROM t1; 99c d 1001 One 1012 Two 1023 Three 103ALTER TABLE t1 ENGINE = CONNECT TABLE_TYPE=DBF; 104SHOW CREATE TABLE t1; 105Table Create Table 106t1 CREATE TABLE `t1` ( 107 `c` int(11) NOT NULL, 108 `d` char(10) NOT NULL, 109 KEY `xc` (`c`), 110 KEY `xd` (`d`) 111) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`=DBF 112SHOW INDEX FROM t1; 113Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment 114t1 1 xc 1 c A NULL NULL NULL XINDEX 115t1 1 xd 1 d A NULL NULL NULL XINDEX 116SELECT * FROM t1; 117c d 1181 One 1192 Two 1203 Three 121DROP TABLE t1, t2; 122# 123# Testing ALTER on outward tables 124# 125CREATE TABLE t1 (c INT NOT NULL, d CHAR(10) NOT NULL) ENGINE=CONNECT TABLE_TYPE=fix FILE_NAME='tf1.txt' ENDING=1; 126INSERT INTO t1 VALUES (1,'One'), (2,'Two'), (3,'Three'); 127SELECT * FROM t1; 128c d 1291 One 1302 Two 1313 Three 132CREATE TABLE t2 (line VARCHAR(100) NOT NULL) ENGINE=CONNECT FILE_NAME='tf1.txt'; 133Warnings: 134Warning 1105 No table_type. Will be set to DOS 135SELECT * FROM t2; 136line 137 1One 138 2Two 139 3Three 140# 141# Indexing works the same 142# 143ALTER TABLE t1 ADD INDEX xc (c), ADD INDEX xd (d); 144SHOW INDEX FROM t1; 145Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment 146t1 1 xc 1 c A NULL NULL NULL XINDEX 147t1 1 xd 1 d A NULL NULL NULL XINDEX 148SELECT d FROM t1 WHERE c = 2; 149d 150Two 151ALTER TABLE t1 DROP INDEX xc, DROP INDEX xd; 152SHOW INDEX FROM t1; 153Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment 154# 155# Other alterations do not modify the file 156# 157ALTER TABLE t1 MODIFY COLUMN c CHAR(5) NOT NULL; 158Warnings: 159Warning 1105 This is an outward table, table data were not modified. 160SELECT * FROM t2; 161line 162 1One 163 2Two 164 3Three 165SHOW CREATE TABLE t1; 166Table Create Table 167t1 CREATE TABLE `t1` ( 168 `c` char(5) NOT NULL, 169 `d` char(10) NOT NULL 170) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`=fix `FILE_NAME`='tf1.txt' `ENDING`=1 171SELECT * FROM t1; 172ERROR HY000: Got error 174 'File tf1.txt is not fixed length, len=66 lrecl=16' from CONNECT 173ALTER TABLE t1 MODIFY COLUMN c INT NOT NULL; 174Warnings: 175Warning 1105 This is an outward table, table data were not modified. 176# 177# Changing column order 178# 179ALTER TABLE t1 MODIFY COLUMN c INT NOT NULL AFTER d; 180Warnings: 181Warning 1105 This is an outward table, table data were not modified. 182SELECT * FROM t2; 183line 184 1One 185 2Two 186 3Three 187SHOW CREATE TABLE t1; 188Table Create Table 189t1 CREATE TABLE `t1` ( 190 `d` char(10) NOT NULL, 191 `c` int(11) NOT NULL 192) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`=fix `FILE_NAME`='tf1.txt' `ENDING`=1 193# Wrong result 194SELECT * FROM t1; 195d c 196 1 197 2 198 3 199ALTER TABLE t1 MODIFY COLUMN c INT NOT NULL FIRST; 200Warnings: 201Warning 1105 This is an outward table, table data were not modified. 202# What should have been done 203ALTER TABLE t1 MODIFY c INT NOT NULL FLAG=0 AFTER d, MODIFY d CHAR(10) NOT NULL FLAG=11; 204Warnings: 205Warning 1105 This is an outward table, table data were not modified. 206SHOW CREATE TABLE t1; 207Table Create Table 208t1 CREATE TABLE `t1` ( 209 `d` char(10) NOT NULL `FLAG`=11, 210 `c` int(11) NOT NULL `FLAG`=0 211) ENGINE=CONNECT DEFAULT CHARSET=latin1 `TABLE_TYPE`=fix `FILE_NAME`='tf1.txt' `ENDING`=1 212SELECT * FROM t1; 213d c 214One 1 215Two 2 216Three 3 217# 218# Changing to another engine is Ok 219# However, the data file is not deleted. 220# 221ALTER TABLE t1 ENGINE=ARIA; 222SHOW CREATE TABLE t1; 223Table Create Table 224t1 CREATE TABLE `t1` ( 225 `d` char(10) NOT NULL /* `FLAG`=11 */, 226 `c` int(11) NOT NULL /* `FLAG`=0 */ 227) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1 /* `TABLE_TYPE`=fix `FILE_NAME`='tf1.txt' `ENDING`=1 */ 228set @old_sql_mode=@@sql_mode; 229set sql_mode=ignore_bad_table_options; 230SHOW CREATE TABLE t1; 231Table Create Table 232t1 CREATE TABLE `t1` ( 233 `d` char(10) NOT NULL `FLAG`=11, 234 `c` int(11) NOT NULL `FLAG`=0 235) ENGINE=Aria DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1 `TABLE_TYPE`=fix `FILE_NAME`='tf1.txt' `ENDING`=1 236set sql_mode=@old_sql_mode; 237SELECT * from t1; 238d c 239One 1 240Two 2 241Three 3 242SELECT * from t2; 243line 244 1One 245 2Two 246 3Three 247# 248# Changing back to CONNECT fails 249# Sure enough, the data file was not deleted. 250# 251ALTER TABLE t1 ENGINE=CONNECT; 252ERROR HY000: Operation denied. Table data would be modified. 253# 254# But changing back to CONNECT succeed 255# if the data file does not exist. 256# 257ALTER TABLE t1 ENGINE=CONNECT; 258SHOW CREATE TABLE t1; 259Table Create Table 260t1 CREATE TABLE `t1` ( 261 `d` char(10) NOT NULL `FLAG`=11, 262 `c` int(11) NOT NULL `FLAG`=0 263) ENGINE=CONNECT DEFAULT CHARSET=latin1 PAGE_CHECKSUM=1 `TABLE_TYPE`=fix `FILE_NAME`='tf1.txt' `ENDING`=1 264SELECT * from t1; 265d c 266One 1 267Two 2 268Three 3 269SELECT * from t2; 270line 271 1One 272 2Two 273 3Three 274DROP TABLE t1, t2; 275