Skip to content

Commit 409b8a8

Browse files
committed
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).
1 parent 65e0d0e commit 409b8a8

File tree

9 files changed

+23
-16
lines changed

9 files changed

+23
-16
lines changed

sql/handler.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6201,7 +6201,7 @@ static my_bool discover_existence(THD *thd, plugin_ref plugin,
62016201
bool ha_table_exists(THD *thd, const LEX_CSTRING *db,
62026202
const LEX_CSTRING *table_name, LEX_CUSTRING *table_id,
62036203
LEX_CSTRING *partition_engine_name,
6204-
handlerton **hton, bool *is_sequence)
6204+
handlerton **hton, bool *is_sequence, uint flags)
62056205
{
62066206
handlerton *dummy;
62076207
bool dummy2;
@@ -6256,7 +6256,7 @@ bool ha_table_exists(THD *thd, const LEX_CSTRING *db,
62566256
#endif
62576257
char path[FN_REFLEN + 1];
62586258
size_t path_len = build_table_filename(path, sizeof(path) - 1,
6259-
db->str, table_name->str, "", 0);
6259+
db->str, table_name->str, "", flags);
62606260
st_discover_existence_args args= {path, path_len, db->str, table_name->str, 0, true};
62616261

62626262
if (file_ext_exists(path, path_len, reg_ext))

sql/handler.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5289,9 +5289,10 @@ int ha_discover_table_names(THD *thd, LEX_CSTRING *db, MY_DIR *dirp,
52895289
Discovered_table_list *result, bool reusable);
52905290
bool ha_table_exists(THD *thd, const LEX_CSTRING *db,
52915291
const LEX_CSTRING *table_name,
5292-
LEX_CUSTRING *table_version= 0,
5293-
LEX_CSTRING *partition_engine_name= 0,
5294-
handlerton **hton= 0, bool *is_sequence= 0);
5292+
LEX_CUSTRING *table_version,
5293+
LEX_CSTRING *partition_engine_name,
5294+
handlerton **hton, bool *is_sequence,
5295+
uint flags);
52955296
bool ha_check_if_updates_are_ignored(THD *thd, handlerton *hton,
52965297
const char *op);
52975298
#endif /* MYSQL_SERVER */

