summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2018-07-17 14:35:04 +0200
committerSergei Golubchik <serg@mariadb.org>2018-09-04 08:37:44 +0200
commit22bcfa011acd81c44c2ad969a0edc2401a32a311 (patch)
tree165f6ab775eb9af5418970292325c87a83a817e9
parentb9bc3c24630980b260b91fc856689dbad336064e (diff)
downloadmariadb-git-22bcfa011acd81c44c2ad969a0edc2401a32a311.tar.gz
cleanup: FOREIGN_KEY_INFO
instead of returning strings for CASCADE/RESTRICT from every storage engine, use enum values Backport of a3614d33e8a
-rw-r--r--sql/sql_class.h2
-rw-r--r--sql/sql_lex.h4
-rw-r--r--sql/sql_show.cc9
-rw-r--r--sql/sql_yacc.yy20
-rw-r--r--sql/table.cc13
-rw-r--r--sql/table.h9
-rw-r--r--storage/innobase/handler/ha_innodb.cc32
-rw-r--r--storage/innobase/handler/handler0alter.cc20
-rw-r--r--storage/mroonga/ha_mroonga.cpp6
-rw-r--r--storage/xtradb/handler/ha_innodb.cc32
-rw-r--r--storage/xtradb/handler/handler0alter.cc20
11 files changed, 75 insertions, 92 deletions
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 9428f6f6ce5..3145f70df2d 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -324,8 +324,6 @@ class Foreign_key: public Key {
public:
enum fk_match_opt { FK_MATCH_UNDEF, FK_MATCH_FULL,
FK_MATCH_PARTIAL, FK_MATCH_SIMPLE};
- enum fk_option { FK_OPTION_UNDEF, FK_OPTION_RESTRICT, FK_OPTION_CASCADE,
- FK_OPTION_SET_NULL, FK_OPTION_NO_ACTION, FK_OPTION_DEFAULT};
LEX_STRING ref_db;
LEX_STRING ref_table;
diff --git a/sql/sql_lex.h b/sql/sql_lex.h
index 3fed9808f57..d58be8b336a 100644
--- a/sql/sql_lex.h
+++ b/sql/sql_lex.h
@@ -2482,8 +2482,8 @@ struct LEX: public Query_tables_list
uint uint_geom_type;
uint grant, grant_tot_col, which_columns;
enum Foreign_key::fk_match_opt fk_match_option;
- enum Foreign_key::fk_option fk_update_opt;
- enum Foreign_key::fk_option fk_delete_opt;
+ enum_fk_option fk_update_opt;
+ enum_fk_option fk_delete_opt;
uint slave_thd_opt, start_transaction_opt;
int nest_level;
/*
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index cdcd6fe47e3..9c2cef80d61 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -7534,6 +7534,7 @@ get_referential_constraints_record(THD *thd, TABLE_LIST *tables,
LEX_STRING *db_name, LEX_STRING *table_name)
{
CHARSET_INFO *cs= system_charset_info;
+ LEX_CSTRING *s;
DBUG_ENTER("get_referential_constraints_record");
if (res)
@@ -7578,10 +7579,10 @@ get_referential_constraints_record(THD *thd, TABLE_LIST *tables,
else
table->field[5]->set_null();
table->field[6]->store(STRING_WITH_LEN("NONE"), cs);
- table->field[7]->store(f_key_info->update_method->str,
- f_key_info->update_method->length, cs);
- table->field[8]->store(f_key_info->delete_method->str,
- f_key_info->delete_method->length, cs);
+ s= fk_option_name(f_key_info->update_method);
+ table->field[7]->store(s->str, s->length, cs);
+ s= fk_option_name(f_key_info->delete_method);
+ table->field[8]->store(s->str, s->length, cs);
if (schema_table_store_record(thd, table))
DBUG_RETURN(1);
}
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 321e6ffc9cd..8d0a4506a0b 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -939,7 +939,7 @@ static bool sp_create_assignment_instr(THD *thd, bool no_lookahead)
struct p_elem_val *p_elem_value;
enum index_hint_type index_hint;
enum enum_filetype filetype;
- enum Foreign_key::fk_option m_fk_option;
+ enum enum_fk_option m_fk_option;
enum enum_yes_no_unknown m_yes_no_unk;
Diag_condition_item_name diag_condition_item_name;
Diagnostics_information::Which_area diag_area;
@@ -6752,19 +6752,19 @@ opt_on_update_delete:
/* empty */
{
LEX *lex= Lex;
- lex->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
- lex->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
+ lex->fk_update_opt= FK_OPTION_UNDEF;
+ lex->fk_delete_opt= FK_OPTION_UNDEF;
}
| ON UPDATE_SYM delete_option
{
LEX *lex= Lex;
lex->fk_update_opt= $3;
- lex->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
+ lex->fk_delete_opt= FK_OPTION_UNDEF;
}
| ON DELETE_SYM delete_option
{
LEX *lex= Lex;
- lex->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
+ lex->fk_update_opt= FK_OPTION_UNDEF;
lex->fk_delete_opt= $3;
}
| ON UPDATE_SYM delete_option
@@ -6784,11 +6784,11 @@ opt_on_update_delete:
;
delete_option:
- RESTRICT { $$= Foreign_key::FK_OPTION_RESTRICT; }
- | CASCADE { $$= Foreign_key::FK_OPTION_CASCADE; }
- | SET NULL_SYM { $$= Foreign_key::FK_OPTION_SET_NULL; }
- | NO_SYM ACTION { $$= Foreign_key::FK_OPTION_NO_ACTION; }
- | SET DEFAULT { $$= Foreign_key::FK_OPTION_DEFAULT; }
+ RESTRICT { $$= FK_OPTION_RESTRICT; }
+ | CASCADE { $$= FK_OPTION_CASCADE; }
+ | SET NULL_SYM { $$= FK_OPTION_SET_NULL; }
+ | NO_SYM ACTION { $$= FK_OPTION_NO_ACTION; }
+ | SET DEFAULT { $$= FK_OPTION_SET_DEFAULT; }
;
normal_key_type:
diff --git a/sql/table.cc b/sql/table.cc
index 5ea5d8cf3c5..144720986f2 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -7251,3 +7251,16 @@ double KEY::actual_rec_per_key(uint i)
read_stats->get_avg_frequency(i) : (double) rec_per_key[i]);
}
+LEX_CSTRING *fk_option_name(enum_fk_option opt)
+{
+ static LEX_CSTRING names[]=
+ {
+ { STRING_WITH_LEN("???") },
+ { STRING_WITH_LEN("RESTRICT") },
+ { STRING_WITH_LEN("CASCADE") },
+ { STRING_WITH_LEN("SET NULL") },
+ { STRING_WITH_LEN("NO ACTION") },
+ { STRING_WITH_LEN("SET DEFAULT") }
+ };
+ return names + opt;
+}
diff --git a/sql/table.h b/sql/table.h
index 05596b605a5..1b7a447eaf1 100644
--- a/sql/table.h
+++ b/sql/table.h
@@ -1429,6 +1429,9 @@ enum enum_schema_table_state
PROCESSED_BY_JOIN_EXEC
};
+enum enum_fk_option { FK_OPTION_UNDEF, FK_OPTION_RESTRICT, FK_OPTION_CASCADE,
+ FK_OPTION_SET_NULL, FK_OPTION_NO_ACTION, FK_OPTION_SET_DEFAULT};
+
typedef struct st_foreign_key_info
{
LEX_STRING *foreign_id;
@@ -1436,13 +1439,15 @@ typedef struct st_foreign_key_info
LEX_STRING *foreign_table;
LEX_STRING *referenced_db;
LEX_STRING *referenced_table;
- LEX_STRING *update_method;
- LEX_STRING *delete_method;
+ enum_fk_option update_method;
+ enum_fk_option delete_method;
LEX_STRING *referenced_key_name;
List<LEX_STRING> foreign_fields;
List<LEX_STRING> referenced_fields;
} FOREIGN_KEY_INFO;
+LEX_CSTRING *fk_option_name(enum_fk_option opt);
+
#define MY_I_S_MAYBE_NULL 1
#define MY_I_S_UNSIGNED 2
diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
index 3959b49b600..35693cf4ece 100644
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -12461,41 +12461,25 @@ get_foreign_key_info(
} while (++i < foreign->n_fields);
if (foreign->type & DICT_FOREIGN_ON_DELETE_CASCADE) {
- len = 7;
- ptr = "CASCADE";
+ f_key_info.delete_method = FK_OPTION_CASCADE;
} else if (foreign->type & DICT_FOREIGN_ON_DELETE_SET_NULL) {
- len = 8;
- ptr = "SET NULL";
+ f_key_info.delete_method = FK_OPTION_SET_NULL;
} else if (foreign->type & DICT_FOREIGN_ON_DELETE_NO_ACTION) {
- len = 9;
- ptr = "NO ACTION";
+ f_key_info.delete_method = FK_OPTION_NO_ACTION;
} else {
- len = 8;
- ptr = "RESTRICT";
+ f_key_info.delete_method = FK_OPTION_RESTRICT;
}
- f_key_info.delete_method = thd_make_lex_string(
- thd, f_key_info.delete_method, ptr,
- static_cast<unsigned int>(len), 1);
-
if (foreign->type & DICT_FOREIGN_ON_UPDATE_CASCADE) {
- len = 7;
- ptr = "CASCADE";
+ f_key_info.update_method = FK_OPTION_CASCADE;
} else if (foreign->type & DICT_FOREIGN_ON_UPDATE_SET_NULL) {
- len = 8;
- ptr = "SET NULL";
+ f_key_info.update_method = FK_OPTION_SET_NULL;
} else if (foreign->type & DICT_FOREIGN_ON_UPDATE_NO_ACTION) {
- len = 9;
- ptr = "NO ACTION";
+ f_key_info.update_method = FK_OPTION_NO_ACTION;
} else {
- len = 8;
- ptr = "RESTRICT";
+ f_key_info.update_method = FK_OPTION_RESTRICT;
}
- f_key_info.update_method = thd_make_lex_string(
- thd, f_key_info.update_method, ptr,
- static_cast<unsigned int>(len), 1);
-
if (foreign->referenced_index && foreign->referenced_index->name) {
referenced_key_name = thd_make_lex_string(thd,
f_key_info.referenced_key_name,
diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc
index 6a3e9575eb1..8d5eefc4f2b 100644
--- a/storage/innobase/handler/handler0alter.cc
+++ b/storage/innobase/handler/handler0alter.cc
@@ -729,29 +729,29 @@ innobase_set_foreign_key_option(
ut_ad(!foreign->type);
switch (fk_key->delete_opt) {
- case Foreign_key::FK_OPTION_NO_ACTION:
- case Foreign_key::FK_OPTION_RESTRICT:
- case Foreign_key::FK_OPTION_DEFAULT:
+ case FK_OPTION_NO_ACTION:
+ case FK_OPTION_RESTRICT:
+ case FK_OPTION_SET_DEFAULT:
foreign->type = DICT_FOREIGN_ON_DELETE_NO_ACTION;
break;
- case Foreign_key::FK_OPTION_CASCADE:
+ case FK_OPTION_CASCADE:
foreign->type = DICT_FOREIGN_ON_DELETE_CASCADE;
break;
- case Foreign_key::FK_OPTION_SET_NULL:
+ case FK_OPTION_SET_NULL:
foreign->type = DICT_FOREIGN_ON_DELETE_SET_NULL;
break;
}
switch (fk_key->update_opt) {
- case Foreign_key::FK_OPTION_NO_ACTION:
- case Foreign_key::FK_OPTION_RESTRICT:
- case Foreign_key::FK_OPTION_DEFAULT:
+ case FK_OPTION_NO_ACTION:
+ case FK_OPTION_RESTRICT:
+ case FK_OPTION_SET_DEFAULT:
foreign->type |= DICT_FOREIGN_ON_UPDATE_NO_ACTION;
break;
- case Foreign_key::FK_OPTION_CASCADE:
+ case FK_OPTION_CASCADE:
foreign->type |= DICT_FOREIGN_ON_UPDATE_CASCADE;
break;
- case Foreign_key::FK_OPTION_SET_NULL:
+ case FK_OPTION_SET_NULL:
foreign->type |= DICT_FOREIGN_ON_UPDATE_SET_NULL;
break;
}
diff --git a/storage/mroonga/ha_mroonga.cpp b/storage/mroonga/ha_mroonga.cpp
index 08942deed8d..e4b6698cdf6 100644
--- a/storage/mroonga/ha_mroonga.cpp
+++ b/storage/mroonga/ha_mroonga.cpp
@@ -15755,10 +15755,8 @@ int ha_mroonga::storage_get_foreign_key_list(THD *thd,
ref_table_buff,
ref_table_name_length,
TRUE);
- f_key_info.update_method = thd_make_lex_string(thd, NULL, "RESTRICT",
- 8, TRUE);
- f_key_info.delete_method = thd_make_lex_string(thd, NULL, "RESTRICT",
- 8, TRUE);
+ f_key_info.update_method = FK_OPTION_RESTRICT;
+ f_key_info.delete_method = FK_OPTION_RESTRICT;
f_key_info.referenced_key_name = thd_make_lex_string(thd, NULL, "PRIMARY",
7, TRUE);
LEX_STRING *field_name = thd_make_lex_string(thd, NULL, column_name,
diff --git a/storage/xtradb/handler/ha_innodb.cc b/storage/xtradb/handler/ha_innodb.cc
index 3553674040a..82a59031453 100644
--- a/storage/xtradb/handler/ha_innodb.cc
+++ b/storage/xtradb/handler/ha_innodb.cc
@@ -13327,41 +13327,25 @@ get_foreign_key_info(
} while (++i < foreign->n_fields);
if (foreign->type & DICT_FOREIGN_ON_DELETE_CASCADE) {
- len = 7;
- ptr = "CASCADE";
+ f_key_info.delete_method = FK_OPTION_CASCADE;
} else if (foreign->type & DICT_FOREIGN_ON_DELETE_SET_NULL) {
- len = 8;
- ptr = "SET NULL";
+ f_key_info.delete_method = FK_OPTION_SET_NULL;
} else if (foreign->type & DICT_FOREIGN_ON_DELETE_NO_ACTION) {
- len = 9;
- ptr = "NO ACTION";
+ f_key_info.delete_method = FK_OPTION_NO_ACTION;
} else {
- len = 8;
- ptr = "RESTRICT";
+ f_key_info.delete_method = FK_OPTION_RESTRICT;
}
- f_key_info.delete_method = thd_make_lex_string(
- thd, f_key_info.delete_method, ptr,
- static_cast<unsigned int>(len), 1);
-
if (foreign->type & DICT_FOREIGN_ON_UPDATE_CASCADE) {
- len = 7;
- ptr = "CASCADE";
+ f_key_info.update_method = FK_OPTION_CASCADE;
} else if (foreign->type & DICT_FOREIGN_ON_UPDATE_SET_NULL) {
- len = 8;
- ptr = "SET NULL";
+ f_key_info.update_method = FK_OPTION_SET_NULL;
} else if (foreign->type & DICT_FOREIGN_ON_UPDATE_NO_ACTION) {
- len = 9;
- ptr = "NO ACTION";
+ f_key_info.update_method = FK_OPTION_NO_ACTION;
} else {
- len = 8;
- ptr = "RESTRICT";
+ f_key_info.update_method = FK_OPTION_RESTRICT;
}
- f_key_info.update_method = thd_make_lex_string(
- thd, f_key_info.update_method, ptr,
- static_cast<unsigned int>(len), 1);
-
if (foreign->referenced_index && foreign->referenced_index->name) {
referenced_key_name = thd_make_lex_string(thd,
f_key_info.referenced_key_name,
diff --git a/storage/xtradb/handler/handler0alter.cc b/storage/xtradb/handler/handler0alter.cc
index bc6a6dd68d4..8235263b305 100644
--- a/storage/xtradb/handler/handler0alter.cc
+++ b/storage/xtradb/handler/handler0alter.cc
@@ -730,29 +730,29 @@ innobase_set_foreign_key_option(
ut_ad(!foreign->type);
switch (fk_key->delete_opt) {
- case Foreign_key::FK_OPTION_NO_ACTION:
- case Foreign_key::FK_OPTION_RESTRICT:
- case Foreign_key::FK_OPTION_DEFAULT:
+ case FK_OPTION_NO_ACTION:
+ case FK_OPTION_RESTRICT:
+ case FK_OPTION_SET_DEFAULT:
foreign->type = DICT_FOREIGN_ON_DELETE_NO_ACTION;
break;
- case Foreign_key::FK_OPTION_CASCADE:
+ case FK_OPTION_CASCADE:
foreign->type = DICT_FOREIGN_ON_DELETE_CASCADE;
break;
- case Foreign_key::FK_OPTION_SET_NULL:
+ case FK_OPTION_SET_NULL:
foreign->type = DICT_FOREIGN_ON_DELETE_SET_NULL;
break;
}
switch (fk_key->update_opt) {
- case Foreign_key::FK_OPTION_NO_ACTION:
- case Foreign_key::FK_OPTION_RESTRICT:
- case Foreign_key::FK_OPTION_DEFAULT:
+ case FK_OPTION_NO_ACTION:
+ case FK_OPTION_RESTRICT:
+ case FK_OPTION_SET_DEFAULT:
foreign->type |= DICT_FOREIGN_ON_UPDATE_NO_ACTION;
break;
- case Foreign_key::FK_OPTION_CASCADE:
+ case FK_OPTION_CASCADE:
foreign->type |= DICT_FOREIGN_ON_UPDATE_CASCADE;
break;
- case Foreign_key::FK_OPTION_SET_NULL:
+ case FK_OPTION_SET_NULL:
foreign->type |= DICT_FOREIGN_ON_UPDATE_SET_NULL;
break;
}