mirror of
https://github.com/MariaDB/server.git
synced 2025-08-12 20:49:12 +03:00
cleanup: FOREIGN_KEY_INFO
instead of returning strings for CASCADE/RESTRICT from every storage engine, use enum values
This commit is contained in:
@@ -446,8 +446,6 @@ class Foreign_key: public Key {
|
|||||||
public:
|
public:
|
||||||
enum fk_match_opt { FK_MATCH_UNDEF, FK_MATCH_FULL,
|
enum fk_match_opt { FK_MATCH_UNDEF, FK_MATCH_FULL,
|
||||||
FK_MATCH_PARTIAL, FK_MATCH_SIMPLE};
|
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_db;
|
||||||
LEX_STRING ref_table;
|
LEX_STRING ref_table;
|
||||||
|
@@ -2675,8 +2675,8 @@ public:
|
|||||||
uint profile_options;
|
uint profile_options;
|
||||||
uint grant, grant_tot_col, which_columns;
|
uint grant, grant_tot_col, which_columns;
|
||||||
enum Foreign_key::fk_match_opt fk_match_option;
|
enum Foreign_key::fk_match_opt fk_match_option;
|
||||||
enum Foreign_key::fk_option fk_update_opt;
|
enum_fk_option fk_update_opt;
|
||||||
enum Foreign_key::fk_option fk_delete_opt;
|
enum_fk_option fk_delete_opt;
|
||||||
uint slave_thd_opt, start_transaction_opt;
|
uint slave_thd_opt, start_transaction_opt;
|
||||||
int nest_level;
|
int nest_level;
|
||||||
/*
|
/*
|
||||||
|
@@ -7365,6 +7365,7 @@ get_referential_constraints_record(THD *thd, TABLE_LIST *tables,
|
|||||||
LEX_STRING *db_name, LEX_STRING *table_name)
|
LEX_STRING *db_name, LEX_STRING *table_name)
|
||||||
{
|
{
|
||||||
CHARSET_INFO *cs= system_charset_info;
|
CHARSET_INFO *cs= system_charset_info;
|
||||||
|
LEX_CSTRING *s;
|
||||||
DBUG_ENTER("get_referential_constraints_record");
|
DBUG_ENTER("get_referential_constraints_record");
|
||||||
|
|
||||||
if (res)
|
if (res)
|
||||||
@@ -7409,10 +7410,10 @@ get_referential_constraints_record(THD *thd, TABLE_LIST *tables,
|
|||||||
else
|
else
|
||||||
table->field[5]->set_null();
|
table->field[5]->set_null();
|
||||||
table->field[6]->store(STRING_WITH_LEN("NONE"), cs);
|
table->field[6]->store(STRING_WITH_LEN("NONE"), cs);
|
||||||
table->field[7]->store(f_key_info->update_method->str,
|
s= fk_option_name(f_key_info->update_method);
|
||||||
f_key_info->update_method->length, cs);
|
table->field[7]->store(s->str, s->length, cs);
|
||||||
table->field[8]->store(f_key_info->delete_method->str,
|
s= fk_option_name(f_key_info->delete_method);
|
||||||
f_key_info->delete_method->length, cs);
|
table->field[8]->store(s->str, s->length, cs);
|
||||||
if (schema_table_store_record(thd, table))
|
if (schema_table_store_record(thd, table))
|
||||||
DBUG_RETURN(1);
|
DBUG_RETURN(1);
|
||||||
}
|
}
|
||||||
|
@@ -1001,7 +1001,7 @@ Virtual_column_info *add_virtual_expression(THD *thd, const char *txt,
|
|||||||
enum enum_diag_condition_item_name diag_condition_item_name;
|
enum enum_diag_condition_item_name diag_condition_item_name;
|
||||||
enum Diagnostics_information::Which_area diag_area;
|
enum Diagnostics_information::Which_area diag_area;
|
||||||
enum Field::geometry_type geom_type;
|
enum Field::geometry_type geom_type;
|
||||||
enum Foreign_key::fk_option m_fk_option;
|
enum enum_fk_option m_fk_option;
|
||||||
enum Item_udftype udf_type;
|
enum Item_udftype udf_type;
|
||||||
enum Key::Keytype key_type;
|
enum Key::Keytype key_type;
|
||||||
enum Statement_information_item::Name stmt_info_item_name;
|
enum Statement_information_item::Name stmt_info_item_name;
|
||||||
@@ -6876,19 +6876,19 @@ opt_on_update_delete:
|
|||||||
/* empty */
|
/* empty */
|
||||||
{
|
{
|
||||||
LEX *lex= Lex;
|
LEX *lex= Lex;
|
||||||
lex->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
|
lex->fk_update_opt= FK_OPTION_UNDEF;
|
||||||
lex->fk_delete_opt= Foreign_key::FK_OPTION_UNDEF;
|
lex->fk_delete_opt= FK_OPTION_UNDEF;
|
||||||
}
|
}
|
||||||
| ON UPDATE_SYM delete_option
|
| ON UPDATE_SYM delete_option
|
||||||
{
|
{
|
||||||
LEX *lex= Lex;
|
LEX *lex= Lex;
|
||||||
lex->fk_update_opt= $3;
|
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
|
| ON DELETE_SYM delete_option
|
||||||
{
|
{
|
||||||
LEX *lex= Lex;
|
LEX *lex= Lex;
|
||||||
lex->fk_update_opt= Foreign_key::FK_OPTION_UNDEF;
|
lex->fk_update_opt= FK_OPTION_UNDEF;
|
||||||
lex->fk_delete_opt= $3;
|
lex->fk_delete_opt= $3;
|
||||||
}
|
}
|
||||||
| ON UPDATE_SYM delete_option
|
| ON UPDATE_SYM delete_option
|
||||||
@@ -6908,11 +6908,11 @@ opt_on_update_delete:
|
|||||||
;
|
;
|
||||||
|
|
||||||
delete_option:
|
delete_option:
|
||||||
RESTRICT { $$= Foreign_key::FK_OPTION_RESTRICT; }
|
RESTRICT { $$= FK_OPTION_RESTRICT; }
|
||||||
| CASCADE { $$= Foreign_key::FK_OPTION_CASCADE; }
|
| CASCADE { $$= FK_OPTION_CASCADE; }
|
||||||
| SET NULL_SYM { $$= Foreign_key::FK_OPTION_SET_NULL; }
|
| SET NULL_SYM { $$= FK_OPTION_SET_NULL; }
|
||||||
| NO_SYM ACTION { $$= Foreign_key::FK_OPTION_NO_ACTION; }
|
| NO_SYM ACTION { $$= FK_OPTION_NO_ACTION; }
|
||||||
| SET DEFAULT { $$= Foreign_key::FK_OPTION_DEFAULT; }
|
| SET DEFAULT { $$= FK_OPTION_SET_DEFAULT; }
|
||||||
;
|
;
|
||||||
|
|
||||||
constraint_key_type:
|
constraint_key_type:
|
||||||
|
14
sql/table.cc
14
sql/table.cc
@@ -8146,3 +8146,17 @@ Item* TABLE_LIST::build_pushable_cond_for_table(THD *thd, Item *cond)
|
|||||||
return cond->build_clone(thd, thd->mem_root);
|
return cond->build_clone(thd, thd->mem_root);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
@@ -1478,6 +1478,9 @@ enum enum_schema_table_state
|
|||||||
PROCESSED_BY_JOIN_EXEC
|
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
|
typedef struct st_foreign_key_info
|
||||||
{
|
{
|
||||||
LEX_STRING *foreign_id;
|
LEX_STRING *foreign_id;
|
||||||
@@ -1485,13 +1488,15 @@ typedef struct st_foreign_key_info
|
|||||||
LEX_STRING *foreign_table;
|
LEX_STRING *foreign_table;
|
||||||
LEX_STRING *referenced_db;
|
LEX_STRING *referenced_db;
|
||||||
LEX_STRING *referenced_table;
|
LEX_STRING *referenced_table;
|
||||||
LEX_STRING *update_method;
|
enum_fk_option update_method;
|
||||||
LEX_STRING *delete_method;
|
enum_fk_option delete_method;
|
||||||
LEX_STRING *referenced_key_name;
|
LEX_STRING *referenced_key_name;
|
||||||
List<LEX_STRING> foreign_fields;
|
List<LEX_STRING> foreign_fields;
|
||||||
List<LEX_STRING> referenced_fields;
|
List<LEX_STRING> referenced_fields;
|
||||||
} FOREIGN_KEY_INFO;
|
} FOREIGN_KEY_INFO;
|
||||||
|
|
||||||
|
LEX_CSTRING *fk_option_name(enum_fk_option opt);
|
||||||
|
|
||||||
#define MY_I_S_MAYBE_NULL 1
|
#define MY_I_S_MAYBE_NULL 1
|
||||||
#define MY_I_S_UNSIGNED 2
|
#define MY_I_S_UNSIGNED 2
|
||||||
|
|
||||||
|
@@ -16959,41 +16959,26 @@ get_foreign_key_info(
|
|||||||
} while (++i < foreign->n_fields);
|
} while (++i < foreign->n_fields);
|
||||||
|
|
||||||
if (foreign->type & DICT_FOREIGN_ON_DELETE_CASCADE) {
|
if (foreign->type & DICT_FOREIGN_ON_DELETE_CASCADE) {
|
||||||
len = 7;
|
f_key_info.delete_method = FK_OPTION_CASCADE;
|
||||||
ptr = "CASCADE";
|
|
||||||
} else if (foreign->type & DICT_FOREIGN_ON_DELETE_SET_NULL) {
|
} else if (foreign->type & DICT_FOREIGN_ON_DELETE_SET_NULL) {
|
||||||
len = 8;
|
f_key_info.delete_method = FK_OPTION_SET_NULL;
|
||||||
ptr = "SET NULL";
|
|
||||||
} else if (foreign->type & DICT_FOREIGN_ON_DELETE_NO_ACTION) {
|
} else if (foreign->type & DICT_FOREIGN_ON_DELETE_NO_ACTION) {
|
||||||
len = 9;
|
f_key_info.delete_method = FK_OPTION_NO_ACTION;
|
||||||
ptr = "NO ACTION";
|
|
||||||
} else {
|
} else {
|
||||||
len = 8;
|
f_key_info.delete_method = FK_OPTION_RESTRICT;
|
||||||
ptr = "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) {
|
if (foreign->type & DICT_FOREIGN_ON_UPDATE_CASCADE) {
|
||||||
len = 7;
|
f_key_info.update_method = FK_OPTION_CASCADE;
|
||||||
ptr = "CASCADE";
|
|
||||||
} else if (foreign->type & DICT_FOREIGN_ON_UPDATE_SET_NULL) {
|
} else if (foreign->type & DICT_FOREIGN_ON_UPDATE_SET_NULL) {
|
||||||
len = 8;
|
f_key_info.update_method = FK_OPTION_SET_NULL;
|
||||||
ptr = "SET NULL";
|
|
||||||
} else if (foreign->type & DICT_FOREIGN_ON_UPDATE_NO_ACTION) {
|
} else if (foreign->type & DICT_FOREIGN_ON_UPDATE_NO_ACTION) {
|
||||||
len = 9;
|
f_key_info.update_method = FK_OPTION_NO_ACTION;
|
||||||
ptr = "NO ACTION";
|
|
||||||
} else {
|
} else {
|
||||||
len = 8;
|
f_key_info.update_method = FK_OPTION_RESTRICT;
|
||||||
ptr = "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
|
if (foreign->referenced_index
|
||||||
&& foreign->referenced_index->name != NULL) {
|
&& foreign->referenced_index->name != NULL) {
|
||||||
referenced_key_name = thd_make_lex_string(
|
referenced_key_name = thd_make_lex_string(
|
||||||
|
@@ -1225,29 +1225,29 @@ innobase_set_foreign_key_option(
|
|||||||
|
|
||||||
switch (fk_key->delete_opt) {
|
switch (fk_key->delete_opt) {
|
||||||
// JAN: TODO: ? MySQL 5.7 used enum fk_option directly from sql_lex.h
|
// JAN: TODO: ? MySQL 5.7 used enum fk_option directly from sql_lex.h
|
||||||
case Foreign_key::FK_OPTION_NO_ACTION:
|
case FK_OPTION_NO_ACTION:
|
||||||
case Foreign_key::FK_OPTION_RESTRICT:
|
case FK_OPTION_RESTRICT:
|
||||||
case Foreign_key::FK_OPTION_DEFAULT:
|
case FK_OPTION_SET_DEFAULT:
|
||||||
foreign->type = DICT_FOREIGN_ON_DELETE_NO_ACTION;
|
foreign->type = DICT_FOREIGN_ON_DELETE_NO_ACTION;
|
||||||
break;
|
break;
|
||||||
case Foreign_key::FK_OPTION_CASCADE:
|
case FK_OPTION_CASCADE:
|
||||||
foreign->type = DICT_FOREIGN_ON_DELETE_CASCADE;
|
foreign->type = DICT_FOREIGN_ON_DELETE_CASCADE;
|
||||||
break;
|
break;
|
||||||
case Foreign_key::FK_OPTION_SET_NULL:
|
case FK_OPTION_SET_NULL:
|
||||||
foreign->type = DICT_FOREIGN_ON_DELETE_SET_NULL;
|
foreign->type = DICT_FOREIGN_ON_DELETE_SET_NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (fk_key->update_opt) {
|
switch (fk_key->update_opt) {
|
||||||
case Foreign_key::FK_OPTION_NO_ACTION:
|
case FK_OPTION_NO_ACTION:
|
||||||
case Foreign_key::FK_OPTION_RESTRICT:
|
case FK_OPTION_RESTRICT:
|
||||||
case Foreign_key::FK_OPTION_DEFAULT:
|
case FK_OPTION_SET_DEFAULT:
|
||||||
foreign->type |= DICT_FOREIGN_ON_UPDATE_NO_ACTION;
|
foreign->type |= DICT_FOREIGN_ON_UPDATE_NO_ACTION;
|
||||||
break;
|
break;
|
||||||
case Foreign_key::FK_OPTION_CASCADE:
|
case FK_OPTION_CASCADE:
|
||||||
foreign->type |= DICT_FOREIGN_ON_UPDATE_CASCADE;
|
foreign->type |= DICT_FOREIGN_ON_UPDATE_CASCADE;
|
||||||
break;
|
break;
|
||||||
case Foreign_key::FK_OPTION_SET_NULL:
|
case FK_OPTION_SET_NULL:
|
||||||
foreign->type |= DICT_FOREIGN_ON_UPDATE_SET_NULL;
|
foreign->type |= DICT_FOREIGN_ON_UPDATE_SET_NULL;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@@ -16124,10 +16124,8 @@ int ha_mroonga::storage_get_foreign_key_list(THD *thd,
|
|||||||
ref_table_buff,
|
ref_table_buff,
|
||||||
ref_table_name_length,
|
ref_table_name_length,
|
||||||
TRUE);
|
TRUE);
|
||||||
f_key_info.update_method = thd_make_lex_string(thd, NULL, "RESTRICT",
|
f_key_info.update_method = FK_OPTION_RESTRICT;
|
||||||
8, TRUE);
|
f_key_info.delete_method = FK_OPTION_RESTRICT;
|
||||||
f_key_info.delete_method = thd_make_lex_string(thd, NULL, "RESTRICT",
|
|
||||||
8, TRUE);
|
|
||||||
f_key_info.referenced_key_name = thd_make_lex_string(thd, NULL, "PRIMARY",
|
f_key_info.referenced_key_name = thd_make_lex_string(thd, NULL, "PRIMARY",
|
||||||
7, TRUE);
|
7, TRUE);
|
||||||
LEX_STRING *field_name = thd_make_lex_string(thd, NULL, column_name,
|
LEX_STRING *field_name = thd_make_lex_string(thd, NULL, column_name,
|
||||||
|
Reference in New Issue
Block a user