1 /***************************************************************************** 2 3 Copyright (c) 1996, 2019, Oracle and/or its affiliates. All Rights Reserved. 4 5 This program is free software; you can redistribute it and/or modify it under 6 the terms of the GNU General Public License, version 2.0, as published by the 7 Free Software Foundation. 8 9 This program is also distributed with certain software (including but not 10 limited to OpenSSL) that is licensed under separate terms, as designated in a 11 particular file or component or in included license documentation. The authors 12 of MySQL hereby grant you an additional permission to link the program and 13 your derivative works with the separately licensed software that they have 14 included with MySQL. 15 16 This program is distributed in the hope that it will be useful, but WITHOUT 17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, 19 for more details. 20 21 You should have received a copy of the GNU General Public License along with 22 this program; if not, write to the Free Software Foundation, Inc., 23 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 24 25 *****************************************************************************/ 26 27 /** @file include/dict0crea.h 28 Database object creation 29 30 Created 1/8/1996 Heikki Tuuri 31 *******************************************************/ 32 33 #ifndef dict0crea_h 34 #define dict0crea_h 35 36 #include "dict0dict.h" 37 #include "dict0types.h" 38 #include "fsp0space.h" 39 #include "mtr0mtr.h" 40 #include "que0types.h" 41 #include "row0types.h" 42 #include "univ.i" 43 44 /** Build a table definition without updating SYSTEM TABLES 45 @param[in,out] table dict table object 46 @param[in,out] trx transaction instance 47 @return DB_SUCCESS or error code */ 48 dberr_t dict_build_table_def(dict_table_t *table, trx_t *trx); 49 50 /** Builds a tablespace to store various objects. 51 @param[in,out] trx DD transaction 52 @param[in,out] tablespace Tablespace object describing what to build. 53 @return DB_SUCCESS or error code. */ 54 dberr_t dict_build_tablespace(trx_t *trx, Tablespace *tablespace); 55 56 /** Builds a tablespace to contain a table, using file-per-table=1. 57 @param[in,out] table Table to build in its own tablespace. 58 @param[in,out] trx Transaction 59 @return DB_SUCCESS or error code */ 60 dberr_t dict_build_tablespace_for_table(dict_table_t *table, trx_t *trx); 61 62 /** Assign a new table ID and put it into the table cache and the transaction. 63 @param[in,out] table Table that needs an ID 64 @param[in,out] trx Transaction */ 65 void dict_table_assign_new_id(dict_table_t *table, trx_t *trx); 66 67 /** Builds an index definition but doesn't update sys_table. */ 68 void dict_build_index_def(const dict_table_t *table, /*!< in: table */ 69 dict_index_t *index, /*!< in/out: index */ 70 trx_t *trx); /*!< in/out: InnoDB transaction 71 handle */ 72 /** Creates an index tree for the index if it is not a member of a cluster. 73 @param[in,out] index InnoDB index object 74 @param[in,out] trx transaction 75 @return DB_SUCCESS or DB_OUT_OF_FILE_SPACE */ 76 dberr_t dict_create_index_tree_in_mem(dict_index_t *index, trx_t *trx); 77 78 /** Drop an index tree belonging to a temporary table. 79 @param[in] index index in a temporary table 80 @param[in] root_page_no index root page number */ 81 void dict_drop_temporary_table_index(const dict_index_t *index, 82 page_no_t root_page_no); 83 84 /** Generate a foreign key constraint name when it was not named by the user. 85 A generated constraint has a name of the format dbname/tablename_ibfk_NUMBER, 86 where the numbers start from 1, and are given locally for this table, that is, 87 the number is not global, as it used to be before MySQL 4.0.18. 88 @param[in,out] id_nr number to use in id generation; incremented if used 89 @param[in] name table name 90 @param[in,out] foreign foreign key */ 91 UNIV_INLINE 92 dberr_t dict_create_add_foreign_id(ulint *id_nr, const char *name, 93 dict_foreign_t *foreign); 94 95 /** Check if a foreign constraint is on columns server as base columns 96 of any stored column. This is to prevent creating SET NULL or CASCADE 97 constraint on such columns 98 @param[in] local_fk_set set of foreign key objects, to be added to 99 the dictionary tables 100 @param[in] table table to which the foreign key objects in 101 local_fk_set belong to 102 @return true if yes, otherwise, false */ 103 bool dict_foreigns_has_s_base_col(const dict_foreign_set &local_fk_set, 104 const dict_table_t *table); 105 106 /* Table create node structure */ 107 struct tab_node_t { 108 que_common_t common; /*!< node type: QUE_NODE_TABLE_CREATE */ 109 dict_table_t *table; /*!< table to create, built as a 110 memory data structure with 111 dict_mem_... functions */ 112 ins_node_t *tab_def; /*!< child node which does the insert of 113 the table definition; the row to be 114 inserted is built by the parent node */ 115 ins_node_t *col_def; /*!< child node which does the inserts 116 of the column definitions; the row to 117 be inserted is built by the parent 118 node */ 119 ins_node_t *v_col_def; /*!< child node which does the inserts 120 of the sys_virtual row definitions; 121 the row to be inserted is built by 122 the parent node */ 123 /*----------------------*/ 124 /* Local storage for this graph node */ 125 ulint state; /*!< node execution state */ 126 ulint col_no; /*!< next column definition to insert */ 127 ulint base_col_no; /*!< next base column to insert */ 128 mem_heap_t *heap; /*!< memory heap used as auxiliary 129 storage */ 130 }; 131 132 /** Create in-memory tablespace dictionary index & table 133 @param[in] space tablespace id 134 @param[in] space_discarded true if space is discarded 135 @param[in] in_flags space flags to use when space_discarded is true 136 @param[in] is_create true when creating SDI index 137 @return in-memory index structure for tablespace dictionary or NULL */ 138 dict_index_t *dict_sdi_create_idx_in_mem(space_id_t space, bool space_discarded, 139 uint32_t in_flags, bool is_create); 140 141 /* Index create node struct */ 142 143 struct ind_node_t { 144 que_common_t common; /*!< node type: QUE_NODE_INDEX_CREATE */ 145 dict_index_t *index; /*!< index to create, built as a 146 memory data structure with 147 dict_mem_... functions */ 148 ins_node_t *ind_def; /*!< child node which does the insert of 149 the index definition; the row to be 150 inserted is built by the parent node */ 151 ins_node_t *field_def; /*!< child node which does the inserts 152 of the field definitions; the row to 153 be inserted is built by the parent 154 node */ 155 /*----------------------*/ 156 /* Local storage for this graph node */ 157 ulint state; /*!< node execution state */ 158 ulint page_no; /* root page number of the index */ 159 dict_table_t *table; /*!< table which owns the index */ 160 dtuple_t *ind_row; /* index definition row built */ 161 ulint field_no; /* next field definition to insert */ 162 mem_heap_t *heap; /*!< memory heap used as auxiliary 163 storage */ 164 const dict_add_v_col_t *add_v; /*!< new virtual columns that being 165 added along with an add index call */ 166 }; 167 168 /** Compose a column number for a virtual column, stored in the "POS" field 169 of Sys_columns. The column number includes both its virtual column sequence 170 (the "nth" virtual column) and its actual column position in original table 171 @param[in] v_pos virtual column sequence 172 @param[in] col_pos column position in original table definition 173 @return composed column position number */ 174 UNIV_INLINE 175 ulint dict_create_v_col_pos(ulint v_pos, ulint col_pos); 176 177 /** Get the column number for a virtual column (the column position in 178 original table), stored in the "POS" field of Sys_columns 179 @param[in] pos virtual column position 180 @return column position in original table */ 181 UNIV_INLINE 182 ulint dict_get_v_col_mysql_pos(ulint pos); 183 184 /** Get a virtual column sequence (the "nth" virtual column) for a 185 virtual column, stord in the "POS" field of Sys_columns 186 @param[in] pos virtual column position 187 @return virtual column sequence */ 188 UNIV_INLINE 189 ulint dict_get_v_col_pos(ulint pos); 190 191 #include "dict0crea.ic" 192 193 #endif 194