From 409b8a86de45efc96377c618a99cff1301523150 Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Wed, 31 Aug 2022 11:55:03 +0300 Subject: [PATCH] MDEV-25292 ha_table_exists() cleanup and improvement Removed default values for arguments, added flags argument to specify filename flags (FN_TO_IS_TMP, FN_FROM_IS_TMP). --- sql/handler.cc | 4 ++-- sql/handler.h | 7 ++++--- sql/sql_acl.cc | 3 ++- sql/sql_base.cc | 5 +++-- sql/sql_db.cc | 3 ++- sql/sql_rename.cc | 4 ++-- sql/sql_show.cc | 2 +- sql/sql_table.cc | 8 +++++--- sql/sql_view.cc | 3 ++- 9 files changed, 23 insertions(+), 16 deletions(-) diff --git a/sql/handler.cc b/sql/handler.cc index 9835d42c8c5..6a42643919f 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -6201,7 +6201,7 @@ static my_bool discover_existence(THD *thd, plugin_ref plugin, bool ha_table_exists(THD *thd, const LEX_CSTRING *db, const LEX_CSTRING *table_name, LEX_CUSTRING *table_id, LEX_CSTRING *partition_engine_name, - handlerton **hton, bool *is_sequence) + handlerton **hton, bool *is_sequence, uint flags) { handlerton *dummy; bool dummy2; @@ -6256,7 +6256,7 @@ retry_from_frm: #endif char path[FN_REFLEN + 1]; size_t path_len = build_table_filename(path, sizeof(path) - 1, - db->str, table_name->str, "", 0); + db->str, table_name->str, "", flags); st_discover_existence_args args= {path, path_len, db->str, table_name->str, 0, true}; if (file_ext_exists(path, path_len, reg_ext)) diff --git a/sql/handler.h b/sql/handler.h index 027d8351831..3c7401a9199 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -5289,9 +5289,10 @@ int ha_discover_table_names(THD *thd, LEX_CSTRING *db, MY_DIR *dirp, Discovered_table_list *result, bool reusable); bool ha_table_exists(THD *thd, const LEX_CSTRING *db, const LEX_CSTRING *table_name, - LEX_CUSTRING *table_version= 0, - LEX_CSTRING *partition_engine_name= 0, - handlerton **hton= 0, bool *is_sequence= 0); + LEX_CUSTRING *table_version, + LEX_CSTRING *partition_engine_name, + handlerton **hton, bool *is_sequence, + uint flags); bool ha_check_if_updates_are_ignored(THD *thd, handlerton *hton, const char *op); #endif /* MYSQL_SERVER */ diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index f75905f07e1..b4120879e83 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -7111,7 +7111,8 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list, { if (!(rights & CREATE_ACL)) { - if (!ha_table_exists(thd, &table_list->db, &table_list->table_name)) + if (!ha_table_exists(thd, &table_list->db, &table_list->table_name, + NULL, NULL, NULL, NULL, 0)) { my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->db.str, table_list->alias.str); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 54296af5a0b..9279e2eccde 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -2008,7 +2008,8 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx) if (table_list->open_strategy == TABLE_LIST::OPEN_IF_EXISTS) { - if (!ha_table_exists(thd, &table_list->db, &table_list->table_name)) + if (!ha_table_exists(thd, &table_list->db, &table_list->table_name, + NULL, NULL, NULL, NULL, 0)) DBUG_RETURN(FALSE); } else if (table_list->open_strategy == TABLE_LIST::OPEN_STUB) @@ -4223,7 +4224,7 @@ static bool upgrade_lock_if_not_exists(THD *thd, DEBUG_SYNC(thd,"create_table_before_check_if_exists"); if (!create_info.or_replace() && ha_table_exists(thd, &create_table->db, &create_table->table_name, - NULL, NULL, &create_table->db_type)) + NULL, NULL, &create_table->db_type, NULL, 0)) { if (create_info.if_not_exists()) { diff --git a/sql/sql_db.cc b/sql/sql_db.cc index 7be4ba00b86..765509056b5 100644 --- a/sql/sql_db.cc +++ b/sql/sql_db.cc @@ -1236,7 +1236,8 @@ update_binlog: char quoted_name[FN_REFLEN+3]; // Only write drop table to the binlog for tables that no longer exist. - if (ha_table_exists(thd, &tbl->db, &tbl->table_name)) + if (ha_table_exists(thd, &tbl->db, &tbl->table_name, + NULL, NULL, NULL, NULL, 0)) continue; tbl_name_len= my_snprintf(quoted_name, sizeof(quoted_name), "%`s", diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc index 5b0f77f5bcb..5ed80d69ff8 100644 --- a/sql/sql_rename.cc +++ b/sql/sql_rename.cc @@ -281,7 +281,7 @@ rename_check_preconditions(THD *thd, rename_param *param, if (!ha_table_exists(thd, &ren_table->db, ¶m->old_alias, ¶m->old_version, NULL, - ¶m->from_table_hton) || + ¶m->from_table_hton, NULL, 0) || !param->from_table_hton) { my_error(ER_NO_SUCH_TABLE, MYF(if_exists ? ME_NOTE : 0), @@ -301,7 +301,7 @@ rename_check_preconditions(THD *thd, rename_param *param, DBUG_RETURN(-1); } - if (ha_table_exists(thd, new_db, ¶m->new_alias, NULL, NULL, 0)) + if (ha_table_exists(thd, new_db, ¶m->new_alias, NULL, NULL, NULL, NULL, 0)) { my_error(ER_TABLE_EXISTS_ERROR, MYF(0), param->new_alias.str); DBUG_RETURN(1); // This can't be skipped diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 6290a47ee30..ed82e6deae3 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -4819,7 +4819,7 @@ static int fill_schema_table_names(THD *thd, TABLE_LIST *tables, bool is_sequence; if (ha_table_exists(thd, db_name, table_name, NULL, NULL, - &hton, &is_sequence)) + &hton, &is_sequence, 0)) { if (hton == view_pseudo_hton) table->field[3]->store(STRING_WITH_LEN("VIEW"), cs); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 0d6f7e7a2c0..dd940b24f61 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -4427,8 +4427,9 @@ int create_table_impl(THD *thd, handlerton *db_type; if (!internal_tmp_table && - ha_table_exists(thd, &db, &table_name, - &create_info->org_tabledef_version, NULL, &db_type)) + ha_table_exists(thd, &orig_db, &orig_table_name, + &create_info->org_tabledef_version, + NULL, &db_type, NULL, 0)) { if (ha_check_if_updates_are_ignored(thd, db_type, "CREATE")) { @@ -10080,7 +10081,8 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db, on the name, now we can safely try to find out for sure. */ if (!(alter_info->partition_flags & ALTER_PARTITION_CONVERT_IN) && - ha_table_exists(thd, &alter_ctx.new_db, &alter_ctx.new_name)) + ha_table_exists(thd, &alter_ctx.new_db, &alter_ctx.new_name, + NULL, NULL, NULL, NULL, 0)) { /* Table will be closed in do_command() */ my_error(ER_TABLE_EXISTS_ERROR, MYF(0), alter_ctx.new_alias.str); diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 166b67b6816..be82fc166c9 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -1091,7 +1091,8 @@ loop_out: fn_format(path_buff, file.str, dir.str, "", MY_UNPACK_FILENAME); path.length= strlen(path_buff); - if (ha_table_exists(thd, &view->db, &view->table_name)) + if (ha_table_exists(thd, &view->db, &view->table_name, + NULL, NULL, NULL, NULL, 0)) { old_view_exists= 1; if (lex->create_info.if_not_exists())