From e81f101dac5c8514c362732a3b9dbc2f896390a6 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 17 Jul 2018 17:12:05 +0200 Subject: create a reusable function that tells what FK actions can write Backport of 794f71cbc41 --- sql/sql_base.cc | 5 ++--- sql/table.cc | 6 ++++++ sql/table.h | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) (limited to 'sql') diff --git a/sql/sql_base.cc b/sql/sql_base.cc index be87ad27d6b..be7d9008aa4 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -4883,12 +4883,11 @@ handle_table(THD *thd, Query_tables_list *prelocking_ctx, while ((fk= fk_list_it++)) { // FK_OPTION_RESTRICT and FK_OPTION_NO_ACTION only need read access - static bool can_write[]= { true, false, true, true, false, true }; uint8 op= table_list->trg_event_map; thr_lock_type lock_type; - if ((op & (1 << TRG_EVENT_DELETE) && can_write[fk->delete_method]) - || (op & (1 << TRG_EVENT_UPDATE) && can_write[fk->update_method])) + if ((op & (1 << TRG_EVENT_DELETE) && fk_modifies_child(fk->delete_method)) + || (op & (1 << TRG_EVENT_UPDATE) && fk_modifies_child(fk->update_method))) lock_type= TL_WRITE_ALLOW_WRITE; else lock_type= TL_READ; diff --git a/sql/table.cc b/sql/table.cc index 144720986f2..86eac73a416 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -7264,3 +7264,9 @@ LEX_CSTRING *fk_option_name(enum_fk_option opt) }; return names + opt; } + +bool fk_modifies_child(enum_fk_option opt) +{ + static bool can_write[]= { false, false, true, true, false, true }; + return can_write[opt]; +} diff --git a/sql/table.h b/sql/table.h index 9ba282b8c49..23f97ed18d0 100644 --- a/sql/table.h +++ b/sql/table.h @@ -1447,6 +1447,7 @@ typedef struct st_foreign_key_info } FOREIGN_KEY_INFO; LEX_CSTRING *fk_option_name(enum_fk_option opt); +bool fk_modifies_child(enum_fk_option opt); #define MY_I_S_MAYBE_NULL 1 #define MY_I_S_UNSIGNED 2 -- cgit v1.2.1