diff options
author | Marko Mäkelä <marko.makela@mariadb.com> | 2018-03-23 17:25:56 +0200 |
---|---|---|
committer | Marko Mäkelä <marko.makela@mariadb.com> | 2018-03-29 20:47:37 +0300 |
commit | 428e02895b4464e12ed0d76064ae49b03300861f (patch) | |
tree | 7f6d682e97fd453f0b1c23f4518a79d73c01289e /storage/innobase | |
parent | 604fea1ad6d7b0463e5a30471a04b3b417467df9 (diff) | |
download | mariadb-git-428e02895b4464e12ed0d76064ae49b03300861f.tar.gz |
MDEV-12266: Remove dict_index_t::table_name
Replace index->table_name with index->table->name.
Diffstat (limited to 'storage/innobase')
28 files changed, 304 insertions, 501 deletions
diff --git a/storage/innobase/dict/dict0boot.cc b/storage/innobase/dict/dict0boot.cc index 9929c4fe4c1..c4bb5f8adb0 100644 --- a/storage/innobase/dict/dict0boot.cc +++ b/storage/innobase/dict/dict0boot.cc @@ -283,7 +283,6 @@ dict_boot(void) dict_hdr_t* dict_hdr; mem_heap_t* heap; mtr_t mtr; - dberr_t error; /* Be sure these constants do not ever change. To avoid bloat, only check the *NUM_FIELDS* in each table */ @@ -356,34 +355,27 @@ dict_boot(void) dict_sys->sys_tables = table; mem_heap_empty(heap); - index = dict_mem_index_create("SYS_TABLES", "CLUST_IND", + index = dict_mem_index_create(table, "CLUST_IND", DICT_UNIQUE | DICT_CLUSTERED, 1); dict_mem_index_add_field(index, "NAME", 0); index->id = DICT_TABLES_ID; - - error = dict_index_add_to_cache(table, index, - mtr_read_ulint(dict_hdr - + DICT_HDR_TABLES, - MLOG_4BYTES, &mtr), - FALSE); - ut_a(error == DB_SUCCESS); + index = dict_index_add_to_cache( + index, mach_read_from_4(dict_hdr + DICT_HDR_TABLES)); + ut_a(index); ut_ad(!table->is_instant()); table->indexes.start->n_core_null_bytes = UT_BITS_IN_BYTES( table->indexes.start->n_nullable); /*-------------------------*/ - index = dict_mem_index_create("SYS_TABLES", "ID_IND", DICT_UNIQUE, 1); + index = dict_mem_index_create(table, "ID_IND", DICT_UNIQUE, 1); dict_mem_index_add_field(index, "ID", 0); index->id = DICT_TABLE_IDS_ID; - error = dict_index_add_to_cache(table, index, - mtr_read_ulint(dict_hdr - + DICT_HDR_TABLE_IDS, - MLOG_4BYTES, &mtr), - FALSE); - ut_a(error == DB_SUCCESS); + index = dict_index_add_to_cache( + index, mach_read_from_4(dict_hdr + DICT_HDR_TABLE_IDS)); + ut_a(index); /*-------------------------*/ table = dict_mem_table_create("SYS_COLUMNS", DICT_HDR_SPACE, @@ -404,19 +396,16 @@ dict_boot(void) dict_sys->sys_columns = table; mem_heap_empty(heap); - index = dict_mem_index_create("SYS_COLUMNS", "CLUST_IND", + index = dict_mem_index_create(table, "CLUST_IND", DICT_UNIQUE | DICT_CLUSTERED, 2); dict_mem_index_add_field(index, "TABLE_ID", 0); dict_mem_index_add_field(index, "POS", 0); index->id = DICT_COLUMNS_ID; - error = dict_index_add_to_cache(table, index, - mtr_read_ulint(dict_hdr - + DICT_HDR_COLUMNS, - MLOG_4BYTES, &mtr), - FALSE); - ut_a(error == DB_SUCCESS); + index = dict_index_add_to_cache( + index, mach_read_from_4(dict_hdr + DICT_HDR_COLUMNS)); + ut_a(index); ut_ad(!table->is_instant()); table->indexes.start->n_core_null_bytes = UT_BITS_IN_BYTES( table->indexes.start->n_nullable); @@ -450,19 +439,16 @@ dict_boot(void) dict_sys->sys_indexes = table; mem_heap_empty(heap); - index = dict_mem_index_create("SYS_INDEXES", "CLUST_IND", + index = dict_mem_index_create(table, "CLUST_IND", DICT_UNIQUE | DICT_CLUSTERED, 2); dict_mem_index_add_field(index, "TABLE_ID", 0); dict_mem_index_add_field(index, "ID", 0); index->id = DICT_INDEXES_ID; - error = dict_index_add_to_cache(table, index, - mtr_read_ulint(dict_hdr - + DICT_HDR_INDEXES, - MLOG_4BYTES, &mtr), - FALSE); - ut_a(error == DB_SUCCESS); + index = dict_index_add_to_cache( + index, mach_read_from_4(dict_hdr + DICT_HDR_INDEXES)); + ut_a(index); ut_ad(!table->is_instant()); table->indexes.start->n_core_null_bytes = UT_BITS_IN_BYTES( table->indexes.start->n_nullable); @@ -481,19 +467,16 @@ dict_boot(void) dict_sys->sys_fields = table; mem_heap_free(heap); - index = dict_mem_index_create("SYS_FIELDS", "CLUST_IND", + index = dict_mem_index_create(table, "CLUST_IND", DICT_UNIQUE | DICT_CLUSTERED, 2); dict_mem_index_add_field(index, "INDEX_ID", 0); dict_mem_index_add_field(index, "POS", 0); index->id = DICT_FIELDS_ID; - error = dict_index_add_to_cache(table, index, - mtr_read_ulint(dict_hdr - + DICT_HDR_FIELDS, - MLOG_4BYTES, &mtr), - FALSE); - ut_a(error == DB_SUCCESS); + index = dict_index_add_to_cache( + index, mach_read_from_4(dict_hdr + DICT_HDR_FIELDS)); + ut_a(index); ut_ad(!table->is_instant()); table->indexes.start->n_core_null_bytes = UT_BITS_IN_BYTES( table->indexes.start->n_nullable); diff --git a/storage/innobase/dict/dict0crea.cc b/storage/innobase/dict/dict0crea.cc index f24ac1dce98..4da02a2a292 100644 --- a/storage/innobase/dict/dict0crea.cc +++ b/storage/innobase/dict/dict0crea.cc @@ -462,7 +462,6 @@ dict_create_sys_indexes_tuple( tuple is allocated */ { dict_table_t* sys_indexes; - dict_table_t* table; dtuple_t* entry; dfield_t* dfield; byte* ptr; @@ -473,8 +472,6 @@ dict_create_sys_indexes_tuple( sys_indexes = dict_sys->sys_indexes; - table = dict_table_get_low(index->table_name); - entry = dtuple_create( heap, DICT_NUM_COLS__SYS_INDEXES + DATA_N_SYS_COLS); @@ -485,7 +482,7 @@ dict_create_sys_indexes_tuple( entry, DICT_COL__SYS_INDEXES__TABLE_ID); ptr = static_cast<byte*>(mem_heap_alloc(heap, 8)); - mach_write_to_8(ptr, table->id); + mach_write_to_8(ptr, index->table->id); dfield_set_data(dfield, ptr, 8); @@ -539,7 +536,7 @@ dict_create_sys_indexes_tuple( entry, DICT_COL__SYS_INDEXES__SPACE); ptr = static_cast<byte*>(mem_heap_alloc(heap, 4)); - mach_write_to_4(ptr, table->space); + mach_write_to_4(ptr, index->table->space); dfield_set_data(dfield, ptr, 4); @@ -707,7 +704,8 @@ dict_build_index_def_step( index = node->index; - table = dict_table_get_low(index->table_name); + table = index->table = node->table = dict_table_open_on_name( + node->table_name, TRUE, FALSE, DICT_ERR_IGNORE_NONE); if (table == NULL) { return(DB_TABLE_NOT_FOUND); @@ -718,8 +716,6 @@ dict_build_index_def_step( trx->table_id = table->id; } - node->table = table; - ut_ad((UT_LIST_GET_LEN(table->indexes) > 0) || dict_index_is_clust(index)); @@ -738,6 +734,7 @@ dict_build_index_def_step( index->trx_id = trx->id; ut_ad(table->def_trx_id <= trx->id); table->def_trx_id = trx->id; + dict_table_close(table, true, false); return(DB_SUCCESS); } @@ -1201,6 +1198,7 @@ tab_create_graph_create( /** Creates an index create graph. @param[in] index index to create, built as a memory data structure +@param[in] table table name @param[in,out] heap heap where created @param[in] add_v new virtual columns added in the same clause with add index @@ -1208,6 +1206,7 @@ tab_create_graph_create( ind_node_t* ind_create_graph_create( dict_index_t* index, + const char* table, mem_heap_t* heap, const dict_add_v_col_t* add_v) { @@ -1220,6 +1219,8 @@ ind_create_graph_create( node->index = index; + node->table_name = table; + node->add_v = add_v; node->state = INDEX_BUILD_INDEX_DEF; @@ -1438,18 +1439,14 @@ dict_create_index_step( } if (node->state == INDEX_ADD_TO_CACHE) { + ut_ad(node->index->table == node->table); + node->index = dict_index_add_to_cache( + node->index, FIL_NULL, trx_is_strict(trx), + &err, node->add_v); - index_id_t index_id = node->index->id; - - err = dict_index_add_to_cache_w_vcol( - node->table, node->index, node->add_v, FIL_NULL, - trx_is_strict(trx)); - - node->index = dict_index_get_if_in_cache_low(index_id); - ut_a((node->index == NULL) == (err != DB_SUCCESS)); - - if (err != DB_SUCCESS) { + ut_ad((node->index == NULL) == (err != DB_SUCCESS)); + if (!node->index) { goto function_exit; } diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc index ace3a91097e..da9d94b3391 100644 --- a/storage/innobase/dict/dict0dict.cc +++ b/storage/innobase/dict/dict0dict.cc @@ -125,14 +125,12 @@ static bool innodb_index_stats_not_found_reported = false; /*******************************************************************//** Tries to find column names for the index and sets the col field of the index. -@param[in] table table @param[in] index index @param[in] add_v new virtual columns added along with an add index call -@return TRUE if the column names were found */ +@return whether the column names were found */ static -ibool +bool dict_index_find_cols( - const dict_table_t* table, dict_index_t* index, const dict_add_v_col_t* add_v); /*******************************************************************//** @@ -143,7 +141,6 @@ static dict_index_t* dict_index_build_internal_clust( /*============================*/ - const dict_table_t* table, /*!< in: table */ dict_index_t* index); /*!< in: user representation of a clustered index */ /*******************************************************************//** @@ -154,7 +151,6 @@ static dict_index_t* dict_index_build_internal_non_clust( /*================================*/ - const dict_table_t* table, /*!< in: table */ dict_index_t* index); /*!< in: user representation of a non-clustered index */ /**********************************************************************//** @@ -164,7 +160,6 @@ static dict_index_t* dict_index_build_internal_fts( /*==========================*/ - dict_table_t* table, /*!< in: table */ dict_index_t* index); /*!< in: user representation of an FTS index */ /**********************************************************************//** @@ -1568,7 +1563,6 @@ dict_table_rename_in_cache( { dberr_t err; dict_foreign_t* foreign; - dict_index_t* index; ulint fold; char old_name[MAX_FULL_NAME_LEN + 1]; os_file_type_t ftype; @@ -1716,14 +1710,6 @@ dict_table_rename_in_cache( HASH_INSERT(dict_table_t, name_hash, dict_sys->table_hash, fold, table); - /* Update the table_name field in indexes */ - for (index = dict_table_get_first_index(table); - index != NULL; - index = dict_table_get_next_index(index)) { - - index->table_name = table->name.m_name; - } - if (!rename_also_foreigns) { /* In ALTER TABLE we think of the rename table operation in the direction table -> temporary table (#sql...) @@ -2391,45 +2377,26 @@ add_field_size: return(FALSE); } -/** Adds an index to the dictionary cache. -@param[in,out] table table on which the index is -@param[in,out] index index; NOTE! The index memory - object is freed in this function! -@param[in] page_no root page number of the index -@param[in] strict TRUE=refuse to create the index - if records could be too big to fit in - an B-tree page -@return DB_SUCCESS, DB_TOO_BIG_RECORD, or DB_CORRUPTION */ -dberr_t -dict_index_add_to_cache( - dict_table_t* table, - dict_index_t* index, - ulint page_no, - ibool strict) -{ - return(dict_index_add_to_cache_w_vcol( - table, index, NULL, page_no, strict)); -} - /** Adds an index to the dictionary cache, with possible indexing newly added column. -@param[in,out] table table on which the index is -@param[in,out] index index; NOTE! The index memory +@param[in] index index; NOTE! The index memory object is freed in this function! -@param[in] add_v new virtual column that being added along with - an add index call @param[in] page_no root page number of the index @param[in] strict TRUE=refuse to create the index if records could be too big to fit in an B-tree page -@return DB_SUCCESS, DB_TOO_BIG_RECORD, or DB_CORRUPTION */ -dberr_t -dict_index_add_to_cache_w_vcol( - dict_table_t* table, +@param[out] err DB_SUCCESS, DB_TOO_BIG_RECORD, or DB_CORRUPTION +@param[in] add_v new virtual column that being added along with + an add index call +@return the added index +@retval NULL on error */ +dict_index_t* +dict_index_add_to_cache( dict_index_t* index, - const dict_add_v_col_t* add_v, ulint page_no, - ibool strict) + bool strict, + dberr_t* err, + const dict_add_v_col_t* add_v) { dict_index_t* new_index; ulint n_ord; @@ -2444,24 +2411,25 @@ dict_index_add_to_cache_w_vcol( ut_d(mem_heap_validate(index->heap)); ut_a(!dict_index_is_clust(index) - || UT_LIST_GET_LEN(table->indexes) == 0); - ut_ad(dict_index_is_clust(index) || !table->no_rollback()); + || UT_LIST_GET_LEN(index->table->indexes) == 0); + ut_ad(dict_index_is_clust(index) || !index->table->no_rollback()); - if (!dict_index_find_cols(table, index, add_v)) { + if (!dict_index_find_cols(index, add_v)) { dict_mem_index_free(index); - return(DB_CORRUPTION); + if (err) *err = DB_CORRUPTION; + return NULL; } /* Build the cache internal representation of the index, containing also the added system fields */ if (dict_index_is_clust(index)) { - new_index = dict_index_build_internal_clust(table, index); + new_index = dict_index_build_internal_clust(index); } else { new_index = (index->type & DICT_FTS) - ? dict_index_build_internal_fts(table, index) - : dict_index_build_internal_non_clust(table, index); + ? dict_index_build_internal_fts(index) + : dict_index_build_internal_non_clust(index); new_index->n_core_null_bytes = UT_BITS_IN_BYTES( new_index->n_nullable); } @@ -2477,16 +2445,17 @@ dict_index_add_to_cache_w_vcol( new_index->disable_ahi = index->disable_ahi; #endif - if (dict_index_too_big_for_tree(table, new_index, strict)) { + if (dict_index_too_big_for_tree(index->table, new_index, strict)) { if (strict) { dict_mem_index_free(new_index); dict_mem_index_free(index); - return(DB_TOO_BIG_RECORD); + if (err) *err = DB_TOO_BIG_RECORD; + return NULL; } else if (current_thd != NULL) { /* Avoid the warning to be printed during recovery. */ - ib_warn_row_too_big((const dict_table_t*)table); + ib_warn_row_too_big(index->table); } } @@ -2548,9 +2517,7 @@ dict_index_add_to_cache_w_vcol( /* Add the new index as the last index for the table */ - UT_LIST_ADD_LAST(table->indexes, new_index); - new_index->table = table; - new_index->table_name = table->name.m_name; + UT_LIST_ADD_LAST(new_index->table->indexes, new_index); #ifdef BTR_CUR_ADAPT new_index->search_info = btr_search_info_create(new_index->heap); #endif /* BTR_CUR_ADAPT */ @@ -2562,8 +2529,8 @@ dict_index_add_to_cache_w_vcol( new_index->n_core_fields = new_index->n_fields; dict_mem_index_free(index); - - return(DB_SUCCESS); + if (err) *err = DB_SUCCESS; + return new_index; } /**********************************************************************//** @@ -2696,18 +2663,17 @@ index. @param[in] table table @param[in,out] index index @param[in] add_v new virtual columns added along with an add index call -@return TRUE if the column names were found */ +@return whether the column names were found */ static -ibool +bool dict_index_find_cols( - const dict_table_t* table, dict_index_t* index, const dict_add_v_col_t* add_v) { std::vector<ulint, ut_allocator<ulint> > col_added; std::vector<ulint, ut_allocator<ulint> > v_col_added; - ut_ad(table != NULL && index != NULL); + const dict_table_t* table = index->table; ut_ad(table->magic_n == DICT_TABLE_MAGIC_N); ut_ad(mutex_own(&dict_sys->mutex)); @@ -2864,8 +2830,7 @@ void dict_index_copy( /*============*/ dict_index_t* index1, /*!< in: index to copy to */ - dict_index_t* index2, /*!< in: index to copy from */ - const dict_table_t* table, /*!< in: table */ + const dict_index_t* index2, /*!< in: index to copy from */ ulint start, /*!< in: first position to copy */ ulint end) /*!< in: last position to copy */ { @@ -2878,7 +2843,7 @@ dict_index_copy( field = dict_index_get_nth_field(index2, i); - dict_index_add_col(index1, table, field->col, + dict_index_add_col(index1, index2->table, field->col, field->prefix_len); } } @@ -2999,25 +2964,23 @@ static dict_index_t* dict_index_build_internal_clust( /*============================*/ - const dict_table_t* table, /*!< in: table */ dict_index_t* index) /*!< in: user representation of a clustered index */ { + dict_table_t* table = index->table; dict_index_t* new_index; dict_field_t* field; ulint trx_id_pos; ulint i; ibool* indexed; - ut_ad(table && index); ut_ad(dict_index_is_clust(index)); ut_ad(!dict_index_is_ibuf(index)); ut_ad(mutex_own(&dict_sys->mutex)); - ut_ad(table->magic_n == DICT_TABLE_MAGIC_N); /* Create a new index object with certainly enough fields */ - new_index = dict_mem_index_create(table->name.m_name, index->name, + new_index = dict_mem_index_create(index->table, index->name, index->type, index->n_fields + table->n_cols); @@ -3029,7 +2992,7 @@ dict_index_build_internal_clust( new_index->id = index->id; /* Copy the fields of index */ - dict_index_copy(new_index, index, table, 0, index->n_fields); + dict_index_copy(new_index, index, 0, index->n_fields); if (dict_index_is_unique(index)) { /* Only the fields defined so far are needed to identify @@ -3159,13 +3122,13 @@ static dict_index_t* dict_index_build_internal_non_clust( /*================================*/ - const dict_table_t* table, /*!< in: table */ dict_index_t* index) /*!< in: user representation of a non-clustered index */ { dict_field_t* field; dict_index_t* new_index; dict_index_t* clust_index; + dict_table_t* table = index->table; ulint i; ibool* indexed; @@ -3173,7 +3136,6 @@ dict_index_build_internal_non_clust( ut_ad(!dict_index_is_clust(index)); ut_ad(!dict_index_is_ibuf(index)); ut_ad(mutex_own(&dict_sys->mutex)); - ut_ad(table->magic_n == DICT_TABLE_MAGIC_N); /* The clustered index should be the first in the list of indexes */ clust_index = UT_LIST_GET_FIRST(table->indexes); @@ -3184,7 +3146,7 @@ dict_index_build_internal_non_clust( /* Create a new index */ new_index = dict_mem_index_create( - table->name.m_name, index->name, index->type, + index->table, index->name, index->type, index->n_fields + 1 + clust_index->n_uniq); /* Copy other relevant data from the old index @@ -3195,7 +3157,7 @@ dict_index_build_internal_non_clust( new_index->id = index->id; /* Copy fields from index to new_index */ - dict_index_copy(new_index, index, table, 0, index->n_fields); + dict_index_copy(new_index, index, 0, index->n_fields); /* Remember the table columns already contained in new_index */ indexed = static_cast<ibool*>( @@ -3262,20 +3224,16 @@ static dict_index_t* dict_index_build_internal_fts( /*==========================*/ - dict_table_t* table, /*!< in: table */ dict_index_t* index) /*!< in: user representation of an FTS index */ { dict_index_t* new_index; - ut_ad(table && index); ut_ad(index->type == DICT_FTS); ut_ad(mutex_own(&dict_sys->mutex)); - ut_ad(table->magic_n == DICT_TABLE_MAGIC_N); /* Create a new index */ - new_index = dict_mem_index_create( - table->name.m_name, index->name, index->type, - index->n_fields); + new_index = dict_mem_index_create(index->table, index->name, + index->type, index->n_fields); /* Copy other relevant data from the old index struct to the new struct: it inherits the values */ @@ -3285,11 +3243,13 @@ dict_index_build_internal_fts( new_index->id = index->id; /* Copy fields from index to new_index */ - dict_index_copy(new_index, index, table, 0, index->n_fields); + dict_index_copy(new_index, index, 0, index->n_fields); new_index->n_uniq = 0; new_index->cached = TRUE; + dict_table_t* table = index->table; + if (table->fts->cache == NULL) { table->fts->cache = fts_cache_create(table); } @@ -6263,11 +6223,9 @@ dict_ind_init() dict_mem_table_add_col(table, NULL, NULL, DATA_CHAR, DATA_ENGLISH | DATA_NOT_NULL, 8); - dict_ind_redundant = dict_mem_index_create("SYS_DUMMY1", "SYS_DUMMY1", - 0, 1); + dict_ind_redundant = dict_mem_index_create(table, "SYS_DUMMY1", 0, 1); dict_index_add_col(dict_ind_redundant, table, dict_table_get_nth_col(table, 0), 0); - dict_ind_redundant->table = table; /* avoid ut_ad(index->cached) in dict_index_get_n_unique_in_tree */ dict_ind_redundant->cached = TRUE; } diff --git a/storage/innobase/dict/dict0load.cc b/storage/innobase/dict/dict0load.cc index 23e0cd6228c..465de71bf2e 100644 --- a/storage/innobase/dict/dict0load.cc +++ b/storage/innobase/dict/dict0load.cc @@ -113,7 +113,6 @@ dict_load_index_low( byte* table_id, /*!< in/out: table id (8 bytes), an "in" value if allocate=TRUE and "out" when allocate=FALSE */ - const char* table_name, /*!< in: table name */ mem_heap_t* heap, /*!< in/out: temporary memory heap */ const rec_t* rec, /*!< in: SYS_INDEXES record */ ibool allocate, /*!< in: TRUE=allocate *index, @@ -450,8 +449,7 @@ dict_process_sys_indexes_rec( buf = static_cast<byte*>(mem_heap_alloc(heap, 8)); /* Parse the record, and get "dict_index_t" struct filled */ - err_msg = dict_load_index_low(buf, NULL, - heap, rec, FALSE, &index); + err_msg = dict_load_index_low(buf, heap, rec, FALSE, &index); *table_id = mach_read_from_8(buf); @@ -2240,7 +2238,6 @@ dict_load_index_low( byte* table_id, /*!< in/out: table id (8 bytes), an "in" value if allocate=TRUE and "out" when allocate=FALSE */ - const char* table_name, /*!< in: table name */ mem_heap_t* heap, /*!< in/out: temporary memory heap */ const rec_t* rec, /*!< in: SYS_INDEXES record */ ibool allocate, /*!< in: TRUE=allocate *index, @@ -2359,12 +2356,11 @@ err_len: } if (allocate) { - *index = dict_mem_index_create(table_name, name_buf, - type, n_fields); + *index = dict_mem_index_create(NULL, name_buf, type, n_fields); } else { ut_a(*index); - dict_mem_fill_index_struct(*index, NULL, NULL, name_buf, + dict_mem_fill_index_struct(*index, NULL, name_buf, type, n_fields); } @@ -2471,8 +2467,7 @@ dict_load_indexes( } } - err_msg = dict_load_index_low( - buf, table->name.m_name, heap, rec, TRUE, &index); + err_msg = dict_load_index_low(buf, heap, rec, TRUE, &index); ut_ad((index == NULL && err_msg != NULL) || (index != NULL && err_msg == NULL)); @@ -2603,17 +2598,15 @@ corrupted: dict_mem_index_free(index); } else { dict_load_fields(index, heap); - - error = dict_index_add_to_cache( - table, index, index->page, FALSE); + index->table = table; /* The data dictionary tables should never contain invalid index definitions. If we ignored this error and simply did not load this index definition, the .frm file would disagree with the index definitions inside InnoDB. */ - if (UNIV_UNLIKELY(error != DB_SUCCESS)) { - + if (!dict_index_add_to_cache( + index, index->page, false, &error)) { goto func_exit; } } diff --git a/storage/innobase/dict/dict0mem.cc b/storage/innobase/dict/dict0mem.cc index bddfbf7c47c..8ed4089023c 100644 --- a/storage/innobase/dict/dict0mem.cc +++ b/storage/innobase/dict/dict0mem.cc @@ -721,7 +721,7 @@ Creates an index memory object. dict_index_t* dict_mem_index_create( /*==================*/ - const char* table_name, /*!< in: table name */ + dict_table_t* table, /*!< in: table */ const char* index_name, /*!< in: index name */ ulint type, /*!< in: DICT_UNIQUE, DICT_CLUSTERED, ... ORed */ @@ -730,15 +730,16 @@ dict_mem_index_create( dict_index_t* index; mem_heap_t* heap; - ut_ad(table_name && index_name); + ut_ad(!table || table->magic_n == DICT_TABLE_MAGIC_N); + ut_ad(index_name); heap = mem_heap_create(DICT_HEAP_SIZE); index = static_cast<dict_index_t*>( mem_heap_zalloc(heap, sizeof(*index))); + index->table = table; - dict_mem_fill_index_struct(index, heap, table_name, index_name, - type, n_fields); + dict_mem_fill_index_struct(index, heap, index_name, type, n_fields); dict_index_zip_pad_mutex_create_lazy(index); diff --git a/storage/innobase/dict/dict0stats.cc b/storage/innobase/dict/dict0stats.cc index c5ead3c1913..ddb77309535 100644 --- a/storage/innobase/dict/dict0stats.cc +++ b/storage/innobase/dict/dict0stats.cc @@ -451,8 +451,6 @@ dict_stats_table_clone_create( idx->name = mem_heap_strdup(heap, index->name); - idx->table_name = t->name.m_name; - idx->table = t; idx->type = index->type; diff --git a/storage/innobase/fts/fts0fts.cc b/storage/innobase/fts/fts0fts.cc index d2a475cdd46..50480313a1a 100644 --- a/storage/innobase/fts/fts0fts.cc +++ b/storage/innobase/fts/fts0fts.cc @@ -1819,7 +1819,7 @@ fts_create_one_common_table( if (error == DB_SUCCESS) { dict_index_t* index = dict_mem_index_create( - fts_table_name, "FTS_COMMON_TABLE_IND", + new_table, "FTS_COMMON_TABLE_IND", DICT_UNIQUE|DICT_CLUSTERED, 1); if (!is_config) { @@ -1863,16 +1863,14 @@ CREATE TABLE $FTS_PREFIX_BEING_DELETED_CACHE CREATE TABLE $FTS_PREFIX_CONFIG (key CHAR(50), value CHAR(200), UNIQUE CLUSTERED INDEX on key) @param[in,out] trx transaction -@param[in] table table with FTS index -@param[in] name table name normalized +@param[in,out] table table with FTS index @param[in] skip_doc_id_index Skip index on doc id @return DB_SUCCESS if succeed */ dberr_t fts_create_common_tables( - trx_t* trx, - const dict_table_t* table, - const char* name, - bool skip_doc_id_index) + trx_t* trx, + dict_table_t* table, + bool skip_doc_id_index) { dberr_t error; que_t* graph; @@ -1945,7 +1943,7 @@ fts_create_common_tables( goto func_exit; } - index = dict_mem_index_create(name, FTS_DOC_ID_INDEX_NAME, + index = dict_mem_index_create(table, FTS_DOC_ID_INDEX_NAME, DICT_UNIQUE, 1); dict_mem_index_add_field(index, FTS_DOC_ID_COL_NAME, 0); @@ -2037,7 +2035,7 @@ fts_create_one_index_table( if (error == DB_SUCCESS) { dict_index_t* index = dict_mem_index_create( - table_name, "FTS_INDEX_TABLE_IND", + new_table, "FTS_INDEX_TABLE_IND", DICT_UNIQUE|DICT_CLUSTERED, 2); dict_mem_index_add_field(index, "word", 0); dict_mem_index_add_field(index, "first_doc_id", 0); @@ -2060,18 +2058,24 @@ fts_create_one_index_table( return(new_table); } -/** Create auxiliary index tables for an FTS index. -@param[in,out] trx transaction -@param[in] index the index instance -@param[in] table_name table name -@param[in] table_id the table id +/** Creates the column specific ancillary tables needed for supporting an +FTS index on the given table. row_mysql_lock_data_dictionary must have +been called before this. + +All FTS AUX Index tables have the following schema. +CREAT TABLE $FTS_PREFIX_INDEX_[1-6]( + word VARCHAR(FTS_MAX_WORD_LEN), + first_doc_id INT NOT NULL, + last_doc_id UNSIGNED NOT NULL, + doc_count UNSIGNED INT NOT NULL, + ilist VARBINARY NOT NULL, + UNIQUE CLUSTERED INDEX ON (word, first_doc_id)) +@param[in,out] trx dictionary transaction +@param[in] index fulltext index +@param[in] id table id @return DB_SUCCESS or error code */ dberr_t -fts_create_index_tables_low( - trx_t* trx, - const dict_index_t* index, - const char* table_name, - table_id_t table_id) +fts_create_index_tables(trx_t* trx, const dict_index_t* index, table_id_t id) { ulint i; fts_table_t fts_table; @@ -2080,8 +2084,8 @@ fts_create_index_tables_low( fts_table.type = FTS_INDEX_TABLE; fts_table.index_id = index->id; - fts_table.table_id = table_id; - fts_table.parent = table_name; + fts_table.table_id = id; + fts_table.parent = index->table->name.m_name; fts_table.table = index->table; /* aux_idx_tables vector is used for dropping FTS AUX INDEX @@ -2134,41 +2138,6 @@ fts_create_index_tables_low( return(error); } -/** Creates the column specific ancillary tables needed for supporting an -FTS index on the given table. row_mysql_lock_data_dictionary must have -been called before this. - -All FTS AUX Index tables have the following schema. -CREAT TABLE $FTS_PREFIX_INDEX_[1-6]( - word VARCHAR(FTS_MAX_WORD_LEN), - first_doc_id INT NOT NULL, - last_doc_id UNSIGNED NOT NULL, - doc_count UNSIGNED INT NOT NULL, - ilist VARBINARY NOT NULL, - UNIQUE CLUSTERED INDEX ON (word, first_doc_id)) -@param[in,out] trx transaction -@param[in] index index instance -@return DB_SUCCESS or error code */ -dberr_t -fts_create_index_tables( - trx_t* trx, - const dict_index_t* index) -{ - dberr_t err; - dict_table_t* table; - - table = dict_table_get_low(index->table_name); - ut_a(table != NULL); - - err = fts_create_index_tables_low( - trx, index, table->name.m_name, table->id); - - if (err == DB_SUCCESS) { - trx_commit(trx); - } - - return(err); -} #if 0 /******************************************************************//** Return string representation of state. */ @@ -3836,7 +3805,7 @@ fts_doc_fetch_by_doc_id( pars_info_bind_function(info, "my_func", callback, arg); select_str = fts_get_select_columns_str(index, info, info->heap); - pars_info_bind_id(info, TRUE, "table_name", index->table_name); + pars_info_bind_id(info, TRUE, "table_name", index->table->name.m_name); if (!get_doc || !get_doc->get_document_graph) { if (option == FTS_FETCH_DOC_BY_ID_EQUAL) { diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index e9119bf0fca..83738630772 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -10979,9 +10979,7 @@ create_table_info_t::create_table_def() /* Raise error if the Doc ID column is of wrong type or name */ if (doc_id_col == ULINT_UNDEFINED) { - - err = DB_ERROR; - goto error_ret; + DBUG_RETURN(HA_ERR_GENERIC); } else { has_doc_id_col = TRUE; } @@ -11113,9 +11111,7 @@ err_col: dict_mem_table_free(table); mem_heap_free(heap); ut_ad(trx_state_eq(m_trx, TRX_STATE_NOT_STARTED)); - - err = DB_ERROR; - goto error_ret; + DBUG_RETURN(HA_ERR_GENERIC); } if (!is_virtual) { @@ -11225,7 +11221,18 @@ err_col: DBUG_EXECUTE_IF("ib_create_err_tablespace_exist", err = DB_TABLESPACE_EXISTS;); - if (err == DB_DUPLICATE_KEY || err == DB_TABLESPACE_EXISTS) { + switch (err) { + case DB_SUCCESS: + ut_ad(table); + m_table = table; + if (m_flags2 & DICT_TF2_FTS) { + fts_optimize_add_table(table); + } + DBUG_RETURN(0); + default: + break; + case DB_DUPLICATE_KEY: + case DB_TABLESPACE_EXISTS: char display_name[FN_REFLEN]; char* buf_end = innobase_convert_identifier( display_name, sizeof(display_name) - 1, @@ -11239,13 +11246,7 @@ err_col: : ER_TABLESPACE_EXISTS, MYF(0), display_name); } - if (err == DB_SUCCESS && (m_flags2 & DICT_TF2_FTS)) { - fts_optimize_add_table(table); - } - -error_ret: - DBUG_RETURN(convert_error_code_to_mysql(err, m_flags, m_thd)); -} + DBUG_RETURN(convert_error_code_to_mysql(err, m_flags, m_thd));} /*****************************************************************//** Creates an index in an InnoDB database. */ @@ -11256,8 +11257,7 @@ create_index( trx_t* trx, /*!< in: InnoDB transaction handle */ const TABLE* form, /*!< in: information on table columns and indexes */ - ulint flags, /*!< in: InnoDB table flags */ - const char* table_name, /*!< in: table name */ + dict_table_t* table, /*!< in,out: table */ uint key_num) /*!< in: index number */ { dict_index_t* index; @@ -11282,7 +11282,7 @@ create_index( if (ind_type != 0) { - index = dict_mem_index_create(table_name, key->name.str, + index = dict_mem_index_create(table, key->name.str, ind_type, key->user_defined_key_parts); @@ -11303,8 +11303,7 @@ create_index( DBUG_RETURN(convert_error_code_to_mysql( row_create_index_for_mysql( index, trx, NULL), - flags, NULL)); - + table->flags, NULL)); } ind_type = 0; @@ -11324,7 +11323,7 @@ create_index( /* We pass 0 as the space id, and determine at a lower level the space id where to store the table */ - index = dict_mem_index_create(table_name, key->name.str, + index = dict_mem_index_create(table, key->name.str, ind_type, key->user_defined_key_parts); for (ulint i = 0; i < key->user_defined_key_parts; i++) { @@ -11374,7 +11373,7 @@ create_index( " prefix index field, on an" " inappropriate data type. Table" " name %s, column name %s.", - table_name, + form->s->table_name.str, key_part->field->field_name.str); prefix_len = 0; @@ -11400,38 +11399,13 @@ create_index( error = convert_error_code_to_mysql( row_create_index_for_mysql(index, trx, field_lengths), - flags, NULL); + table->flags, NULL); my_free(field_lengths); DBUG_RETURN(error); } -/*****************************************************************//** -Creates an index to an InnoDB table when the user has defined no -primary index. */ -inline -int -create_clustered_index_when_no_primary( -/*===================================*/ - trx_t* trx, /*!< in: InnoDB transaction handle */ - ulint flags, /*!< in: InnoDB table flags */ - const char* table_name) /*!< in: table name */ -{ - dict_index_t* index; - dberr_t error; - - /* We pass 0 as the space id, and determine at a lower level the space - id where to store the table */ - index = dict_mem_index_create(table_name, - innobase_index_reserve_name, - DICT_CLUSTERED, 0); - - error = row_create_index_for_mysql(index, trx, NULL); - - return(convert_error_code_to_mysql(error, flags, NULL)); -} - /** Return a display name for the row format @param[in] row_format Row Format @return row format name */ @@ -12450,7 +12424,6 @@ create_table_info_t::create_table() int error; int primary_key_no; uint i; - dict_table_t* innobase_table = NULL; const char* stmt; size_t stmt_len; @@ -12476,9 +12449,12 @@ create_table_info_t::create_table() /* Create an index which is used as the clustered index; order the rows by their row id which is internally generated by InnoDB */ - - error = create_clustered_index_when_no_primary( - m_trx, m_flags, m_table_name); + dict_index_t* index = dict_mem_index_create( + m_table, innobase_index_reserve_name, + DICT_CLUSTERED, 0); + error = convert_error_code_to_mysql( + row_create_index_for_mysql(index, m_trx, NULL), + m_table->flags, m_thd); if (error) { DBUG_RETURN(error); } @@ -12487,7 +12463,7 @@ create_table_info_t::create_table() if (primary_key_no != -1) { /* In InnoDB the clustered index must always be created first */ - if ((error = create_index(m_trx, m_form, m_flags, m_table_name, + if ((error = create_index(m_trx, m_form, m_table, (uint) primary_key_no))) { DBUG_RETURN(error); } @@ -12498,11 +12474,6 @@ create_table_info_t::create_table() if (m_flags2 & DICT_TF2_FTS) { fts_doc_id_index_enum ret; - innobase_table = dict_table_open_on_name( - m_table_name, TRUE, FALSE, DICT_ERR_IGNORE_NONE); - - ut_a(innobase_table); - /* Check whether there already exists FTS_DOC_ID_INDEX */ ret = innobase_fts_check_doc_id_index_in_def( m_form->s->keys, m_form->key_info); @@ -12521,13 +12492,12 @@ create_table_info_t::create_table() " make sure it is of correct" " type\n", FTS_DOC_ID_INDEX_NAME, - innobase_table->name.m_name); + m_table->name.m_name); - if (innobase_table->fts) { - fts_free(innobase_table); + if (m_table->fts) { + fts_free(m_table); } - dict_table_close(innobase_table, TRUE, FALSE); my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), FTS_DOC_ID_INDEX_NAME); error = -1; @@ -12538,13 +12508,11 @@ create_table_info_t::create_table() } dberr_t err = fts_create_common_tables( - m_trx, innobase_table, m_table_name, + m_trx, m_table, (ret == FTS_EXIST_DOC_ID_INDEX)); error = convert_error_code_to_mysql(err, 0, NULL); - dict_table_close(innobase_table, TRUE, FALSE); - if (error) { trx_rollback_to_savepoint(m_trx, NULL); m_trx->error_state = DB_SUCCESS; @@ -12557,24 +12525,20 @@ create_table_info_t::create_table() } for (i = 0; i < m_form->s->keys; i++) { - - if (i != static_cast<uint>(primary_key_no)) { - - if ((error = create_index(m_trx, m_form, m_flags, - m_table_name, i))) { - DBUG_RETURN(error); - } + if (i != uint(primary_key_no) + && (error = create_index(m_trx, m_form, m_table, i))) { + DBUG_RETURN(error); } } /* Cache all the FTS indexes on this table in the FTS specific structure. They are used for FTS indexed column update handling. */ if (m_flags2 & DICT_TF2_FTS) { - fts_t* fts = innobase_table->fts; + fts_t* fts = m_table->fts; ut_a(fts != NULL); - dict_table_get_all_fts_indexes(innobase_table, fts->indexes); + dict_table_get_all_fts_indexes(m_table, fts->indexes); } stmt = innobase_get_stmt_unsafe(m_thd, &stmt_len); @@ -12625,13 +12589,6 @@ create_table_info_t::create_table() } } - innobase_table = dict_table_open_on_name( - m_table_name, TRUE, FALSE, DICT_ERR_IGNORE_NONE); - - if (innobase_table != NULL) { - dict_table_close(innobase_table, TRUE, FALSE); - } - DBUG_RETURN(0); } diff --git a/storage/innobase/handler/ha_innodb.h b/storage/innobase/handler/ha_innodb.h index 34c01929a56..ae4da973b4f 100644 --- a/storage/innobase/handler/ha_innodb.h +++ b/storage/innobase/handler/ha_innodb.h @@ -688,7 +688,7 @@ public: :m_thd(thd), m_form(form), m_create_info(create_info), - m_table_name(table_name), + m_table_name(table_name), m_table(NULL), m_remote_path(remote_path), m_innodb_file_per_table(srv_file_per_table) {} @@ -798,6 +798,8 @@ private: /** Table name */ char* m_table_name; + /** Table */ + dict_table_t* m_table; /** Remote path (DATA DIRECTORY) or zero length-string */ char* m_remote_path; diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc index 4c27234da6e..66198afb1f7 100644 --- a/storage/innobase/handler/handler0alter.cc +++ b/storage/innobase/handler/handler0alter.cc @@ -4682,10 +4682,10 @@ innodb_v_adjust_idx_col( @param[in,out] trx dictionary transaction @param[in,out] index index being created @param[in] add_v virtual columns that are being added, or NULL -@return DB_SUCCESS or error code */ +@return the created index */ MY_ATTRIBUTE((nonnull(1,2), warn_unused_result)) static -dberr_t +dict_index_t* create_index_dict( trx_t* trx, dict_index_t* index, @@ -4694,7 +4694,8 @@ create_index_dict( DBUG_ENTER("create_index_dict"); mem_heap_t* heap = mem_heap_create(512); - ind_node_t* node = ind_create_graph_create(index, heap, add_v); + ind_node_t* node = ind_create_graph_create( + index, index->table->name.m_name, heap, add_v); que_thr_t* thr = pars_complete_graph_for_exec(node, trx, heap, NULL); que_fork_start_command( @@ -4702,9 +4703,11 @@ create_index_dict( que_run_threads(thr); + index = node->index; + que_graph_free((que_t*) que_node_get_parent(thr)); - DBUG_RETURN(trx->error_state); + DBUG_RETURN(trx->error_state == DB_SUCCESS ? index : NULL); } /** Update internal structures with concurrent writes blocked, @@ -5198,9 +5201,10 @@ new_clustered_failed: DBUG_ASSERT(ctx->new_table->n_cols > ctx->old_table->n_cols); for (uint a = 0; a < ctx->num_to_add_index; a++) { - error = dict_index_add_to_cache_w_vcol( - ctx->new_table, ctx->add_index[a], add_v, - FIL_NULL, false); + ctx->add_index[a]->table = ctx->new_table; + ctx->add_index[a] = dict_index_add_to_cache( + ctx->add_index[a], FIL_NULL, false, + &error, add_v); ut_a(error == DB_SUCCESS); } DBUG_ASSERT(ha_alter_info->key_count @@ -5423,18 +5427,16 @@ new_table_failed: for (ulint a = 0; a < ctx->num_to_add_index; a++) { dict_index_t*& index = ctx->add_index[a]; const bool has_new_v_col = index->has_new_v_col; - error = create_index_dict(ctx->trx, index, add_v); - if (error != DB_SUCCESS) { + index = create_index_dict(ctx->trx, index, add_v); + if (!index) { + error = ctx->trx->error_state; + ut_ad(error != DB_SUCCESS); while (++a < ctx->num_to_add_index) { dict_mem_index_free(ctx->add_index[a]); } goto error_handling; } - index = dict_table_get_index_on_name( - ctx->new_table, index_defs[a].name, true); - ut_a(index); - index->parser = index_defs[a].parser; index->has_new_v_col = has_new_v_col; /* Note the id of the transaction that created this @@ -5505,8 +5507,10 @@ new_table_failed: for (ulint a = 0; a < ctx->num_to_add_index; a++) { dict_index_t*& index = ctx->add_index[a]; const bool has_new_v_col = index->has_new_v_col; - error = create_index_dict(ctx->trx, index, add_v); - if (error != DB_SUCCESS) { + index = create_index_dict(ctx->trx, index, add_v); + if (!index) { + error = ctx->trx->error_state; + ut_ad(error != DB_SUCCESS); error_handling_drop_uncached: while (++a < ctx->num_to_add_index) { dict_mem_index_free(ctx->add_index[a]); @@ -5514,10 +5518,6 @@ error_handling_drop_uncached: goto error_handling; } - index = dict_table_get_index_on_name( - ctx->new_table, index_defs[a].name, false); - ut_a(index); - index->parser = index_defs[a].parser; index->has_new_v_col = has_new_v_col; /* Note the id of the transaction that created this @@ -5597,10 +5597,8 @@ op_ok: DBUG_ASSERT(ctx->new_table->fts_doc_id_index != NULL); } - /* This function will commit the transaction and reset - the trx_t::dict_operation flag on success. */ - - error = fts_create_index_tables(ctx->trx, fts_index); + error = fts_create_index_tables(ctx->trx, fts_index, + ctx->new_table->id); DBUG_EXECUTE_IF("innodb_test_fail_after_fts_index_table", error = DB_LOCK_WAIT_TIMEOUT; @@ -5610,13 +5608,13 @@ op_ok: goto error_handling; } + trx_commit(ctx->trx); trx_start_for_ddl(ctx->trx, op); if (!ctx->new_table->fts || ib_vector_size(ctx->new_table->fts->indexes) == 0) { error = fts_create_common_tables( - ctx->trx, ctx->new_table, - user_table->name.m_name, TRUE); + ctx->trx, ctx->new_table, true); DBUG_EXECUTE_IF( "innodb_test_fail_after_fts_common_table", diff --git a/storage/innobase/handler/i_s.cc b/storage/innobase/handler/i_s.cc index 51c36dbbbfe..f51565a4660 100644 --- a/storage/innobase/handler/i_s.cc +++ b/storage/innobase/handler/i_s.cc @@ -1723,7 +1723,7 @@ i_s_cmp_per_index_fill_low( char db_utf8[MAX_DB_UTF8_LEN]; char table_utf8[MAX_TABLE_UTF8_LEN]; - dict_fs2utf8(index->table_name, + dict_fs2utf8(index->table->name.m_name, db_utf8, sizeof(db_utf8), table_utf8, sizeof(table_utf8)); @@ -4922,8 +4922,8 @@ i_s_innodb_buffer_page_fill( page_info->index_id)) { table_name_end = innobase_convert_name( table_name, sizeof(table_name), - index->table_name, - strlen(index->table_name), + index->table->name.m_name, + strlen(index->table->name.m_name), thd); ret = fields[IDX_BUFFER_PAGE_TABLE_NAME] @@ -5641,8 +5641,8 @@ i_s_innodb_buf_page_lru_fill( page_info->index_id)) { table_name_end = innobase_convert_name( table_name, sizeof(table_name), - index->table_name, - strlen(index->table_name), + index->table->name.m_name, + strlen(index->table->name.m_name), thd); ret = fields[IDX_BUF_LRU_PAGE_TABLE_NAME] diff --git a/storage/innobase/ibuf/ibuf0ibuf.cc b/storage/innobase/ibuf/ibuf0ibuf.cc index a337be68ff9..07c4f0de4bc 100644 --- a/storage/innobase/ibuf/ibuf0ibuf.cc +++ b/storage/innobase/ibuf/ibuf0ibuf.cc @@ -560,11 +560,11 @@ ibuf_init_at_db_start(void) mtr.commit(); ibuf->index = dict_mem_index_create( - "innodb_change_buffer", "CLUST_IND", + dict_mem_table_create("innodb_change_buffer", + IBUF_SPACE_ID, 1, 0, 0, 0), + "CLUST_IND", DICT_CLUSTERED | DICT_IBUF, 1); ibuf->index->id = DICT_IBUF_ID_MIN + IBUF_SPACE_ID; - ibuf->index->table = dict_mem_table_create( - "innodb_change_buffer", IBUF_SPACE_ID, 1, 0, 0, 0); ibuf->index->n_uniq = REC_MAX_N_FIELDS; rw_lock_create(index_tree_rw_lock_key, &ibuf->index->lock, SYNC_IBUF_INDEX_TREE); @@ -1498,9 +1498,7 @@ ibuf_dummy_index_create( DICT_HDR_SPACE, n, 0, comp ? DICT_TF_COMPACT : 0, 0); - index = dict_mem_index_create("IBUF_DUMMY", "IBUF_DUMMY", 0, n); - - index->table = table; + index = dict_mem_index_create(table, "IBUF_DUMMY", 0, n); /* avoid ut_ad(index->cached) in dict_index_get_n_unique_in_tree */ index->cached = TRUE; diff --git a/storage/innobase/include/dict0crea.h b/storage/innobase/include/dict0crea.h index 5d149f24921..64bab80b6e0 100644 --- a/storage/innobase/include/dict0crea.h +++ b/storage/innobase/include/dict0crea.h @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2017, MariaDB Corporation. +Copyright (c) 2017, 2018, 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 @@ -50,6 +50,7 @@ tab_create_graph_create( /** Creates an index create graph. @param[in] index index to create, built as a memory data structure +@param[in] table table name @param[in,out] heap heap where created @param[in] add_v new virtual columns added in the same clause with add index @@ -57,8 +58,9 @@ tab_create_graph_create( ind_node_t* ind_create_graph_create( dict_index_t* index, + const char* table, mem_heap_t* heap, - const dict_add_v_col_t* add_v); + const dict_add_v_col_t* add_v = NULL); /***********************************************************//** Creates a table. This is a high-level function used in SQL execution graphs. @@ -316,6 +318,7 @@ struct ind_node_t{ dict_index_t* index; /*!< index to create, built as a memory data structure with dict_mem_... functions */ + const char* table_name; /*!< table name */ ins_node_t* ind_def; /*!< child node which does the insert of the index definition; the row to be inserted is built by the parent node */ diff --git a/storage/innobase/include/dict0dict.h b/storage/innobase/include/dict0dict.h index 480be4fdef4..c503a3f0bce 100644 --- a/storage/innobase/include/dict0dict.h +++ b/storage/innobase/include/dict0dict.h @@ -1087,43 +1087,28 @@ dict_make_room_in_cache( #define BIG_ROW_SIZE 1024 -/** Adds an index to the dictionary cache. -@param[in] table table on which the index is -@param[in] index index; NOTE! The index memory - object is freed in this function! -@param[in] page_no root page number of the index -@param[in] strict TRUE=refuse to create the index - if records could be too big to fit in - an B-tree page -@return DB_SUCCESS, DB_TOO_BIG_RECORD, or DB_CORRUPTION */ -dberr_t -dict_index_add_to_cache( - dict_table_t* table, - dict_index_t* index, - ulint page_no, - ibool strict) - MY_ATTRIBUTE((warn_unused_result)); - /** Adds an index to the dictionary cache, with possible indexing newly added column. -@param[in] table table on which the index is @param[in] index index; NOTE! The index memory object is freed in this function! -@param[in] add_v new virtual column that being added along with - an add index call @param[in] page_no root page number of the index -@param[in] strict TRUE=refuse to create the index +@param[in] strict true=refuse to create the index if records could be too big to fit in an B-tree page -@return DB_SUCCESS, DB_TOO_BIG_RECORD, or DB_CORRUPTION */ -dberr_t -dict_index_add_to_cache_w_vcol( - dict_table_t* table, +@param[out] err DB_SUCCESS, DB_TOO_BIG_RECORD, or DB_CORRUPTION +@param[in] add_v new virtual column that being added along with + an add index call +@return the added index +@retval NULL on error */ +dict_index_t* +dict_index_add_to_cache( dict_index_t* index, - const dict_add_v_col_t* add_v, ulint page_no, - ibool strict) - MY_ATTRIBUTE((warn_unused_result)); + bool strict = false, + dberr_t* err = NULL, + const dict_add_v_col_t* add_v = NULL) + MY_ATTRIBUTE((nonnull(1))); + /********************************************************************//** Gets the number of fields in the internal representation of an index, including fields added by the dictionary system. diff --git a/storage/innobase/include/dict0mem.h b/storage/innobase/include/dict0mem.h index 6e116b2d78c..01755787bb7 100644 --- a/storage/innobase/include/dict0mem.h +++ b/storage/innobase/include/dict0mem.h @@ -397,7 +397,6 @@ dict_mem_fill_index_struct( /*=======================*/ dict_index_t* index, /*!< out: index to be filled */ mem_heap_t* heap, /*!< in: memory heap */ - const char* table_name, /*!< in: table name */ const char* index_name, /*!< in: index name */ ulint type, /*!< in: DICT_UNIQUE, DICT_CLUSTERED, ... ORed */ @@ -408,7 +407,7 @@ Creates an index memory object. dict_index_t* dict_mem_index_create( /*==================*/ - const char* table_name, /*!< in: table name */ + dict_table_t* table, /*!< in: table */ const char* index_name, /*!< in: index name */ ulint type, /*!< in: DICT_UNIQUE, DICT_CLUSTERED, ... ORed */ @@ -877,7 +876,6 @@ struct dict_index_t{ index_id_t id; /*!< id of the index */ mem_heap_t* heap; /*!< memory heap */ id_name_t name; /*!< index name */ - const char* table_name;/*!< table name */ dict_table_t* table; /*!< back pointer to table */ unsigned page:32;/*!< index tree root page number */ unsigned merge_threshold:6; diff --git a/storage/innobase/include/dict0mem.ic b/storage/innobase/include/dict0mem.ic index 1fcd6346a96..70424af7347 100644 --- a/storage/innobase/include/dict0mem.ic +++ b/storage/innobase/include/dict0mem.ic @@ -37,7 +37,6 @@ dict_mem_fill_index_struct( /*=======================*/ dict_index_t* index, /*!< out: index to be filled */ mem_heap_t* heap, /*!< in: memory heap */ - const char* table_name, /*!< in: table name */ const char* index_name, /*!< in: index name */ ulint type, /*!< in: DICT_UNIQUE, DICT_CLUSTERED, ... ORed */ @@ -60,7 +59,6 @@ dict_mem_fill_index_struct( index->type = unsigned(type); index->page = FIL_NULL; index->merge_threshold = DICT_INDEX_MERGE_THRESHOLD_DEFAULT; - index->table_name = table_name; index->n_fields = (unsigned int) n_fields; index->n_core_fields = (unsigned int) n_fields; /* The '1 +' above prevents allocation diff --git a/storage/innobase/include/fts0fts.h b/storage/innobase/include/fts0fts.h index 362bdcb7fe6..04bb26da7da 100644 --- a/storage/innobase/include/fts0fts.h +++ b/storage/innobase/include/fts0fts.h @@ -488,47 +488,49 @@ fts_trx_free( /*=========*/ fts_trx_t* fts_trx); /*!< in, own: FTS trx */ -/******************************************************************//** -Creates the common ancillary tables needed for supporting an FTS index -on the given table. row_mysql_lock_data_dictionary must have been -called before this. -@return DB_SUCCESS or error code */ +/** Creates the common auxiliary tables needed for supporting an FTS index +on the given table. row_mysql_lock_data_dictionary must have been called +before this. +The following tables are created. +CREATE TABLE $FTS_PREFIX_DELETED + (doc_id BIGINT UNSIGNED, UNIQUE CLUSTERED INDEX on doc_id) +CREATE TABLE $FTS_PREFIX_DELETED_CACHE + (doc_id BIGINT UNSIGNED, UNIQUE CLUSTERED INDEX on doc_id) +CREATE TABLE $FTS_PREFIX_BEING_DELETED + (doc_id BIGINT UNSIGNED, UNIQUE CLUSTERED INDEX on doc_id) +CREATE TABLE $FTS_PREFIX_BEING_DELETED_CACHE + (doc_id BIGINT UNSIGNED, UNIQUE CLUSTERED INDEX on doc_id) +CREATE TABLE $FTS_PREFIX_CONFIG + (key CHAR(50), value CHAR(200), UNIQUE CLUSTERED INDEX on key) +@param[in,out] trx transaction +@param[in] table table with FTS index +@param[in] skip_doc_id_index Skip index on doc id +@return DB_SUCCESS if succeed */ dberr_t fts_create_common_tables( -/*=====================*/ - trx_t* trx, /*!< in: transaction handle */ - const dict_table_t* - table, /*!< in: table with one FTS - index */ - const char* name, /*!< in: table name */ - bool skip_doc_id_index) /*!< in: Skip index on doc id */ - MY_ATTRIBUTE((warn_unused_result)); -/******************************************************************//** -Wrapper function of fts_create_index_tables_low(), create auxiliary -tables for an FTS index -@return DB_SUCCESS or error code */ -dberr_t -fts_create_index_tables( -/*====================*/ - trx_t* trx, /*!< in: transaction handle */ - const dict_index_t* index) /*!< in: the FTS index - instance */ - MY_ATTRIBUTE((warn_unused_result)); -/******************************************************************//** -Creates the column specific ancillary tables needed for supporting an + trx_t* trx, + dict_table_t* table, + bool skip_doc_id_index) + MY_ATTRIBUTE((nonnull, warn_unused_result)); +/** Creates the column specific ancillary tables needed for supporting an FTS index on the given table. row_mysql_lock_data_dictionary must have been called before this. + +All FTS AUX Index tables have the following schema. +CREAT TABLE $FTS_PREFIX_INDEX_[1-6]( + word VARCHAR(FTS_MAX_WORD_LEN), + first_doc_id INT NOT NULL, + last_doc_id UNSIGNED NOT NULL, + doc_count UNSIGNED INT NOT NULL, + ilist VARBINARY NOT NULL, + UNIQUE CLUSTERED INDEX ON (word, first_doc_id)) +@param[in,out] trx dictionary transaction +@param[in] index fulltext index +@param[in] id table id @return DB_SUCCESS or error code */ dberr_t -fts_create_index_tables_low( -/*========================*/ - trx_t* trx, /*!< in: transaction handle */ - const dict_index_t* - index, /*!< in: the FTS index - instance */ - const char* table_name, /*!< in: the table name */ - table_id_t table_id) /*!< in: the table id */ - MY_ATTRIBUTE((warn_unused_result)); +fts_create_index_tables(trx_t* trx, const dict_index_t* index, table_id_t id) + MY_ATTRIBUTE((nonnull, warn_unused_result)); /******************************************************************//** Add the FTS document id hidden column. */ void diff --git a/storage/innobase/include/row0ftsort.h b/storage/innobase/include/row0ftsort.h index c8556cc4ca4..25204895f1a 100644 --- a/storage/innobase/include/row0ftsort.h +++ b/storage/innobase/include/row0ftsort.h @@ -1,7 +1,7 @@ /***************************************************************************** Copyright (c) 2010, 2016, Oracle and/or its affiliates. All Rights Reserved. -Copyright (c) 2015, 2017, MariaDB Corporation. +Copyright (c) 2015, 2018, 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 @@ -175,15 +175,15 @@ tokenized doc string. The index has three "fields": dict_index_t* row_merge_create_fts_sort_index( /*============================*/ - dict_index_t* index, /*!< in: Original FTS index - based on which this sort index - is created */ - const dict_table_t* table, /*!< in: table that FTS index - is being created on */ - ibool* opt_doc_id_size); - /*!< out: whether to use 4 bytes - instead of 8 bytes integer to - store Doc ID during sort */ + dict_index_t* index, /*!< in: Original FTS index + based on which this sort index + is created */ + dict_table_t* table, /*!< in,out: table that FTS index + is being created on */ + ibool* opt_doc_id_size); + /*!< out: whether to use 4 bytes + instead of 8 bytes integer to + store Doc ID during sort */ /********************************************************************//** Initialize FTS parallel sort structures. diff --git a/storage/innobase/lock/lock0lock.cc b/storage/innobase/lock/lock0lock.cc index 0644480a16d..b44a38947a2 100644 --- a/storage/innobase/lock/lock0lock.cc +++ b/storage/innobase/lock/lock0lock.cc @@ -4469,7 +4469,7 @@ lock_rec_print(FILE* file, const lock_t* lock) (ulong) space, (ulong) page_no, (ulong) lock_rec_get_n_bits(lock), lock->index->name()); - ut_print_name(file, lock->trx, lock->index->table_name); + ut_print_name(file, lock->trx, lock->index->table->name.m_name); fprintf(file, " trx id " TRX_ID_FMT, trx_get_id_for_print(lock->trx)); if (lock_get_mode(lock) == LOCK_S) { diff --git a/storage/innobase/mtr/mtr0log.cc b/storage/innobase/mtr/mtr0log.cc index 5637959d334..2eb3244e7ab 100644 --- a/storage/innobase/mtr/mtr0log.cc +++ b/storage/innobase/mtr/mtr0log.cc @@ -590,8 +590,7 @@ mlog_parse_index( } table = dict_mem_table_create("LOG_DUMMY", DICT_HDR_SPACE, n, 0, comp ? DICT_TF_COMPACT : 0, 0); - ind = dict_mem_index_create("LOG_DUMMY", "LOG_DUMMY", 0, n); - ind->table = table; + ind = dict_mem_index_create(table, "LOG_DUMMY", 0, n); ind->n_uniq = (unsigned int) n_uniq; if (n_uniq != n) { ut_a(n_uniq + DATA_ROLL_PTR <= n); diff --git a/storage/innobase/page/page0zip.cc b/storage/innobase/page/page0zip.cc index a2c826d0ebf..1db1771dfa8 100644 --- a/storage/innobase/page/page0zip.cc +++ b/storage/innobase/page/page0zip.cc @@ -1382,7 +1382,7 @@ page_zip_compress( && !dict_index_is_ibuf(index) && page_get_n_recs(page) >= 2 && ((ulint)(rand() % 100) < srv_simulate_comp_failures) - && strcasecmp(index->table_name, "IBUF_DUMMY") != 0) { + && strcmp(index->table->name.m_name, "IBUF_DUMMY")) { #ifdef UNIV_DEBUG ib::error() @@ -1709,8 +1709,7 @@ page_zip_fields_decode( table = dict_mem_table_create("ZIP_DUMMY", DICT_HDR_SPACE, n, 0, DICT_TF_COMPACT, 0); - index = dict_mem_index_create("ZIP_DUMMY", "ZIP_DUMMY", 0, n); - index->table = table; + index = dict_mem_index_create(table, "ZIP_DUMMY", 0, n); index->n_uniq = unsigned(n); /* avoid ut_ad(index->cached) in dict_index_get_n_unique_in_tree */ index->cached = TRUE; diff --git a/storage/innobase/pars/pars0opt.cc b/storage/innobase/pars/pars0opt.cc index f08037d15aa..bbc8eec0774 100644 --- a/storage/innobase/pars/pars0opt.cc +++ b/storage/innobase/pars/pars0opt.cc @@ -1257,7 +1257,7 @@ opt_print_query_plan( fprintf(stderr, "Index %s of table %s" "; exact m. %lu, match %lu, end conds %lu\n", - plan->index->name(), plan->index->table_name, + plan->index->name(), plan->index->table->name.m_name, (unsigned long) plan->n_exact_match, (unsigned long) n_fields, (unsigned long) UT_LIST_GET_LEN(plan->end_conds)); diff --git a/storage/innobase/pars/pars0pars.cc b/storage/innobase/pars/pars0pars.cc index b50d6233d43..8595f341d26 100644 --- a/storage/innobase/pars/pars0pars.cc +++ b/storage/innobase/pars/pars0pars.cc @@ -1,6 +1,7 @@ /***************************************************************************** Copyright (c) 1996, 2016, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 2018, 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 @@ -1974,7 +1975,7 @@ pars_create_index( ind_type = ind_type | DICT_CLUSTERED; } - index = dict_mem_index_create(table_sym->name, index_sym->name, + index = dict_mem_index_create(NULL, index_sym->name, ind_type, n_fields); column = column_list; @@ -1987,7 +1988,8 @@ pars_create_index( column = static_cast<sym_node_t*>(que_node_get_next(column)); } - node = ind_create_graph_create(index, pars_sym_tab_global->heap, NULL); + node = ind_create_graph_create(index, table_sym->name, + pars_sym_tab_global->heap); table_sym->resolved = TRUE; table_sym->token_type = SYM_TABLE; diff --git a/storage/innobase/row/row0ftsort.cc b/storage/innobase/row/row0ftsort.cc index f9ce5eb3a10..49462e8c22c 100644 --- a/storage/innobase/row/row0ftsort.cc +++ b/storage/innobase/row/row0ftsort.cc @@ -70,15 +70,15 @@ integer value) dict_index_t* row_merge_create_fts_sort_index( /*============================*/ - dict_index_t* index, /*!< in: Original FTS index - based on which this sort index - is created */ - const dict_table_t* table, /*!< in: table that FTS index - is being created on */ - ibool* opt_doc_id_size) - /*!< out: whether to use 4 bytes - instead of 8 bytes integer to - store Doc ID during sort */ + dict_index_t* index, /*!< in: Original FTS index + based on which this sort index + is created */ + dict_table_t* table, /*!< in,out: table that FTS index + is being created on */ + ibool* opt_doc_id_size) + /*!< out: whether to use 4 bytes + instead of 8 bytes integer to + store Doc ID during sort */ { dict_index_t* new_index; dict_field_t* field; @@ -86,11 +86,9 @@ row_merge_create_fts_sort_index( CHARSET_INFO* charset; // FIXME: This name shouldn't be hard coded here. - new_index = dict_mem_index_create( - index->table->name.m_name, "tmp_fts_idx", DICT_FTS, 3); + new_index = dict_mem_index_create(table, "tmp_fts_idx", DICT_FTS, 3); new_index->id = index->id; - new_index->table = (dict_table_t*) table; new_index->n_uniq = FTS_NUM_FIELDS_SORT; new_index->n_def = FTS_NUM_FIELDS_SORT; new_index->cached = TRUE; diff --git a/storage/innobase/row/row0log.cc b/storage/innobase/row/row0log.cc index 72bb897e469..cad36e31f28 100644 --- a/storage/innobase/row/row0log.cc +++ b/storage/innobase/row/row0log.cc @@ -2870,7 +2870,7 @@ all_done: buf, ofs, srv_sort_buf_size)) { ib::error() << "Unable to read temporary file" - " for table " << index->table_name; + " for table " << index->table->name; goto corruption; } diff --git a/storage/innobase/row/row0merge.cc b/storage/innobase/row/row0merge.cc index f1074cdb766..681e57eeb4f 100644 --- a/storage/innobase/row/row0merge.cc +++ b/storage/innobase/row/row0merge.cc @@ -4468,10 +4468,8 @@ row_merge_create_index( a persistent operation. We pass 0 as the space id, and determine at a lower level the space id where to store the table. */ - index = dict_mem_index_create(table->name.m_name, index_def->name, + index = dict_mem_index_create(table, index_def->name, index_def->ind_type, n_fields); - - index->table = table; index->set_committed(index_def->rebuild); for (i = 0; i < n_fields; i++) { diff --git a/storage/innobase/row/row0mysql.cc b/storage/innobase/row/row0mysql.cc index 404f58f3b7f..fdd70553b26 100644 --- a/storage/innobase/row/row0mysql.cc +++ b/storage/innobase/row/row0mysql.cc @@ -2509,28 +2509,15 @@ row_create_index_for_mysql( dberr_t err; ulint i; ulint len; - char* table_name; - char* index_name; - dict_table_t* table = NULL; - ibool is_fts; + dict_table_t* table = index->table; trx->op_info = "creating index"; - /* Copy the table name because we may want to drop the - table later, after the index object is freed (inside - que_run_threads()) and thus index->table_name is not available. */ - table_name = mem_strdup(index->table_name); - index_name = mem_strdup(index->name); - - is_fts = (index->type == DICT_FTS); - ut_ad(rw_lock_own(dict_operation_lock, RW_LOCK_X)); ut_ad(mutex_own(&dict_sys->mutex)); - table = dict_table_open_on_name(table_name, TRUE, TRUE, - DICT_ERR_IGNORE_NONE); - if (!dict_table_is_temporary(table)) { + if (!table->is_temporary()) { trx_start_if_not_started_xa(trx, true); } @@ -2563,13 +2550,14 @@ row_create_index_for_mysql( /* For temp-table we avoid insertion into SYSTEM TABLES to maintain performance and so we have separate path that directly just updates dictonary cache. */ - if (!dict_table_is_temporary(table)) { + if (!table->is_temporary()) { /* Note that the space id where we store the index is inherited from the table in dict_build_index_def_step() in dict0crea.cc. */ heap = mem_heap_create(512); - node = ind_create_graph_create(index, heap, NULL); + node = ind_create_graph_create(index, table->name.m_name, + heap); thr = pars_complete_graph_for_exec(node, trx, heap, NULL); @@ -2581,50 +2569,36 @@ row_create_index_for_mysql( err = trx->error_state; - que_graph_free((que_t*) que_node_get_parent(thr)); - } else { - dict_build_index_def(table, index, trx); + index = node->index; - index_id_t index_id = index->id; + ut_ad(!index == (err != DB_SUCCESS)); - /* add index to dictionary cache and also free index object. */ - err = dict_index_add_to_cache( - table, index, FIL_NULL, trx_is_strict(trx)); + que_graph_free((que_t*) que_node_get_parent(thr)); - if (err != DB_SUCCESS) { - goto error_handling; + if (index && (index->type & DICT_FTS)) { + err = fts_create_index_tables(trx, index, table->id); } + } else { + dict_build_index_def(table, index, trx); - /* as above function has freed index object re-load it - now from dictionary cache using index_id */ - index = dict_index_get_if_in_cache_low(index_id); - ut_a(index != NULL); - index->table = table; - ut_ad(!index->is_instant()); - index->n_core_null_bytes = UT_BITS_IN_BYTES(index->n_nullable); + /* add index to dictionary cache and also free index object. */ + index = dict_index_add_to_cache( + index, FIL_NULL, trx_is_strict(trx), &err); + if (index) { + ut_ad(!index->is_instant()); + index->n_core_null_bytes = UT_BITS_IN_BYTES( + index->n_nullable); - err = dict_create_index_tree_in_mem(index, trx); + err = dict_create_index_tree_in_mem(index, trx); - if (err != DB_SUCCESS) { - dict_index_remove_from_cache(table, index); + if (err != DB_SUCCESS) { + dict_index_remove_from_cache(table, index); + } } } - /* Create the index specific FTS auxiliary tables. */ - if (err == DB_SUCCESS && is_fts) { - dict_index_t* idx; - - idx = dict_table_get_index_on_name(table, index_name); - - ut_ad(idx); - err = fts_create_index_tables_low( - trx, idx, table->name.m_name, table->id); - } - -error_handling: - dict_table_close(table, TRUE, FALSE); - if (err != DB_SUCCESS) { +error_handling: /* We have special error handling here */ trx->error_state = DB_SUCCESS; @@ -2634,7 +2608,7 @@ error_handling: trx_rollback_to_savepoint(trx, NULL); } - row_drop_table_for_mysql(table_name, trx, FALSE, true); + row_drop_table_for_mysql(table->name.m_name, trx, FALSE, true); if (trx_is_started(trx)) { @@ -2646,9 +2620,6 @@ error_handling: trx->op_info = ""; - ut_free(table_name); - ut_free(index_name); - return(err); } diff --git a/storage/innobase/row/row0trunc.cc b/storage/innobase/row/row0trunc.cc index 08d19137823..8fb39d4fba7 100644 --- a/storage/innobase/row/row0trunc.cc +++ b/storage/innobase/row/row0trunc.cc @@ -1324,10 +1324,7 @@ row_truncate_fts( fts_table.data_dir_path = table->data_dir_path; - dberr_t err; - - err = fts_create_common_tables( - trx, &fts_table, table->name.m_name, TRUE); + dberr_t err = fts_create_common_tables(trx, &fts_table, true); for (ulint i = 0; i < ib_vector_size(table->fts->indexes) && err == DB_SUCCESS; @@ -1338,8 +1335,7 @@ row_truncate_fts( fts_index = static_cast<dict_index_t*>( ib_vector_getp(table->fts->indexes, i)); - err = fts_create_index_tables_low( - trx, fts_index, table->name.m_name, new_id); + err = fts_create_index_tables(trx, fts_index, new_id); } DBUG_EXECUTE_IF("ib_err_trunc_during_fts_trunc", |