1--source include/have_innodb.inc 2 3# check if "IF [NOT] EXISTS" option works as expected for 4# "CREATE/DROP COMPRESSION_DICTIONARY ..." 5 6# creating a dictionary with a non-taken name must not be 7# affected by "IF NOT EXISTS" option 8CREATE COMPRESSION_DICTIONARY IF NOT EXISTS ddd('foo'); 9# creating a dictionary with the same name and content 10# must generate a warning 11CREATE COMPRESSION_DICTIONARY IF NOT EXISTS ddd('foo'); 12# creating a dictionary with the same name but different content 13# must generate a warning and leave content intact 14CREATE COMPRESSION_DICTIONARY IF NOT EXISTS ddd('bar'); 15# dropping an existing dictionary must not be affected by 16# "IF EXISTS" option 17DROP COMPRESSION_DICTIONARY IF EXISTS ddd; 18# dropping a non-existing dictionary must generate a warning 19DROP COMPRESSION_DICTIONARY IF EXISTS ddd; 20 21# check if dictionary data supplied to "CREATE COMPRESSION_DICTIONARY ..." 22# statements is the same as in the information_schema (NUL characters 23# must not be ignored and must not be treated as string terminators) 24 25CREATE COMPRESSION_DICTIONARY d1(''); 26CREATE COMPRESSION_DICTIONARY d2(_ucs2''); 27CREATE COMPRESSION_DICTIONARY d3('aaaaaaaabbbbbbbbccccccccdddddddd'); 28CREATE COMPRESSION_DICTIONARY d4(_ucs2'aaaaaaaabbbbbbbbccccccccdddddddd'); 29 30CREATE COMPRESSION_DICTIONARY d5(' '); 31CREATE COMPRESSION_DICTIONARY d6('\0'); 32CREATE COMPRESSION_DICTIONARY d7('\0aaaaaaaabbbbbbbbccccccccdddddddd'); 33 34# check if it is possible to create a compression dictionary with 35# string data passed via variable 36SET @dict_data8 = 'aaaaaaaabbbbbbbbccccccccdddddddd'; 37CREATE COMPRESSION_DICTIONARY d8(@dict_data8); 38 39# variable containing empty string 40SET @dict_data9 = ''; 41CREATE COMPRESSION_DICTIONARY d9(@dict_data9); 42 43# numeric variable 44SET @dict_data10 = 123; 45CREATE COMPRESSION_DICTIONARY d10(@dict_data10); 46 47# variable of DATETIME type 48SET @dict_data11 = STR_TO_DATE('02/29/2016', '%m/%d/%Y'); 49CREATE COMPRESSION_DICTIONARY d11(@dict_data11); 50 51# NULL variable 52SET @dict_data12 = NULL; 53CREATE COMPRESSION_DICTIONARY d12(@dict_data12); 54 55# "CREATE COMPRESSION_DICTIONARY <dict>(@<var> := <expr>)" must 56# generate a syntax error 57--error ER_PARSE_ERROR 58CREATE COMPRESSION_DICTIONARY d12(@dict_data12 := 'blah'); 59 60# max dictionary name length is 64 characters - check if an 61# error is reported if this number is exceeded 62SET @long_dictionary_name = REPEAT('d', 64); 63--let $long_dictionary_name=`SELECT @long_dictionary_name` 64--eval CREATE COMPRESSION_DICTIONARY $long_dictionary_name('abcd') 65 66--error ER_COMPRESSION_DICTIONARY_NAME_TOO_LONG 67--eval CREATE COMPRESSION_DICTIONARY d$long_dictionary_name('abcd') 68 69# max dictionary data size is 32506 bytes - check if an error 70# is reported if this number is exceeded 71SET @long_dictionary_data = REPEAT('ab', 32506 / 2); 72CREATE COMPRESSION_DICTIONARY d13(@long_dictionary_data); 73 74SET @longer_dictionary_data = CONCAT(@long_dictionary_data, 'a'); 75--error ER_COMPRESSION_DICTIONARY_DATA_TOO_LONG 76CREATE COMPRESSION_DICTIONARY d14(@longer_dictionary_data); 77 78# we use MD5() function here to get rid of NUL characters in the output 79SELECT id, name, MD5(zip_dict), LENGTH(zip_dict) 80 FROM information_schema.xtradb_zip_dict 81 ORDER BY id; 82 83# check if dictionary data stored in SYS_ZIP_DICT can be extracted 84# without corruption 85SELECT zip_dict = 'abcd' AS short_zip_dict_data_must_match 86 FROM information_schema.xtradb_zip_dict 87 WHERE name = @long_dictionary_name; 88SELECT zip_dict = @long_dictionary_data AS long_zip_dict_data_must_match 89 FROM information_schema.xtradb_zip_dict 90 WHERE name = 'd13'; 91 92# creating a compression dictionary with a name already taken is an error 93--error ER_COMPRESSION_DICTIONARY_EXISTS 94CREATE COMPRESSION_DICTIONARY d1('data'); 95 96--let $dict_name=d1 97--let $table_name=t1 98 99# getting compression dictionary id for $dict_name 100eval SELECT id INTO @dict_id FROM information_schema.xtradb_zip_dict 101 WHERE name = '$dict_name'; 102 103# creating a new table which references a non-existing compression dictionary 104# must generate an error 105--error ER_COMPRESSION_DICTIONARY_DOES_NOT_EXIST 106eval CREATE TABLE $table_name( 107 id INT, 108 a BLOB COLUMN_FORMAT COMPRESSED, 109 b BLOB COLUMN_FORMAT COMPRESSED WITH COMPRESSION_DICTIONARY d100 110) ENGINE=InnoDB; 111 112# creating a new table $table_name with 2 compressed columns (with and without dictionary) 113eval CREATE TABLE $table_name( 114 id INT, 115 a BLOB COLUMN_FORMAT COMPRESSED, 116 b BLOB COLUMN_FORMAT COMPRESSED WITH COMPRESSION_DICTIONARY $dict_name 117) ENGINE=InnoDB; 118 119# check if compression dictionary references are reflected in SHOW CREATE TABLE output 120eval SHOW CREATE TABLE $table_name; 121 122# getting table id for $table_name 123eval SELECT table_id INTO @table_id FROM information_schema.innodb_sys_tables 124 WHERE name=CONCAT(DATABASE(), '/', '$table_name'); 125 126# the number of column<->dict_id links for $table_name must be exactly one 127SELECT COUNT(*) = 1 AS only_one_dictionary_reference FROM information_schema.xtradb_zip_dict_cols 128 WHERE table_id = @table_id; 129 130SELECT dict_id = @dict_id AS dict_ids_must_match FROM information_schema.xtradb_zip_dict_cols 131 WHERE table_id = @table_id AND column_pos = 2; 132 133# check if it is OK to refer to an empty dictionary 134SET @long_string_value = REPEAT('a', 128); 135eval INSERT INTO $table_name VALUES(1, @long_string_value, @long_string_value); 136eval SELECT a = @long_string_value AS a_match, b = @long_string_value AS b_match FROM $table_name 137 WHERE id = 1; 138 139# dropping non-existing compression dictionary must generate an error 140--error ER_COMPRESSION_DICTIONARY_DOES_NOT_EXIST 141DROP COMPRESSION_DICTIONARY d100; 142 143# dropping a dictionary in use must generate an error 144--error ER_COMPRESSION_DICTIONARY_IS_REFERENCED 145--eval DROP COMPRESSION_DICTIONARY $dict_name 146 147# dropping existing compression dictionary must be reflected in "xtradb_zip_dict" 148DROP COMPRESSION_DICTIONARY d13; 149 150SELECT COUNT(*) = 0 AS dict_must_be_deleted 151 FROM information_schema.xtradb_zip_dict 152 WHERE name = 'd13'; 153 154# droppping all created compression dictionaries except d1 155DROP COMPRESSION_DICTIONARY d2; 156DROP COMPRESSION_DICTIONARY d3; 157DROP COMPRESSION_DICTIONARY d4; 158DROP COMPRESSION_DICTIONARY d5; 159DROP COMPRESSION_DICTIONARY d6; 160DROP COMPRESSION_DICTIONARY d7; 161DROP COMPRESSION_DICTIONARY d8; 162DROP COMPRESSION_DICTIONARY d9; 163DROP COMPRESSION_DICTIONARY d10; 164DROP COMPRESSION_DICTIONARY d11; 165DROP COMPRESSION_DICTIONARY d12; 166--eval DROP COMPRESSION_DICTIONARY $long_dictionary_name 167 168# check if the changes are reflected properly in "xtradb_zip_dict" 169SELECT id, name, zip_dict, LENGTH(zip_dict) 170 FROM information_schema.xtradb_zip_dict; 171 172# dropping table with references to compression dictionaries must also clean 173# SYS_ZIP_DICT_COLS InnoDB system table 174--eval DROP TABLE $table_name 175 176SELECT COUNT(*) = 1 AS compression_dictionary_exists FROM information_schema.xtradb_zip_dict 177 WHERE id = @dict_id; 178SELECT COUNT(*) = 0 AS references_cleared FROM information_schema.xtradb_zip_dict_cols 179 WHERE table_id = @table_id; 180 181# check if tables deleted implicitly via "DROP DATABASE" also perform 182# SYS_ZIP_DICT_COLS cleanup 183--let $aux_database_name = db1 184 185eval CREATE DATABASE $aux_database_name; 186eval CREATE TABLE $aux_database_name.$table_name( 187 id INT, 188 a BLOB COLUMN_FORMAT COMPRESSED, 189 b BLOB COLUMN_FORMAT COMPRESSED WITH COMPRESSION_DICTIONARY $dict_name 190) ENGINE=InnoDB; 191 192# getting table id for $aux_database_name.$table_name 193eval SELECT table_id INTO @table_id FROM information_schema.innodb_sys_tables 194 WHERE name=CONCAT('$aux_database_name', '/', '$table_name'); 195 196# the number of column<->dict_id links for $aux_database_name.$table_name must be exactly one 197SELECT COUNT(*) = 1 AS only_one_dictionary_reference FROM information_schema.xtradb_zip_dict_cols 198 WHERE table_id = @table_id; 199 200SELECT dict_id = @dict_id AS dict_ids_must_match FROM information_schema.xtradb_zip_dict_cols 201 WHERE table_id = @table_id AND column_pos = 2; 202 203--eval DROP DATABASE $aux_database_name 204 205SELECT COUNT(*) = 1 AS compression_dictionary_exists FROM information_schema.xtradb_zip_dict 206 WHERE id = @dict_id; 207SELECT COUNT(*) = 0 AS references_cleared FROM information_schema.xtradb_zip_dict_cols 208 WHERE table_id = @table_id; 209 210# saving current @default_storage_engine 211SET @saved_default_storage_engine = @@default_storage_engine; 212 213--echo # check if "CREATE TABLE ... LIKE ..." does not lose "COLUMN_FORMAT COMPRESSED" attribute 214--let $original_table_name = t1 215--let $original_column_name = a 216--let $original_column_type = BLOB 217--let $original_dict_name = * 218--let $modified_table_name = t2 219--let $modified_column_name = $original_column_name 220--let $modified_column_type = $original_column_type 221--let $modified_dict_name = $original_dict_name 222--let $alter_table_algorithm = DEFAULT 223--source suite/innodb/include/xtradb_compressed_columns_alter_table_pre.inc 224eval CREATE TABLE $modified_table_name LIKE $original_table_name; 225eval DROP TABLE $original_table_name; 226--source suite/innodb/include/xtradb_compressed_columns_alter_table_post.inc 227 228--echo # check if "CREATE TABLE ... AS SELECT * FROM ..." discards "COLUMN_FORMAT COMPRESSED" attribute (implicit SE) 229--let $modified_dict_name = 230--source suite/innodb/include/xtradb_compressed_columns_alter_table_pre.inc 231SET default_storage_engine = InnoDB; 232eval CREATE TABLE $modified_table_name AS SELECT * FROM $original_table_name; 233eval DROP TABLE $original_table_name; 234--source suite/innodb/include/xtradb_compressed_columns_alter_table_post.inc 235 236--echo # check if "CREATE TABLE ... AS SELECT * FROM ..." discards "COLUMN_FORMAT COMPRESSED" attribute (explicit SE) 237--source suite/innodb/include/xtradb_compressed_columns_alter_table_pre.inc 238SET default_storage_engine = MyISAM; 239eval CREATE TABLE $modified_table_name ENGINE=InnoDB AS SELECT * FROM $original_table_name; 240eval DROP TABLE $original_table_name; 241--source suite/innodb/include/xtradb_compressed_columns_alter_table_post.inc 242 243--echo # check if "CREATE TABLE ... AS SELECT * FROM ..." discards "COLUMN_FORMAT COMPRESSED" attribute (implicitly changing SE) 244--let $storage_engine_changed = 1 245--source suite/innodb/include/xtradb_compressed_columns_alter_table_pre.inc 246SET default_storage_engine = MyISAM; 247eval CREATE TABLE $modified_table_name AS SELECT * FROM $original_table_name; 248eval DROP TABLE $original_table_name; 249--source suite/innodb/include/xtradb_compressed_columns_alter_table_post.inc 250--let $storage_engine_changed = 251 252--echo # check if "CREATE TABLE ... AS SELECT * FROM ..." discards "COLUMN_FORMAT COMPRESSED" attribute (explicitly changing SE) 253--let $storage_engine_changed = 1 254--source suite/innodb/include/xtradb_compressed_columns_alter_table_pre.inc 255SET default_storage_engine = InnoDB; 256eval CREATE TABLE $modified_table_name ENGINE=MyISAM AS SELECT * FROM $original_table_name; 257eval DROP TABLE $original_table_name; 258--source suite/innodb/include/xtradb_compressed_columns_alter_table_post.inc 259--let $storage_engine_changed = 260 261--echo # check if "CREATE TABLE ... AS SELECT * FROM ..." with dummy expression does not trigger ER_ILLEGAL_HA_CREATE_OPTION (no dictionary, implicit SE) 262--let $storage_engine_changed = 1 263--source suite/innodb/include/xtradb_compressed_columns_alter_table_pre.inc 264SET default_storage_engine = MyISAM; 265eval CREATE TABLE $modified_table_name AS SELECT id, dummy, CONCAT($original_column_name, '') AS $original_column_name, last FROM $original_table_name; 266eval DROP TABLE $original_table_name; 267--source suite/innodb/include/xtradb_compressed_columns_alter_table_post.inc 268--let $storage_engine_changed = 269 270--echo # check if "CREATE TABLE ... AS SELECT * FROM ..." with dummy expression does not trigger ER_ILLEGAL_HA_CREATE_OPTION (no dictionary, explicit SE) 271--let $storage_engine_changed = 1 272--source suite/innodb/include/xtradb_compressed_columns_alter_table_pre.inc 273SET default_storage_engine = InnoDB; 274eval CREATE TABLE $modified_table_name ENGINE=MyISAM AS SELECT id, dummy, CONCAT($original_column_name, '') AS $original_column_name, last FROM $original_table_name; 275eval DROP TABLE $original_table_name; 276--source suite/innodb/include/xtradb_compressed_columns_alter_table_post.inc 277--let $storage_engine_changed = 278 279 280--echo # check if "CREATE TABLE ... LIKE ..." does not lose compression dictionary references 281--let $original_table_name = t1 282--let $modified_table_name = t2 283--let $original_dict_name = $dict_name 284--let $modified_dict_name = $original_dict_name 285--source suite/innodb/include/xtradb_compressed_columns_alter_table_pre.inc 286eval CREATE TABLE $modified_table_name LIKE $original_table_name; 287eval DROP TABLE $original_table_name; 288--source suite/innodb/include/xtradb_compressed_columns_alter_table_post.inc 289 290--echo # check if "CREATE TABLE ... AS SELECT * FROM ..." discards compression dictionary references (implicit SE) 291--let $modified_dict_name = 292--source suite/innodb/include/xtradb_compressed_columns_alter_table_pre.inc 293SET default_storage_engine = InnoDB; 294eval CREATE TABLE $modified_table_name AS SELECT * FROM $original_table_name; 295eval DROP TABLE $original_table_name; 296--source suite/innodb/include/xtradb_compressed_columns_alter_table_post.inc 297 298--echo # check if "CREATE TABLE ... AS SELECT * FROM ..." discards compression dictionary references (explicit SE) 299--source suite/innodb/include/xtradb_compressed_columns_alter_table_pre.inc 300SET default_storage_engine = MyISAM; 301eval CREATE TABLE $modified_table_name ENGINE=InnoDB AS SELECT * FROM $original_table_name; 302eval DROP TABLE $original_table_name; 303--source suite/innodb/include/xtradb_compressed_columns_alter_table_post.inc 304 305--echo # check if "CREATE TABLE ... AS SELECT * FROM ..." discards compression dictionary references (implicitly changing SE) 306--let $storage_engine_changed = 1 307--source suite/innodb/include/xtradb_compressed_columns_alter_table_pre.inc 308SET default_storage_engine = MyISAM; 309eval CREATE TABLE $modified_table_name AS SELECT * FROM $original_table_name; 310eval DROP TABLE $original_table_name; 311--source suite/innodb/include/xtradb_compressed_columns_alter_table_post.inc 312--let $storage_engine_changed = 313 314--echo # check if "CREATE TABLE ... AS SELECT * FROM ..." discards compression dictionary references (explicitly changing SE) 315--let $storage_engine_changed = 1 316--source suite/innodb/include/xtradb_compressed_columns_alter_table_pre.inc 317SET default_storage_engine = InnoDB; 318eval CREATE TABLE $modified_table_name ENGINE=MyISAM AS SELECT * FROM $original_table_name; 319eval DROP TABLE $original_table_name; 320--source suite/innodb/include/xtradb_compressed_columns_alter_table_post.inc 321--let $storage_engine_changed = 322 323--echo # check if "CREATE TABLE ... AS SELECT * FROM ..." with dummy expression does not trigger ER_ILLEGAL_HA_CREATE_OPTION (with a dictionary, implicit SE) 324--let $storage_engine_changed = 1 325--source suite/innodb/include/xtradb_compressed_columns_alter_table_pre.inc 326SET default_storage_engine = MyISAM; 327eval CREATE TABLE $modified_table_name AS SELECT id, dummy, CONCAT($original_column_name, '') AS $original_column_name, last FROM $original_table_name; 328eval DROP TABLE $original_table_name; 329--source suite/innodb/include/xtradb_compressed_columns_alter_table_post.inc 330--let $storage_engine_changed = 331 332--echo # check if "CREATE TABLE ... AS SELECT * FROM ..." with dummy expression does not trigger ER_ILLEGAL_HA_CREATE_OPTION (with a dictionary, explicit SE) 333--let $storage_engine_changed = 1 334--source suite/innodb/include/xtradb_compressed_columns_alter_table_pre.inc 335SET default_storage_engine = InnoDB; 336eval CREATE TABLE $modified_table_name ENGINE=MyISAM AS SELECT id, dummy, CONCAT($original_column_name, '') AS $original_column_name, last FROM $original_table_name; 337eval DROP TABLE $original_table_name; 338--source suite/innodb/include/xtradb_compressed_columns_alter_table_post.inc 339--let $storage_engine_changed = 340 341# restoring @default_storage_engine 342SET default_storage_engine = @saved_default_storage_engine; 343 344--echo # check if "TRUNCATE TABLE ..." updates compression dictionary references in SYS_ZIP_DICT_COLS 345--let $temporary_table_name = tmp 346--let $original_table_name = t1 347--let $modified_table_name = $original_table_name 348--let $original_dict_name = $dict_name 349--let $modified_dict_name = $original_dict_name 350--source suite/innodb/include/xtradb_compressed_columns_alter_table_pre.inc 351eval CREATE TEMPORARY TABLE $temporary_table_name AS SELECT * FROM $original_table_name; 352eval TRUNCATE TABLE $original_table_name; 353eval INSERT INTO $original_table_name SELECT * FROM $temporary_table_name; 354eval DROP TEMPORARY TABLE $temporary_table_name; 355--source suite/innodb/include/xtradb_compressed_columns_alter_table_post.inc 356 357# remove remaining compression dictionary 358--eval DROP COMPRESSION_DICTIONARY $dict_name 359SELECT COUNT(*) = 0 AS compression_dictionary_removed FROM information_schema.xtradb_zip_dict 360 WHERE id = @dict_id; 361 362# check if dropping a table without compressed dictionary references does not crash 363--eval CREATE TABLE $table_name(id INT, a BLOB) ENGINE=InnoDB 364--eval DROP TABLE $table_name 365 366# 367# Check if tablespace datafile is removed properly on unsuccessful attempt to create 368# a table referencing non-existing compression dictionary 369# 370--error ER_COMPRESSION_DICTIONARY_DOES_NOT_EXIST 371CREATE TABLE t1(c1 TEXT COLUMN_FORMAT COMPRESSED WITH COMPRESSION_DICTIONARY unknown); 372CREATE TABLE t1(c1 TEXT COLUMN_FORMAT COMPRESSED); 373DROP TABLE t1; 374 375CREATE COMPRESSION_DICTIONARY existing_dict('aaaa'); 376SELECT id INTO @existing_dict_id FROM information_schema.xtradb_zip_dict 377 WHERE name = 'existing_dict'; 378--error ER_COMPRESSION_DICTIONARY_DOES_NOT_EXIST 379CREATE TABLE t1( 380 c1 TEXT COLUMN_FORMAT COMPRESSED WITH COMPRESSION_DICTIONARY existing_dict, 381 c2 TEXT COLUMN_FORMAT COMPRESSED WITH COMPRESSION_DICTIONARY unknown 382); 383SELECT COUNT(*) = 0 AS no_dict_references_created FROM information_schema.xtradb_zip_dict_cols 384 WHERE dict_id = @existing_dict_id; 385DROP COMPRESSION_DICTIONARY existing_dict; 386 387 388# 389# Bug lp:1630500 "handle_fatal_signal (sig=6) in row_log_abort_sec" 390# 391CREATE TABLE t1( 392 c1 TEXT COLUMN_FORMAT COMPRESSED, 393 c2 VARCHAR(1) COLUMN_FORMAT COMPRESSED 394); 395--error ER_COMPRESSION_DICTIONARY_DOES_NOT_EXIST 396ALTER TABLE t1 ADD COLUMN b BLOB COLUMN_FORMAT COMPRESSED WITH COMPRESSION_DICTIONARY dict1; 397DROP TABLE t1; 398 399CREATE COMPRESSION_DICTIONARY existing_dict('aaaa'); 400SELECT id INTO @existing_dict_id FROM information_schema.xtradb_zip_dict 401 WHERE name = 'existing_dict'; 402CREATE TABLE t1( 403 c1 TEXT COLUMN_FORMAT COMPRESSED WITH COMPRESSION_DICTIONARY existing_dict 404); 405SELECT COUNT(*) = 1 AS one_dict_reference_created FROM information_schema.xtradb_zip_dict_cols 406 WHERE dict_id = @existing_dict_id; 407 408--error ER_COMPRESSION_DICTIONARY_DOES_NOT_EXIST 409ALTER TABLE t1 ADD COLUMN c2 TEXT COLUMN_FORMAT COMPRESSED WITH COMPRESSION_DICTIONARY unknown; 410SELECT COUNT(*) = 1 AS one_dict_reference_after_adding_one_column FROM information_schema.xtradb_zip_dict_cols 411 WHERE dict_id = @existing_dict_id; 412 413--error ER_COMPRESSION_DICTIONARY_DOES_NOT_EXIST 414ALTER TABLE t1 415 ADD COLUMN c2 TEXT COLUMN_FORMAT COMPRESSED WITH COMPRESSION_DICTIONARY existing_dict, 416 ADD COLUMN c3 TEXT COLUMN_FORMAT COMPRESSED WITH COMPRESSION_DICTIONARY unknown 417; 418SELECT COUNT(*) = 1 AS one_dict_reference_after_adding_two_columns FROM information_schema.xtradb_zip_dict_cols 419 WHERE dict_id = @existing_dict_id; 420 421DROP TABLE t1; 422DROP COMPRESSION_DICTIONARY existing_dict; 423