Debian Codegraph @

storage/innobase/include/dict0crea.h

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