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).
This commit is contained in:
Aleksey Midenkov 2022-08-31 11:55:03 +03:00
parent 65e0d0ea66
commit 409b8a86de
9 changed files with 23 additions and 16 deletions

View file

@ -6201,7 +6201,7 @@ static my_bool discover_existence(THD *thd, plugin_ref plugin,
bool ha_table_exists(THD *thd, const LEX_CSTRING *db, bool ha_table_exists(THD *thd, const LEX_CSTRING *db,
const LEX_CSTRING *table_name, LEX_CUSTRING *table_id, const LEX_CSTRING *table_name, LEX_CUSTRING *table_id,
LEX_CSTRING *partition_engine_name, LEX_CSTRING *partition_engine_name,
handlerton **hton, bool *is_sequence) handlerton **hton, bool *is_sequence, uint flags)
{ {
handlerton *dummy; handlerton *dummy;
bool dummy2; bool dummy2;
@ -6256,7 +6256,7 @@ retry_from_frm:
#endif #endif
char path[FN_REFLEN + 1]; char path[FN_REFLEN + 1];
size_t path_len = build_table_filename(path, sizeof(path) - 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}; st_discover_existence_args args= {path, path_len, db->str, table_name->str, 0, true};
if (file_ext_exists(path, path_len, reg_ext)) if (file_ext_exists(path, path_len, reg_ext))

View file

@ -5289,9 +5289,10 @@ int ha_discover_table_names(THD *thd, LEX_CSTRING *db, MY_DIR *dirp,
Discovered_table_list *result, bool reusable); Discovered_table_list *result, bool reusable);
bool ha_table_exists(THD *thd, const LEX_CSTRING *db, bool ha_table_exists(THD *thd, const LEX_CSTRING *db,
const LEX_CSTRING *table_name, const LEX_CSTRING *table_name,
LEX_CUSTRING *table_version= 0, LEX_CUSTRING *table_version,
LEX_CSTRING *partition_engine_name= 0, LEX_CSTRING *partition_engine_name,
handlerton **hton= 0, bool *is_sequence= 0); handlerton **hton, bool *is_sequence,
uint flags);
bool ha_check_if_updates_are_ignored(THD *thd, handlerton *hton, bool ha_check_if_updates_are_ignored(THD *thd, handlerton *hton,
const char *op); const char *op);
#endif /* MYSQL_SERVER */ #endif /* MYSQL_SERVER */

View file

@ -7111,7 +7111,8 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
{ {
if (!(rights & CREATE_ACL)) 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, my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->db.str,
table_list->alias.str); table_list->alias.str);

View file

@ -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 (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); DBUG_RETURN(FALSE);
} }
else if (table_list->open_strategy == TABLE_LIST::OPEN_STUB) 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"); DEBUG_SYNC(thd,"create_table_before_check_if_exists");
if (!create_info.or_replace() && if (!create_info.or_replace() &&
ha_table_exists(thd, &create_table->db, &create_table->table_name, 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()) if (create_info.if_not_exists())
{ {

View file

@ -1236,7 +1236,8 @@ update_binlog:
char quoted_name[FN_REFLEN+3]; char quoted_name[FN_REFLEN+3];
// Only write drop table to the binlog for tables that no longer exist. // 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; continue;
tbl_name_len= my_snprintf(quoted_name, sizeof(quoted_name), "%`s", tbl_name_len= my_snprintf(quoted_name, sizeof(quoted_name), "%`s",

View file

@ -281,7 +281,7 @@ rename_check_preconditions(THD *thd, rename_param *param,
if (!ha_table_exists(thd, &ren_table->db, &param->old_alias, if (!ha_table_exists(thd, &ren_table->db, &param->old_alias,
&param->old_version, NULL, &param->old_version, NULL,
&param->from_table_hton) || &param->from_table_hton, NULL, 0) ||
!param->from_table_hton) !param->from_table_hton)
{ {
my_error(ER_NO_SUCH_TABLE, MYF(if_exists ? ME_NOTE : 0), 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); DBUG_RETURN(-1);
} }
if (ha_table_exists(thd, new_db, &param->new_alias, NULL, NULL, 0)) if (ha_table_exists(thd, new_db, &param->new_alias, NULL, NULL, NULL, NULL, 0))
{ {
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), param->new_alias.str); my_error(ER_TABLE_EXISTS_ERROR, MYF(0), param->new_alias.str);
DBUG_RETURN(1); // This can't be skipped DBUG_RETURN(1); // This can't be skipped

View file

@ -4819,7 +4819,7 @@ static int fill_schema_table_names(THD *thd, TABLE_LIST *tables,
bool is_sequence; bool is_sequence;
if (ha_table_exists(thd, db_name, table_name, NULL, NULL, if (ha_table_exists(thd, db_name, table_name, NULL, NULL,
&hton, &is_sequence)) &hton, &is_sequence, 0))
{ {
if (hton == view_pseudo_hton) if (hton == view_pseudo_hton)
table->field[3]->store(STRING_WITH_LEN("VIEW"), cs); table->field[3]->store(STRING_WITH_LEN("VIEW"), cs);

View file

@ -4427,8 +4427,9 @@ int create_table_impl(THD *thd,
handlerton *db_type; handlerton *db_type;
if (!internal_tmp_table && if (!internal_tmp_table &&
ha_table_exists(thd, &db, &table_name, ha_table_exists(thd, &orig_db, &orig_table_name,
&create_info->org_tabledef_version, NULL, &db_type)) &create_info->org_tabledef_version,
NULL, &db_type, NULL, 0))
{ {
if (ha_check_if_updates_are_ignored(thd, db_type, "CREATE")) 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. on the name, now we can safely try to find out for sure.
*/ */
if (!(alter_info->partition_flags & ALTER_PARTITION_CONVERT_IN) && 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() */ /* Table will be closed in do_command() */
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), alter_ctx.new_alias.str); my_error(ER_TABLE_EXISTS_ERROR, MYF(0), alter_ctx.new_alias.str);

View file

@ -1091,7 +1091,8 @@ loop_out:
fn_format(path_buff, file.str, dir.str, "", MY_UNPACK_FILENAME); fn_format(path_buff, file.str, dir.str, "", MY_UNPACK_FILENAME);
path.length= strlen(path_buff); 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; old_view_exists= 1;
if (lex->create_info.if_not_exists()) if (lex->create_info.if_not_exists())