1
0
mirror of https://github.com/MariaDB/server.git synced 2026-10-23 18:49:29 +03:00

ha_table_exists() cleanup and improvement

This is part of MDEV-25292 Atomic CREATE OR REPLACE TABLE.

Removed default values for arguments, added flags argument to specify
filename flags (FN_TO_IS_TMP, FN_FROM_IS_TMP) and forward the flag to
build_table_name().

Original patch from: Aleksey Midenkov <midenok@gmail.com>
This commit is contained in:
Monty
2025-01-02 18:41:05 +02:00
parent c17f00dce5
commit 2577a12600
9 changed files with 18 additions and 14 deletions

View File

@@ -7142,7 +7142,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,
handlerton **hton, bool *is_sequence)
handlerton **hton, bool *is_sequence, uint flags)
{
handlerton *dummy;
bool dummy2;
@@ -7179,7 +7179,7 @@ bool ha_table_exists(THD *thd, const LEX_CSTRING *db,
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))

View File

@@ -5850,8 +5850,8 @@ int ha_discover_table_names(THD *thd, const 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,
handlerton **hton= 0, bool *is_sequence= 0);
LEX_CUSTRING *table_version,
handlerton **hton, bool *is_sequence, uint flags);
bool ha_check_if_updates_are_ignored(THD *thd, handlerton *hton,
const char *op);
#endif /* MYSQL_SERVER */

View File

@@ -8770,7 +8770,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, 0))
{
my_error(ER_NO_SUCH_TABLE, MYF(0), table_list->db.str,
table_list->alias.str);

View File

@@ -2146,7 +2146,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, 0))
DBUG_RETURN(FALSE);
}
else if (table_list->open_strategy == TABLE_LIST::OPEN_STUB)
@@ -4524,7 +4525,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, &create_table->db_type))
NULL, &create_table->db_type, NULL, 0))
{
if (create_info.if_not_exists())
{

View File

@@ -1255,7 +1255,7 @@ 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, 0))
continue;
tbl_name_len= my_snprintf(quoted_name, sizeof(quoted_name), "%sQ",

View File

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

View File

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

View File

@@ -4805,7 +4805,8 @@ 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, &db_type))
&create_info->org_tabledef_version, &db_type,
NULL, 0))
{
if (ha_check_if_updates_are_ignored(thd, db_type, "CREATE"))
{
@@ -11120,7 +11121,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, 0))
{
/* Table will be closed in do_command() */
my_error(ER_TABLE_EXISTS_ERROR, MYF(0), alter_ctx.new_alias.str);

View File

@@ -1150,7 +1150,7 @@ 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, 0))
{
old_view_exists= 1;
if (lex->create_info.if_not_exists())