Skip to content

Commit

Permalink
feat(sql):add NO_KEY_ERROR to sql_mode for ignoring unsupported error.(
Browse files Browse the repository at this point in the history
…#1318)

Add NO_KEY_ERROR to sql_mode.
Add judgement for secondary index、unique index、trigger、etc.
  • Loading branch information
DandreChen authored and mergify[bot] committed Feb 22, 2023
1 parent dc2c64b commit ae42cbf
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
3 changes: 2 additions & 1 deletion sql/auth/sql_authorization.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4390,7 +4390,8 @@ bool check_fk_parent_table_access(THD *thd,
// Return if engine does not support Foreign key Constraint.
if (!ha_check_storage_engine_flag(db_type, HTON_SUPPORTS_FOREIGN_KEYS)) {
if (db_type == tianmu_hton &&
(alter_info->flags & Alter_info::ADD_FOREIGN_KEY)) {
(alter_info->flags & Alter_info::ADD_FOREIGN_KEY) &&
(!(thd->variables.sql_mode & MODE_NO_KEY_ERROR))) {
my_error(ER_TIANMU_NOT_SUPPORTED_FOREIGN_KEY, MYF(0));
return true;
}
Expand Down
3 changes: 2 additions & 1 deletion sql/sql_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,8 @@ enum enum_binlog_format {
#define MODE_NO_ENGINE_SUBSTITUTION (MODE_HIGH_NOT_PRECEDENCE*2)
#define MODE_PAD_CHAR_TO_FULL_LENGTH (1ULL << 31)
//Force the engine to be tianmu when acting as a slave library
#define MODE_MANDATORY_TIANMU (1ULL << 32)
#define MODE_MANDATORY_TIANMU (1ULL << 32)
#define MODE_NO_KEY_ERROR (1ULL << 33)

/*
Replication uses 8 bytes to store SQL_MODE in the binary log. The day you
Expand Down
25 changes: 16 additions & 9 deletions sql/sql_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3927,21 +3927,24 @@ mysql_prepare_create_table(THD *thd, const char *error_schema_name,
(fk_key->name.str ? fk_key->name.str :
"foreign key without name"),
ER(ER_KEY_REF_DO_NOT_MATCH_TABLE_REF));
DBUG_RETURN(TRUE);
DBUG_RETURN(TRUE);
}
continue;
}
(*key_count)++;
tmp=file->max_key_parts();

if (create_info->db_type->db_type == DB_TYPE_TIANMU) {
if ((create_info->db_type->db_type == DB_TYPE_TIANMU) &&
(thd->lex->sql_command != SQLCOM_CREATE_TABLE)) {
if ((file->ha_table_flags() & HA_NON_SECONDARY_KEY) &&
key->type == KEYTYPE_MULTIPLE) {
(key->type == KEYTYPE_MULTIPLE) &&
!(thd->variables.sql_mode & MODE_NO_KEY_ERROR)) {
my_error(ER_TIANMU_NOT_SUPPORTED_SECONDARY_INDEX, MYF(0));
DBUG_RETURN(TRUE);
}
if (file->ha_table_flags() & HA_NON_UNIQUE_KEY &&
key->type == KEYTYPE_UNIQUE) {
if ((file->ha_table_flags() & HA_NON_UNIQUE_KEY) &&
(key->type == KEYTYPE_UNIQUE) &&
(!(thd->variables.sql_mode & MODE_NO_KEY_ERROR))) {
my_error(ER_TIANMU_NOT_SUPPORTED_UNIQUE_INDEX, MYF(0));
DBUG_RETURN(TRUE);
}
Expand Down Expand Up @@ -4078,7 +4081,8 @@ mysql_prepare_create_table(THD *thd, const char *error_schema_name,
MYF(0));
DBUG_RETURN(TRUE);
}
if (create_info->db_type->db_type == DB_TYPE_TIANMU) {
if ((create_info->db_type->db_type == DB_TYPE_TIANMU) &&
(!(thd->variables.sql_mode & MODE_NO_KEY_ERROR))) {
my_message(ER_TIANMU_NOT_SUPPORTED_FULLTEXT_INDEX,
ER(ER_TIANMU_NOT_SUPPORTED_FULLTEXT_INDEX), MYF(0));
} else {
Expand Down Expand Up @@ -8493,7 +8497,8 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
while ((drop=drop_it++)) {
switch (drop->type) {
case Alter_drop::KEY:
if (create_info->db_type->db_type == DB_TYPE_TIANMU) {
if ((create_info->db_type->db_type == DB_TYPE_TIANMU) &&
(!(thd->variables.sql_mode & MODE_NO_KEY_ERROR))) {
my_error(ER_TIANMU_NOT_FOUND_INDEX, MYF(0));
goto err;
}
Expand All @@ -8503,7 +8508,8 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
alter_info->drop_list.head()->name);
goto err;
case Alter_drop::FOREIGN_KEY:
if (create_info->db_type->db_type == DB_TYPE_TIANMU) {
if ((create_info->db_type->db_type == DB_TYPE_TIANMU) &&
(!(thd->variables.sql_mode & MODE_NO_KEY_ERROR))) {
my_error(ER_TIANMU_NOT_SUPPORTED_FOREIGN_KEY, MYF(0));
}
break;
Expand All @@ -8517,7 +8523,8 @@ mysql_prepare_alter_table(THD *thd, TABLE *table,
}
if (rename_key_list.elements)
{
if (create_info->db_type->db_type == DB_TYPE_TIANMU) {
if ((create_info->db_type->db_type == DB_TYPE_TIANMU) &&
(!(thd->variables.sql_mode & MODE_NO_KEY_ERROR))) {
my_error(ER_TIANMU_NOT_FOUND_INDEX, MYF(0));
} else {
my_error(ER_KEY_DOES_NOT_EXITS, MYF(0), rename_key_list.head()->old_name,
Expand Down
3 changes: 2 additions & 1 deletion sql/sql_trigger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ bool mysql_create_or_drop_trigger(THD *thd, TABLE_LIST *tables, bool create)
}
table= tables->table;
table->pos_in_table_list= tables;
if (table->file && table->file->ht == tianmu_hton) {
if ((table->file && table->file->ht == tianmu_hton) &&
(!(thd->variables.sql_mode & MODE_NO_KEY_ERROR))) {
my_error(ER_TIANMU_NOT_SUPPORTED_TRIGGER, MYF(0));
goto end;
}
Expand Down
2 changes: 1 addition & 1 deletion sql/sys_vars.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3904,7 +3904,7 @@ static const char *sql_mode_names[]=
"STRICT_ALL_TABLES", "NO_ZERO_IN_DATE", "NO_ZERO_DATE",
"ALLOW_INVALID_DATES", "ERROR_FOR_DIVISION_BY_ZERO", "TRADITIONAL",
"NO_AUTO_CREATE_USER", "HIGH_NOT_PRECEDENCE", "NO_ENGINE_SUBSTITUTION",
"PAD_CHAR_TO_FULL_LENGTH", "MANDATORY_TIANMU",
"PAD_CHAR_TO_FULL_LENGTH", "MANDATORY_TIANMU", "NO_KEY_ERROR",
0
};
export bool sql_mode_string_representation(THD *thd, sql_mode_t sql_mode,
Expand Down
7 changes: 7 additions & 0 deletions storage/tianmu/handler/ha_tianmu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,13 @@ enum_alter_inplace_result ha_tianmu::check_if_supported_inplace_alter([[maybe_un
if (ha_alter_info->handler_flags & Alter_inplace_info::ADD_PK_INDEX ||
ha_alter_info->handler_flags & Alter_inplace_info::DROP_PK_INDEX)
DBUG_RETURN(HA_ALTER_INPLACE_NOT_SUPPORTED);
// support alter table: mix add/drop key
if ((ha_alter_info->handler_flags & Alter_inplace_info::ADD_INDEX ||
ha_alter_info->handler_flags & Alter_inplace_info::DROP_INDEX ||
ha_alter_info->handler_flags & Alter_inplace_info::ADD_UNIQUE_INDEX ||
ha_alter_info->handler_flags & Alter_inplace_info::DROP_UNIQUE_INDEX) &&
(ha_thd()->variables.sql_mode & MODE_NO_KEY_ERROR))
DBUG_RETURN(HA_ALTER_INPLACE_NOT_SUPPORTED);

DBUG_RETURN(HA_ALTER_ERROR);
}
Expand Down

0 comments on commit ae42cbf

Please sign in to comment.