diff options
author | Yuchen Pei <yuchen.pei@mariadb.com> | 2023-02-15 17:25:01 +1100 |
---|---|---|
committer | Yuchen Pei <yuchen.pei@mariadb.com> | 2023-02-17 15:37:01 +1100 |
commit | f8dc6074c38d1659479f1d272be64212093ed98b (patch) | |
tree | eb5ca16e4c2db09f9a0fe01ced31e717e44d9772 | |
parent | 6252a281b5020d28685777c11ee27688a9db3d66 (diff) | |
download | mariadb-git-bb-11.0-mdev-26137-wip-cfg-clone.tar.gz |
WIP try creating a table using cfg and cloning exiting tablebb-11.0-mdev-26137-wip-cfg-clone
-rw-r--r-- | storage/innobase/dict/dict0stats.cc | 60 | ||||
-rw-r--r-- | storage/innobase/handler/ha_innodb.cc | 59 |
2 files changed, 81 insertions, 38 deletions
diff --git a/storage/innobase/dict/dict0stats.cc b/storage/innobase/dict/dict0stats.cc index f3e11c10bad..48cabf47cdf 100644 --- a/storage/innobase/dict/dict0stats.cc +++ b/storage/innobase/dict/dict0stats.cc @@ -632,52 +632,54 @@ dict_stats_table_clone_create( continue; } - dict_index_t* idx; + dict_index_t* idx = index->clone(); - idx = (dict_index_t*) mem_heap_zalloc(heap, sizeof(*idx)); + // idx = (dict_index_t*) mem_heap_zalloc(heap, sizeof(*idx)); - MEM_CHECK_DEFINED(&index->id, sizeof(index->id)); - idx->id = index->id; + // MEM_CHECK_DEFINED(&index->id, sizeof(index->id)); + // idx->id = index->id; - idx->name = mem_heap_strdup(heap, index->name); + // idx->name = mem_heap_strdup(heap, index->name); - idx->table = t; + // idx->table = t; - idx->type = index->type; + // idx->type = index->type; - idx->to_be_dropped = 0; + // idx->to_be_dropped = 0; - idx->online_status = ONLINE_INDEX_COMPLETE; - idx->set_committed(true); + // idx->online_status = ONLINE_INDEX_COMPLETE; + // idx->set_committed(true); - idx->n_uniq = index->n_uniq; + // idx->n_uniq = index->n_uniq; - idx->fields = (dict_field_t*) mem_heap_zalloc( - heap, idx->n_uniq * sizeof(idx->fields[0])); + // idx->fields = (dict_field_t*) mem_heap_zalloc( + // heap, idx->n_uniq * sizeof(idx->fields[0])); - for (ulint i = 0; i < idx->n_uniq; i++) { - idx->fields[i].name = mem_heap_strdup( - heap, index->fields[i].name); - } + // for (ulint i = 0; i < idx->n_uniq; i++) { + // idx->fields[i].name = mem_heap_strdup( + // heap, index->fields[i].name); + // idx->fields[i].col + // } /* hook idx into t->indexes */ UT_LIST_ADD_LAST(t->indexes, idx); - idx->stat_n_diff_key_vals = (ib_uint64_t*) mem_heap_zalloc( - heap, - idx->n_uniq * sizeof(idx->stat_n_diff_key_vals[0])); + // idx->stat_n_diff_key_vals = (ib_uint64_t*) mem_heap_zalloc( + // heap, + // idx->n_uniq * sizeof(idx->stat_n_diff_key_vals[0])); - idx->stat_n_sample_sizes = (ib_uint64_t*) mem_heap_zalloc( - heap, - idx->n_uniq * sizeof(idx->stat_n_sample_sizes[0])); + // idx->stat_n_sample_sizes = (ib_uint64_t*) mem_heap_zalloc( + // heap, + // idx->n_uniq * sizeof(idx->stat_n_sample_sizes[0])); - idx->stat_n_non_null_key_vals = (ib_uint64_t*) mem_heap_zalloc( - heap, - idx->n_uniq * sizeof(idx->stat_n_non_null_key_vals[0])); - ut_d(idx->magic_n = DICT_INDEX_MAGIC_N); + // idx->stat_n_non_null_key_vals = (ib_uint64_t*) mem_heap_zalloc( + // heap, + // idx->n_uniq * sizeof(idx->stat_n_non_null_key_vals[0])); + // ut_d(idx->magic_n = DICT_INDEX_MAGIC_N); - idx->stat_defrag_n_page_split = 0; - idx->stat_defrag_n_pages_freed = 0; + // idx->stat_defrag_n_page_split = 0; + // idx->stat_defrag_n_pages_freed = 0; + // idx->cached = index->cached; } ut_d(t->magic_n = DICT_TABLE_MAGIC_N); diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index ee647430098..aa281680f26 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -80,6 +80,7 @@ this program; if not, write to the Free Software Foundation, Inc., #include "btr0defragment.h" #include "dict0crea.h" #include "dict0stats.h" +#include "../dict/dict0stats.cc" #include "dict0stats_bg.h" #include "fil0fil.h" #include "fsp0fsp.h" @@ -93,6 +94,7 @@ this program; if not, write to the Free Software Foundation, Inc., #include "os0file.h" #include "page0zip.h" #include "row0import.h" +#include "../row/row0import.cc" #include "row0ins.h" #include "row0log.h" #include "row0merge.h" @@ -5823,19 +5825,55 @@ ha_innobase::open(const char* name, int, uint) THD* thd = ha_thd(); dict_table_t* ib_table = open_dict_table(name, norm_name, is_part, DICT_ERR_IGNORE_FK_NOKEY); + // bool try_import = false; DEBUG_SYNC(thd, "ib_open_after_dict_open"); if (NULL == ib_table) { - - if (is_part) { - sql_print_error("Failed to open table %s.\n", - norm_name); - } - set_my_errno(ENOENT); - - DBUG_RETURN(HA_ERR_NO_SUCH_TABLE); - } + /** check .cfg file exists. If exists then fetch the old table name */ + table_name_t table_name(const_cast<char*>(name)); + FILE* file = fopen(fil_make_filepath(fil_path_to_mysql_datadir, + table_name, CFG, + fil_path_to_mysql_datadir != nullptr), + "rb"); + row_import cfg; + if (!(row_import_read_meta_data(file, thd, cfg))) + { + /** open_dict_table using old table name */ + const char *old_name = reinterpret_cast<const char *>(cfg.m_table_name); + char old_norm_name[FN_REFLEN]; + normalize_table_name(old_norm_name, old_name); + dict_table_t *old_table = open_dict_table(old_name, old_norm_name, is_part, DICT_ERR_IGNORE_FK_NOKEY); + /** clone the table object and change the table name,*/ + ib_table = dict_stats_table_clone_create(old_table); + for (dict_index_t* index = dict_table_get_first_index(ib_table); + index != NULL; + index = dict_table_get_next_index(index)) + { + index->table= ib_table; + } + ib_table->n_cols = old_table->n_cols; + ib_table->name = table_name; + ib_table->flags2 |= DICT_TF2_DISCARDED; + ib_table->acquire(); + ib_table->file_unreadable = true; + // try_import = true; + // m_prebuilt = row_create_prebuilt(ib_table, table->s->reclength); + // m_prebuilt->default_rec = table->s->default_values; + // ut_ad(m_prebuilt->default_rec); + // m_prebuilt->m_mysql_table = table; + // discard_or_import_tablespace(false); + } else + { + if (is_part) + { + sql_print_error("Failed to open table %s.\n", norm_name); + } + set_my_errno(ENOENT); + + DBUG_RETURN(HA_ERR_NO_SUCH_TABLE); + } + } size_t n_fields = omits_virtual_cols(*table_share) ? table_share->stored_fields : table_share->fields; @@ -5910,6 +5948,9 @@ ha_innobase::open(const char* name, int, uint) m_prebuilt->m_mysql_table = table; + // if (try_import) + // discard_or_import_tablespace(false); + /* Looks like MySQL-3.23 sometimes has primary key number != 0 */ m_primary_key = table->s->primary_key; |