diff options
Diffstat (limited to 'storage/innobase/dict')
-rw-r--r-- | storage/innobase/dict/dict0boot.c | 83 | ||||
-rw-r--r-- | storage/innobase/dict/dict0crea.c | 164 | ||||
-rw-r--r-- | storage/innobase/dict/dict0dict.c | 557 | ||||
-rw-r--r-- | storage/innobase/dict/dict0load.c | 291 | ||||
-rw-r--r-- | storage/innobase/dict/dict0mem.c | 42 |
5 files changed, 571 insertions, 566 deletions
diff --git a/storage/innobase/dict/dict0boot.c b/storage/innobase/dict/dict0boot.c index 18a707a1b93..9c98338e603 100644 --- a/storage/innobase/dict/dict0boot.c +++ b/storage/innobase/dict/dict0boot.c @@ -29,14 +29,14 @@ Gets a pointer to the dictionary header and x-latches its page. */ dict_hdr_t* dict_hdr_get( /*=========*/ - /* out: pointer to the dictionary header, + /* out: pointer to the dictionary header, page x-latched */ mtr_t* mtr) /* in: mtr */ { dict_hdr_t* header; ut_ad(mtr); - + header = DICT_HDR + buf_page_get(DICT_HDR_SPACE, DICT_HDR_PAGE_NO, RW_X_LATCH, mtr); #ifdef UNIV_SYNC_DEBUG @@ -59,21 +59,21 @@ dict_hdr_get_new_id( mtr_t mtr; ut_ad((type == DICT_HDR_TABLE_ID) || (type == DICT_HDR_INDEX_ID) - || (type == DICT_HDR_MIX_ID)); + || (type == DICT_HDR_MIX_ID)); mtr_start(&mtr); dict_hdr = dict_hdr_get(&mtr); - id = mtr_read_dulint(dict_hdr + type, &mtr); + id = mtr_read_dulint(dict_hdr + type, &mtr); id = ut_dulint_add(id, 1); - - mlog_write_dulint(dict_hdr + type, id, &mtr); + + mlog_write_dulint(dict_hdr + type, id, &mtr); mtr_commit(&mtr); return(id); -} +} /************************************************************************** Writes the current value of the row id counter to the dictionary header file @@ -96,11 +96,11 @@ dict_hdr_flush_row_id(void) mtr_start(&mtr); dict_hdr = dict_hdr_get(&mtr); - - mlog_write_dulint(dict_hdr + DICT_HDR_ROW_ID, id, &mtr); + + mlog_write_dulint(dict_hdr + DICT_HDR_ROW_ID, id, &mtr); mtr_commit(&mtr); -} +} /********************************************************************* Creates the file page for the dictionary header. This function is @@ -116,7 +116,7 @@ dict_hdr_create( ulint hdr_page_no; ulint root_page_no; page_t* page; - + ut_ad(mtr); /* Create the dictionary header file block in a new, allocated file @@ -125,7 +125,7 @@ dict_hdr_create( DICT_HDR + DICT_HDR_FSEG_HEADER, mtr); hdr_page_no = buf_frame_get_page_no(page); - + ut_a(DICT_HDR_PAGE_NO == hdr_page_no); dict_header = dict_hdr_get(mtr); @@ -147,7 +147,7 @@ dict_hdr_create( /* Create the B-tree roots for the clustered indexes of the basic system tables */ - /*--------------------------*/ + /*--------------------------*/ root_page_no = btr_create(DICT_CLUSTERED | DICT_UNIQUE, DICT_HDR_SPACE, DICT_TABLES_ID, FALSE, mtr); if (root_page_no == FIL_NULL) { @@ -157,7 +157,7 @@ dict_hdr_create( mlog_write_ulint(dict_header + DICT_HDR_TABLES, root_page_no, MLOG_4BYTES, mtr); - /*--------------------------*/ + /*--------------------------*/ root_page_no = btr_create(DICT_UNIQUE, DICT_HDR_SPACE, DICT_TABLE_IDS_ID, FALSE, mtr); if (root_page_no == FIL_NULL) { @@ -167,7 +167,7 @@ dict_hdr_create( mlog_write_ulint(dict_header + DICT_HDR_TABLE_IDS, root_page_no, MLOG_4BYTES, mtr); - /*--------------------------*/ + /*--------------------------*/ root_page_no = btr_create(DICT_CLUSTERED | DICT_UNIQUE, DICT_HDR_SPACE, DICT_COLUMNS_ID, FALSE, mtr); if (root_page_no == FIL_NULL) { @@ -177,7 +177,7 @@ dict_hdr_create( mlog_write_ulint(dict_header + DICT_HDR_COLUMNS, root_page_no, MLOG_4BYTES, mtr); - /*--------------------------*/ + /*--------------------------*/ root_page_no = btr_create(DICT_CLUSTERED | DICT_UNIQUE, DICT_HDR_SPACE, DICT_INDEXES_ID, FALSE, mtr); if (root_page_no == FIL_NULL) { @@ -187,7 +187,7 @@ dict_hdr_create( mlog_write_ulint(dict_header + DICT_HDR_INDEXES, root_page_no, MLOG_4BYTES, mtr); - /*--------------------------*/ + /*--------------------------*/ root_page_no = btr_create(DICT_CLUSTERED | DICT_UNIQUE, DICT_HDR_SPACE, DICT_FIELDS_ID, FALSE, mtr); if (root_page_no == FIL_NULL) { @@ -197,7 +197,7 @@ dict_hdr_create( mlog_write_ulint(dict_header + DICT_HDR_FIELDS, root_page_no, MLOG_4BYTES, mtr); - /*--------------------------*/ + /*--------------------------*/ return(TRUE); } @@ -217,12 +217,12 @@ dict_boot(void) ibool success; mtr_start(&mtr); - + /* Create the hash tables etc. */ dict_init(); mutex_enter(&(dict_sys->mutex)); - + /* Get the dictionary header */ dict_hdr = dict_hdr_get(&mtr); @@ -237,16 +237,15 @@ dict_boot(void) header. */ dict_sys->row_id = ut_dulint_add( - ut_dulint_align_up( - mtr_read_dulint(dict_hdr + DICT_HDR_ROW_ID, - &mtr), - DICT_HDR_ROW_ID_WRITE_MARGIN), - DICT_HDR_ROW_ID_WRITE_MARGIN); + ut_dulint_align_up( + mtr_read_dulint(dict_hdr + DICT_HDR_ROW_ID, &mtr), + DICT_HDR_ROW_ID_WRITE_MARGIN), + DICT_HDR_ROW_ID_WRITE_MARGIN); /* Insert into the dictionary cache the descriptions of the basic system tables */ /*-------------------------*/ - table = dict_mem_table_create("SYS_TABLES", DICT_HDR_SPACE, 8, FALSE); + table = dict_mem_table_create("SYS_TABLES", DICT_HDR_SPACE, 8, 0); dict_mem_table_add_col(table, "NAME", DATA_BINARY, 0, 0, 0); dict_mem_table_add_col(table, "ID", DATA_BINARY, 0, 0, 0); @@ -258,14 +257,14 @@ dict_boot(void) dict_mem_table_add_col(table, "SPACE", DATA_INT, 0, 4, 0); table->id = DICT_TABLES_ID; - + dict_table_add_to_cache(table); dict_sys->sys_tables = table; - + index = dict_mem_index_create("SYS_TABLES", "CLUST_IND", DICT_HDR_SPACE, DICT_UNIQUE | DICT_CLUSTERED, 1); - dict_mem_index_add_field(index, "NAME", 0, 0); + dict_mem_index_add_field(index, "NAME", 0); index->id = DICT_TABLES_ID; @@ -275,14 +274,14 @@ dict_boot(void) /*-------------------------*/ index = dict_mem_index_create("SYS_TABLES", "ID_IND", DICT_HDR_SPACE, DICT_UNIQUE, 1); - dict_mem_index_add_field(index, "ID", 0, 0); + dict_mem_index_add_field(index, "ID", 0); index->id = DICT_TABLE_IDS_ID; success = dict_index_add_to_cache(table, index, mtr_read_ulint( dict_hdr + DICT_HDR_TABLE_IDS, MLOG_4BYTES, &mtr)); ut_a(success); /*-------------------------*/ - table = dict_mem_table_create("SYS_COLUMNS", DICT_HDR_SPACE, 7, FALSE); + table = dict_mem_table_create("SYS_COLUMNS", DICT_HDR_SPACE, 7, 0); dict_mem_table_add_col(table, "TABLE_ID", DATA_BINARY,0,0,0); dict_mem_table_add_col(table, "POS", DATA_INT, 0, 4, 0); @@ -291,7 +290,7 @@ dict_boot(void) dict_mem_table_add_col(table, "PRTYPE", DATA_INT, 0, 4, 0); dict_mem_table_add_col(table, "LEN", DATA_INT, 0, 4, 0); dict_mem_table_add_col(table, "PREC", DATA_INT, 0, 4, 0); - + table->id = DICT_COLUMNS_ID; dict_table_add_to_cache(table); @@ -300,15 +299,15 @@ dict_boot(void) index = dict_mem_index_create("SYS_COLUMNS", "CLUST_IND", DICT_HDR_SPACE, DICT_UNIQUE | DICT_CLUSTERED, 2); - dict_mem_index_add_field(index, "TABLE_ID", 0, 0); - dict_mem_index_add_field(index, "POS", 0, 0); + dict_mem_index_add_field(index, "TABLE_ID", 0); + dict_mem_index_add_field(index, "POS", 0); index->id = DICT_COLUMNS_ID; success = dict_index_add_to_cache(table, index, mtr_read_ulint( dict_hdr + DICT_HDR_COLUMNS, MLOG_4BYTES, &mtr)); ut_a(success); /*-------------------------*/ - table = dict_mem_table_create("SYS_INDEXES", DICT_HDR_SPACE, 7, FALSE); + table = dict_mem_table_create("SYS_INDEXES", DICT_HDR_SPACE, 7, 0); dict_mem_table_add_col(table, "TABLE_ID", DATA_BINARY, 0,0,0); dict_mem_table_add_col(table, "ID", DATA_BINARY, 0, 0, 0); @@ -336,15 +335,15 @@ dict_boot(void) index = dict_mem_index_create("SYS_INDEXES", "CLUST_IND", DICT_HDR_SPACE, DICT_UNIQUE | DICT_CLUSTERED, 2); - dict_mem_index_add_field(index, "TABLE_ID", 0, 0); - dict_mem_index_add_field(index, "ID", 0, 0); + dict_mem_index_add_field(index, "TABLE_ID", 0); + dict_mem_index_add_field(index, "ID", 0); index->id = DICT_INDEXES_ID; success = dict_index_add_to_cache(table, index, mtr_read_ulint( dict_hdr + DICT_HDR_INDEXES, MLOG_4BYTES, &mtr)); ut_a(success); /*-------------------------*/ - table = dict_mem_table_create("SYS_FIELDS", DICT_HDR_SPACE, 3, FALSE); + table = dict_mem_table_create("SYS_FIELDS", DICT_HDR_SPACE, 3, 0); dict_mem_table_add_col(table, "INDEX_ID", DATA_BINARY, 0,0,0); dict_mem_table_add_col(table, "POS", DATA_INT, 0, 4, 0); @@ -357,8 +356,8 @@ dict_boot(void) index = dict_mem_index_create("SYS_FIELDS", "CLUST_IND", DICT_HDR_SPACE, DICT_UNIQUE | DICT_CLUSTERED, 2); - dict_mem_index_add_field(index, "INDEX_ID", 0, 0); - dict_mem_index_add_field(index, "POS", 0, 0); + dict_mem_index_add_field(index, "INDEX_ID", 0); + dict_mem_index_add_field(index, "POS", 0); index->id = DICT_FIELDS_ID; success = dict_index_add_to_cache(table, index, mtr_read_ulint( @@ -378,7 +377,7 @@ dict_boot(void) dict_load_sys_table(dict_sys->sys_columns); dict_load_sys_table(dict_sys->sys_indexes); dict_load_sys_table(dict_sys->sys_fields); - + mutex_exit(&(dict_sys->mutex)); } @@ -407,7 +406,7 @@ dict_create(void) dict_hdr_create(&mtr); mtr_commit(&mtr); - + dict_boot(); dict_insert_initial_data(); diff --git a/storage/innobase/dict/dict0crea.c b/storage/innobase/dict/dict0crea.c index c7d6ffd2c22..6f0a81296ac 100644 --- a/storage/innobase/dict/dict0crea.c +++ b/storage/innobase/dict/dict0crea.c @@ -33,7 +33,7 @@ dtuple_t* dict_create_sys_tables_tuple( /*=========================*/ /* out: the tuple which should be inserted */ - dict_table_t* table, /* in: table */ + dict_table_t* table, /* in: table */ mem_heap_t* heap) /* in: memory heap from which the memory for the built tuple is allocated */ { @@ -45,7 +45,7 @@ dict_create_sys_tables_tuple( ut_ad(table && heap); sys_tables = dict_sys->sys_tables; - + entry = dtuple_create(heap, 8 + DATA_N_SYS_COLS); /* 0: NAME -----------------------------*/ @@ -62,9 +62,13 @@ dict_create_sys_tables_tuple( /* 4: N_COLS ---------------------------*/ dfield = dtuple_get_nth_field(entry, 2); +#if DICT_TF_COMPACT != 1 +#error +#endif + ptr = mem_heap_alloc(heap, 4); mach_write_to_4(ptr, table->n_def - | ((ulint) table->comp << 31)); + | ((table->flags & DICT_TF_COMPACT) << 31)); dfield_set_data(dfield, ptr, 4); /* 5: TYPE -----------------------------*/ dfield = dtuple_get_nth_field(entry, 3); @@ -91,7 +95,7 @@ dict_create_sys_tables_tuple( /* 8: CLUSTER_NAME ---------------------*/ dfield = dtuple_get_nth_field(entry, 6); - if (table->type == DICT_TABLE_CLUSTER_MEMBER) { + if (table->type == DICT_TABLE_CLUSTER_MEMBER) { dfield_set_data(dfield, table->cluster_name, ut_strlen(table->cluster_name)); ut_error; /* Oracle-style clusters are not supported yet */ @@ -108,9 +112,9 @@ dict_create_sys_tables_tuple( /*----------------------------------*/ dict_table_copy_types(entry, sys_tables); - + return(entry); -} +} /********************************************************************* Based on a table object, this function builds the entry to be inserted @@ -120,7 +124,7 @@ dtuple_t* dict_create_sys_columns_tuple( /*==========================*/ /* out: the tuple which should be inserted */ - dict_table_t* table, /* in: table */ + dict_table_t* table, /* in: table */ ulint i, /* in: column number */ mem_heap_t* heap) /* in: memory heap from which the memory for the built tuple is allocated */ @@ -136,7 +140,7 @@ dict_create_sys_columns_tuple( column = dict_table_get_nth_col(table, i); sys_columns = dict_sys->sys_columns; - + entry = dtuple_create(heap, 7 + DATA_N_SYS_COLS); /* 0: TABLE_ID -----------------------*/ @@ -190,7 +194,7 @@ dict_create_sys_columns_tuple( dict_table_copy_types(entry, sys_columns); return(entry); -} +} /******************************************************************* Builds a table definition to insert. */ @@ -236,7 +240,7 @@ dict_build_table_def_step( cluster_table = dict_table_get_low(table->cluster_name); if (cluster_table == NULL) { - + return(DB_CLUSTER_NOT_FOUND); } @@ -244,7 +248,7 @@ dict_build_table_def_step( table->space = cluster_table->space; table->mix_len = cluster_table->mix_len; - + table->mix_id = dict_hdr_get_new_id(DICT_HDR_MIX_ID); } @@ -256,7 +260,7 @@ dict_build_table_def_step( - page 2 is the first inode page, - page 3 will contain the root of the clustered index of the table we create here. */ - + table->space = 0; /* reset to zero for the call below */ if (table->dir_path_of_temp_table) { @@ -281,7 +285,7 @@ dict_build_table_def_step( mtr_start(&mtr); fsp_header_init(table->space, FIL_IBD_FILE_INITIAL_SIZE, &mtr); - + mtr_commit(&mtr); } @@ -306,7 +310,7 @@ dict_build_col_def_step( row = dict_create_sys_columns_tuple(node->table, node->col_no, node->heap); ins_node_set_new_row(node->col_def, row); - + return(DB_SUCCESS); } @@ -318,7 +322,7 @@ dtuple_t* dict_create_sys_indexes_tuple( /*==========================*/ /* out: the tuple which should be inserted */ - dict_index_t* index, /* in: index */ + dict_index_t* index, /* in: index */ mem_heap_t* heap) /* in: memory heap from which the memory for the built tuple is allocated */ { @@ -336,7 +340,7 @@ dict_create_sys_indexes_tuple( sys_indexes = dict_sys->sys_indexes; table = dict_table_get_low(index->table_name); - + entry = dtuple_create(heap, 7 + DATA_N_SYS_COLS); /* 0: TABLE_ID -----------------------*/ @@ -400,7 +404,7 @@ dict_create_sys_indexes_tuple( dict_table_copy_types(entry, sys_indexes); return(entry); -} +} /********************************************************************* Based on an index object, this function builds the entry to be inserted @@ -410,7 +414,7 @@ dtuple_t* dict_create_sys_fields_tuple( /*=========================*/ /* out: the tuple which should be inserted */ - dict_index_t* index, /* in: index */ + dict_index_t* index, /* in: index */ ulint i, /* in: field number */ mem_heap_t* heap) /* in: memory heap from which the memory for the built tuple is allocated */ @@ -426,15 +430,15 @@ dict_create_sys_fields_tuple( ut_ad(index && heap); for (j = 0; j < index->n_fields; j++) { - if (dict_index_get_nth_field(index, j)->prefix_len > 0) { - index_contains_column_prefix_field = TRUE; + if (dict_index_get_nth_field(index, j)->prefix_len > 0) { + index_contains_column_prefix_field = TRUE; } } field = dict_index_get_nth_field(index, i); sys_fields = dict_sys->sys_fields; - + entry = dtuple_create(heap, 3 + DATA_N_SYS_COLS); /* 0: INDEX_ID -----------------------*/ @@ -449,19 +453,19 @@ dict_create_sys_fields_tuple( dfield = dtuple_get_nth_field(entry, 1); ptr = mem_heap_alloc(heap, 4); - + if (index_contains_column_prefix_field) { /* If there are column prefix fields in the index, then we store the number of the field to the 2 HIGH bytes and the prefix length to the 2 low bytes, */ - mach_write_to_4(ptr, (i << 16) + field->prefix_len); + mach_write_to_4(ptr, (i << 16) + field->prefix_len); } else { - /* Else we store the number of the field to the 2 LOW bytes. + /* Else we store the number of the field to the 2 LOW bytes. This is to keep the storage format compatible with InnoDB versions < 4.0.14. */ - - mach_write_to_4(ptr, i); + + mach_write_to_4(ptr, i); } dfield_set_data(dfield, ptr, 4); @@ -473,9 +477,9 @@ dict_create_sys_fields_tuple( /*---------------------------------*/ dict_table_copy_types(entry, sys_fields); - + return(entry); -} +} /********************************************************************* Creates the tuple with which the index entry is searched for writing the index @@ -498,13 +502,13 @@ dict_create_search_tuple( search_tuple = dtuple_create(heap, 2); - field1 = dtuple_get_nth_field(tuple, 0); - field2 = dtuple_get_nth_field(search_tuple, 0); + field1 = dtuple_get_nth_field(tuple, 0); + field2 = dtuple_get_nth_field(search_tuple, 0); dfield_copy(field2, field1); - field1 = dtuple_get_nth_field(tuple, 1); - field2 = dtuple_get_nth_field(search_tuple, 1); + field1 = dtuple_get_nth_field(tuple, 1); + field2 = dtuple_get_nth_field(search_tuple, 1); dfield_copy(field2, field1); @@ -547,8 +551,8 @@ dict_build_index_def_step( node->table = table; ut_ad((UT_LIST_GET_LEN(table->indexes) > 0) - || (index->type & DICT_CLUSTERED)); - + || (index->type & DICT_CLUSTERED)); + index->id = dict_hdr_get_new_id(DICT_HDR_INDEX_ID); /* Inherit the space id from the table; we store all indexes of a @@ -577,7 +581,7 @@ dict_build_field_def_step( dtuple_t* row; index = node->index; - + row = dict_create_sys_fields_tuple(index, node->field_no, node->heap); ins_node_set_new_row(node->field_def, row); @@ -605,7 +609,7 @@ dict_create_index_tree_step( ut_ad(mutex_own(&(dict_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ - index = node->index; + index = node->index; table = node->table; sys_indexes = dict_sys->sys_indexes; @@ -626,7 +630,7 @@ dict_create_index_tree_step( mtr_start(&mtr); search_tuple = dict_create_search_tuple(node->ind_row, node->heap); - + btr_pcur_open(UT_LIST_GET_FIRST(sys_indexes->indexes), search_tuple, PAGE_CUR_L, BTR_MODIFY_LEAF, &pcur, &mtr); @@ -634,7 +638,7 @@ dict_create_index_tree_step( btr_pcur_move_to_next_user_rec(&pcur, &mtr); node->page_no = btr_create(index->type, index->space, index->id, - table->comp, &mtr); + dict_table_is_comp(table), &mtr); /* printf("Created a new index tree in space %lu root page %lu\n", index->space, index->page_no); */ @@ -666,16 +670,16 @@ dict_drop_index_tree( ulint space; byte* ptr; ulint len; - + #ifdef UNIV_SYNC_DEBUG ut_ad(mutex_own(&(dict_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ - ut_a(!dict_sys->sys_indexes->comp); + ut_a(!dict_table_is_comp(dict_sys->sys_indexes)); ptr = rec_get_nth_field_old(rec, DICT_SYS_INDEXES_PAGE_NO_FIELD, &len); ut_ad(len == 4); - + root_page_no = mtr_read_ulint(ptr, MLOG_4BYTES, mtr); if (root_page_no == FIL_NULL) { @@ -706,7 +710,7 @@ dict_drop_index_tree( /* Then we free the root page in the same mini-transaction where we write FIL_NULL to the appropriate field in the SYS_INDEXES record: this mini-transaction marks the B-tree totally freed */ - + /* printf("Dropping index tree in space %lu root page %lu\n", space, root_page_no); */ btr_free_root(space, root_page_no, mtr); @@ -743,7 +747,7 @@ dict_truncate_index_tree( ut_ad(mutex_own(&(dict_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ - ut_a(!dict_sys->sys_indexes->comp); + ut_a(!dict_table_is_comp(dict_sys->sys_indexes)); ptr = rec_get_nth_field_old(rec, DICT_SYS_INDEXES_PAGE_NO_FIELD, &len); ut_ad(len == 4); @@ -853,7 +857,7 @@ tab_create_graph_create( tab_node_t* node; node = mem_heap_alloc(heap, sizeof(tab_node_t)); - + node->common.type = QUE_NODE_CREATE_TABLE; node->table = table; @@ -862,9 +866,9 @@ tab_create_graph_create( node->heap = mem_heap_create(256); node->tab_def = ins_node_create(INS_DIRECT, dict_sys->sys_tables, - heap); + heap); node->tab_def->common.parent = node; - + node->col_def = ins_node_create(INS_DIRECT, dict_sys->sys_columns, heap); node->col_def->common.parent = node; @@ -899,7 +903,7 @@ ind_create_graph_create( node->heap = mem_heap_create(256); node->ind_def = ins_node_create(INS_DIRECT, - dict_sys->sys_indexes, heap); + dict_sys->sys_indexes, heap); node->ind_def->common.parent = node; node->field_def = ins_node_create(INS_DIRECT, @@ -931,7 +935,7 @@ dict_create_table_step( #endif /* UNIV_SYNC_DEBUG */ trx = thr_get_trx(thr); - + node = thr->run_node; ut_ad(que_node_get_type(node) == QUE_NODE_CREATE_TABLE); @@ -950,7 +954,7 @@ dict_create_table_step( goto function_exit; } - + node->state = TABLE_BUILD_COL_DEF; node->col_no = 0; @@ -971,7 +975,7 @@ dict_create_table_step( } node->col_no++; - + thr->run_node = node->col_def; return(thr); @@ -985,7 +989,7 @@ dict_create_table_step( /* Table was correctly defined: do NOT commit the transaction (CREATE TABLE does NOT do an implicit commit of the current transaction) */ - + node->state = TABLE_ADD_TO_CACHE; /* thr->run_node = node->commit_node; @@ -1018,7 +1022,7 @@ function_exit: thr->run_node = que_node_get_parent(node); return(thr); -} +} /*************************************************************** Creates an index. This is a high-level function used in SQL execution @@ -1041,7 +1045,7 @@ dict_create_index_step( #endif /* UNIV_SYNC_DEBUG */ trx = thr_get_trx(thr); - + node = thr->run_node; ut_ad(que_node_get_type(node) == QUE_NODE_CREATE_INDEX); @@ -1058,7 +1062,7 @@ dict_create_index_step( goto function_exit; } - + node->state = INDEX_BUILD_FIELD_DEF; node->field_no = 0; @@ -1079,7 +1083,7 @@ dict_create_index_step( } node->field_no++; - + thr->run_node = node->field_def; return(thr); @@ -1105,7 +1109,7 @@ dict_create_index_step( /* Index was correctly defined: do NOT commit the transaction (CREATE INDEX does NOT currently do an implicit commit of the current transaction) */ - + node->state = INDEX_ADD_TO_CACHE; /* thr->run_node = node->commit_node; @@ -1141,7 +1145,7 @@ function_exit: thr->run_node = que_node_get_parent(node); return(thr); -} +} /******************************************************************** Creates the foreign key constraints system tables inside InnoDB @@ -1159,29 +1163,29 @@ dict_create_or_check_foreign_constraint_tables(void) que_t* graph; ulint error; trx_t* trx; - const char* str; + const char* str; mutex_enter(&(dict_sys->mutex)); table1 = dict_table_get_low("SYS_FOREIGN"); table2 = dict_table_get_low("SYS_FOREIGN_COLS"); - + if (table1 && table2 - && UT_LIST_GET_LEN(table1->indexes) == 3 - && UT_LIST_GET_LEN(table2->indexes) == 1) { + && UT_LIST_GET_LEN(table1->indexes) == 3 + && UT_LIST_GET_LEN(table2->indexes) == 1) { - /* Foreign constraint system tables have already been - created, and they are ok */ + /* Foreign constraint system tables have already been + created, and they are ok */ mutex_exit(&(dict_sys->mutex)); - return(DB_SUCCESS); - } + return(DB_SUCCESS); + } mutex_exit(&(dict_sys->mutex)); trx = trx_allocate_for_mysql(); - + trx->op_info = "creating foreign key sys tables"; row_mysql_lock_data_dictionary(trx); @@ -1204,7 +1208,7 @@ dict_create_or_check_foreign_constraint_tables(void) /* NOTE: in dict_load_foreigns we use the fact that there are 2 secondary indexes on SYS_FOREIGN, and they are defined just like below */ - + /* NOTE: when designing InnoDB's foreign key support in 2001, we made an error and made the table names and the foreign key id of type 'CHAR' (internally, really a VARCHAR). We should have made the type @@ -1243,7 +1247,7 @@ dict_create_or_check_foreign_constraint_tables(void) if (error != DB_SUCCESS) { fprintf(stderr, "InnoDB: error %lu in creation\n", (ulong) error); - + ut_a(error == DB_OUT_OF_FILE_SPACE); fprintf(stderr, "InnoDB: creation failed\n"); @@ -1258,14 +1262,14 @@ dict_create_or_check_foreign_constraint_tables(void) } que_graph_free(graph); - + trx->op_info = ""; row_mysql_unlock_data_dictionary(trx); - trx_free_for_mysql(trx); + trx_free_for_mysql(trx); - if (error == DB_SUCCESS) { + if (error == DB_SUCCESS) { fprintf(stderr, "InnoDB: Foreign key constraint system tables created\n"); } @@ -1324,7 +1328,7 @@ dict_create_add_foreigns_to_dictionary( if (NULL == dict_table_get_low("SYS_FOREIGN")) { fprintf(stderr, - "InnoDB: table SYS_FOREIGN not found from internal data dictionary\n"); +"InnoDB: table SYS_FOREIGN not found from internal data dictionary\n"); return(DB_ERROR); } @@ -1432,12 +1436,12 @@ loop: "in front of the user-defined constraint name).\n", ef); fputs("Note that InnoDB's FOREIGN KEY system tables store\n" - "constraint names as case-insensitive, with the\n" - "MySQL standard latin1_swedish_ci collation. If you\n" - "create tables or databases whose names differ only in\n" - "the character case, then collisions in constraint\n" - "names can occur. Workaround: name your constraints\n" - "explicitly with unique names.\n", + "constraint names as case-insensitive, with the\n" + "MySQL standard latin1_swedish_ci collation. If you\n" + "create tables or databases whose names differ only in\n" + "the character case, then collisions in constraint\n" + "names can occur. Workaround: name your constraints\n" + "explicitly with unique names.\n", ef); mutex_exit(&dict_foreign_err_mutex); @@ -1446,7 +1450,7 @@ loop: } if (error != DB_SUCCESS) { - fprintf(stderr, + fprintf(stderr, "InnoDB: Foreign key constraint creation failed:\n" "InnoDB: internal error number %lu\n", (ulong) error); @@ -1461,7 +1465,7 @@ loop: return(error); } - + foreign = UT_LIST_GET_NEXT(foreign_list, foreign); goto loop; diff --git a/storage/innobase/dict/dict0dict.c b/storage/innobase/dict/dict0dict.c index fb95ffbd80c..720074a4911 100644 --- a/storage/innobase/dict/dict0dict.c +++ b/storage/innobase/dict/dict0dict.c @@ -132,7 +132,7 @@ dict_index_find_cols( /*=================*/ /* out: TRUE if success */ dict_table_t* table, /* in: table */ - dict_index_t* index); /* in: index */ + dict_index_t* index); /* in: index */ /*********************************************************************** Builds the internal dictionary cache representation for a clustered index, containing also system fields not defined by the user. */ @@ -144,7 +144,7 @@ dict_index_build_internal_clust( of the clustered index */ dict_table_t* table, /* in: table */ dict_index_t* index); /* in: user representation of a clustered - index */ + index */ /*********************************************************************** Builds the internal dictionary cache representation for a non-clustered index, containing also system fields not defined by the user. */ @@ -156,7 +156,7 @@ dict_index_build_internal_non_clust( of the non-clustered index */ dict_table_t* table, /* in: table */ dict_index_t* index); /* in: user representation of a non-clustered - index */ + index */ /************************************************************************** Removes a foreign constraint struct from the dictionary cache. */ static @@ -196,9 +196,10 @@ dict_foreign_free( /* Stream for storing detailed information about the latest foreign key and unique key errors */ FILE* dict_foreign_err_file = NULL; -mutex_t dict_foreign_err_mutex; /* mutex protecting the foreign +mutex_t dict_foreign_err_mutex; /* mutex protecting the foreign and unique error buffers */ - + +#ifndef UNIV_HOTBACKUP /********************************************************************** Makes all characters in a NUL-terminated UTF-8 string lower case. */ @@ -209,6 +210,7 @@ dict_casedn_str( { innobase_casedn_str(a); } +#endif /* !UNIV_HOTBACKUP */ /************************************************************************ Checks if the database name in two table names is the same. */ @@ -263,7 +265,7 @@ dict_get_db_name_len( ut_a(s); return(s - name); } - + /************************************************************************ Reserves the dictionary system mutex for MySQL. */ @@ -273,7 +275,7 @@ dict_mutex_enter_for_mysql(void) { mutex_enter(&(dict_sys->mutex)); } - + /************************************************************************ Releases the dictionary system mutex for MySQL. */ @@ -283,7 +285,7 @@ dict_mutex_exit_for_mysql(void) { mutex_exit(&(dict_sys->mutex)); } - + /************************************************************************ Decrements the count of open MySQL handles to a table. */ @@ -297,7 +299,7 @@ dict_table_decrement_handle_count( ut_a(table->n_mysql_handles_opened > 0); table->n_mysql_handles_opened--; - + mutex_exit(&(dict_sys->mutex)); } @@ -350,7 +352,7 @@ dict_table_get_index_noninline( { return(dict_table_get_index(table, name)); } - + /************************************************************************ Initializes the autoinc counter. It is not an error to initialize an already initialized counter. */ @@ -390,7 +392,7 @@ dict_table_autoinc_get( value = table->autoinc; table->autoinc = table->autoinc + 1; } - + mutex_exit(&(table->autoinc_mutex)); return(value); @@ -407,7 +409,7 @@ dict_table_autoinc_decrement( mutex_enter(&(table->autoinc_mutex)); table->autoinc = table->autoinc - 1; - + mutex_exit(&(table->autoinc_mutex)); } @@ -431,7 +433,7 @@ dict_table_autoinc_read( } else { value = table->autoinc; } - + mutex_exit(&(table->autoinc_mutex)); return(value); @@ -476,7 +478,7 @@ dict_table_autoinc_update( if (value >= table->autoinc) { table->autoinc = value + 1; } - } + } mutex_exit(&(table->autoinc_mutex)); } @@ -497,7 +499,7 @@ dict_index_get_nth_col_pos( dict_col_t* col; ulint pos; ulint n_fields; - + ut_ad(index); ut_ad(index->magic_n == DICT_INDEX_MAGIC_N); @@ -509,7 +511,7 @@ dict_index_get_nth_col_pos( } n_fields = dict_index_get_n_fields(index); - + for (pos = 0; pos < n_fields; pos++) { field = dict_index_get_nth_field(index, pos); @@ -537,7 +539,7 @@ dict_index_contains_col_or_prefix( dict_col_t* col; ulint pos; ulint n_fields; - + ut_ad(index); ut_ad(index->magic_n == DICT_INDEX_MAGIC_N); @@ -549,7 +551,7 @@ dict_index_contains_col_or_prefix( col = dict_table_get_nth_col(index->table, n); n_fields = dict_index_get_n_fields(index); - + for (pos = 0; pos < n_fields; pos++) { field = dict_index_get_nth_field(index, pos); @@ -582,21 +584,21 @@ dict_index_get_nth_field_pos( dict_field_t* field2; ulint n_fields; ulint pos; - + ut_ad(index); ut_ad(index->magic_n == DICT_INDEX_MAGIC_N); field2 = dict_index_get_nth_field(index2, n); n_fields = dict_index_get_n_fields(index); - + for (pos = 0; pos < n_fields; pos++) { field = dict_index_get_nth_field(index, pos); if (field->col == field2->col - && (field->prefix_len == 0 + && (field->prefix_len == 0 || (field->prefix_len >= field2->prefix_len - && field2->prefix_len != 0))) { + && field2->prefix_len != 0))) { return(pos); } @@ -616,7 +618,7 @@ dict_table_get_on_id( trx_t* trx) /* in: transaction handle */ { dict_table_t* table; - + if (ut_dulint_cmp(table_id, DICT_FIELDS_ID) <= 0 || trx->dict_operation_lock_mode == RW_X_LATCH) { /* It is a system table which will always exist in the table @@ -634,7 +636,7 @@ dict_table_get_on_id( mutex_enter(&(dict_sys->mutex)); table = dict_table_get_on_id_low(table_id, trx); - + mutex_exit(&(dict_sys->mutex)); return(table); @@ -672,7 +674,7 @@ dict_table_col_in_clustered_key( dict_col_t* col; ulint pos; ulint n_fields; - + ut_ad(table); col = dict_table_get_nth_col(table, n); @@ -680,7 +682,7 @@ dict_table_col_in_clustered_key( index = dict_table_get_first_index(table); n_fields = dict_index_get_n_unique(index); - + for (pos = 0; pos < n_fields; pos++) { field = dict_index_get_nth_field(index, pos); @@ -745,17 +747,17 @@ dict_table_get( UT_NOT_USED(trx); mutex_enter(&(dict_sys->mutex)); - + table = dict_table_get_low(table_name); mutex_exit(&(dict_sys->mutex)); if (table != NULL) { - if (!table->stat_initialized) { + if (!table->stat_initialized) { dict_update_statistics(table); } } - + return(table); } @@ -775,22 +777,22 @@ dict_table_get_and_increment_handle_count( UT_NOT_USED(trx); mutex_enter(&(dict_sys->mutex)); - + table = dict_table_get_low(table_name); if (table != NULL) { - table->n_mysql_handles_opened++; + table->n_mysql_handles_opened++; } mutex_exit(&(dict_sys->mutex)); if (table != NULL) { - if (!table->stat_initialized && !table->ibd_file_missing) { + if (!table->stat_initialized && !table->ibd_file_missing) { dict_update_statistics(table); } } - + return(table); } @@ -805,7 +807,7 @@ dict_table_add_to_cache( ulint fold; ulint id_fold; ulint i; - + ut_ad(table); #ifdef UNIV_SYNC_DEBUG ut_ad(mutex_own(&(dict_sys->mutex))); @@ -813,12 +815,12 @@ dict_table_add_to_cache( ut_ad(table->n_def == table->n_cols - DATA_N_SYS_COLS); ut_ad(table->magic_n == DICT_TABLE_MAGIC_N); ut_ad(table->cached == FALSE); - + fold = ut_fold_string(table->name); id_fold = ut_fold_dulint(table->id); - + table->cached = TRUE; - + /* NOTE: the system columns MUST be added in the following order (so that they can be indexed by the numerical value of DATA_ROW_ID, etc.) and as the last columns of the table memory object. @@ -847,7 +849,7 @@ dict_table_add_to_cache( #endif /* This check reminds that if a new system column is added to - the program, it should be dealt with here */ + the program, it should be dealt with here */ #if DATA_N_SYS_COLS != 4 #error "DATA_N_SYS_COLS != 4" #endif @@ -909,7 +911,7 @@ dict_index_find_on_id_low( { dict_table_t* table; dict_index_t* index; - + table = UT_LIST_GET_FIRST(dict_sys->table_LRU); while (table) { @@ -951,16 +953,16 @@ dict_table_rename_in_cache( char* old_name; ibool success; ulint i; - + ut_ad(table); #ifdef UNIV_SYNC_DEBUG ut_ad(mutex_own(&(dict_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ old_size = mem_heap_get_size(table->heap); - + fold = ut_fold_string(new_name); - + /* Look for a table with the same name: error if such exists */ { dict_table_t* table2; @@ -969,7 +971,7 @@ dict_table_rename_in_cache( if (table2) { fprintf(stderr, "InnoDB: Error: dictionary cache already contains a table of name %s\n", - new_name); + new_name); return(FALSE); } } @@ -1018,7 +1020,7 @@ dict_table_rename_in_cache( while (index != NULL) { index->table_name = table->name; - + index = dict_table_get_next_index(index); } @@ -1030,7 +1032,7 @@ dict_table_rename_in_cache( constraints from the dictionary cache here. The foreign key constraints will be inherited to the new table from the system tables through a call of dict_load_foreigns. */ - + /* Remove the foreign constraints from the cache */ foreign = UT_LIST_GET_LAST(table->foreign_list); @@ -1046,14 +1048,14 @@ dict_table_rename_in_cache( while (foreign != NULL) { foreign->referenced_table = NULL; foreign->referenced_index = NULL; - + foreign = UT_LIST_GET_NEXT(referenced_list, foreign); } /* Make the list of referencing constraints empty */ UT_LIST_INIT(table->referenced_list); - + return(TRUE); } @@ -1085,10 +1087,10 @@ dict_table_rename_in_cache( old_id = mem_strdup(foreign->id); if (ut_strlen(foreign->id) > ut_strlen(old_name) - + ((sizeof dict_ibfk) - 1) - && 0 == ut_memcmp(foreign->id, old_name, - ut_strlen(old_name)) - && 0 == ut_memcmp( + + ((sizeof dict_ibfk) - 1) + && 0 == ut_memcmp(foreign->id, old_name, + ut_strlen(old_name)) + && 0 == ut_memcmp( foreign->id + ut_strlen(old_name), dict_ibfk, (sizeof dict_ibfk) - 1)) { @@ -1096,11 +1098,11 @@ dict_table_rename_in_cache( if (ut_strlen(table->name) > ut_strlen(old_name)) { foreign->id = mem_heap_alloc( - foreign->heap, + foreign->heap, ut_strlen(table->name) + ut_strlen(old_id) + 1); } - + /* Replace the prefix 'databasename/tablename' with the new names */ strcpy(foreign->id, table->name); @@ -1112,16 +1114,16 @@ dict_table_rename_in_cache( db_len = dict_get_db_name_len(table->name) + 1; if (dict_get_db_name_len(table->name) - > dict_get_db_name_len(foreign->id)) { + > dict_get_db_name_len(foreign->id)) { foreign->id = mem_heap_alloc( - foreign->heap, - db_len + ut_strlen(old_id) + 1); + foreign->heap, + db_len + ut_strlen(old_id) + 1); } /* Replace the database prefix in id with the one from table->name */ - + ut_memcpy(foreign->id, table->name, db_len); strcpy(foreign->id + db_len, @@ -1194,7 +1196,7 @@ dict_table_remove_from_cache( dict_index_t* index; ulint size; ulint i; - + ut_ad(table); #ifdef UNIV_SYNC_DEBUG ut_ad(mutex_own(&(dict_sys->mutex))); @@ -1222,7 +1224,7 @@ dict_table_remove_from_cache( while (foreign != NULL) { foreign->referenced_table = NULL; foreign->referenced_index = NULL; - + foreign = UT_LIST_GET_NEXT(referenced_list, foreign); } @@ -1308,7 +1310,7 @@ dict_col_add_to_cache( ut_ad(mutex_own(&(dict_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ ut_ad(table->magic_n == DICT_TABLE_MAGIC_N); - + fold = ut_fold_ulint_pair(ut_fold_string(table->name), ut_fold_string(col->name)); @@ -1318,7 +1320,7 @@ dict_col_add_to_cache( HASH_SEARCH(hash, dict_sys->col_hash, fold, col2, (ut_strcmp(col->name, col2->name) == 0) && (ut_strcmp((col2->table)->name, table->name) - == 0)); + == 0)); ut_a(col2 == NULL); } @@ -1341,7 +1343,7 @@ dict_col_remove_from_cache( ut_ad(mutex_own(&(dict_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ ut_ad(table->magic_n == DICT_TABLE_MAGIC_N); - + fold = ut_fold_ulint_pair(ut_fold_string(table->name), ut_fold_string(col->name)); @@ -1366,7 +1368,7 @@ dict_col_reposition_in_cache( ut_ad(mutex_own(&(dict_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ ut_ad(table->magic_n == DICT_TABLE_MAGIC_N); - + fold = ut_fold_ulint_pair(ut_fold_string(table->name), ut_fold_string(col->name)); @@ -1374,7 +1376,7 @@ dict_col_reposition_in_cache( fold = ut_fold_ulint_pair(ut_fold_string(new_name), ut_fold_string(col->name)); - + HASH_INSERT(dict_col_t, hash, dict_sys->col_hash, fold, col); } @@ -1397,14 +1399,14 @@ dict_index_add_to_cache( ulint n_ord; ibool success; ulint i; - + ut_ad(index); #ifdef UNIV_SYNC_DEBUG ut_ad(mutex_own(&(dict_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ ut_ad(index->n_def == index->n_fields); ut_ad(index->magic_n == DICT_INDEX_MAGIC_N); - + ut_ad(mem_heap_validate(index->heap)); { @@ -1418,7 +1420,7 @@ dict_index_add_to_cache( } ut_a(UT_LIST_GET_LEN(table->indexes) == 0 - || (index->type & DICT_CLUSTERED) == 0); + || (index->type & DICT_CLUSTERED) == 0); } success = dict_index_find_cols(table, index); @@ -1428,7 +1430,7 @@ dict_index_add_to_cache( return(FALSE); } - + /* Build the cache internal representation of the index, containing also the added system fields */ @@ -1439,15 +1441,15 @@ dict_index_add_to_cache( } new_index->search_info = btr_search_info_create(new_index->heap); - + /* Set the n_fields value in new_index to the actual defined number of fields in the cache internal representation */ new_index->n_fields = new_index->n_def; - + /* Add the new index as the last index for the table */ - UT_LIST_ADD_LAST(indexes, table->indexes, new_index); + UT_LIST_ADD_LAST(indexes, table->indexes, new_index); new_index->table = table; new_index->table_name = table->name; @@ -1468,7 +1470,7 @@ dict_index_add_to_cache( if (table->type == DICT_TABLE_CLUSTER_MEMBER) { /* The index tree is found from the cluster object */ - + cluster = dict_table_get_low(table->cluster_name); tree = dict_index_get_tree( @@ -1496,10 +1498,10 @@ dict_index_add_to_cache( new_index->stat_n_diff_key_vals[i] = 100; } } - + /* Add the index to the list of indexes stored in the tree */ - UT_LIST_ADD_LAST(tree_indexes, tree->tree_indexes, new_index); - + UT_LIST_ADD_LAST(tree_indexes, tree->tree_indexes, new_index); + /* If the dictionary cache grows too big, trim the table LRU list */ dict_sys->size += mem_heap_get_size(new_index->heap); @@ -1563,13 +1565,13 @@ dict_index_find_cols( /*=================*/ /* out: TRUE if success */ dict_table_t* table, /* in: table */ - dict_index_t* index) /* in: index */ + dict_index_t* index) /* in: index */ { dict_col_t* col; dict_field_t* field; ulint fold; ulint i; - + ut_ad(table && index); ut_ad(table->magic_n == DICT_TABLE_MAGIC_N); #ifdef UNIV_SYNC_DEBUG @@ -1580,15 +1582,15 @@ dict_index_find_cols( field = dict_index_get_nth_field(index, i); fold = ut_fold_ulint_pair(ut_fold_string(table->name), - ut_fold_string(field->name)); - + ut_fold_string(field->name)); + HASH_SEARCH(hash, dict_sys->col_hash, fold, col, (ut_strcmp(col->name, field->name) == 0) && (ut_strcmp((col->table)->name, table->name) - == 0)); + == 0)); if (col == NULL) { - return(FALSE); + return(FALSE); } else { field->col = col; } @@ -1596,7 +1598,7 @@ dict_index_find_cols( return(TRUE); } - + /*********************************************************************** Adds a column to index. */ @@ -1605,12 +1607,11 @@ dict_index_add_col( /*===============*/ dict_index_t* index, /* in: index */ dict_col_t* col, /* in: column */ - ulint order, /* in: order criterion */ ulint prefix_len) /* in: column prefix length */ { dict_field_t* field; - dict_mem_index_add_field(index, col->name, order, prefix_len); + dict_mem_index_add_field(index, col->name, prefix_len); field = dict_index_get_nth_field(index, index->n_def - 1); @@ -1632,17 +1633,6 @@ dict_index_add_col( if (!(dtype_get_prtype(&col->type) & DATA_NOT_NULL)) { index->n_nullable++; } - - if (index->n_def > 1) { - const dict_field_t* field2 = - dict_index_get_nth_field(index, index->n_def - 2); - field->fixed_offs = (!field2->fixed_len || - field2->fixed_offs == ULINT_UNDEFINED) - ? ULINT_UNDEFINED - : field2->fixed_len + field2->fixed_offs; - } else { - field->fixed_offs = 0; - } } /*********************************************************************** @@ -1658,14 +1648,13 @@ dict_index_copy( { dict_field_t* field; ulint i; - + /* Copy fields contained in index2 */ for (i = start; i < end; i++) { field = dict_index_get_nth_field(index2, i); - dict_index_add_col(index1, field->col, field->order, - field->prefix_len); + dict_index_add_col(index1, field->col, field->prefix_len); } } @@ -1732,7 +1721,7 @@ dict_index_build_internal_clust( of the clustered index */ dict_table_t* table, /* in: table */ dict_index_t* index) /* in: user representation of a clustered - index */ + index */ { dict_index_t* new_index; dict_field_t* field; @@ -1750,26 +1739,24 @@ dict_index_build_internal_clust( /* Create a new index object with certainly enough fields */ new_index = dict_mem_index_create(table->name, - index->name, - table->space, - index->type, - index->n_fields + table->n_cols); + index->name, table->space, index->type, + index->n_fields + table->n_cols); /* Copy other relevant data from the old index struct to the new struct: it inherits the values */ new_index->n_user_defined_cols = index->n_fields; - + new_index->id = index->id; if (table->type != DICT_TABLE_ORDINARY) { /* The index is mixed: copy common key prefix fields */ - + dict_index_copy(new_index, index, 0, table->mix_len); /* Add the mix id column */ dict_index_add_col(new_index, - dict_table_get_sys_col(table, DATA_MIX_ID), 0, 0); + dict_table_get_sys_col(table, DATA_MIX_ID), 0); /* Copy the rest of fields */ dict_index_copy(new_index, index, table->mix_len, @@ -1783,7 +1770,7 @@ dict_index_build_internal_clust( /* No fixed number of fields determines an entry uniquely */ new_index->n_uniq = ULINT_MAX; - + } else if (index->type & DICT_UNIQUE) { /* Only the fields defined so far are needed to identify the index entry uniquely */ @@ -1801,21 +1788,27 @@ dict_index_build_internal_clust( trx_id_pos = new_index->n_def; - ut_ad(DATA_ROW_ID == 0); - ut_ad(DATA_TRX_ID == 1); - ut_ad(DATA_ROLL_PTR == 2); +#if DATA_ROW_ID != 0 +# error "DATA_ROW_ID != 0" +#endif +#if DATA_TRX_ID != 1 +# error "DATA_TRX_ID != 1" +#endif +#if DATA_ROLL_PTR != 2 +# error "DATA_ROLL_PTR != 2" +#endif if (!(index->type & DICT_UNIQUE)) { dict_index_add_col(new_index, - dict_table_get_sys_col(table, DATA_ROW_ID), 0, 0); + dict_table_get_sys_col(table, DATA_ROW_ID), 0); trx_id_pos++; } dict_index_add_col(new_index, - dict_table_get_sys_col(table, DATA_TRX_ID), 0, 0); - + dict_table_get_sys_col(table, DATA_TRX_ID), 0); + dict_index_add_col(new_index, - dict_table_get_sys_col(table, DATA_ROLL_PTR), 0, 0); + dict_table_get_sys_col(table, DATA_ROLL_PTR), 0); for (i = 0; i < trx_id_pos; i++) { @@ -1829,7 +1822,7 @@ dict_index_build_internal_clust( } if (dict_index_get_nth_field(new_index, i)->prefix_len - > 0) { + > 0) { new_index->trx_id_offset = 0; break; @@ -1857,10 +1850,10 @@ dict_index_build_internal_clust( if (field->prefix_len == 0) { - field->col->aux = 0; + field->col->aux = 0; } } - + /* Add to new_index non-system columns of table not yet included there */ for (i = 0; i < table->n_cols - DATA_N_SYS_COLS; i++) { @@ -1869,7 +1862,7 @@ dict_index_build_internal_clust( ut_ad(col->type.mtype != DATA_SYS); if (col->aux == ULINT_UNDEFINED) { - dict_index_add_col(new_index, col, 0, 0); + dict_index_add_col(new_index, col, 0); } } @@ -1884,14 +1877,14 @@ dict_index_build_internal_clust( if (field->prefix_len == 0) { - field->col->clust_pos = i; + field->col->clust_pos = i; } } - + new_index->cached = TRUE; return(new_index); -} +} /*********************************************************************** Builds the internal dictionary cache representation for a non-clustered @@ -1904,7 +1897,7 @@ dict_index_build_internal_non_clust( of the non-clustered index */ dict_table_t* table, /* in: table */ dict_index_t* index) /* in: user representation of a non-clustered - index */ + index */ { dict_field_t* field; dict_index_t* new_index; @@ -1920,24 +1913,21 @@ dict_index_build_internal_non_clust( /* The clustered index should be the first in the list of indexes */ clust_index = UT_LIST_GET_FIRST(table->indexes); - + ut_ad(clust_index); ut_ad(clust_index->type & DICT_CLUSTERED); ut_ad(!(clust_index->type & DICT_UNIVERSAL)); /* Create a new index */ new_index = dict_mem_index_create(table->name, - index->name, - index->space, - index->type, - index->n_fields - + 1 + clust_index->n_uniq); + index->name, index->space, index->type, + index->n_fields + 1 + clust_index->n_uniq); /* Copy other relevant data from the old index struct to the new struct: it inherits the values */ new_index->n_user_defined_cols = index->n_fields; - + new_index->id = index->id; /* Copy fields from index to new_index */ @@ -1961,7 +1951,7 @@ dict_index_build_internal_non_clust( if (field->prefix_len == 0) { - field->col->aux = 0; + field->col->aux = 0; } } @@ -1973,8 +1963,8 @@ dict_index_build_internal_non_clust( field = dict_index_get_nth_field(clust_index, i); if (field->col->aux == ULINT_UNDEFINED) { - dict_index_add_col(new_index, field->col, 0, - field->prefix_len); + dict_index_add_col(new_index, field->col, + field->prefix_len); } } @@ -1992,7 +1982,7 @@ dict_index_build_internal_non_clust( new_index->cached = TRUE; return(new_index); -} +} /*====================== FOREIGN KEY PROCESSING ========================*/ @@ -2007,7 +1997,7 @@ dict_table_referenced_by_foreign_key( dict_table_t* table) /* in: InnoDB table */ { if (UT_LIST_GET_LEN(table->referenced_list) > 0) { - + return(TRUE); } @@ -2037,7 +2027,7 @@ dict_foreign_remove_from_cache( ut_ad(mutex_own(&(dict_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ ut_a(foreign); - + if (foreign->referenced_table) { UT_LIST_REMOVE(referenced_list, foreign->referenced_table->referenced_list, foreign); @@ -2078,7 +2068,7 @@ dict_foreign_find( foreign = UT_LIST_GET_NEXT(foreign_list, foreign); } - + foreign = UT_LIST_GET_FIRST(table->referenced_list); while (foreign) { @@ -2091,7 +2081,7 @@ dict_foreign_find( } return(NULL); -} +} /************************************************************************* Tries to find an index whose first fields are the columns in the array, @@ -2104,14 +2094,17 @@ dict_foreign_find_index( dict_table_t* table, /* in: table */ const char** columns,/* in: array of column names */ ulint n_cols, /* in: number of columns */ - dict_index_t* types_idx)/* in: NULL or an index to whose types the - column types must match */ + dict_index_t* types_idx, /* in: NULL or an index to whose types the + column types must match */ + ibool check_charsets) /* in: whether to check charsets. + only has an effect if types_idx != + NULL. */ { #ifndef UNIV_HOTBACKUP dict_index_t* index; const char* col_name; ulint i; - + index = dict_table_get_first_index(table); while (index != NULL) { @@ -2124,21 +2117,22 @@ dict_foreign_find_index( ->prefix_len != 0) { /* We do not accept column prefix indexes here */ - + break; } if (0 != innobase_strcasecmp(columns[i], col_name)) { - break; + break; } if (types_idx && !cmp_types_are_equal( - dict_index_get_nth_type(index, i), - dict_index_get_nth_type(types_idx, i))) { + dict_index_get_nth_type(index, i), + dict_index_get_nth_type(types_idx, i), + check_charsets)) { - break; - } + break; + } } if (i == n_cols) { @@ -2157,6 +2151,7 @@ dict_foreign_find_index( InnoDB Hot Backup builds. Besides, this function should never be called in InnoDB Hot Backup. */ ut_error; + return(NULL); #endif /* UNIV_HOTBACKUP */ } @@ -2190,8 +2185,9 @@ dict_foreign_error_report( fputs(msg, file); fputs(" Constraint:\n", file); dict_print_info_on_foreign_key_in_create_format(file, NULL, fk, TRUE); + putc('\n', file); if (fk->foreign_index) { - fputs("\nThe index in the foreign key in table is ", file); + fputs("The index in the foreign key in table is ", file); ut_print_name(file, NULL, fk->foreign_index->name); fputs( "\nSee http://dev.mysql.com/doc/mysql/en/InnoDB_foreign_key_constraints.html\n" @@ -2212,14 +2208,15 @@ dict_foreign_add_to_cache( /*======================*/ /* out: DB_SUCCESS or error code */ dict_foreign_t* foreign, /* in, own: foreign key constraint */ - ibool check_types) /* in: TRUE=check type compatibility */ + ibool check_charsets) /* in: TRUE=check charset + compatibility */ { dict_table_t* for_table; dict_table_t* ref_table; dict_foreign_t* for_in_cache = NULL; dict_index_t* index; ibool added_to_referenced_list= FALSE; - FILE* ef = dict_foreign_err_file; + FILE* ef = dict_foreign_err_file; #ifdef UNIV_SYNC_DEBUG ut_ad(mutex_own(&(dict_sys->mutex))); @@ -2227,7 +2224,7 @@ dict_foreign_add_to_cache( for_table = dict_table_check_if_in_cache_low( foreign->foreign_table_name); - + ref_table = dict_table_check_if_in_cache_low( foreign->referenced_table_name); ut_a(for_table || ref_table); @@ -2248,16 +2245,10 @@ dict_foreign_add_to_cache( } if (for_in_cache->referenced_table == NULL && ref_table) { - dict_index_t* types_idx; - if (check_types) { - types_idx = for_in_cache->foreign_index; - } else { - types_idx = NULL; - } index = dict_foreign_find_index(ref_table, (const char**) for_in_cache->referenced_col_names, for_in_cache->n_fields, - types_idx); + for_in_cache->foreign_index, check_charsets); if (index == NULL) { dict_foreign_error_report(ef, for_in_cache, @@ -2269,7 +2260,7 @@ dict_foreign_add_to_cache( mem_heap_free(foreign->heap); } - return(DB_CANNOT_ADD_CONSTRAINT); + return(DB_CANNOT_ADD_CONSTRAINT); } for_in_cache->referenced_table = ref_table; @@ -2281,16 +2272,10 @@ dict_foreign_add_to_cache( } if (for_in_cache->foreign_table == NULL && for_table) { - dict_index_t* types_idx; - if (check_types) { - types_idx = for_in_cache->referenced_index; - } else { - types_idx = NULL; - } index = dict_foreign_find_index(for_table, (const char**) for_in_cache->foreign_col_names, for_in_cache->n_fields, - types_idx); + for_in_cache->referenced_index, check_charsets); if (index == NULL) { dict_foreign_error_report(ef, for_in_cache, @@ -2304,11 +2289,11 @@ dict_foreign_add_to_cache( ref_table->referenced_list, for_in_cache); } - + mem_heap_free(foreign->heap); } - return(DB_CANNOT_ADD_CONSTRAINT); + return(DB_CANNOT_ADD_CONSTRAINT); } for_in_cache->foreign_table = for_table; @@ -2381,15 +2366,15 @@ dict_accept( const char* old_ptr2; *success = FALSE; - + while (isspace(*ptr)) { ptr++; } old_ptr2 = ptr; - + ptr = dict_scan_to(ptr, string); - + if (*ptr == '\0' || old_ptr2 != ptr) { return(old_ptr); } @@ -2459,8 +2444,8 @@ dict_scan_id( } } else { while (!isspace(*ptr) && *ptr != '(' && *ptr != ')' - && (accept_also_dot || *ptr != '.') - && *ptr != ',' && *ptr != '\0') { + && (accept_also_dot || *ptr != '.') + && *ptr != ',' && *ptr != '\0') { ptr++; } @@ -2497,9 +2482,9 @@ dict_scan_id( b = (byte*)(*id); id_len = strlen((char*) b); - + if (id_len >= 3 && b[id_len - 1] == 0xA0 - && b[id_len - 2] == 0xC2) { + && b[id_len - 2] == 0xC2) { /* Strip the 2 last bytes */ @@ -2542,28 +2527,29 @@ dict_scan_col( *success = TRUE; *column = NULL; } else { - for (i = 0; i < dict_table_get_n_cols(table); i++) { + for (i = 0; i < dict_table_get_n_cols(table); i++) { col = dict_table_get_nth_col(table, i); if (0 == innobase_strcasecmp(col->name, *name)) { - /* Found */ + /* Found */ - *success = TRUE; - *column = col; - strcpy((char*) *name, col->name); + *success = TRUE; + *column = col; + strcpy((char*) *name, col->name); - break; + break; } } } - + return(ptr); #else /* UNIV_HOTBACKUP */ /* This function depends on MySQL code that is not included in InnoDB Hot Backup builds. Besides, this function should never be called in InnoDB Hot Backup. */ ut_error; + return(NULL); #endif /* UNIV_HOTBACKUP */ } @@ -2592,11 +2578,11 @@ dict_scan_table_name( *success = FALSE; *table = NULL; - - ptr = dict_scan_id(ptr, heap, &scan_name, FALSE); + + ptr = dict_scan_id(ptr, heap, &scan_name, FALSE); if (scan_name == NULL) { - + return(ptr); /* Syntax error */ } @@ -2669,6 +2655,7 @@ dict_scan_table_name( InnoDB Hot Backup builds. Besides, this function should never be called in InnoDB Hot Backup. */ ut_error; + return(NULL); #endif /* UNIV_HOTBACKUP */ } @@ -2684,7 +2671,7 @@ dict_skip_word( left in string or a syntax error */ { const char* start; - + *success = FALSE; ptr = dict_scan_id(ptr, NULL, &start, TRUE); @@ -2692,7 +2679,7 @@ dict_skip_word( if (start) { *success = TRUE; } - + return(ptr); } @@ -2714,8 +2701,8 @@ dict_strip_comments( char* str; const char* sptr; char* ptr; - /* unclosed quote character (0 if none) */ - char quote = 0; + /* unclosed quote character (0 if none) */ + char quote = 0; str = mem_alloc(strlen(sql_string) + 1); @@ -2743,15 +2730,15 @@ scan_more: /* Starting quote: remember the quote character. */ quote = *sptr; } else if (*sptr == '#' - || (sptr[0] == '-' && sptr[1] == '-' && - sptr[2] == ' ')) { + || (sptr[0] == '-' && sptr[1] == '-' && + sptr[2] == ' ')) { for (;;) { /* In Unix a newline is 0x0A while in Windows it is 0x0D followed by 0x0A */ if (*sptr == (char)0x0A - || *sptr == (char)0x0D - || *sptr == '\0') { + || *sptr == (char)0x0D + || *sptr == '\0') { goto scan_more; } @@ -2762,7 +2749,7 @@ scan_more: for (;;) { if (*sptr == '*' && *(sptr + 1) == '/') { - sptr += 2; + sptr += 2; goto scan_more; } @@ -2808,9 +2795,10 @@ dict_table_get_highest_foreign_id( while (foreign) { if (ut_strlen(foreign->id) > ((sizeof dict_ibfk) - 1) + len - && 0 == ut_memcmp(foreign->id, table->name, len) - && 0 == ut_memcmp(foreign->id + len, - dict_ibfk, (sizeof dict_ibfk) - 1)) { + && 0 == ut_memcmp(foreign->id, table->name, len) + && 0 == ut_memcmp(foreign->id + len, + dict_ibfk, (sizeof dict_ibfk) - 1) + && foreign->id[len + ((sizeof dict_ibfk) - 1)] != '0') { /* It is of the >= 4.0.18 format */ id = strtoul(foreign->id + len + ((sizeof dict_ibfk) - 1), @@ -2884,7 +2872,7 @@ dict_create_foreign_constraints_low( ulint highest_id_so_far = 0; dict_index_t* index; dict_foreign_t* foreign; - const char* ptr = sql_string; + const char* ptr = sql_string; const char* start_of_latest_foreign = sql_string; FILE* ef = dict_foreign_err_file; const char* constraint_name; @@ -2900,7 +2888,7 @@ dict_create_foreign_constraints_low( dict_col_t* columns[500]; const char* column_names[500]; const char* referenced_table_name; - + #ifdef UNIV_SYNC_DEBUG ut_ad(mutex_own(&(dict_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ @@ -2982,7 +2970,7 @@ loop: ut_a(success); if (!isspace(*ptr) && *ptr != '"' && *ptr != '`') { - goto loop; + goto loop; } while (isspace(*ptr)) { @@ -3005,15 +2993,14 @@ loop: command, determine if there are any foreign keys, and if so, immediately reject the command if the table is a temporary one. For now, this kludge will work. */ - if (reject_fks && (UT_LIST_GET_LEN(table->foreign_list) > 0)) - { + if (reject_fks && (UT_LIST_GET_LEN(table->foreign_list) > 0)) { return DB_CANNOT_ADD_CONSTRAINT; } - + /**********************************************************/ /* The following call adds the foreign key constraints to the data dictionary system tables on disk */ - + error = dict_create_add_foreigns_to_dictionary( highest_id_so_far, table, trx); return(error); @@ -3021,14 +3008,14 @@ loop: start_of_latest_foreign = ptr; - ptr = dict_accept(ptr, "FOREIGN", &success); - + ptr = dict_accept(ptr, "FOREIGN", &success); + if (!success) { goto loop; } if (!isspace(*ptr)) { - goto loop; + goto loop; } ptr = dict_accept(ptr, "KEY", &success); @@ -3057,7 +3044,7 @@ loop: /* We do not flag a syntax error here because in an ALTER TABLE we may also have DROP FOREIGN KEY abc */ - goto loop; + goto loop; } } @@ -3079,13 +3066,13 @@ col_loop1: } i++; - + ptr = dict_accept(ptr, ",", &success); if (success) { goto col_loop1; } - + ptr = dict_accept(ptr, ")", &success); if (!success) { @@ -3097,7 +3084,7 @@ col_loop1: /* Try to find an index which contains the columns as the first fields and in the right order */ - index = dict_foreign_find_index(table, column_names, i, NULL); + index = dict_foreign_find_index(table, column_names, i, NULL, TRUE); if (!index) { mutex_enter(&dict_foreign_err_mutex); @@ -3126,7 +3113,7 @@ col_loop1: foreign = dict_mem_foreign_create(); if (constraint_name) { - ulint db_len; + ulint db_len; /* Catenate 'databasename/' to the constraint name specified by the user: we conceive the constraint as belonging to the @@ -3154,7 +3141,7 @@ col_loop1: foreign->foreign_col_names[i] = mem_heap_strdup(foreign->heap, columns[i]->name); } - + ptr = dict_scan_table_name(ptr, &referenced_table, name, &success, heap, &referenced_table_name); @@ -3173,7 +3160,7 @@ col_loop1: return(DB_CANNOT_ADD_CONSTRAINT); } - + ptr = dict_accept(ptr, "(", &success); if (!success) { @@ -3190,7 +3177,7 @@ col_loop2: ptr = dict_scan_col(ptr, &success, referenced_table, columns + i, heap, column_names + i); i++; - + if (!success) { dict_foreign_free(foreign); @@ -3209,12 +3196,12 @@ col_loop2: if (success) { goto col_loop2; } - + ptr = dict_accept(ptr, ")", &success); if (!success || foreign->n_fields != i) { dict_foreign_free(foreign); - + dict_foreign_report_syntax_err(name, start_of_latest_foreign, ptr); return(DB_CANNOT_ADD_CONSTRAINT); @@ -3222,7 +3209,7 @@ col_loop2: n_on_deletes = 0; n_on_updates = 0; - + scan_on_conditions: /* Loop here as long as we can find ON ... conditions */ @@ -3240,7 +3227,7 @@ scan_on_conditions: if (!success) { dict_foreign_free(foreign); - + dict_foreign_report_syntax_err(name, start_of_latest_foreign, ptr); return(DB_CANNOT_ADD_CONSTRAINT); @@ -3280,7 +3267,7 @@ scan_on_conditions: dict_foreign_free(foreign); dict_foreign_report_syntax_err(name, start_of_latest_foreign, ptr); - + return(DB_CANNOT_ADD_CONSTRAINT); } @@ -3337,13 +3324,13 @@ scan_on_conditions: } else { foreign->type |= DICT_FOREIGN_ON_UPDATE_SET_NULL; } - + goto scan_on_conditions; try_find_index: if (n_on_deletes > 1 || n_on_updates > 1) { /* It is an error to define more than 1 action */ - + dict_foreign_free(foreign); mutex_enter(&dict_foreign_err_mutex); @@ -3362,8 +3349,7 @@ try_find_index: if (referenced_table) { index = dict_foreign_find_index(referenced_table, - column_names, i, - foreign->foreign_index); + column_names, i, foreign->foreign_index, TRUE); if (!index) { dict_foreign_free(foreign); mutex_enter(&dict_foreign_err_mutex); @@ -3392,7 +3378,7 @@ try_find_index: foreign->referenced_table_name = mem_heap_strdup(foreign->heap, referenced_table_name); - + foreign->referenced_col_names = mem_heap_alloc(foreign->heap, i * sizeof(void*)); for (i = 0; i < foreign->n_fields; i++) { @@ -3401,7 +3387,7 @@ try_find_index: } /* We found an ok constraint definition: add to the lists */ - + UT_LIST_ADD_LAST(foreign_list, table->foreign_list, foreign); if (referenced_table) { @@ -3453,7 +3439,7 @@ dict_create_foreign_constraints( mem_heap_free(heap); mem_free(str); - return(err); + return(err); } /************************************************************************** @@ -3481,7 +3467,7 @@ dict_foreign_parse_drop_constraints( const char* ptr; const char* id; FILE* ef = dict_foreign_err_file; - + *n = 0; *constraints_to_drop = mem_heap_alloc(heap, 1000 * sizeof(char*)); @@ -3497,7 +3483,7 @@ loop: if (*ptr == '\0') { mem_free(str); - + return(DB_SUCCESS); } @@ -3505,14 +3491,14 @@ loop: if (!isspace(*ptr)) { - goto loop; + goto loop; } ptr = dict_accept(ptr, "FOREIGN", &success); - + if (!success) { - goto loop; + goto loop; } ptr = dict_accept(ptr, "KEY", &success); @@ -3532,20 +3518,20 @@ loop: ut_a(*n < 1000); (*constraints_to_drop)[*n] = id; (*n)++; - + /* Look for the given constraint id */ foreign = UT_LIST_GET_FIRST(table->foreign_list); while (foreign != NULL) { if (0 == strcmp(foreign->id, id) - || (strchr(foreign->id, '/') - && 0 == strcmp(id, + || (strchr(foreign->id, '/') + && 0 == strcmp(id, dict_remove_db_name(foreign->id)))) { /* Found */ break; } - + foreign = UT_LIST_GET_NEXT(foreign_list, foreign); } @@ -3569,7 +3555,7 @@ loop: return(DB_CANNOT_DROP_CONSTRAINT); } - goto loop; + goto loop; syntax_error: mutex_enter(&dict_foreign_err_mutex); @@ -3606,7 +3592,7 @@ dict_index_get_if_in_cache( } mutex_enter(&(dict_sys->mutex)); - + table = UT_LIST_GET_FIRST(dict_sys->table_LRU); while (table) { @@ -3654,7 +3640,7 @@ dict_tree_create( tree->page = page_no; tree->id = index->id; - + UT_LIST_INIT(tree->tree_indexes); tree->magic_n = DICT_TREE_MAGIC_N; @@ -3696,16 +3682,16 @@ dict_tree_find_index_low( dict_table_t* table; dulint mix_id; ulint len; - + index = UT_LIST_GET_FIRST(tree->tree_indexes); ut_ad(index); table = index->table; - + if ((index->type & DICT_CLUSTERED) && UNIV_UNLIKELY(table->type != DICT_TABLE_ORDINARY)) { /* Get the mix id of the record */ - ut_a(!table->comp); + ut_a(!dict_table_is_comp(table)); mix_id = mach_dulint_read_compressed( rec_get_nth_field_old(rec, table->mix_len, &len)); @@ -3733,9 +3719,9 @@ dict_tree_find_index( index */ { dict_index_t* index; - + index = dict_tree_find_index_low(tree, rec); - + return(index); } @@ -3756,7 +3742,7 @@ dict_tree_find_index_for_tuple( dulint mix_id; ut_ad(dtuple_check_typed(tuple)); - + if (UT_LIST_GET_LEN(tree->tree_indexes) == 1) { return(UT_LIST_GET_FIRST(tree->tree_indexes)); @@ -3801,7 +3787,7 @@ dict_is_mixed_table_rec( byte* mix_id_field; ulint len; - ut_ad(!table->comp); + ut_ad(!dict_table_is_comp(table)); mix_id_field = rec_get_nth_field_old(rec, table->mix_len, &len); @@ -3847,7 +3833,7 @@ dict_tree_build_node_ptr( pointer */ ulint page_no,/* in: page number to put in node pointer */ mem_heap_t* heap, /* in: memory heap where pointer created */ - ulint level) /* in: level of rec in tree: 0 means leaf + ulint level) /* in: level of rec in tree: 0 means leaf level */ { dtuple_t* tuple; @@ -3857,21 +3843,21 @@ dict_tree_build_node_ptr( ulint n_unique; ind = dict_tree_find_index_low(tree, rec); - + if (UNIV_UNLIKELY(tree->type & DICT_UNIVERSAL)) { /* In a universal index tree, we take the whole record as the node pointer if the reord is on the leaf level, on non-leaf levels we remove the last field, which contains the page number of the child page */ - ut_a(!ind->table->comp); + ut_a(!dict_table_is_comp(ind->table)); n_unique = rec_get_n_fields_old(rec); if (level > 0) { - ut_a(n_unique > 1); - n_unique--; + ut_a(n_unique > 1); + n_unique--; } - } else { + } else { n_unique = dict_index_get_n_unique_in_tree(ind); } @@ -3882,15 +3868,15 @@ dict_tree_build_node_ptr( levels in the tree there may be identical node pointers with a different page number; therefore, we set the n_fields_cmp to one less: */ - + dtuple_set_n_fields_cmp(tuple, n_unique); dict_index_copy_types(tuple, ind, n_unique); - + buf = mem_heap_alloc(heap, 4); mach_write_to_4(buf, page_no); - + field = dtuple_get_nth_field(tuple, n_unique); dfield_set_data(field, buf, 4); @@ -3903,8 +3889,8 @@ dict_tree_build_node_ptr( ut_ad(dtuple_check_typed(tuple)); return(tuple); -} - +} + /************************************************************************** Copies an initial segment of a physical record, long enough to specify an index entry uniquely. */ @@ -3927,7 +3913,7 @@ dict_tree_copy_rec_order_prefix( index = dict_tree_find_index_low(tree, rec); if (UNIV_UNLIKELY(tree->type & DICT_UNIVERSAL)) { - ut_a(!index->table->comp); + ut_a(!dict_table_is_comp(index->table)); n = rec_get_n_fields_old(rec); } else { n = dict_index_get_n_unique_in_tree(index); @@ -3954,9 +3940,10 @@ dict_tree_build_data_tuple( ind = dict_tree_find_index_low(tree, rec); - ut_ad(ind->table->comp || n_fields <= rec_get_n_fields_old(rec)); - - tuple = dtuple_create(heap, n_fields); + ut_ad(dict_table_is_comp(ind->table) + || n_fields <= rec_get_n_fields_old(rec)); + + tuple = dtuple_create(heap, n_fields); dict_index_copy_types(tuple, ind, n_fields); @@ -3965,8 +3952,8 @@ dict_tree_build_data_tuple( ut_ad(dtuple_check_typed(tuple)); return(tuple); -} - +} + /************************************************************************* Calculates the minimum record length in an index. */ @@ -3978,7 +3965,7 @@ dict_index_calc_min_rec_len( ulint sum = 0; ulint i; - if (UNIV_LIKELY(index->table->comp)) { + if (dict_table_is_comp(index->table)) { ulint nullable = 0; sum = REC_N_NEW_EXTRA_BYTES; for (i = 0; i < dict_index_get_n_fields(index); i++) { @@ -4023,8 +4010,8 @@ dict_update_statistics_low( /*=======================*/ dict_table_t* table, /* in: table */ ibool has_dict_mutex __attribute__((unused))) - /* in: TRUE if the caller has the - dictionary mutex */ + /* in: TRUE if the caller has the + dictionary mutex */ { dict_index_t* index; ulint size; @@ -4053,11 +4040,11 @@ dict_update_statistics_low( /* Find out the sizes of the indexes and how many different values for the key they approximately have */ - index = dict_table_get_first_index(table); + index = dict_table_get_first_index(table); if (index == NULL) { /* Table definition is corrupt */ - + return; } @@ -4076,7 +4063,7 @@ dict_update_statistics_low( } index->stat_n_leaf_pages = size; - + btr_estimate_number_of_different_key_vals(index); index = dict_table_get_next_index(index); @@ -4094,7 +4081,7 @@ dict_update_statistics_low( table->stat_initialized = TRUE; - table->stat_modified_counter = 0; + table->stat_modified_counter = 0; } /************************************************************************* @@ -4133,7 +4120,7 @@ dict_foreign_print_low( fprintf(stderr, " )\n" " REFERENCES %s (", foreign->referenced_table_name); - + for (i = 0; i < foreign->n_fields; i++) { fprintf(stderr, " %s", foreign->referenced_col_names[i]); } @@ -4169,7 +4156,7 @@ dict_table_print_by_name( table = dict_table_get_low(name); ut_a(table); - + dict_table_print_low(table); mutex_exit(&(dict_sys->mutex)); } @@ -4191,7 +4178,7 @@ dict_table_print_low( #endif /* UNIV_SYNC_DEBUG */ dict_update_statistics_low(table, TRUE); - + fprintf(stderr, "--------------------------------------\n" "TABLE: name %s, id %lu %lu, columns %lu, indexes %lu, appr.rows %lu\n" @@ -4200,7 +4187,7 @@ dict_table_print_low( (ulong) ut_dulint_get_high(table->id), (ulong) ut_dulint_get_low(table->id), (ulong) table->n_cols, - (ulong) UT_LIST_GET_LEN(table->indexes), + (ulong) UT_LIST_GET_LEN(table->indexes), (ulong) table->stat_n_rows); for (i = 0; i < table->n_cols - 1; i++) { @@ -4278,7 +4265,7 @@ dict_index_print_low( } fprintf(stderr, - " INDEX: name %s, id %lu %lu, fields %lu/%lu, type %lu\n" + " INDEX: name %s, id %lu %lu, fields %lu/%lu, uniq %lu, type %lu\n" " root page %lu, appr.key vals %lu," " leaf pages %lu, size pages %lu\n" " FIELDS: ", @@ -4286,12 +4273,14 @@ dict_index_print_low( (ulong) ut_dulint_get_high(tree->id), (ulong) ut_dulint_get_low(tree->id), (ulong) index->n_user_defined_cols, - (ulong) index->n_fields, (ulong) index->type, + (ulong) index->n_fields, + (ulong) index->n_uniq, + (ulong) index->type, (ulong) tree->page, (ulong) n_vals, (ulong) index->stat_n_leaf_pages, (ulong) index->stat_index_size); - + for (i = 0; i < index->n_fields; i++) { dict_field_print_low(dict_index_get_nth_field(index, i)); } @@ -4337,7 +4326,7 @@ dict_print_info_on_foreign_key_in_create_format( { const char* stripped_id; ulint i; - + if (strchr(foreign->id, '/')) { /* Strip the preceding database name from the constraint id */ stripped_id = foreign->id + 1 @@ -4347,14 +4336,14 @@ dict_print_info_on_foreign_key_in_create_format( } putc(',', file); - + if (add_newline) { /* SHOW CREATE TABLE wants constraints each printed nicely on its own line, while error messages want no newlines inserted. */ fputs("\n ", file); } - + fputs(" CONSTRAINT ", file); ut_print_name(file, trx, stripped_id); fputs(" FOREIGN KEY (", file); @@ -4363,7 +4352,7 @@ dict_print_info_on_foreign_key_in_create_format( ut_print_name(file, trx, foreign->foreign_col_names[i]); if (++i < foreign->n_fields) { fputs(", ", file); - } else { + } else { break; } } @@ -4406,7 +4395,7 @@ dict_print_info_on_foreign_key_in_create_format( if (foreign->type & DICT_FOREIGN_ON_DELETE_CASCADE) { fputs(" ON DELETE CASCADE", file); } - + if (foreign->type & DICT_FOREIGN_ON_DELETE_SET_NULL) { fputs(" ON DELETE SET NULL", file); } @@ -4418,7 +4407,7 @@ dict_print_info_on_foreign_key_in_create_format( if (foreign->type & DICT_FOREIGN_ON_UPDATE_CASCADE) { fputs(" ON UPDATE CASCADE", file); } - + if (foreign->type & DICT_FOREIGN_ON_UPDATE_SET_NULL) { fputs(" ON UPDATE SET NULL", file); } @@ -4489,7 +4478,7 @@ dict_print_info_on_foreign_keys( if (foreign->type == DICT_FOREIGN_ON_DELETE_CASCADE) { fputs(" ON DELETE CASCADE", file); } - + if (foreign->type == DICT_FOREIGN_ON_DELETE_SET_NULL) { fputs(" ON DELETE SET NULL", file); } @@ -4501,7 +4490,7 @@ dict_print_info_on_foreign_keys( if (foreign->type & DICT_FOREIGN_ON_UPDATE_CASCADE) { fputs(" ON UPDATE CASCADE", file); } - + if (foreign->type & DICT_FOREIGN_ON_UPDATE_SET_NULL) { fputs(" ON UPDATE SET NULL", file); } diff --git a/storage/innobase/dict/dict0load.c b/storage/innobase/dict/dict0load.c index 9bafcf33553..09935c03288 100644 --- a/storage/innobase/dict/dict0load.c +++ b/storage/innobase/dict/dict0load.c @@ -47,18 +47,18 @@ dict_get_first_table_name_in_db( byte* field; ulint len; mtr_t mtr; - + #ifdef UNIV_SYNC_DEBUG ut_ad(mutex_own(&(dict_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ heap = mem_heap_create(1000); - + mtr_start(&mtr); sys_tables = dict_table_get_low("SYS_TABLES"); sys_index = UT_LIST_GET_FIRST(sys_tables->indexes); - ut_a(!sys_tables->comp); + ut_a(!dict_table_is_comp(sys_tables)); tuple = dtuple_create(heap, 1); dfield = dtuple_get_nth_field(tuple, 0); @@ -77,36 +77,36 @@ loop: btr_pcur_close(&pcur); mtr_commit(&mtr); mem_heap_free(heap); - + return(NULL); - } + } field = rec_get_nth_field_old(rec, 0, &len); if (len < strlen(name) - || ut_memcmp(name, field, strlen(name)) != 0) { + || ut_memcmp(name, field, strlen(name)) != 0) { /* Not found */ btr_pcur_close(&pcur); mtr_commit(&mtr); mem_heap_free(heap); - + return(NULL); } - if (!rec_get_deleted_flag(rec, sys_tables->comp)) { + if (!rec_get_deleted_flag(rec, 0)) { /* We found one */ - char* table_name = mem_strdupl((char*) field, len); - + char* table_name = mem_strdupl((char*) field, len); + btr_pcur_close(&pcur); mtr_commit(&mtr); mem_heap_free(heap); - + return(table_name); } - + btr_pcur_move_to_next_user_rec(&pcur, &mtr); goto loop; @@ -128,7 +128,7 @@ dict_print(void) byte* field; ulint len; mtr_t mtr; - + /* Enlarge the fatal semaphore wait timeout during the InnoDB table monitor printout */ @@ -155,7 +155,7 @@ loop: btr_pcur_close(&pcur); mtr_commit(&mtr); - + mutex_exit(&(dict_sys->mutex)); /* Restore the fatal semaphore wait timeout */ @@ -165,15 +165,15 @@ loop: mutex_exit(&kernel_mutex); return; - } + } field = rec_get_nth_field_old(rec, 0, &len); - if (!rec_get_deleted_flag(rec, sys_tables->comp)) { + if (!rec_get_deleted_flag(rec, 0)) { /* We found one */ - char* table_name = mem_strdupl((char*) field, len); + char* table_name = mem_strdupl((char*) field, len); btr_pcur_store_position(&pcur, &mtr); @@ -228,14 +228,14 @@ dict_check_tablespaces_and_store_max_id( ulint space_id; ulint max_space_id = 0; mtr_t mtr; - + mutex_enter(&(dict_sys->mutex)); mtr_start(&mtr); sys_tables = dict_table_get_low("SYS_TABLES"); sys_index = UT_LIST_GET_FIRST(sys_tables->indexes); - ut_a(!sys_tables->comp); + ut_a(!dict_table_is_comp(sys_tables)); btr_pcur_open_at_index_side(TRUE, sys_index, BTR_SEARCH_LEAF, &pcur, TRUE, &mtr); @@ -249,40 +249,40 @@ loop: btr_pcur_close(&pcur); mtr_commit(&mtr); - + /* We must make the tablespace cache aware of the biggest known space id */ /* printf("Biggest space id in data dictionary %lu\n", - max_space_id); */ + max_space_id); */ fil_set_max_space_id_if_bigger(max_space_id); mutex_exit(&(dict_sys->mutex)); return; - } + } field = rec_get_nth_field_old(rec, 0, &len); - if (!rec_get_deleted_flag(rec, sys_tables->comp)) { + if (!rec_get_deleted_flag(rec, 0)) { /* We found one */ - char* name = mem_strdupl((char*) field, len); + char* name = mem_strdupl((char*) field, len); field = rec_get_nth_field_old(rec, 9, &len); ut_a(len == 4); - + space_id = mach_read_from_4(field); btr_pcur_store_position(&pcur, &mtr); mtr_commit(&mtr); - + if (space_id != 0 && in_crash_recovery) { /* Check that the tablespace (the .ibd file) really exists; print a warning to the .err log if not */ - + fil_space_for_table_exists_in_mem(space_id, name, FALSE, TRUE, TRUE); } @@ -334,7 +334,7 @@ dict_load_columns( ulint prec; ulint i; mtr_t mtr; - + #ifdef UNIV_SYNC_DEBUG ut_ad(mutex_own(&(dict_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ @@ -343,7 +343,7 @@ dict_load_columns( sys_columns = dict_table_get_low("SYS_COLUMNS"); sys_index = UT_LIST_GET_FIRST(sys_columns->indexes); - ut_a(!sys_columns->comp); + ut_a(!dict_table_is_comp(sys_columns)); tuple = dtuple_create(heap, 1); dfield = dtuple_get_nth_field(tuple, 0); @@ -356,13 +356,13 @@ dict_load_columns( btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE, BTR_SEARCH_LEAF, &pcur, &mtr); - for (i = 0; i < table->n_cols - DATA_N_SYS_COLS; i++) { + for (i = 0; i < table->n_cols - DATA_N_SYS_COLS; i++) { rec = btr_pcur_get_rec(&pcur); ut_a(btr_pcur_is_on_user_rec(&pcur, &mtr)); - ut_a(!rec_get_deleted_flag(rec, sys_columns->comp)); + ut_a(!rec_get_deleted_flag(rec, 0)); field = rec_get_nth_field_old(rec, 0, &len); ut_ad(len == 8); @@ -385,13 +385,23 @@ dict_load_columns( field = rec_get_nth_field_old(rec, 6, &len); prtype = mach_read_from_4(field); - if (dtype_is_non_binary_string_type(mtype, prtype) - && dtype_get_charset_coll(prtype) == 0) { - /* This is a non-binary string type, and the table - was created with < 4.1.2. Use the default charset. */ + if (dtype_get_charset_coll(prtype) == 0 + && dtype_is_string_type(mtype)) { + /* The table was created with < 4.1.2. */ + + if (dtype_is_binary_string_type(mtype, prtype)) { + /* Use the binary collation for + string columns of binary type. */ + + prtype = dtype_form_prtype(prtype, + DATA_MYSQL_BINARY_CHARSET_COLL); + } else { + /* Use the default charset for + other than binary columns. */ - prtype = dtype_form_prtype(prtype, + prtype = dtype_form_prtype(prtype, data_mysql_default_charset_coll); + } } field = rec_get_nth_field_old(rec, 7, &len); @@ -407,7 +417,7 @@ dict_load_columns( dict_mem_table_add_col(table, name, mtype, prtype, col_len, prec); btr_pcur_move_to_next_user_rec(&pcur, &mtr); - } + } btr_pcur_close(&pcur); mtr_commit(&mtr); @@ -455,7 +465,7 @@ dict_load_fields( byte* buf; ulint i; mtr_t mtr; - + #ifdef UNIV_SYNC_DEBUG ut_ad(mutex_own(&(dict_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ @@ -466,7 +476,7 @@ dict_load_fields( sys_fields = dict_table_get_low("SYS_FIELDS"); sys_index = UT_LIST_GET_FIRST(sys_fields->indexes); - ut_a(!sys_fields->comp); + ut_a(!dict_table_is_comp(sys_fields)); tuple = dtuple_create(heap, 1); dfield = dtuple_get_nth_field(tuple, 0); @@ -479,15 +489,15 @@ dict_load_fields( btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE, BTR_SEARCH_LEAF, &pcur, &mtr); - for (i = 0; i < index->n_fields; i++) { + for (i = 0; i < index->n_fields; i++) { rec = btr_pcur_get_rec(&pcur); ut_a(btr_pcur_is_on_user_rec(&pcur, &mtr)); - if (rec_get_deleted_flag(rec, sys_fields->comp)) { + if (rec_get_deleted_flag(rec, 0)) { dict_load_report_deleted_index(table->name, i); } - + field = rec_get_nth_field_old(rec, 0, &len); ut_ad(len == 8); ut_a(ut_memcmp(buf, field, len) == 0); @@ -506,14 +516,14 @@ dict_load_fields( pos_and_prefix_len = mach_read_from_4(field); ut_a((pos_and_prefix_len & 0xFFFFUL) == i - || (pos_and_prefix_len & 0xFFFF0000UL) == (i << 16)); + || (pos_and_prefix_len & 0xFFFF0000UL) == (i << 16)); if ((i == 0 && pos_and_prefix_len > 0) - || (pos_and_prefix_len & 0xFFFF0000UL) > 0) { + || (pos_and_prefix_len & 0xFFFF0000UL) > 0) { - prefix_len = pos_and_prefix_len & 0xFFFFUL; + prefix_len = pos_and_prefix_len & 0xFFFFUL; } else { - prefix_len = 0; + prefix_len = 0; } ut_a(0 == ut_strcmp("COL_NAME", @@ -523,10 +533,10 @@ dict_load_fields( field = rec_get_nth_field_old(rec, 4, &len); dict_mem_index_add_field(index, - mem_heap_strdupl(heap, (char*) field, len), 0, prefix_len); + mem_heap_strdupl(heap, (char*) field, len), prefix_len); btr_pcur_move_to_next_user_rec(&pcur, &mtr); - } + } btr_pcur_close(&pcur); mtr_commit(&mtr); @@ -563,23 +573,23 @@ dict_load_indexes( ibool is_sys_table; dulint id; mtr_t mtr; - + #ifdef UNIV_SYNC_DEBUG ut_ad(mutex_own(&(dict_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ if ((ut_dulint_get_high(table->id) == 0) - && (ut_dulint_get_low(table->id) < DICT_HDR_FIRST_ID)) { + && (ut_dulint_get_low(table->id) < DICT_HDR_FIRST_ID)) { is_sys_table = TRUE; } else { is_sys_table = FALSE; } - + mtr_start(&mtr); sys_indexes = dict_table_get_low("SYS_INDEXES"); sys_index = UT_LIST_GET_FIRST(sys_indexes->indexes); - ut_a(!sys_indexes->comp); + ut_a(!dict_table_is_comp(sys_indexes)); tuple = dtuple_create(heap, 1); dfield = dtuple_get_nth_field(tuple, 0); @@ -592,14 +602,14 @@ dict_load_indexes( btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE, BTR_SEARCH_LEAF, &pcur, &mtr); - for (;;) { + for (;;) { if (!btr_pcur_is_on_user_rec(&pcur, &mtr)) { break; } rec = btr_pcur_get_rec(&pcur); - + field = rec_get_nth_field_old(rec, 0, &len); ut_ad(len == 8); @@ -607,7 +617,7 @@ dict_load_indexes( break; } - if (rec_get_deleted_flag(rec, table->comp)) { + if (rec_get_deleted_flag(rec, dict_table_is_comp(table))) { dict_load_report_deleted_index(table->name, ULINT_UNDEFINED); @@ -658,7 +668,7 @@ dict_load_indexes( } if ((type & DICT_CLUSTERED) == 0 - && NULL == dict_table_get_first_index(table)) { + && NULL == dict_table_get_first_index(table)) { fprintf(stderr, "InnoDB: Error: trying to load index %s for table %s\n" @@ -670,27 +680,27 @@ dict_load_indexes( return(FALSE); } - + if (is_sys_table - && ((type & DICT_CLUSTERED) - || ((table == dict_sys->sys_tables) - && (name_len == (sizeof "ID_IND") - 1) - && (0 == ut_memcmp(name_buf, "ID_IND", + && ((type & DICT_CLUSTERED) + || ((table == dict_sys->sys_tables) + && (name_len == (sizeof "ID_IND") - 1) + && (0 == ut_memcmp(name_buf, "ID_IND", name_len))))) { /* The index was created in memory already at booting of the database server */ } else { - index = dict_mem_index_create(table->name, name_buf, + index = dict_mem_index_create(table->name, name_buf, space, type, n_fields); index->id = id; - + dict_load_fields(table, index, heap); dict_index_add_to_cache(table, index, page_no); } btr_pcur_move_to_next_user_rec(&pcur, &mtr); - } + } btr_pcur_close(&pcur); mtr_commit(&mtr); @@ -729,20 +739,21 @@ dict_load_table( ulint len; ulint space; ulint n_cols; + ulint flags; ulint err; mtr_t mtr; - + #ifdef UNIV_SYNC_DEBUG ut_ad(mutex_own(&(dict_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ heap = mem_heap_create(1000); - + mtr_start(&mtr); sys_tables = dict_table_get_low("SYS_TABLES"); sys_index = UT_LIST_GET_FIRST(sys_tables->indexes); - ut_a(!sys_tables->comp); + ut_a(!dict_table_is_comp(sys_tables)); tuple = dtuple_create(heap, 1); dfield = dtuple_get_nth_field(tuple, 0); @@ -755,15 +766,15 @@ dict_load_table( rec = btr_pcur_get_rec(&pcur); if (!btr_pcur_is_on_user_rec(&pcur, &mtr) - || rec_get_deleted_flag(rec, sys_tables->comp)) { + || rec_get_deleted_flag(rec, 0)) { /* Not found */ btr_pcur_close(&pcur); mtr_commit(&mtr); mem_heap_free(heap); - + return(NULL); - } + } field = rec_get_nth_field_old(rec, 0, &len); @@ -772,14 +783,14 @@ dict_load_table( btr_pcur_close(&pcur); mtr_commit(&mtr); mem_heap_free(heap); - + return(NULL); } ut_a(0 == ut_strcmp("SPACE", dict_field_get_col( dict_index_get_nth_field(sys_index, 9))->name)); - + field = rec_get_nth_field_old(rec, 9, &len); space = mach_read_from_4(field); @@ -817,10 +828,15 @@ dict_load_table( field = rec_get_nth_field_old(rec, 4, &len); n_cols = mach_read_from_4(field); + flags = 0; + /* The high-order bit of N_COLS is the "compact format" flag. */ - table = dict_mem_table_create(name, space, - n_cols & ~0x80000000UL, - !!(n_cols & 0x80000000UL)); + if (n_cols & 0x80000000UL) { + flags |= DICT_TF_COMPACT; + } + + table = dict_mem_table_create(name, space, n_cols & ~0x80000000UL, + flags); table->ibd_file_missing = ibd_file_missing; @@ -846,7 +862,7 @@ dict_load_table( } if ((table->type == DICT_TABLE_CLUSTER) - || (table->type == DICT_TABLE_CLUSTER_MEMBER)) { + || (table->type == DICT_TABLE_CLUSTER_MEMBER)) { field = rec_get_nth_field_old(rec, 7, &len); ut_a(len == 4); @@ -865,17 +881,17 @@ dict_load_table( dict_load_columns(table, heap); dict_table_add_to_cache(table); - + dict_load_indexes(table, heap); - + err = dict_load_foreigns(table->name, TRUE); /* if (err != DB_SUCCESS) { - - mutex_enter(&dict_foreign_err_mutex); - ut_print_timestamp(stderr); - + mutex_enter(&dict_foreign_err_mutex); + + ut_print_timestamp(stderr); + fprintf(stderr, " InnoDB: Error: could not make a foreign key definition to match\n" "InnoDB: the foreign key table or the referenced table!\n" @@ -883,7 +899,7 @@ dict_load_table( "InnoDB: and recreate the foreign key table or the referenced table.\n" "InnoDB: Submit a detailed bug report to http://bugs.mysql.com\n" "InnoDB: Latest foreign key error printout:\n%s\n", dict_foreign_err_buf); - + mutex_exit(&dict_foreign_err_mutex); } */ @@ -899,21 +915,21 @@ dict_table_t* dict_load_table_on_id( /*==================*/ /* out: table; NULL if table does not exist */ - dulint table_id) /* in: table id */ + dulint table_id) /* in: table id */ { byte id_buf[8]; btr_pcur_t pcur; - mem_heap_t* heap; + mem_heap_t* heap; dtuple_t* tuple; dfield_t* dfield; dict_index_t* sys_table_ids; dict_table_t* sys_tables; rec_t* rec; byte* field; - ulint len; + ulint len; dict_table_t* table; mtr_t mtr; - + #ifdef UNIV_SYNC_DEBUG ut_ad(mutex_own(&(dict_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ @@ -922,13 +938,13 @@ dict_load_table_on_id( the dictionary mutex, and therefore no deadlocks can occur with other dictionary operations. */ - mtr_start(&mtr); + mtr_start(&mtr); /*---------------------------------------------------*/ - /* Get the secondary index based on ID for table SYS_TABLES */ + /* Get the secondary index based on ID for table SYS_TABLES */ sys_tables = dict_sys->sys_tables; sys_table_ids = dict_table_get_next_index( dict_table_get_first_index(sys_tables)); - ut_a(!sys_tables->comp); + ut_a(!dict_table_is_comp(sys_tables)); heap = mem_heap_create(256); tuple = dtuple_create(heap, 1); @@ -936,22 +952,22 @@ dict_load_table_on_id( /* Write the table id in byte format to id_buf */ mach_write_to_8(id_buf, table_id); - + dfield_set_data(dfield, id_buf, 8); dict_index_copy_types(tuple, sys_table_ids, 1); btr_pcur_open_on_user_rec(sys_table_ids, tuple, PAGE_CUR_GE, BTR_SEARCH_LEAF, &pcur, &mtr); rec = btr_pcur_get_rec(&pcur); - + if (!btr_pcur_is_on_user_rec(&pcur, &mtr) - || rec_get_deleted_flag(rec, sys_tables->comp)) { + || rec_get_deleted_flag(rec, 0)) { /* Not found */ btr_pcur_close(&pcur); mtr_commit(&mtr); mem_heap_free(heap); - + return(NULL); } @@ -969,15 +985,15 @@ dict_load_table_on_id( btr_pcur_close(&pcur); mtr_commit(&mtr); mem_heap_free(heap); - + return(NULL); } - + /* Now we get the table name from the record */ field = rec_get_nth_field_old(rec, 1, &len); /* Load the table definition to memory */ table = dict_load_table(mem_heap_strdupl(heap, (char*) field, len)); - + btr_pcur_close(&pcur); mtr_commit(&mtr); mem_heap_free(heap); @@ -1004,7 +1020,7 @@ dict_load_sys_table( heap = mem_heap_create(1000); dict_load_indexes(table, heap); - + mem_heap_free(heap); } @@ -1028,7 +1044,7 @@ dict_load_foreign_cols( ulint len; ulint i; mtr_t mtr; - + #ifdef UNIV_SYNC_DEBUG ut_ad(mutex_own(&(dict_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ @@ -1042,7 +1058,7 @@ dict_load_foreign_cols( sys_foreign_cols = dict_table_get_low("SYS_FOREIGN_COLS"); sys_index = UT_LIST_GET_FIRST(sys_foreign_cols->indexes); - ut_a(!sys_foreign_cols->comp); + ut_a(!dict_table_is_comp(sys_foreign_cols)); tuple = dtuple_create(foreign->heap, 1); dfield = dtuple_get_nth_field(tuple, 0); @@ -1052,12 +1068,12 @@ dict_load_foreign_cols( btr_pcur_open_on_user_rec(sys_index, tuple, PAGE_CUR_GE, BTR_SEARCH_LEAF, &pcur, &mtr); - for (i = 0; i < foreign->n_fields; i++) { + for (i = 0; i < foreign->n_fields; i++) { rec = btr_pcur_get_rec(&pcur); ut_a(btr_pcur_is_on_user_rec(&pcur, &mtr)); - ut_a(!rec_get_deleted_flag(rec, sys_foreign_cols->comp)); + ut_a(!rec_get_deleted_flag(rec, 0)); field = rec_get_nth_field_old(rec, 0, &len); ut_a(len == ut_strlen(id)); @@ -1069,14 +1085,14 @@ dict_load_foreign_cols( field = rec_get_nth_field_old(rec, 4, &len); foreign->foreign_col_names[i] = - mem_heap_strdupl(foreign->heap, (char*) field, len); + mem_heap_strdupl(foreign->heap, (char*) field, len); field = rec_get_nth_field_old(rec, 5, &len); foreign->referenced_col_names[i] = - mem_heap_strdupl(foreign->heap, (char*) field, len); + mem_heap_strdupl(foreign->heap, (char*) field, len); btr_pcur_move_to_next_user_rec(&pcur, &mtr); - } + } btr_pcur_close(&pcur); mtr_commit(&mtr); @@ -1091,8 +1107,8 @@ dict_load_foreign( /* out: DB_SUCCESS or error code */ const char* id, /* in: foreign constraint id as a null-terminated string */ - ibool check_types)/* in: TRUE=check type compatibility */ -{ + ibool check_charsets)/* in: TRUE=check charset compatibility */ +{ dict_foreign_t* foreign; dict_table_t* sys_foreign; btr_pcur_t pcur; @@ -1104,18 +1120,18 @@ dict_load_foreign( byte* field; ulint len; mtr_t mtr; - + #ifdef UNIV_SYNC_DEBUG ut_ad(mutex_own(&(dict_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ heap2 = mem_heap_create(1000); - + mtr_start(&mtr); sys_foreign = dict_table_get_low("SYS_FOREIGN"); sys_index = UT_LIST_GET_FIRST(sys_foreign->indexes); - ut_a(!sys_foreign->comp); + ut_a(!dict_table_is_comp(sys_foreign)); tuple = dtuple_create(heap2, 1); dfield = dtuple_get_nth_field(tuple, 0); @@ -1128,7 +1144,7 @@ dict_load_foreign( rec = btr_pcur_get_rec(&pcur); if (!btr_pcur_is_on_user_rec(&pcur, &mtr) - || rec_get_deleted_flag(rec, sys_foreign->comp)) { + || rec_get_deleted_flag(rec, 0)) { /* Not found */ fprintf(stderr, @@ -1138,9 +1154,9 @@ dict_load_foreign( btr_pcur_close(&pcur); mtr_commit(&mtr); mem_heap_free(heap2); - + return(DB_ERROR); - } + } field = rec_get_nth_field_old(rec, 0, &len); @@ -1154,7 +1170,7 @@ dict_load_foreign( btr_pcur_close(&pcur); mtr_commit(&mtr); mem_heap_free(heap2); - + return(DB_ERROR); } @@ -1162,7 +1178,7 @@ dict_load_foreign( with the constraint */ mem_heap_free(heap2); - + foreign = dict_mem_foreign_create(); foreign->n_fields = @@ -1171,19 +1187,19 @@ dict_load_foreign( ut_a(len == 4); /* We store the type to the bits 24-31 of n_fields */ - + foreign->type = foreign->n_fields >> 24; foreign->n_fields = foreign->n_fields & 0xFFFFFFUL; - + foreign->id = mem_heap_strdup(foreign->heap, id); field = rec_get_nth_field_old(rec, 3, &len); foreign->foreign_table_name = - mem_heap_strdupl(foreign->heap, (char*) field, len); + mem_heap_strdupl(foreign->heap, (char*) field, len); field = rec_get_nth_field_old(rec, 4, &len); foreign->referenced_table_name = - mem_heap_strdupl(foreign->heap, (char*) field, len); + mem_heap_strdupl(foreign->heap, (char*) field, len); btr_pcur_close(&pcur); mtr_commit(&mtr); @@ -1204,7 +1220,7 @@ dict_load_foreign( a new foreign key constraint but loading one from the data dictionary. */ - return(dict_foreign_add_to_cache(foreign, check_types)); + return(dict_foreign_add_to_cache(foreign, check_charsets)); } /*************************************************************************** @@ -1219,21 +1235,22 @@ dict_load_foreigns( /*===============*/ /* out: DB_SUCCESS or error code */ const char* table_name, /* in: table name */ - ibool check_types) /* in: TRUE=check type compatibility */ + ibool check_charsets) /* in: TRUE=check charset + compatibility */ { btr_pcur_t pcur; - mem_heap_t* heap; + mem_heap_t* heap; dtuple_t* tuple; dfield_t* dfield; dict_index_t* sec_index; dict_table_t* sys_foreign; rec_t* rec; byte* field; - ulint len; + ulint len; char* id ; ulint err; mtr_t mtr; - + #ifdef UNIV_SYNC_DEBUG ut_ad(mutex_own(&(dict_sys->mutex))); #endif /* UNIV_SYNC_DEBUG */ @@ -1245,15 +1262,15 @@ dict_load_foreigns( fprintf(stderr, "InnoDB: Error: no foreign key system tables in the database\n"); - + return(DB_ERROR); } - ut_a(!sys_foreign->comp); - mtr_start(&mtr); + ut_a(!dict_table_is_comp(sys_foreign)); + mtr_start(&mtr); /* Get the secondary index based on FOR_NAME from table - SYS_FOREIGN */ + SYS_FOREIGN */ sec_index = dict_table_get_next_index( dict_table_get_first_index(sys_foreign)); @@ -1270,7 +1287,7 @@ start_load: BTR_SEARCH_LEAF, &pcur, &mtr); loop: rec = btr_pcur_get_rec(&pcur); - + if (!btr_pcur_is_on_user_rec(&pcur, &mtr)) { /* End of index */ @@ -1290,7 +1307,7 @@ loop: if (0 != cmp_data_data(dfield_get_type(dfield), dfield_get_data(dfield), dfield_get_len(dfield), field, len)) { - + goto load_next_index; } @@ -1303,8 +1320,8 @@ loop: goto next_rec; } - - if (rec_get_deleted_flag(rec, sys_foreign->comp)) { + + if (rec_get_deleted_flag(rec, 0)) { goto next_rec; } @@ -1312,14 +1329,14 @@ loop: /* Now we get a foreign key constraint id */ field = rec_get_nth_field_old(rec, 1, &len); id = mem_heap_strdupl(heap, (char*) field, len); - + btr_pcur_store_position(&pcur, &mtr); mtr_commit(&mtr); /* Load the foreign constraint definition to the dictionary cache */ - - err = dict_load_foreign(id, check_types); + + err = dict_load_foreign(id, check_charsets); if (err != DB_SUCCESS) { btr_pcur_close(&pcur); @@ -1340,12 +1357,12 @@ load_next_index: btr_pcur_close(&pcur); mtr_commit(&mtr); mem_heap_free(heap); - + sec_index = dict_table_get_next_index(sec_index); if (sec_index != NULL) { - mtr_start(&mtr); + mtr_start(&mtr); goto start_load; } diff --git a/storage/innobase/dict/dict0mem.c b/storage/innobase/dict/dict0mem.c index eec35310039..d9f0ad3d84e 100644 --- a/storage/innobase/dict/dict0mem.c +++ b/storage/innobase/dict/dict0mem.c @@ -36,13 +36,13 @@ dict_mem_table_create( ignored if the table is made a member of a cluster */ ulint n_cols, /* in: number of columns */ - ibool comp) /* in: TRUE=compact page format */ + ulint flags) /* in: table flags */ { dict_table_t* table; mem_heap_t* heap; - + ut_ad(name); - ut_ad(comp == FALSE || comp == TRUE); + ut_ad(!(flags & ~DICT_TF_COMPACT)); heap = mem_heap_create(DICT_HEAP_SIZE); @@ -51,24 +51,24 @@ dict_mem_table_create( table->heap = heap; table->type = DICT_TABLE_ORDINARY; + table->flags = flags; table->name = mem_heap_strdup(heap, name); table->dir_path_of_temp_table = NULL; table->space = space; table->ibd_file_missing = FALSE; table->tablespace_discarded = FALSE; - table->comp = comp; table->n_def = 0; table->n_cols = n_cols + DATA_N_SYS_COLS; table->mem_fix = 0; table->n_mysql_handles_opened = 0; table->n_foreign_key_checks_running = 0; - + table->cached = FALSE; - + table->mix_id = ut_dulint_zero; table->mix_len = 0; - + table->cols = mem_heap_alloc(heap, (n_cols + DATA_N_SYS_COLS) * sizeof(dict_col_t)); UT_LIST_INIT(table->indexes); @@ -86,14 +86,14 @@ dict_mem_table_create( table->stat_initialized = FALSE; table->stat_modified_counter = 0; - + mutex_create(&(table->autoinc_mutex)); mutex_set_level(&(table->autoinc_mutex), SYNC_DICT_AUTOINC_MUTEX); table->autoinc_inited = FALSE; table->magic_n = DICT_TABLE_MAGIC_N; - + return(table); } @@ -114,7 +114,7 @@ dict_mem_cluster_create( dict_table_t* cluster; /* Clustered tables cannot work with the compact record format. */ - cluster = dict_mem_table_create(name, space, n_cols, FALSE); + cluster = dict_mem_table_create(name, space, n_cols, 0); cluster->type = DICT_TABLE_CLUSTER; cluster->mix_len = mix_len; @@ -150,13 +150,13 @@ dict_mem_table_add_col( { dict_col_t* col; dtype_t* type; - + ut_ad(table && name); ut_ad(table->magic_n == DICT_TABLE_MAGIC_N); - + table->n_def++; - col = dict_table_get_nth_col(table, table->n_def - 1); + col = dict_table_get_nth_col(table, table->n_def - 1); col->ind = table->n_def - 1; col->name = mem_heap_strdup(table->heap, name); @@ -164,7 +164,7 @@ dict_mem_table_add_col( col->ord_part = 0; col->clust_pos = ULINT_UNDEFINED; - + type = dict_col_get_type(col); dtype_set(type, mtype, prtype, len, prec); @@ -188,14 +188,14 @@ dict_mem_index_create( { dict_index_t* index; mem_heap_t* heap; - + ut_ad(table_name && index_name); heap = mem_heap_create(DICT_HEAP_SIZE); index = mem_heap_alloc(heap, sizeof(dict_index_t)); index->heap = heap; - + index->type = type; index->space = space; index->name = mem_heap_strdup(heap, index_name); @@ -261,24 +261,20 @@ dict_mem_index_add_field( /*=====================*/ dict_index_t* index, /* in: index */ const char* name, /* in: column name */ - ulint order, /* in: order criterion; 0 means an - ascending order */ ulint prefix_len) /* in: 0 or the column prefix length in a MySQL index like INDEX (textcol(25)) */ { dict_field_t* field; - + ut_ad(index && name); ut_ad(index->magic_n == DICT_INDEX_MAGIC_N); - + index->n_def++; - field = dict_index_get_nth_field(index, index->n_def - 1); + field = dict_index_get_nth_field(index, index->n_def - 1); field->name = name; - field->order = order; - field->prefix_len = prefix_len; } |