Commit 5ffdb98f authored by Marko Mäkelä's avatar Marko Mäkelä

Do not modify the table when adding it to the cache

dict_table_t::add_to_cache(): Modified from dict_table_add_to_cache().
Let the callers invoke dict_table_add_system_columns() and if needed,
set can_be_evicted.
parent 1ef59971
......@@ -349,7 +349,8 @@ dict_boot(void)
table->id = DICT_TABLES_ID;
dict_table_add_to_cache(table, FALSE, heap);
dict_table_add_system_columns(table, heap);
table->add_to_cache();
dict_sys->sys_tables = table;
mem_heap_empty(heap);
......@@ -398,7 +399,8 @@ dict_boot(void)
table->id = DICT_COLUMNS_ID;
dict_table_add_to_cache(table, FALSE, heap);
dict_table_add_system_columns(table, heap);
table->add_to_cache();
dict_sys->sys_columns = table;
mem_heap_empty(heap);
......@@ -435,7 +437,8 @@ dict_boot(void)
table->id = DICT_INDEXES_ID;
dict_table_add_to_cache(table, FALSE, heap);
dict_table_add_system_columns(table, heap);
table->add_to_cache();
dict_sys->sys_indexes = table;
mem_heap_empty(heap);
......@@ -466,7 +469,8 @@ dict_boot(void)
table->id = DICT_FIELDS_ID;
dict_table_add_to_cache(table, FALSE, heap);
dict_table_add_system_columns(table, heap);
table->add_to_cache();
dict_sys->sys_fields = table;
mem_heap_free(heap);
......
......@@ -1419,7 +1419,9 @@ dict_create_table_step(
if (node->state == TABLE_ADD_TO_CACHE) {
DBUG_EXECUTE_IF("ib_ddl_crash_during_create", DBUG_SUICIDE(););
dict_table_add_to_cache(node->table, TRUE, node->heap);
dict_table_add_system_columns(node->table, node->heap);
node->table->can_be_evicted = true;
node->table->add_to_cache();
err = DB_SUCCESS;
}
......
......@@ -1265,41 +1265,31 @@ dict_table_add_system_columns(
#endif
}
/**********************************************************************//**
Adds a table object to the dictionary cache. */
/** Add the table definition to the data dictionary cache */
void
dict_table_add_to_cache(
/*====================*/
dict_table_t* table, /*!< in: table */
bool can_be_evicted, /*!< in: whether can be evicted */
mem_heap_t* heap) /*!< in: temporary heap */
dict_table_t::add_to_cache()
{
ulint fold;
ulint id_fold;
ut_ad(dict_lru_validate());
ut_ad(mutex_own(&dict_sys->mutex));
dict_table_add_system_columns(table, heap);
table->cached = TRUE;
cached = TRUE;
fold = ut_fold_string(table->name.m_name);
id_fold = ut_fold_ull(table->id);
ulint fold = ut_fold_string(name.m_name);
ulint id_fold = ut_fold_ull(id);
/* Look for a table with the same name: error if such exists */
{
dict_table_t* table2;
HASH_SEARCH(name_hash, dict_sys->table_hash, fold,
dict_table_t*, table2, ut_ad(table2->cached),
!strcmp(table2->name.m_name, table->name.m_name));
!strcmp(table2->name.m_name, name.m_name));
ut_a(table2 == NULL);
#ifdef UNIV_DEBUG
/* Look for the same table pointer with a different name */
HASH_SEARCH_ALL(name_hash, dict_sys->table_hash,
dict_table_t*, table2, ut_ad(table2->cached),
table2 == table);
table2 == this);
ut_ad(table2 == NULL);
#endif /* UNIV_DEBUG */
}
......@@ -1309,32 +1299,30 @@ dict_table_add_to_cache(
dict_table_t* table2;
HASH_SEARCH(id_hash, dict_sys->table_id_hash, id_fold,
dict_table_t*, table2, ut_ad(table2->cached),
table2->id == table->id);
table2->id == id);
ut_a(table2 == NULL);
#ifdef UNIV_DEBUG
/* Look for the same table pointer with a different id */
HASH_SEARCH_ALL(id_hash, dict_sys->table_id_hash,
dict_table_t*, table2, ut_ad(table2->cached),
table2 == table);
table2 == this);
ut_ad(table2 == NULL);
#endif /* UNIV_DEBUG */
}
/* Add table to hash table of tables */
HASH_INSERT(dict_table_t, name_hash, dict_sys->table_hash, fold,
table);
this);
/* Add table to hash table of tables based on table id */
HASH_INSERT(dict_table_t, id_hash, dict_sys->table_id_hash, id_fold,
table);
table->can_be_evicted = can_be_evicted;
this);
if (table->can_be_evicted) {
UT_LIST_ADD_FIRST(dict_sys->table_LRU, table);
if (can_be_evicted) {
UT_LIST_ADD_FIRST(dict_sys->table_LRU, this);
} else {
UT_LIST_ADD_FIRST(dict_sys->table_non_LRU, table);
UT_LIST_ADD_FIRST(dict_sys->table_non_LRU, this);
}
ut_ad(dict_lru_validate());
......
......@@ -3005,10 +3005,11 @@ dict_load_table_one(
dict_load_virtual(table, heap);
dict_table_add_system_columns(table, heap);
if (cached) {
dict_table_add_to_cache(table, TRUE, heap);
} else {
dict_table_add_system_columns(table, heap);
table->can_be_evicted = true;
table->add_to_cache();
}
mem_heap_empty(heap);
......
......@@ -11610,8 +11610,8 @@ create_table_info_t::create_table_def()
temp_table_heap = mem_heap_create(256);
dict_table_add_to_cache(
table, FALSE, temp_table_heap);
dict_table_add_system_columns(table, temp_table_heap);
table->add_to_cache();
DBUG_EXECUTE_IF("ib_ddl_crash_during_create2",
DBUG_SUICIDE(););
......
......@@ -387,15 +387,6 @@ dict_table_add_system_columns(
mem_heap_t* heap) /*!< in: temporary heap */
MY_ATTRIBUTE((nonnull));
/**********************************************************************//**
Adds a table object to the dictionary cache. */
void
dict_table_add_to_cache(
/*====================*/
dict_table_t* table, /*!< in: table */
bool can_be_evicted, /*!< in: whether can be evicted*/
mem_heap_t* heap) /*!< in: temporary heap */
MY_ATTRIBUTE((nonnull));
/**********************************************************************//**
Removes a table object from the dictionary cache. */
void
dict_table_remove_from_cache(
......
......@@ -1514,6 +1514,8 @@ struct dict_table_t {
return(!(flags & DICT_TF_MASK_ZIP_SSIZE));
}
/** Add the table definition to the data dictionary cache */
void add_to_cache();
/** When engaging instant ALTER TABLE, remove a table stub
from the data dictionary cache. */
void remove_stub_from_cache();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment