📄 dict0crea.c
字号:
/******************************************************Database object creation(c) 1996 Innobase OyCreated 1/8/1996 Heikki Tuuri*******************************************************/#include "dict0crea.h"#ifdef UNIV_NONINL#include "dict0crea.ic"#endif#include "btr0pcur.h"#include "btr0btr.h"#include "page0page.h"#include "mach0data.h"#include "dict0boot.h"#include "dict0dict.h"#include "que0que.h"#include "row0ins.h"#include "row0mysql.h"#include "pars0pars.h"#include "trx0roll.h"#include "usr0sess.h"/*********************************************************************Based on a table object, this function builds the entry to be insertedin the SYS_TABLES system table. */staticdtuple_t*dict_create_sys_tables_tuple(/*=========================*/ /* out: the tuple which should be inserted */ dict_table_t* table, /* in: table */ mem_heap_t* heap) /* in: memory heap from which the memory for the built tuple is allocated */{ dict_table_t* sys_tables; dtuple_t* entry; dfield_t* dfield; byte* ptr; ut_ad(table && heap); sys_tables = dict_sys->sys_tables; entry = dtuple_create(heap, 8 + DATA_N_SYS_COLS); /* 0: NAME -----------------------------*/ dfield = dtuple_get_nth_field(entry, 0); dfield_set_data(dfield, table->name, ut_strlen(table->name)); /* 3: ID -------------------------------*/ dfield = dtuple_get_nth_field(entry, 1); ptr = mem_heap_alloc(heap, 8); mach_write_to_8(ptr, table->id); dfield_set_data(dfield, ptr, 8); /* 4: N_COLS ---------------------------*/ dfield = dtuple_get_nth_field(entry, 2); ptr = mem_heap_alloc(heap, 4); mach_write_to_4(ptr, table->n_def | ((ulint) table->comp << 31)); dfield_set_data(dfield, ptr, 4); /* 5: TYPE -----------------------------*/ dfield = dtuple_get_nth_field(entry, 3); ptr = mem_heap_alloc(heap, 4); mach_write_to_4(ptr, table->type); dfield_set_data(dfield, ptr, 4); /* 6: MIX_ID ---------------------------*/ dfield = dtuple_get_nth_field(entry, 4); ptr = mem_heap_alloc(heap, 8); mach_write_to_8(ptr, table->mix_id); dfield_set_data(dfield, ptr, 8); /* 7: MIX_LEN --------------------------*/ dfield = dtuple_get_nth_field(entry, 5); ptr = mem_heap_alloc(heap, 4); mach_write_to_4(ptr, table->mix_len); dfield_set_data(dfield, ptr, 4); /* 8: CLUSTER_NAME ---------------------*/ dfield = dtuple_get_nth_field(entry, 6); 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 */ } else { dfield_set_data(dfield, NULL, UNIV_SQL_NULL); } /* 9: SPACE ----------------------------*/ dfield = dtuple_get_nth_field(entry, 7); ptr = mem_heap_alloc(heap, 4); mach_write_to_4(ptr, table->space); dfield_set_data(dfield, ptr, 4); /*----------------------------------*/ dict_table_copy_types(entry, sys_tables); return(entry);} /*********************************************************************Based on a table object, this function builds the entry to be insertedin the SYS_COLUMNS system table. */staticdtuple_t*dict_create_sys_columns_tuple(/*==========================*/ /* out: the tuple which should be inserted */ 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 */{ dict_table_t* sys_columns; dtuple_t* entry; dict_col_t* column; dfield_t* dfield; byte* ptr; ut_ad(table && heap); 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 -----------------------*/ dfield = dtuple_get_nth_field(entry, 0); ptr = mem_heap_alloc(heap, 8); mach_write_to_8(ptr, table->id); dfield_set_data(dfield, ptr, 8); /* 1: POS ----------------------------*/ dfield = dtuple_get_nth_field(entry, 1); ptr = mem_heap_alloc(heap, 4); mach_write_to_4(ptr, i); dfield_set_data(dfield, ptr, 4); /* 4: NAME ---------------------------*/ dfield = dtuple_get_nth_field(entry, 2); dfield_set_data(dfield, column->name, ut_strlen(column->name)); /* 5: MTYPE --------------------------*/ dfield = dtuple_get_nth_field(entry, 3); ptr = mem_heap_alloc(heap, 4); mach_write_to_4(ptr, (column->type).mtype); dfield_set_data(dfield, ptr, 4); /* 6: PRTYPE -------------------------*/ dfield = dtuple_get_nth_field(entry, 4); ptr = mem_heap_alloc(heap, 4); mach_write_to_4(ptr, (column->type).prtype); dfield_set_data(dfield, ptr, 4); /* 7: LEN ----------------------------*/ dfield = dtuple_get_nth_field(entry, 5); ptr = mem_heap_alloc(heap, 4); mach_write_to_4(ptr, (column->type).len); dfield_set_data(dfield, ptr, 4); /* 8: PREC ---------------------------*/ dfield = dtuple_get_nth_field(entry, 6); ptr = mem_heap_alloc(heap, 4); mach_write_to_4(ptr, (column->type).prec); dfield_set_data(dfield, ptr, 4); /*---------------------------------*/ dict_table_copy_types(entry, sys_columns); return(entry);} /*******************************************************************Builds a table definition to insert. */staticulintdict_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; dict_table_t* cluster_table; dtuple_t* row; ulint error; const char* path_or_name; ibool is_path; mtr_t mtr; ulint i; ulint row_len;#ifdef UNIV_SYNC_DEBUG ut_ad(mutex_own(&(dict_sys->mutex)));#endif /* UNIV_SYNC_DEBUG */ 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 += dtype_get_min_size(dict_col_get_type( &table->cols[i])); } if (row_len > BTR_PAGE_MAX_REC_SIZE) { return(DB_TOO_BIG_RECORD); } if (table->type == DICT_TABLE_CLUSTER_MEMBER) { cluster_table = dict_table_get_low(table->cluster_name); if (cluster_table == NULL) { return(DB_CLUSTER_NOT_FOUND); } /* Inherit space and mix len from the cluster */ table->space = cluster_table->space; table->mix_len = cluster_table->mix_len; table->mix_id = dict_hdr_get_new_id(DICT_HDR_MIX_ID); } 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. */ table->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( &(table->space), path_or_name, is_path, FIL_IBD_FILE_INITIAL_SIZE); 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 column definition to insert. */staticulintdict_build_col_def_step(/*====================*/ /* out: DB_SUCCESS */ tab_node_t* node) /* in: table create node */{ dtuple_t* row; 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);}/*********************************************************************Based on an index object, this function builds the entry to be insertedin the SYS_INDEXES system table. */staticdtuple_t*dict_create_sys_indexes_tuple(/*==========================*/ /* out: the tuple which should be inserted */ dict_index_t* index, /* in: index */ mem_heap_t* heap) /* in: memory heap from which the memory for the built tuple is allocated */{ dict_table_t* sys_indexes; dict_table_t* table; dtuple_t* entry; dfield_t* dfield; byte* ptr;#ifdef UNIV_SYNC_DEBUG ut_ad(mutex_own(&(dict_sys->mutex)));#endif /* UNIV_SYNC_DEBUG */ ut_ad(index && heap); 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 -----------------------*/ dfield = dtuple_get_nth_field(entry, 0); ptr = mem_heap_alloc(heap, 8); mach_write_to_8(ptr, table->id); dfield_set_data(dfield, ptr, 8); /* 1: ID ----------------------------*/ dfield = dtuple_get_nth_field(entry, 1); ptr = mem_heap_alloc(heap, 8); mach_write_to_8(ptr, index->id); dfield_set_data(dfield, ptr, 8); /* 4: NAME --------------------------*/ dfield = dtuple_get_nth_field(entry, 2); dfield_set_data(dfield, index->name, ut_strlen(index->name)); /* 5: N_FIELDS ----------------------*/ dfield = dtuple_get_nth_field(entry, 3); ptr = mem_heap_alloc(heap, 4); mach_write_to_4(ptr, index->n_fields); dfield_set_data(dfield, ptr, 4); /* 6: TYPE --------------------------*/ dfield = dtuple_get_nth_field(entry, 4); ptr = mem_heap_alloc(heap, 4); mach_write_to_4(ptr, index->type); dfield_set_data(dfield, ptr, 4); /* 7: SPACE --------------------------*/#if DICT_SYS_INDEXES_SPACE_NO_FIELD != 7#error "DICT_SYS_INDEXES_SPACE_NO_FIELD != 7"#endif dfield = dtuple_get_nth_field(entry, 5); ptr = mem_heap_alloc(heap, 4); mach_write_to_4(ptr, index->space); dfield_set_data(dfield, ptr, 4); /* 8: PAGE_NO --------------------------*/#if DICT_SYS_INDEXES_PAGE_NO_FIELD != 8#error "DICT_SYS_INDEXES_PAGE_NO_FIELD != 8"#endif dfield = dtuple_get_nth_field(entry, 6); ptr = mem_heap_alloc(heap, 4); mach_write_to_4(ptr, FIL_NULL); dfield_set_data(dfield, ptr, 4); /*--------------------------------*/ dict_table_copy_types(entry, sys_indexes); return(entry);} /*********************************************************************Based on an index object, this function builds the entry to be insertedin the SYS_FIELDS system table. */staticdtuple_t*dict_create_sys_fields_tuple(/*=========================*/ /* out: the tuple which should be inserted */ 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 */{ dict_table_t* sys_fields; dtuple_t* entry; dict_field_t* field; dfield_t* dfield; byte* ptr; ibool index_contains_column_prefix_field = FALSE; ulint j; 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; } } 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 -----------------------*/ dfield = dtuple_get_nth_field(entry, 0); ptr = mem_heap_alloc(heap, 8); mach_write_to_8(ptr, index->id); dfield_set_data(dfield, ptr, 8); /* 1: POS + PREFIX LENGTH ----------------------------*/ 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); } else { /* 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); } dfield_set_data(dfield, ptr, 4); /* 4: COL_NAME -------------------------*/ dfield = dtuple_get_nth_field(entry, 2); dfield_set_data(dfield, field->name, ut_strlen(field->name)); /*---------------------------------*/ dict_table_copy_types(entry, sys_fields); return(entry);} /*********************************************************************Creates the tuple with which the index entry is searched for writing the indextree root page number, if such a tree is created. */staticdtuple_t*dict_create_search_tuple(/*=====================*/ /* out: the tuple for search */ dtuple_t* tuple, /* in: the tuple inserted in the SYS_INDEXES table */ mem_heap_t* heap) /* in: memory heap from which the memory for
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -