Skip to content
Permalink
Browse files
Clean up table_name_t
row_is_mysql_tmp_table_name(): Replaced with
dict_table_t::is_temporary_name() and table_name_t::is_temporary().

table_name_t: Add constructors.
  • Loading branch information
dr-m committed Apr 3, 2019
1 parent 03672a0 commit a1ec7ac
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 81 deletions.
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2016, 2018, MariaDB Corporation.
Copyright (c) 2016, 2019, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -81,7 +81,7 @@ file_unreadable flag in the table object we return */
static
dict_table_t*
dict_load_table_one(
table_name_t& name,
const table_name_t& name,
bool cached,
dict_err_ignore_t ignore_err,
dict_names_t& fk_tables);
@@ -93,9 +93,8 @@ Do not load any columns or indexes.
@param[out,own] table table, or NULL
@return error message
@retval NULL on success */
static
const char*
dict_load_table_low(table_name_t& name, const rec_t* rec, dict_table_t** table)
static const char* dict_load_table_low(const table_name_t& name,
const rec_t* rec, dict_table_t** table)
MY_ATTRIBUTE((nonnull, warn_unused_result));

/** Load an index definition from a SYS_INDEXES record to dict_index_t.
@@ -392,7 +391,6 @@ dict_process_sys_tables_rec_and_mtr_commit(
ulint len;
const char* field;
const char* err_msg = NULL;
table_name_t table_name;

field = (const char*) rec_get_nth_field_old(
rec, DICT_FLD__SYS_TABLES__NAME, &len);
@@ -402,7 +400,7 @@ dict_process_sys_tables_rec_and_mtr_commit(
ut_ad(mtr_memo_contains_page(mtr, rec, MTR_MEMO_PAGE_S_FIX));

/* Get the table name */
table_name.m_name = mem_heap_strdupl(heap, field, len);
table_name_t table_name(mem_heap_strdupl(heap, field, len));

