Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tianmu): The error message displayed is inaccurate when you drop unique … #1356

Merged
merged 3 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions mysql-test/suite/tianmu/r/drop_index.result
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions mysql-test/suite/tianmu/t/drop_index-master.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--sql_mode=NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_KEY_ERROR
54 changes: 54 additions & 0 deletions mysql-test/suite/tianmu/t/drop_index.test
Original file line number Diff line number Diff line change
@@ -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;
33 changes: 30 additions & 3 deletions sql/sql_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down Expand Up @@ -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)
{
Expand Down