29 #include "dict0crea.ic"
52 dict_create_sys_tables_tuple(
74 dfield = dtuple_get_nth_field(entry, 0);
78 dfield = dtuple_get_nth_field(entry, 1);
85 dfield = dtuple_get_nth_field(entry, 2);
87 #if DICT_TF_COMPACT != 1
96 dfield = dtuple_get_nth_field(entry, 3);
102 ut_a((table->
flags & DICT_TF_ZSSIZE_MASK)
112 dfield = dtuple_get_nth_field(entry, 4);
119 dfield = dtuple_get_nth_field(entry, 5);
126 dfield = dtuple_get_nth_field(entry, 6);
130 dfield = dtuple_get_nth_field(entry, 7);
147 dict_create_sys_columns_tuple(
160 const char* col_name;
165 column = dict_table_get_nth_col(table, i);
174 dfield = dtuple_get_nth_field(entry, 0);
181 dfield = dtuple_get_nth_field(entry, 1);
188 dfield = dtuple_get_nth_field(entry, 2);
193 dfield = dtuple_get_nth_field(entry, 3);
200 dfield = dtuple_get_nth_field(entry, 4);
207 dfield = dtuple_get_nth_field(entry, 5);
214 dfield = dtuple_get_nth_field(entry, 6);
230 dict_build_table_def_step(
239 const char* path_or_name;
243 ibool file_per_table;
262 if (file_per_table) {
266 if (UNIV_UNLIKELY(space == ULINT_UNDEFINED)) {
285 path_or_name = table->
name;
295 space, path_or_name, is_path,
298 table->
space = (
unsigned int) space;
300 if (error != DB_SUCCESS) {
315 row = dict_create_sys_tables_tuple(table, node->
heap);
327 dict_build_col_def_step(
333 row = dict_create_sys_columns_tuple(node->
table, node->
col_no,
346 dict_create_sys_indexes_tuple(
372 dfield = dtuple_get_nth_field(entry, 0);
379 dfield = dtuple_get_nth_field(entry, 1);
386 dfield = dtuple_get_nth_field(entry, 2);
390 dfield = dtuple_get_nth_field(entry, 3);
397 dfield = dtuple_get_nth_field(entry, 4);
405 #if DICT_SYS_INDEXES_SPACE_NO_FIELD != 7
406 #error "DICT_SYS_INDEXES_SPACE_NO_FIELD != 7"
409 dfield = dtuple_get_nth_field(entry, 5);
417 #if DICT_SYS_INDEXES_PAGE_NO_FIELD != 8
418 #error "DICT_SYS_INDEXES_PAGE_NO_FIELD != 8"
421 dfield = dtuple_get_nth_field(entry, 6);
438 dict_create_sys_fields_tuple(
451 ibool index_contains_column_prefix_field = FALSE;
457 for (j = 0; j < index->
n_fields; j++) {
458 if (dict_index_get_nth_field(index, j)->prefix_len > 0) {
459 index_contains_column_prefix_field = TRUE;
464 field = dict_index_get_nth_field(index, i);
473 dfield = dtuple_get_nth_field(entry, 0);
481 dfield = dtuple_get_nth_field(entry, 1);
485 if (index_contains_column_prefix_field) {
501 dfield = dtuple_get_nth_field(entry, 2);
516 dict_create_search_tuple(
527 ut_ad(tuple && heap);
531 field1 = dtuple_get_nth_field(tuple, 0);
532 field2 = dtuple_get_nth_field(search_tuple, 0);
536 field1 = dtuple_get_nth_field(tuple, 1);
537 field2 = dtuple_get_nth_field(search_tuple, 1);
541 ut_ad(dtuple_validate(search_tuple));
543 return(search_tuple);
551 dict_build_index_def_step(
570 return(DB_TABLE_NOT_FOUND);
587 row = dict_create_sys_indexes_tuple(index, node->
heap);
603 dict_build_field_def_step(
612 row = dict_create_sys_fields_tuple(index, node->field_no, node->
heap);
624 dict_create_index_tree_step(
647 search_tuple = dict_create_search_tuple(node->ind_row, node->
heap);
658 index->
id, index, &mtr);
663 DICT_SYS_INDEXES_PAGE_NO_FIELD,
664 node->page_no, &mtr);
670 return(DB_OUT_OF_FILE_SPACE);
694 ptr = rec_get_nth_field_old(rec, DICT_SYS_INDEXES_PAGE_NO_FIELD, &len);
706 ptr = rec_get_nth_field_old(rec,
707 DICT_SYS_INDEXES_SPACE_NO_FIELD, &len);
714 if (UNIV_UNLIKELY(zip_size == ULINT_UNDEFINED)) {
735 DICT_SYS_INDEXES_PAGE_NO_FIELD,
770 rec = btr_pcur_get_rec(pcur);
771 ptr = rec_get_nth_field_old(rec, DICT_SYS_INDEXES_PAGE_NO_FIELD, &len);
777 if (drop && root_page_no ==
FIL_NULL) {
781 fprintf(stderr,
" InnoDB: Trying to TRUNCATE"
782 " a missing index of table %s!\n", table->
name);
786 ptr = rec_get_nth_field_old(rec,
787 DICT_SYS_INDEXES_SPACE_NO_FIELD, &len);
797 if (UNIV_UNLIKELY(zip_size == ULINT_UNDEFINED)) {
802 fprintf(stderr,
" InnoDB: Trying to TRUNCATE"
803 " a missing .ibd file of table %s!\n", table->
name);
807 ptr = rec_get_nth_field_old(rec,
808 DICT_SYS_INDEXES_TYPE_FIELD, &len);
812 ptr = rec_get_nth_field_old(rec, 1, &len);
831 btr_block_get(space, zip_size, root_page_no, RW_X_LATCH, mtr);
855 if (index->
id == index_id) {
856 root_page_no =
btr_create(type, space, zip_size,
857 index_id, index, mtr);
858 index->
page = (
unsigned int) root_page_no;
859 return(root_page_no);
865 " InnoDB: Index %llu of table %s is missing\n"
866 "InnoDB: from the data dictionary during TRUNCATE!\n",
892 node->
state = TABLE_BUILD_TABLE_DEF;
928 node->
state = INDEX_BUILD_INDEX_DEF;
956 ulint err = DB_ERROR;
969 node->
state = TABLE_BUILD_TABLE_DEF;
972 if (node->
state == TABLE_BUILD_TABLE_DEF) {
976 err = dict_build_table_def_step(thr, node);
978 if (err != DB_SUCCESS) {
983 node->
state = TABLE_BUILD_COL_DEF;
991 if (node->
state == TABLE_BUILD_COL_DEF) {
995 err = dict_build_col_def_step(node);
997 if (err != DB_SUCCESS) {
1008 node->
state = TABLE_COMMIT_WORK;
1012 if (node->
state == TABLE_COMMIT_WORK) {
1018 node->
state = TABLE_ADD_TO_CACHE;
1025 if (node->
state == TABLE_ADD_TO_CACHE) {
1035 if (err == DB_SUCCESS) {
1038 }
else if (err == DB_LOCK_WAIT) {
1063 ulint err = DB_ERROR;
1076 node->
state = INDEX_BUILD_INDEX_DEF;
1079 if (node->
state == INDEX_BUILD_INDEX_DEF) {
1081 err = dict_build_index_def_step(thr, node);
1083 if (err != DB_SUCCESS) {
1088 node->
state = INDEX_BUILD_FIELD_DEF;
1096 if (node->
state == INDEX_BUILD_FIELD_DEF) {
1098 if (node->field_no < (node->
index)->n_fields) {
1100 err = dict_build_field_def_step(node);
1102 if (err != DB_SUCCESS) {
1113 node->
state = INDEX_ADD_TO_CACHE;
1117 if (node->
state == INDEX_ADD_TO_CACHE) {
1119 index_id_t index_id = node->
index->
id;
1128 ut_a(!node->
index == (err != DB_SUCCESS));
1130 if (err != DB_SUCCESS) {
1135 node->
state = INDEX_CREATE_INDEX_TREE;
1138 if (node->
state == INDEX_CREATE_INDEX_TREE) {
1140 err = dict_create_index_tree_step(node);
1142 if (err != DB_SUCCESS) {
1150 node->
state = INDEX_COMMIT_WORK;
1153 if (node->
state == INDEX_COMMIT_WORK) {
1159 node->
state = INDEX_CREATE_INDEX_TREE;
1169 if (err == DB_SUCCESS) {
1172 }
else if (err == DB_LOCK_WAIT) {
1206 if (table1 && table2
1222 trx->
op_info =
"creating foreign key sys tables";
1224 row_mysql_lock_data_dictionary(trx);
1228 "InnoDB: dropping incompletely created"
1229 " SYS_FOREIGN table\n");
1235 "InnoDB: dropping incompletely created"
1236 " SYS_FOREIGN_COLS table\n");
1241 "InnoDB: Creating foreign key constraint system tables\n");
1255 "PROCEDURE CREATE_FOREIGN_SYS_TABLES_PROC () IS\n"
1258 "SYS_FOREIGN(ID CHAR, FOR_NAME CHAR,"
1259 " REF_NAME CHAR, N_COLS INT);\n"
1260 "CREATE UNIQUE CLUSTERED INDEX ID_IND"
1261 " ON SYS_FOREIGN (ID);\n"
1262 "CREATE INDEX FOR_IND"
1263 " ON SYS_FOREIGN (FOR_NAME);\n"
1264 "CREATE INDEX REF_IND"
1265 " ON SYS_FOREIGN (REF_NAME);\n"
1267 "SYS_FOREIGN_COLS(ID CHAR, POS INT,"
1268 " FOR_COL_NAME CHAR, REF_COL_NAME CHAR);\n"
1269 "CREATE UNIQUE CLUSTERED INDEX ID_IND"
1270 " ON SYS_FOREIGN_COLS (ID, POS);\n"
1274 if (error != DB_SUCCESS) {
1275 fprintf(stderr,
"InnoDB: error %lu in creation\n",
1278 ut_a(error == DB_OUT_OF_FILE_SPACE
1279 || error == DB_TOO_MANY_CONCURRENT_TRXS);
1282 "InnoDB: creation failed\n"
1283 "InnoDB: tablespace is full\n"
1284 "InnoDB: dropping incompletely created"
1285 " SYS_FOREIGN tables\n");
1290 error = DB_MUST_GET_MORE_FILE_SPACE;
1299 if (error == DB_SUCCESS) {
1301 "InnoDB: Foreign key constraint system tables"
1313 dict_foreign_eval_sql(
1322 FILE* ef = dict_foreign_err_file;
1326 if (error == DB_DUPLICATE_KEY) {
1327 mutex_enter(&dict_foreign_err_mutex);
1330 fputs(
" Error in foreign key constraint creation for table ",
1333 fputs(
".\nA foreign key constraint of name ", ef);
1335 fputs(
"\nalready exists."
1336 " (Note that internally InnoDB adds 'databasename'\n"
1337 "in front of the user-defined constraint name.)\n"
1338 "Note that InnoDB's FOREIGN KEY system tables store\n"
1339 "constraint names as case-insensitive, with the\n"
1340 "MySQL standard latin1_swedish_ci collation. If you\n"
1341 "create tables or databases whose names differ only in\n"
1342 "the character case, then collisions in constraint\n"
1343 "names can occur. Workaround: name your constraints\n"
1344 "explicitly with unique names.\n",
1347 mutex_exit(&dict_foreign_err_mutex);
1352 if (error != DB_SUCCESS) {
1354 "InnoDB: Foreign key constraint creation failed:\n"
1355 "InnoDB: internal error number %lu\n", (ulong) error);
1357 mutex_enter(&dict_foreign_err_mutex);
1359 fputs(
" Internal error in foreign key constraint creation"
1363 "See the MySQL .err log in the datadir"
1364 " for more information.\n", ef);
1365 mutex_exit(&dict_foreign_err_mutex);
1379 dict_create_add_foreign_field_to_dictionary(
1398 return(dict_foreign_eval_sql(
1400 "PROCEDURE P () IS\n"
1402 "INSERT INTO SYS_FOREIGN_COLS VALUES"
1403 "(:id, :pos, :for_col_name, :ref_col_name);\n"
1405 table, foreign, trx));
1418 dict_create_add_foreign_to_dictionary(
1431 if (foreign->
id == NULL) {
1433 ulint namelen = strlen(table->
name);
1436 sprintf(
id,
"%s_ibfk_%lu", table->
name, (ulong) (*id_nr)++);
1450 error = dict_foreign_eval_sql(info,
1451 "PROCEDURE P () IS\n"
1453 "INSERT INTO SYS_FOREIGN VALUES"
1454 "(:id, :for_name, :ref_name, :n_cols);\n"
1456 , table, foreign, trx);
1458 if (error != DB_SUCCESS) {
1463 for (i = 0; i < foreign->
n_fields; i++) {
1464 error = dict_create_add_foreign_field_to_dictionary(
1465 i, table, foreign, trx);
1467 if (error != DB_SUCCESS) {
1473 error = dict_foreign_eval_sql(NULL,
1474 "PROCEDURE P () IS\n"
1478 , table, foreign, trx);
1502 ulint number = start_id + 1;
1509 "InnoDB: table SYS_FOREIGN not found"
1510 " in internal data dictionary\n");
1519 error = dict_create_add_foreign_to_dictionary(&number, table,
1522 if (error != DB_SUCCESS) {
#define UT_LIST_GET_LEN(BASE)
dict_table_t * sys_tables
UNIV_INTERN ulint dict_create_or_check_foreign_constraint_tables(void)
UNIV_INTERN ins_node_t * ins_node_create(ulint ins_type, dict_table_t *table, mem_heap_t *heap)
UNIV_INTERN void trx_free_for_mysql(trx_t *trx)
UNIV_INTERN void dict_table_add_to_cache(dict_table_t *table, mem_heap_t *heap)
dict_table_t * sys_fields
#define UT_LIST_GET_NEXT(NAME, N)
#define FIL_IBD_FILE_INITIAL_SIZE
UNIV_INTERN ulint dict_create_add_foreigns_to_dictionary(ulint start_id, dict_table_t *table, trx_t *trx)
UNIV_INTERN ind_node_t * ind_create_graph_create(dict_index_t *index, mem_heap_t *heap)
UNIV_INTERN const char * dict_table_get_col_name(const dict_table_t *table, ulint col_nr)
UNIV_INLINE void mach_write_to_4(byte *b, ulint n)
UNIV_INLINE dtuple_t * dtuple_create(mem_heap_t *heap, ulint n_fields)
UNIV_INTERN ulint dict_truncate_index_tree(dict_table_t *table, ulint space, btr_pcur_t *pcur, mtr_t *mtr)
dict_table_t * sys_columns
UNIV_INLINE ibool dict_table_is_comp(const dict_table_t *table)
UNIV_INLINE void mach_write_to_8(byte *b, ib_uint64_t n)
UNIV_INTERN void ins_node_set_new_row(ins_node_t *node, dtuple_t *row)
UNIV_INTERN ulint fil_space_get_zip_size(ulint id)
#define DICT_TF_FORMAT_ZIP
#define btr_block_get(space, zip_size, page_no, mode, mtr)
UNIV_INTERN void pars_info_add_int4_literal(pars_info_t *info, const char *name, lint val)
#define DICT_TF_ZSSIZE_SHIFT
UNIV_INLINE void dfield_copy(dfield_t *field1, const dfield_t *field2)
UNIV_INTERN ulint trx_commit_for_mysql(trx_t *trx)
UNIV_INLINE dict_table_t * dict_table_get_low(const char *table_name)
char * referenced_table_name
UNIV_INLINE void btr_pcur_close(btr_pcur_t *cursor)
UNIV_INTERN void dict_table_copy_types(dtuple_t *tuple, const dict_table_t *table)
UNIV_INTERN ulint btr_create(ulint type, ulint space, ulint zip_size, index_id_t index_id, dict_index_t *index, mtr_t *mtr)
UNIV_INTERN que_thr_t * dict_create_index_step(que_thr_t *thr)
UNIV_INTERN void pars_info_add_str_literal(pars_info_t *info, const char *name, const char *str)
UNIV_INTERN void mtr_commit(mtr_t *mtr) __attribute__((nonnull))
UNIV_INTERN void dict_hdr_get_new_id(table_id_t *table_id, index_id_t *index_id, ulint *space_id)
UNIV_INLINE void dfield_set_data(dfield_t *field, const void *data, ulint len)
dict_table_t * sys_indexes
UNIV_INLINE ulint dict_table_zip_size(const dict_table_t *table)
const char ** referenced_col_names
UNIV_INTERN ulint mtr_read_ulint(const byte *ptr, ulint type, mtr_t *mtr)
#define DICT_TF_FORMAT_MAX
UNIV_INLINE ulint dict_table_get_format(const dict_table_t *table)
UNIV_INTERN ibool trx_is_strict(trx_t *trx)
UNIV_INTERN dict_index_t * dict_index_get_if_in_cache_low(index_id_t index_id)
UNIV_INLINE ulint dict_index_is_clust(const dict_index_t *index) __attribute__((pure))
UNIV_INTERN que_thr_t * dict_create_table_step(que_thr_t *thr)
UNIV_INTERN void btr_pcur_store_position(btr_pcur_t *cursor, mtr_t *mtr)
UNIV_INTERN tab_node_t * tab_create_graph_create(dict_table_t *table, mem_heap_t *heap)
UNIV_INTERN void ut_print_name(FILE *f, struct trx_struct *trx, ibool table_id, const char *name)
UNIV_INTERN pars_info_t * pars_info_create(void)
UNIV_INLINE void * mem_heap_alloc(mem_heap_t *heap, ulint n)
#define mem_heap_create(N)
UNIV_INTERN ulint que_eval_sql(pars_info_t *info, const char *sql, ibool reserve_dict_mutex, trx_t *trx)
UNIV_INTERN ulint fil_create_new_single_table_tablespace(ulint space_id, const char *tablename, ibool is_temp, ulint flags, ulint size)
UNIV_INLINE void * mem_heap_zalloc(mem_heap_t *heap, ulint n)
#define DICT_TF2_SHIFT
Additional table flags.
#define UT_LIST_GET_FIRST(BASE)
UNIV_INTERN ulint dict_index_add_to_cache(dict_table_t *table, dict_index_t *index, ulint page_no, ibool strict)
my_bool srv_file_per_table
UNIV_INTERN void btr_free_but_not_root(ulint space, ulint zip_size, ulint root_page_no)
UNIV_INTERN trx_t * trx_allocate_for_mysql(void)
UNIV_INLINE que_node_t * que_node_get_parent(que_node_t *node)
UNIV_INTERN void btr_free_root(ulint space, ulint zip_size, ulint root_page_no, mtr_t *mtr)
UNIV_INLINE ulint que_node_get_type(que_node_t *node)
UNIV_INLINE void dfield_set_null(dfield_t *field)
UNIV_INLINE ulint mach_read_from_4(const byte *b) __attribute__((nonnull
#define DICT_TABLE_ORDINARY
UNIV_INTERN void ut_print_timestamp(FILE *file)
UNIV_INLINE trx_t * thr_get_trx(que_thr_t *thr)
UNIV_INTERN commit_node_t * commit_node_create(mem_heap_t *heap)
UNIV_INLINE void mtr_start(mtr_t *mtr) __attribute__((nonnull))
const char * dir_path_of_temp_table
UNIV_INLINE ibool btr_pcur_move_to_next_user_rec(btr_pcur_t *cursor, mtr_t *mtr)
UNIV_INLINE ib_uint64_t mach_read_from_8(const byte *b) __attribute__((nonnull
const char ** foreign_col_names
UNIV_INTERN void page_rec_write_index_page_no(rec_t *rec, ulint i, ulint page_no, mtr_t *mtr)
UNIV_INTERN void row_mysql_unlock_data_dictionary(trx_t *trx)
UNIV_INTERN int row_drop_table_for_mysql(const char *name, trx_t *trx, ibool drop_db)
UNIV_INTERN void fsp_header_init(ulint space, ulint size, mtr_t *mtr)
UNIV_INTERN void dict_drop_index_tree(rec_t *rec, mtr_t *mtr)
UNIV_INLINE ulint ut_strlen(const char *str)
UNIV_INTERN void dict_index_remove_from_cache(dict_table_t *table, dict_index_t *index)