MySQL 26.7.0
Source Code Documentation
dict0crea.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1996, 2026, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 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 */
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[[nodiscard]] dberr_t dict_build_tablespace(trx_t *trx,
59 ib::fsp::Tablespace<> *tablespace);
60
61/** Builds a tablespace to contain a table, using file-per-table=1.
62@param[in,out] table Table to build in its own tablespace.
63@param[in] create_info HA_CREATE_INFO object
64@param[in,out] trx Transaction
65@return DB_SUCCESS or error code */
67 const HA_CREATE_INFO *create_info,
68 trx_t *trx);
69
70/** Assign a new table ID and put it into the table cache and the transaction.
71@param[in,out] table Table that needs an ID */
73
74/** Builds an index definition but doesn't update sys_table. */
75void dict_build_index_def(const dict_table_t *table, /*!< in: table */
76 dict_index_t *index, /*!< in/out: index */
77 trx_t *trx); /*!< in/out: InnoDB transaction
78 handle */
79/** Creates an index tree for the index if it is not a member of a cluster.
80 @param[in,out] index InnoDB index object
81 @param[in,out] trx transaction
82 @return DB_SUCCESS or DB_OUT_OF_FILE_SPACE */
84
85/** Drop an index tree belonging to a temporary table.
86@param[in] index index in a temporary table
87@param[in] root_page_no index root page number */
89 page_no_t root_page_no);
90
91/** Generate a foreign key constraint name when it was not named by the user.
92A generated constraint has a name of the format dbname/tablename_ibfk_NUMBER,
93where the numbers start from 1, and are given locally for this table, that is,
94the number is not global, as it used to be before MySQL 4.0.18.
95@param[in,out] id_nr number to use in id generation; incremented if used
96@param[in] name table name
97@param[in,out] foreign foreign key */
98static inline dberr_t dict_create_add_foreign_id(ulint *id_nr, const char *name,
99 dict_foreign_t *foreign);
100
101/** Check if a foreign constraint is on columns served as base columns
102of any stored column. This is to prevent creating SET NULL or CASCADE
103constraint on such columns
104@param[in] local_fk_set set of foreign key objects, to be added to
105the dictionary tables
106@param[in] table table to which the foreign key objects in
107local_fk_set belong to
108@return true if yes, otherwise, false */
109bool dict_foreigns_has_s_base_col(const dict_foreign_set &local_fk_set,
110 const dict_table_t *table);
111
112/* Table create node structure */
114 que_common_t common; /*!< node type: QUE_NODE_TABLE_CREATE */
115 dict_table_t *table; /*!< table to create, built as a
116 memory data structure with
117 dict_mem_... functions */
118 ins_node_t *tab_def; /*!< child node which does the insert of
119 the table definition; the row to be
120 inserted is built by the parent node */
121 ins_node_t *col_def; /*!< child node which does the inserts
122 of the column definitions; the row to
123 be inserted is built by the parent
124 node */
125 ins_node_t *v_col_def; /*!< child node which does the inserts
126 of the sys_virtual row definitions;
127 the row to be inserted is built by
128 the parent node */
129 /*----------------------*/
130 /* Local storage for this graph node */
131 ulint state; /*!< node execution state */
132 ulint col_no; /*!< next column definition to insert */
133 ulint base_col_no; /*!< next base column to insert */
134 mem_heap_t *heap; /*!< memory heap used as auxiliary
135 storage */
136};
137
138/** Create in-memory tablespace dictionary index & table
139@param[in] space tablespace id
140@param[in] space_discarded true if space is discarded
141@param[in] in_flags space flags to use when space_discarded is true
142@param[in] is_create true when creating SDI index
143@return in-memory index structure for tablespace dictionary or NULL */
144dict_index_t *dict_sdi_create_idx_in_mem(space_id_t space, bool space_discarded,
145 uint32_t in_flags, bool is_create);
146
147/* Index create node struct */
148
150 que_common_t common; /*!< node type: QUE_NODE_INDEX_CREATE */
151 dict_index_t *index; /*!< index to create, built as a
152 memory data structure with
153 dict_mem_... functions */
154 ins_node_t *ind_def; /*!< child node which does the insert of
155 the index definition; the row to be
156 inserted is built by the parent node */
157 ins_node_t *field_def; /*!< child node which does the inserts
158 of the field definitions; the row to
159 be inserted is built by the parent
160 node */
161 /*----------------------*/
162 /* Local storage for this graph node */
163 ulint state; /*!< node execution state */
164 ulint page_no; /* root page number of the index */
165 dict_table_t *table; /*!< table which owns the index */
166 dtuple_t *ind_row; /* index definition row built */
167 ulint field_no; /* next field definition to insert */
168 mem_heap_t *heap; /*!< memory heap used as auxiliary
169 storage */
170 const dict_add_v_col_t *add_v; /*!< new virtual columns that being
171 added along with an add index call */
172};
173
174/** Compose a column number for a virtual column, stored in the "POS" field
175of Sys_columns. The column number includes both its virtual column sequence
176(the "nth" virtual column) and its actual column position in original table
177@param[in] v_pos virtual column sequence
178@param[in] col_pos column position in original table definition
179@return composed column position number */
180static inline ulint dict_create_v_col_pos(ulint v_pos, ulint col_pos);
181
182/** Get the column number for a virtual column (the column position in
183original table), stored in the "POS" field of Sys_columns
184@param[in] pos virtual column position
185@return column position in original table */
187
188/** Get a virtual column sequence (the "nth" virtual column) for a
189virtual column, stord in the "POS" field of Sys_columns
190@param[in] pos virtual column position
191@return virtual column sequence */
192static inline ulint dict_get_v_col_pos(ulint pos);
193
194#include "dict0crea.ic"
195
196#endif
uint32_t space_id_t
Tablespace identifier.
Definition: api0api.h:49
uint32_t page_no_t
Page number.
Definition: api0api.h:47
Data structure that contains the information about an InnoDB tablespace.
Definition: fsp0space.h:82
dberr_t
Definition: db0err.h:39
dict_index_t * dict_sdi_create_idx_in_mem(space_id_t space, bool space_discarded, uint32_t in_flags, bool is_create)
Create in-memory tablespace dictionary index & table.
Definition: dict0crea.cc:557
void dict_drop_temporary_table_index(const dict_index_t *index, page_no_t root_page_no)
Drop an index tree belonging to a temporary table.
Definition: dict0crea.cc:453
static ulint dict_get_v_col_pos(ulint pos)
Get a virtual column sequence (the "nth" virtual column) for a virtual column, stord in the "POS" fie...
void dict_table_assign_new_id(dict_table_t *table)
Assign a new table ID and put it into the table cache and the transaction.
Definition: dict0crea.cc:540
static ulint dict_create_v_col_pos(ulint v_pos, ulint col_pos)
Compose a column number for a virtual column, stored in the "POS" field of Sys_columns.
static dberr_t dict_create_add_foreign_id(ulint *id_nr, const char *name, dict_foreign_t *foreign)
Generate a foreign key constraint name when it was not named by the user.
dberr_t dict_create_index_tree_in_mem(dict_index_t *index, trx_t *trx)
Creates an index tree for the index if it is not a member of a cluster.
Definition: dict0crea.cc:387
bool dict_foreigns_has_s_base_col(const dict_foreign_set &local_fk_set, const dict_table_t *table)
Check if a foreign constraint is on columns served as base columns of any stored column.
Definition: dict0crea.cc:508
dberr_t dict_build_table_def(dict_table_t *table, const HA_CREATE_INFO *create_info, trx_t *trx)
Build a table definition without updating SYSTEM TABLES.
Definition: dict0crea.cc:64
void dict_build_index_def(const dict_table_t *table, dict_index_t *index, trx_t *trx)
Builds an index definition but doesn't update sys_table.
Definition: dict0crea.cc:354
dberr_t dict_build_tablespace(trx_t *trx, ib::fsp::Tablespace<> *tablespace)
Builds a tablespace to store various objects.
Definition: dict0crea.cc:97
dberr_t dict_build_tablespace_for_table(dict_table_t *table, const HA_CREATE_INFO *create_info, trx_t *trx)
Builds a tablespace to contain a table, using file-per-table=1.
Definition: dict0crea.cc:179
static ulint dict_get_v_col_mysql_pos(ulint pos)
Get the column number for a virtual column (the column position in original table),...
Database object creation.
Data dictionary system.
std::set< dict_foreign_t *, dict_foreign_compare, ut::allocator< dict_foreign_t * > > dict_foreign_set
Definition: dict0mem.h:1765
Data dictionary global types.
General shared tablespace implementation.
Mini-transaction buffer.
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:76
Query graph global types.
Row operation global types.
case opt name
Definition: sslopt-case.h:29
Struct to hold information about the table that should be created.
Definition: handler.h:3356
Data structure for newly added virtual column in a table.
Definition: dict0mem.h:831
Data structure for a foreign key constraint; an example: FOREIGN KEY (A, B) REFERENCES TABLE2 (C,...
Definition: dict0mem.h:1675
Data structure for an index.
Definition: dict0mem.h:1069
Data structure for a database table.
Definition: dict0mem.h:1927
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:706
Definition: dict0crea.h:149
const dict_add_v_col_t * add_v
new virtual columns that being added along with an add index call
Definition: dict0crea.h:170
ulint page_no
Definition: dict0crea.h:164
ulint field_no
Definition: dict0crea.h:167
mem_heap_t * heap
memory heap used as auxiliary storage
Definition: dict0crea.h:168
ins_node_t * field_def
child node which does the inserts of the field definitions; the row to be inserted is built by the pa...
Definition: dict0crea.h:157
ulint state
node execution state
Definition: dict0crea.h:163
que_common_t common
node type: QUE_NODE_INDEX_CREATE
Definition: dict0crea.h:150
dict_index_t * index
index to create, built as a memory data structure with dict_mem_... functions
Definition: dict0crea.h:151
ins_node_t * ind_def
child node which does the insert of the index definition; the row to be inserted is built by the pare...
Definition: dict0crea.h:154
dtuple_t * ind_row
Definition: dict0crea.h:166
dict_table_t * table
table which owns the index
Definition: dict0crea.h:165
Definition: row0ins.h:162
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:295
Definition: que0types.h:51
Definition: dict0crea.h:113
ins_node_t * col_def
child node which does the inserts of the column definitions; the row to be inserted is built by the p...
Definition: dict0crea.h:121
que_common_t common
node type: QUE_NODE_TABLE_CREATE
Definition: dict0crea.h:114
ulint state
node execution state
Definition: dict0crea.h:131
ulint base_col_no
next base column to insert
Definition: dict0crea.h:133
dict_table_t * table
table to create, built as a memory data structure with dict_mem_... functions
Definition: dict0crea.h:115
ulint col_no
next column definition to insert
Definition: dict0crea.h:132
ins_node_t * tab_def
child node which does the insert of the table definition; the row to be inserted is built by the pare...
Definition: dict0crea.h:118
ins_node_t * v_col_def
child node which does the inserts of the sys_virtual row definitions; the row to be inserted is built...
Definition: dict0crea.h:125
mem_heap_t * heap
memory heap used as auxiliary storage
Definition: dict0crea.h:134
Definition: trx0trx.h:670
Version control for database, common definitions, and include files.
unsigned long int ulint
Definition: univ.i:403