sql/sql_acl.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7111,7 +7111,8 @@ int mysql_table_grant(THD *thd, TABLE_LIST *table_list,
71117111
{
71127112
if (!(rights & CREATE_ACL))
71137113
{
7114-
if (!ha_table_exists(thd, &table_list->db, &table_list->table_name))
7114+
if (!ha_table_exists(thd, &table_list->db, &table_list->table_name,
7115+
NULL, NULL, NULL, NULL, 0))
71157116
{
71167117
my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->db.str,
71177118
table_list->alias.str);

sql/sql_base.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,7 +2008,8 @@ bool open_table(THD *thd, TABLE_LIST *table_list, Open_table_context *ot_ctx)
20082008

20092009
if (table_list->open_strategy == TABLE_LIST::OPEN_IF_EXISTS)
20102010
{
2011-
if (!ha_table_exists(thd, &table_list->db, &table_list->table_name))
2011+
if (!ha_table_exists(thd, &table_list->db, &table_list->table_name,
2012+
NULL, NULL, NULL, NULL, 0))
20122013
DBUG_RETURN(FALSE);
20132014
}
20142015
else if (table_list->open_strategy == TABLE_LIST::OPEN_STUB)
@@ -4223,7 +4224,7 @@ static bool upgrade_lock_if_not_exists(THD *thd,
42234224
DEBUG_SYNC(thd,"create_table_before_check_if_exists");
42244225
if (!create_info.or_replace() &&
42254226
ha_table_exists(thd, &create_table->db, &create_table->table_name,
4226-
NULL, NULL, &create_table->db_type))
4227+
NULL, NULL, &create_table->db_type, NULL, 0))
42274228
{
42284229
if (create_info.if_not_exists())
42294230
{

sql/sql_db.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1236,7 +1236,8 @@ mysql_rm_db_internal(THD *thd, const LEX_CSTRING *db, bool if_exists,
12361236
char quoted_name[FN_REFLEN+3];
12371237

12381238
// Only write drop table to the binlog for tables that no longer exist.
1239-
if (ha_table_exists(thd, &tbl->db, &tbl->table_name))
1239+
if (ha_table_exists(thd, &tbl->db, &tbl->table_name,
1240+
NULL, NULL, NULL, NULL, 0))
12401241
continue;
12411242

12421243
tbl_name_len= my_snprintf(quoted_name, sizeof(quoted_name), "%`s",

sql/sql_rename.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ rename_check_preconditions(THD *thd, rename_param *param,
281281

282282
if (!ha_table_exists(thd, &ren_table->db, &param->old_alias,
283283
&param->old_version, NULL,
284-
&param->from_table_hton) ||
284+
&param->from_table_hton, NULL, 0) ||
285285
!param->from_table_hton)
286286
{
287287
my_error(ER_NO_SUCH_TABLE, MYF(if_exists ? ME_NOTE : 0),
@@ -301,7 +301,7 @@ rename_check_preconditions(THD *thd, rename_param *param,
301301
DBUG_RETURN(-1);
302302
}
303303

304-
if (ha_table_exists(thd, new_db, &param->new_alias, NULL, NULL, 0))
304+
if (ha_table_exists(thd, new_db, &param->new_alias, NULL, NULL, NULL, NULL, 0))
305305
{
306306
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), param->new_alias.str);
307307
DBUG_RETURN(1); // This can't be skipped

sql/sql_show.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4819,7 +4819,7 @@ static int fill_schema_table_names(THD *thd, TABLE_LIST *tables,
48194819
bool is_sequence;
48204820

48214821
if (ha_table_exists(thd, db_name, table_name, NULL, NULL,
4822-
&hton, &is_sequence))
4822+
&hton, &is_sequence, 0))
48234823
{
48244824
if (hton == view_pseudo_hton)
48254825
table->field[3]->store(STRING_WITH_LEN("VIEW"), cs);

sql/sql_table.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4427,8 +4427,9 @@ int create_table_impl(THD *thd,
44274427

44284428
handlerton *db_type;
44294429
if (!internal_tmp_table &&
4430-
ha_table_exists(thd, &db, &table_name,
4431-
&create_info->org_tabledef_version, NULL, &db_type))
4430+
ha_table_exists(thd, &orig_db, &orig_table_name,
4431+
&create_info->org_tabledef_version,
4432+
NULL, &db_type, NULL, 0))
44324433
{
44334434
if (ha_check_if_updates_are_ignored(thd, db_type, "CREATE"))
44344435
{
@@ -10080,7 +10081,8 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db,
1008010081
on the name, now we can safely try to find out for sure.
1008110082
*/
1008210083
if (!(alter_info->partition_flags & ALTER_PARTITION_CONVERT_IN) &&
10083-
ha_table_exists(thd, &alter_ctx.new_db, &alter_ctx.new_name))
10084+
ha_table_exists(thd, &alter_ctx.new_db, &alter_ctx.new_name,
10085+
NULL, NULL, NULL, NULL, 0))
1008410086
{
1008510087
/* Table will be closed in do_command() */
1008610088
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), alter_ctx.new_alias.str);

sql/sql_view.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,8 @@ static int mysql_register_view(THD *thd, DDL_LOG_STATE *ddl_log_state,
10911091
fn_format(path_buff, file.str, dir.str, "", MY_UNPACK_FILENAME);
10921092
path.length= strlen(path_buff);
10931093

1094-
if (ha_table_exists(thd, &view->db, &view->table_name))
1094+
if (ha_table_exists(thd, &view->db, &view->table_name,
1095+
NULL, NULL, NULL, NULL, 0))
10951096
{
10961097
old_view_exists= 1;
10971098
if (lex->create_info.if_not_exists())

0 commit comments

Comments
 (0)