/* If DICT_TABLE_LOAD_FROM_CACHE is set, first check
whether there is cached dict_table_t struct */
@@ -1397,7 +1395,6 @@ dict_check_sys_tables(
rec = dict_getnext_system(&pcur, &mtr)) {
const byte* field;
ulint len;
table_name_t table_name;
table_id_t table_id;
ulint space_id;
ulint n_cols;
@@ -1413,7 +1410,8 @@ dict_check_sys_tables(
/* Copy the table name from rec */
field = rec_get_nth_field_old(
rec, DICT_FLD__SYS_TABLES__NAME, &len);
table_name.m_name = mem_strdupl((char*) field, len);

table_name_t table_name(mem_strdupl((char*) field, len));
DBUG_PRINT("dict_check_sys_tables",
("name: %p, '%s'", table_name.m_name,
table_name.m_name));
@@ -2660,9 +2658,8 @@ Do not load any columns or indexes.
@param[out,own] table table, or NULL
@return error message
@retval NULL on success */
static
const char*
dict_load_table_low(table_name_t& name, const rec_t* rec, dict_table_t** table)
static const char* dict_load_table_low(const table_name_t& name,
const rec_t* rec, dict_table_t** table)
{
table_id_t table_id;
ulint space_id;
@@ -2792,32 +2789,22 @@ dict_load_table(
dict_names_t fk_list;
dict_table_t* result;
dict_names_t::iterator i;
table_name_t table_name;

DBUG_ENTER("dict_load_table");
DBUG_PRINT("dict_load_table", ("loading table: '%s'", name));

ut_ad(mutex_own(&dict_sys->mutex));

table_name.m_name = const_cast<char*>(name);

result = dict_table_check_if_in_cache_low(name);

if (!result) {
result = dict_load_table_one(table_name, cached, ignore_err,
fk_list);
result = dict_load_table_one(const_cast<char*>(name),
cached, ignore_err, fk_list);
while (!fk_list.empty()) {
table_name_t fk_table_name;
dict_table_t* fk_table;

fk_table_name.m_name =
const_cast<char*>(fk_list.front());
fk_table = dict_table_check_if_in_cache_low(
fk_table_name.m_name);
if (!fk_table) {
dict_load_table_one(fk_table_name, cached,
ignore_err, fk_list);
}
if (!dict_table_check_if_in_cache_low(fk_list.front()))
dict_load_table_one(
const_cast<char*>(fk_list.front()),
cached, ignore_err, fk_list);
fk_list.pop_front();
}
}
@@ -2917,7 +2904,7 @@ file_unreadable flag in the table object we return */
static
dict_table_t*
dict_load_table_one(
table_name_t& name,
const table_name_t& name,
bool cached,
dict_err_ignore_t ignore_err,
dict_names_t& fk_tables)
@@ -13208,10 +13208,8 @@ inline int ha_innobase::delete_table(const char* name, enum_sql_command sqlcom)
err = row_drop_database_for_mysql(norm_name, trx,
&num_partitions);
norm_name[len] = 0;
if (num_partitions == 0
&& !row_is_mysql_tmp_table_name(norm_name)) {
table_name_t tbl_name;
tbl_name.m_name = norm_name;
table_name_t tbl_name(norm_name);
if (num_partitions == 0 && !tbl_name.is_temporary()) {
ib::error() << "Table " << tbl_name <<
" does not exist in the InnoDB"
" internal data dictionary though MariaDB is"
@@ -7449,13 +7449,11 @@ innobase_update_foreign_cache(
fk_tables.front(), true, DICT_ERR_IGNORE_NONE);

if (table == NULL) {
table_name_t table_name;
table_name.m_name = const_cast<char*>(
fk_tables.front());

err = DB_TABLE_NOT_FOUND;
ib::error()
<< "Failed to load table '" << table_name
<< "Failed to load table '"
<< table_name_t(const_cast<char*>
(fk_tables.front()))
<< "' which has a foreign key constraint with"
<< " table '" << user_table->name << "'.";
break;
@@ -28,18 +28,6 @@ Created 1/8/1996 Heikki Tuuri

#include "mem0mem.h"

/*********************************************************************//**
Checks if a table name contains the string "/#sql" which denotes temporary
tables in MySQL.
@return true if temporary table */
bool
row_is_mysql_tmp_table_name(
/*========================*/
const char* name) MY_ATTRIBUTE((warn_unused_result));
/*!< in: table name in the form
'database/tablename' */


/********************************************************************//**
Generate a foreign key constraint name when it was not named by the user.
A generated constraint has a name of the format dbname/tablename_ibfk_NUMBER,
@@ -63,7 +51,7 @@ dict_create_add_foreign_id(
mem_heap_alloc(foreign->heap,
namelen + 20));

if (row_is_mysql_tmp_table_name(name)) {
if (dict_table_t::is_temporary_name(name)) {

/* no overflow if number < 1e13 */
sprintf(id, "%s_ibfk_%lu", name,
@@ -559,6 +559,11 @@ struct table_name_t
/** The name in internal representation */
char* m_name;

/** Default constructor */
table_name_t() {}
/** Constructor */
table_name_t(char* name) : m_name(name) {}

/** @return the end of the schema name */
const char* dbend() const
{
@@ -581,6 +586,9 @@ struct table_name_t
@return the partition name
@retval NULL if the table is not partitioned */
const char* part() const { return strstr(basename(), part_suffix); }

/** @return whether this is a temporary or intermediate table name */
inline bool is_temporary() const;
};

/** Data structure for a column in a table */
@@ -1401,6 +1409,13 @@ struct dict_table_t {
return(UNIV_LIKELY(!file_unreadable));
}

/** Check if a table name contains the string "/#sql"
which denotes temporary or intermediate tables in MariaDB. */
static bool is_temporary_name(const char* name)
{
return strstr(name, "/" TEMP_FILE_PREFIX) != NULL;
}

/** Id of the table. */
table_id_t id;
/** Hash chain node. */
@@ -1770,6 +1785,11 @@ struct dict_table_t {
dict_vcol_templ_t* vc_templ;
};

inline bool table_name_t::is_temporary() const
{
return dict_table_t::is_temporary_name(m_name);
}

inline bool dict_index_t::is_readable() const
{
return(UNIV_LIKELY(!table->file_unreadable));
@@ -1,7 +1,7 @@
/*****************************************************************************
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2017, 2018, MariaDB Corporation.
Copyright (c) 2017, 2019, MariaDB Corporation.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@@ -275,17 +275,6 @@ row_unlock_for_mysql(
row_prebuilt_t* prebuilt,
ibool has_latches_on_recs);

/*********************************************************************//**
Checks if a table name contains the string "/#sql" which denotes temporary
tables in MySQL.
@return true if temporary table */
bool
row_is_mysql_tmp_table_name(
/*========================*/
const char* name) MY_ATTRIBUTE((warn_unused_result));
/*!< in: table name in the form
'database/tablename' */

/*********************************************************************//**
Creates an query graph node of 'update' type to be used in the MySQL
interface.
@@ -3966,7 +3966,7 @@ row_drop_database_for_mysql(

}

if (!row_is_mysql_tmp_table_name(table->name.m_name)) {
if (!table->name.is_temporary()) {
/* There could be orphan temp tables left from
interrupted alter table. Leave them, and handle
the rest.*/
@@ -4060,21 +4060,6 @@ row_drop_database_for_mysql(
DBUG_RETURN(err);
}

/*********************************************************************//**
Checks if a table name contains the string "/#sql" which denotes temporary
tables in MySQL.
@return true if temporary table */
MY_ATTRIBUTE((warn_unused_result))
bool
row_is_mysql_tmp_table_name(
/*========================*/
const char* name) /*!< in: table name in the form
'database/tablename' */
{
return(strstr(name, "/" TEMP_FILE_PREFIX) != NULL);
/* return(strstr(name, "/@0023sql") != NULL); */
}

/****************************************************************//**
Delete a single constraint.
@return error code or DB_SUCCESS */
@@ -4174,8 +4159,8 @@ row_rename_table_for_mysql(

trx->op_info = "renaming table";

old_is_tmp = row_is_mysql_tmp_table_name(old_name);
new_is_tmp = row_is_mysql_tmp_table_name(new_name);
old_is_tmp = dict_table_t::is_temporary_name(old_name);
new_is_tmp = dict_table_t::is_temporary_name(new_name);

dict_locked = trx->dict_operation_lock_mode == RW_X_LATCH;

0 comments on commit a1ec7ac

Please sign in to comment.