From f8df638c2297c2a54a6b4dd35c7d7c62f0abba42 Mon Sep 17 00:00:00 2001 From: lihongjian Date: Mon, 27 Feb 2023 19:36:39 +0800 Subject: [PATCH] feat(tianmu):Optimize code with ternary expression(#1325) --- sql/auth/sql_authorization.cc | 3 +-- sql/sql_table.cc | 12 ++++-------- sql/sql_trigger.cc | 3 +-- storage/tianmu/handler/ha_tianmu.cpp | 4 +--- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/sql/auth/sql_authorization.cc b/sql/auth/sql_authorization.cc index b946b1d64..2874fa0da 100644 --- a/sql/auth/sql_authorization.cc +++ b/sql/auth/sql_authorization.cc @@ -4389,8 +4389,7 @@ 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)) { - sql_mode_t sql_mode = thd->variables.sql_mode; - if(thd->slave_thread) sql_mode = global_system_variables.sql_mode; + sql_mode_t sql_mode = thd->slave_thread ? global_system_variables.sql_mode : thd->variables.sql_mode; if (db_type == tianmu_hton && (alter_info->flags & Alter_info::ADD_FOREIGN_KEY) && (!(sql_mode & MODE_NO_KEY_ERROR))) { diff --git a/sql/sql_table.cc b/sql/sql_table.cc index c0521884c..0bf416a39 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3934,8 +3934,7 @@ mysql_prepare_create_table(THD *thd, const char *error_schema_name, (*key_count)++; tmp=file->max_key_parts(); - sql_mode_t sql_mode = thd->variables.sql_mode; - if(thd->slave_thread) sql_mode = global_system_variables.sql_mode; + 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) && (key->type == KEYTYPE_MULTIPLE) && @@ -4083,8 +4082,7 @@ mysql_prepare_create_table(THD *thd, const char *error_schema_name, DBUG_RETURN(TRUE); } if (create_info->db_type->db_type == DB_TYPE_TIANMU){ - sql_mode_t sql_mode = thd->variables.sql_mode; - if(thd->slave_thread) sql_mode = global_system_variables.sql_mode; + sql_mode_t sql_mode = thd->slave_thread ? global_system_variables.sql_mode : thd->variables.sql_mode; if(!(sql_mode & MODE_NO_KEY_ERROR)) { my_message(ER_TIANMU_NOT_SUPPORTED_FULLTEXT_INDEX, ER(ER_TIANMU_NOT_SUPPORTED_FULLTEXT_INDEX), MYF(0)); @@ -8499,8 +8497,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, // Now this contains only DROP for foreign keys and not-found objects Alter_drop *drop; drop_it.rewind(); - sql_mode_t sql_mode = thd->variables.sql_mode; - if(thd->slave_thread) sql_mode = global_system_variables.sql_mode; + sql_mode_t sql_mode = thd->slave_thread ? global_system_variables.sql_mode : thd->variables.sql_mode; while ((drop=drop_it++)) { switch (drop->type) { case Alter_drop::KEY: @@ -8531,8 +8528,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, if (rename_key_list.elements) { if (create_info->db_type->db_type == DB_TYPE_TIANMU){ - sql_mode_t sql_mode = thd->variables.sql_mode; - if(thd->slave_thread) sql_mode = global_system_variables.sql_mode; + sql_mode_t sql_mode = thd->slave_thread ? global_system_variables.sql_mode : thd->variables.sql_mode; if(!(sql_mode & MODE_NO_KEY_ERROR)){ my_error(ER_TIANMU_NOT_FOUND_INDEX, MYF(0)); goto err; diff --git a/sql/sql_trigger.cc b/sql/sql_trigger.cc index 8503f33fb..8388c8ce2 100644 --- a/sql/sql_trigger.cc +++ b/sql/sql_trigger.cc @@ -227,8 +227,7 @@ 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)){ - sql_mode_t sql_mode = thd->variables.sql_mode; - if(thd->slave_thread) sql_mode = global_system_variables.sql_mode; + sql_mode_t sql_mode = thd->slave_thread ? global_system_variables.sql_mode : thd->variables.sql_mode; if(!(sql_mode & MODE_NO_KEY_ERROR)) { my_error(ER_TIANMU_NOT_SUPPORTED_TRIGGER, MYF(0)); goto end; diff --git a/storage/tianmu/handler/ha_tianmu.cpp b/storage/tianmu/handler/ha_tianmu.cpp index eb8411e56..abfd811bd 100644 --- a/storage/tianmu/handler/ha_tianmu.cpp +++ b/storage/tianmu/handler/ha_tianmu.cpp @@ -1683,9 +1683,7 @@ enum_alter_inplace_result ha_tianmu::check_if_supported_inplace_alter([[maybe_un 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 - sql_mode_t sql_mode = ha_thd()->variables.sql_mode; - if (ha_thd()->slave_thread) - sql_mode = global_system_variables.sql_mode; + sql_mode_t sql_mode = ha_thd()->slave_thread ? global_system_variables.sql_mode : ha_thd()->variables.sql_mode; 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 ||