diff --git a/mysql-test/suite/tianmu/r/drop_index.result b/mysql-test/suite/tianmu/r/drop_index.result new file mode 100644 index 000000000..ced3ddefc --- /dev/null +++ b/mysql-test/suite/tianmu/r/drop_index.result @@ -0,0 +1,40 @@ +DROP DATABASE IF EXISTS drop_index_test; +CREATE DATABASE drop_index_test; +USE drop_index_test; +CREATE TABLE t1 ( +id int(11) DEFAULT NULL, +name varchar(10) DEFAULT NULL, +UNIQUE KEY idx_id (id) +) ENGINE=TIANMU DEFAULT CHARSET=utf8mb4; +CREATE TABLE t2 ( +`id` int(11) NOT NULL, +`name` text, +PRIMARY KEY (`id`), +FULLTEXT KEY `idx_name` (`name`) +) ENGINE=TIANMU DEFAULT CHARSET=utf8mb4; +CREATE TABLE `t3` ( +`id` int(11) NOT NULL AUTO_INCREMENT, +`first_name` varchar(10) NOT NULL, +`last_name` text NOT NULL, +`sex` varchar(5) NOT NULL, +`score` int(11) NOT NULL, +`copy_id` int(11) NOT NULL, +PRIMARY KEY (`id`), +UNIQUE KEY `idx_uk` (`copy_id`), +KEY `idx_firstname` (`first_name`), +FULLTEXT KEY `idx_lastname` (`last_name`) +) ENGINE=TIANMU DEFAULT CHARSET=utf8mb4; +set session sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'; +Warnings: +Warning 3135 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release. +drop index idx_id on t1; +ERROR HY000: Tianmu engine does not support unique index. +drop index idx_name on t2; +ERROR HY000: Tianmu engine does not support fulltext index. +drop index idx_firstname on t3; +ERROR HY000: Tianmu engine does not support secondary index. +drop index idx_lastname on t3; +ERROR HY000: Tianmu engine does not support fulltext index. +drop index idx_uk on t3; +ERROR HY000: Tianmu engine does not support unique index. +DROP DATABASE drop_index_test; diff --git a/mysql-test/suite/tianmu/t/drop_index-master.opt b/mysql-test/suite/tianmu/t/drop_index-master.opt new file mode 100644 index 000000000..4494579d7 --- /dev/null +++ b/mysql-test/suite/tianmu/t/drop_index-master.opt @@ -0,0 +1 @@ +--sql_mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_KEY_ERROR diff --git a/mysql-test/suite/tianmu/t/drop_index.test b/mysql-test/suite/tianmu/t/drop_index.test new file mode 100644 index 000000000..6ad7b74e3 --- /dev/null +++ b/mysql-test/suite/tianmu/t/drop_index.test @@ -0,0 +1,54 @@ +--source include/have_tianmu.inc + +--disable_warnings +DROP DATABASE IF EXISTS drop_index_test; +--enable_warnings + +CREATE DATABASE drop_index_test; + +USE drop_index_test; + +CREATE TABLE t1 ( + id int(11) DEFAULT NULL, + name varchar(10) DEFAULT NULL, + UNIQUE KEY idx_id (id) + ) ENGINE=TIANMU DEFAULT CHARSET=utf8mb4; + +CREATE TABLE t2 ( + `id` int(11) NOT NULL, + `name` text, + PRIMARY KEY (`id`), + FULLTEXT KEY `idx_name` (`name`) +) ENGINE=TIANMU DEFAULT CHARSET=utf8mb4; + +CREATE TABLE `t3` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `first_name` varchar(10) NOT NULL, + `last_name` text NOT NULL, + `sex` varchar(5) NOT NULL, + `score` int(11) NOT NULL, + `copy_id` int(11) NOT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `idx_uk` (`copy_id`), + KEY `idx_firstname` (`first_name`), + FULLTEXT KEY `idx_lastname` (`last_name`) +) ENGINE=TIANMU DEFAULT CHARSET=utf8mb4; + +set session sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'; + +--error ER_TIANMU_NOT_SUPPORTED_UNIQUE_INDEX +drop index idx_id on t1; + +--error ER_TIANMU_NOT_SUPPORTED_FULLTEXT_INDEX +drop index idx_name on t2; + +--error ER_TIANMU_NOT_SUPPORTED_SECONDARY_INDEX +drop index idx_firstname on t3; + +--error ER_TIANMU_NOT_SUPPORTED_FULLTEXT_INDEX +drop index idx_lastname on t3; + +--error ER_TIANMU_NOT_SUPPORTED_UNIQUE_INDEX +drop index idx_uk on t3; + +DROP DATABASE drop_index_test; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 0bf416a39..db9000529 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3933,7 +3933,6 @@ mysql_prepare_create_table(THD *thd, const char *error_schema_name, } (*key_count)++; tmp=file->max_key_parts(); - sql_mode_t sql_mode = thd->slave_thread ? global_system_variables.sql_mode : thd->variables.sql_mode; if ((create_info->db_type->db_type == DB_TYPE_TIANMU)) { if ((file->ha_table_flags() & HA_NON_SECONDARY_KEY) && @@ -8316,8 +8315,36 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, while ((drop=drop_it++)) { if (drop->type == Alter_drop::KEY && - !my_strcasecmp(system_charset_info,key_name, drop->name)) - break; + !my_strcasecmp(system_charset_info,key_name, drop->name)) { + // for issue 1342 and 1343, if sql_mode does not contains NO_KEY_ERROR, + // drop unique key, sencondary index, and fulltext index will return an error. + sql_mode_t sql_mode = thd->slave_thread ? global_system_variables.sql_mode : thd->variables.sql_mode; + if ((create_info->db_type->db_type == DB_TYPE_TIANMU) && + !(sql_mode & MODE_NO_KEY_ERROR)) { + if (key_info->flags & HA_SPATIAL){ + //key_type= KEYTYPE_SPATIAL; + //do nothing + } else if (key_info->flags & HA_NOSAME) { + if (! my_strcasecmp(system_charset_info, key_name, primary_key_name)) { + //key_type= KEYTYPE_PRIMARY; + //do nothing + } else { + //key_type= KEYTYPE_UNIQUE; + my_error(ER_TIANMU_NOT_SUPPORTED_UNIQUE_INDEX, MYF(0)); + goto err; + } + } else if (key_info->flags & HA_FULLTEXT) { + //key_type= KEYTYPE_FULLTEXT; + my_error(ER_TIANMU_NOT_SUPPORTED_FULLTEXT_INDEX, MYF(0)); + goto err; + } else { + //key_type= KEYTYPE_MULTIPLE; + my_error(ER_TIANMU_NOT_SUPPORTED_SECONDARY_INDEX, MYF(0)); + goto err; + } + } + break; + } } if (drop) {