/******************************************************************* Builds a table definition to insert. */ static ulint dict_build_table_def_step( /*======================*/ /* out: DB_SUCCESS or error code */ que_thr_t* thr, /* in: query thread */ tab_node_t* node) /* in: table create node */ { dict_table_t* table; dtuple_t* row; ulint error; const char* path_or_name; ibool is_path; mtr_t mtr; ulint i; ulint row_len; ut_ad(mutex_own(&(dict_sys->mutex))); table = node->table; table->id = dict_hdr_get_new_id(DICT_HDR_TABLE_ID); thr_get_trx(thr)->table_id = table->id; row_len = 0; for (i = 0; i < table->n_def; i++) { row_len += dict_col_get_min_size(&table->cols[i]); } if (row_len > BTR_PAGE_MAX_REC_SIZE) { return(DB_TOO_BIG_RECORD); } if (srv_file_per_table) { /* We create a new single-table tablespace for the table. We initially let it be 4 pages: - page 0 is the fsp header and an extent descriptor page, - page 1 is an ibuf bitmap page, - page 2 is the first inode page, - page 3 will contain the root of the clustered index of the table we create here. */ ulint space = 0; /* reset to zero for the call below */ if (table->dir_path_of_temp_table) { /* We place tables created with CREATE TEMPORARY TABLE in the tmp dir of mysqld server */ path_or_name = table->dir_path_of_temp_table; is_path = TRUE; } else { path_or_name = table->name; is_path = FALSE; } error = fil_create_new_single_table_tablespace( &space, path_or_name, is_path, FIL_IBD_FILE_INITIAL_SIZE); table->space = (unsigned int) space; if (error != DB_SUCCESS) { return(error); } mtr_start(&mtr); fsp_header_init(table->space, FIL_IBD_FILE_INITIAL_SIZE, &mtr); mtr_commit(&mtr); } row = dict_create_sys_tables_tuple(table, node->heap); ins_node_set_new_row(node->tab_def, row); return(DB_SUCCESS); }
/***************************************************************//** Builds a table definition to insert. @return DB_SUCCESS or error code */ static ulint dict_build_table_def_step( /*======================*/ que_thr_t* thr, /*!< in: query thread */ tab_node_t* node) /*!< in: table create node */ { dict_table_t* table; dtuple_t* row; ulint error; ulint flags; const char* path_or_name; ibool is_path; mtr_t mtr; ulint space = 0; ibool file_per_table; ut_ad(mutex_own(&(dict_sys->mutex))); table = node->table; /* Cache the global variable "srv_file_per_table" to a local variable before using it. Please note "srv_file_per_table" is not under dict_sys mutex protection, and could be changed while executing this function. So better to cache the current value to a local variable, and all future reference to "srv_file_per_table" should use this local variable. */ file_per_table = srv_file_per_table; dict_hdr_get_new_id(&table->id, NULL, NULL); thr_get_trx(thr)->table_id = table->id; if (file_per_table) { /* Get a new space id if srv_file_per_table is set */ dict_hdr_get_new_id(NULL, NULL, &space); if (UNIV_UNLIKELY(space == ULINT_UNDEFINED)) { return(DB_ERROR); } /* We create a new single-table tablespace for the table. We initially let it be 4 pages: - page 0 is the fsp header and an extent descriptor page, - page 1 is an ibuf bitmap page, - page 2 is the first inode page, - page 3 will contain the root of the clustered index of the table we create here. */ if (table->dir_path_of_temp_table) { /* We place tables created with CREATE TEMPORARY TABLE in the tmp dir of mysqld server */ path_or_name = table->dir_path_of_temp_table; is_path = TRUE; } else { path_or_name = table->name; is_path = FALSE; } ut_ad(dict_table_get_format(table) <= DICT_TF_FORMAT_MAX); ut_ad(!dict_table_zip_size(table) || dict_table_get_format(table) >= DICT_TF_FORMAT_ZIP); flags = table->flags & ~(~0 << DICT_TF_BITS); error = fil_create_new_single_table_tablespace( space, path_or_name, is_path, flags == DICT_TF_COMPACT ? 0 : flags, FIL_IBD_FILE_INITIAL_SIZE); table->space = (unsigned int) space; if (error != DB_SUCCESS) { return(error); } mtr_start(&mtr); fsp_header_init(table->space, FIL_IBD_FILE_INITIAL_SIZE, &mtr); mtr_commit(&mtr); } else { /* Create in the system tablespace: disallow new features */ table->flags &= (~0 << DICT_TF_BITS) | DICT_TF_COMPACT; } row = dict_create_sys_tables_tuple(table, node->heap); ins_node_set_new_row(node->tab_def, row); return(DB_SUCCESS); }