MySQL  8.0.19
Source Code Documentation
row0ins.h
Go to the documentation of this file.
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/row0ins.h
28  Insert into a table
29 
30  Created 4/20/1996 Heikki Tuuri
31  *******************************************************/
32 
33 #ifndef row0ins_h
34 #define row0ins_h
35 
36 #include "data0data.h"
37 #include "dict0types.h"
38 #include "que0types.h"
39 #include "row0types.h"
40 #include "trx0types.h"
41 #include "univ.i"
42 
43 /** Checks if foreign key constraint fails for an index entry. Sets shared locks
44  which lock either the success or the failure of the constraint. NOTE that
45  the caller must have a shared latch on dict_foreign_key_check_lock.
46  @return DB_SUCCESS, DB_LOCK_WAIT, DB_NO_REFERENCED_ROW, or
47  DB_ROW_IS_REFERENCED */
49  ibool check_ref, /*!< in: TRUE If we want to check that
50  the referenced table is ok, FALSE if we
51  want to check the foreign key table */
52  dict_foreign_t *foreign, /*!< in: foreign constraint; NOTE that the
53  tables mentioned in it must be in the
54  dictionary cache if they exist at all */
55  dict_table_t *table, /*!< in: if check_ref is TRUE, then the foreign
56  table, else the referenced table */
57  dtuple_t *entry, /*!< in: index entry for index */
58  que_thr_t *thr) /*!< in: query thread */
59  MY_ATTRIBUTE((warn_unused_result));
60 /** Creates an insert node struct.
61  @return own: insert node struct */
63  ulint ins_type, /*!< in: INS_VALUES, ... */
64  dict_table_t *table, /*!< in: table where to insert */
65  mem_heap_t *heap); /*!< in: mem heap where created */
66 /** Sets a new row to insert for an INS_DIRECT node. This function is only used
67  if we have constructed the row separately, which is a rare case; this
68  function is quite slow. */
70  ins_node_t *node, /*!< in: insert node */
71  dtuple_t *row); /*!< in: new row (or first row) for the node */
72 /** Tries to insert an entry into a clustered index, ignoring foreign key
73  constraints. If a record with the same unique key is found, the other
74  record is necessarily marked deleted by a committed transaction, or a
75  unique key violation error occurs. The delete marked record is then
76  updated to an existing record, and we must write an undo log record on
77  the delete marked record.
78  @retval DB_SUCCESS on success
79  @retval DB_LOCK_WAIT on lock wait when !(flags & BTR_NO_LOCKING_FLAG)
80  @retval DB_FAIL if retry with BTR_MODIFY_TREE is needed
81  @return error code */
83  ulint flags, /*!< in: undo logging and locking flags */
84  ulint mode, /*!< in: BTR_MODIFY_LEAF or BTR_MODIFY_TREE,
85  depending on whether we wish optimistic or
86  pessimistic descent down the index tree */
87  dict_index_t *index, /*!< in: clustered index */
88  ulint n_uniq, /*!< in: 0 or index->n_uniq */
89  dtuple_t *entry, /*!< in/out: index entry to insert */
90  ulint n_ext, /*!< in: number of externally stored columns */
91  que_thr_t *thr, /*!< in: query thread, or NULL if
92  flags & (BTR_NO_LOCKING_FLAG
93  | BTR_NO_UNDO_LOG_FLAG) and a duplicate
94  can't occur */
95  bool dup_chk_only)
96  /*!< in: if true, just do duplicate check
97  and return. don't execute actual insert. */
98  MY_ATTRIBUTE((warn_unused_result));
99 
100 /** Tries to insert an entry into a secondary index. If a record with exactly
101 the same fields is found, the other record is necessarily marked deleted.
102 It is then unmarked. Otherwise, the entry is just inserted to the index.
103 @param[in] flags undo logging and locking flags
104 @param[in] mode BTR_MODIFY_LEAF or BTR_MODIFY_TREE,
105  depending on whether we wish optimistic or
106  pessimistic descent down the index tree
107 @param[in] index secondary index
108 @param[in,out] offsets_heap memory heap that can be emptied
109 @param[in,out] heap memory heap
110 @param[in,out] entry index entry to insert
111 @param[in] trx_id PAGE_MAX_TRX_ID during row_log_table_apply(),
112  or trx_id when undo log is disabled during
113  alter copy operation or 0
114 @param[in] thr query thread
115 @param[in] dup_chk_only TRUE, just do duplicate check and return.
116  don't execute actual insert
117 @retval DB_SUCCESS on success
118 @retval DB_LOCK_WAIT on lock wait when !(flags & BTR_NO_LOCKING_FLAG)
119 @retval DB_FAIL if retry with BTR_MODIFY_TREE is needed
120 @return error code */
121 dberr_t row_ins_sec_index_entry_low(ulint flags, ulint mode,
123  mem_heap_t *offsets_heap, mem_heap_t *heap,
125  que_thr_t *thr, bool dup_chk_only)
126  MY_ATTRIBUTE((warn_unused_result));
127 
128 /** Sets the values of the dtuple fields in entry from the values of appropriate
129 columns in row.
130 @param[in] index index handler
131 @param[out] entry index entry to make
132 @param[in] row row */
134  const dtuple_t *row);
135 
136 /** Inserts an entry into a clustered index. Tries first optimistic,
137  then pessimistic descent down the tree. If the entry matches enough
138  to a delete marked record, performs the insert by updating or delete
139  unmarking the delete marked record.
140  @return DB_SUCCESS, DB_LOCK_WAIT, DB_DUPLICATE_KEY, or some other error code */
142  dict_index_t *index, /*!< in: clustered index */
143  dtuple_t *entry, /*!< in/out: index entry to insert */
144  que_thr_t *thr, /*!< in: query thread */
145  ulint n_ext, /*!< in: number of externally stored columns */
146  bool dup_chk_only)
147  /*!< in: if true, just do duplicate check
148  and return. don't execute actual insert. */
149  MY_ATTRIBUTE((warn_unused_result));
150 /** Inserts an entry into a secondary index. Tries first optimistic,
151  then pessimistic descent down the tree. If the entry matches enough
152  to a delete marked record, performs the insert by updating or delete
153  unmarking the delete marked record.
154  @return DB_SUCCESS, DB_LOCK_WAIT, DB_DUPLICATE_KEY, or some other error code */
156  dict_index_t *index, /*!< in: secondary index */
157  dtuple_t *entry, /*!< in/out: index entry to insert */
158  que_thr_t *thr, /*!< in: query thread */
159  bool dup_chk_only)
160  /*!< in: if true, just do duplicate check
161  and return. don't execute actual insert. */
162  MY_ATTRIBUTE((warn_unused_result));
163 /** Inserts a row to a table. This is a high-level function used in
164  SQL execution graphs.
165  @return query thread to run next or NULL */
166 que_thr_t *row_ins_step(que_thr_t *thr); /*!< in: query thread */
167 
168 /* Insert node structure */
169 
170 struct ins_node_t {
171  que_common_t common; /*!< node type: QUE_NODE_INSERT */
172  ulint ins_type; /* INS_VALUES, INS_SEARCHED, or INS_DIRECT */
173  dtuple_t *row; /*!< row to insert */
174  dict_table_t *table; /*!< table where to insert */
175  sel_node_t *select; /*!< select in searched insert */
176  que_node_t *values_list; /* list of expressions to evaluate and
177  insert in an INS_VALUES insert */
178  ulint state; /*!< node execution state */
179  dict_index_t *index; /*!< NULL, or the next index where the index
180  entry should be inserted */
181  dtuple_t *entry; /*!< NULL, or entry to insert in the index;
182  after a successful insert of the entry,
183  this should be reset to NULL */
185  entry_list; /* list of entries, one for each index */
186  byte *row_id_buf; /* buffer for the row id sys field in row */
187  trx_id_t trx_id; /*!< trx id or the last trx which executed the
188  node */
189  byte *trx_id_buf; /* buffer for the trx id sys field in row */
191  /* memory heap used as auxiliary storage;
192  entry_list and sys fields are stored here;
193  if this is NULL, entry list should be created
194  and buffers for sys fields in row allocated */
195 
196  /** When there is a lock wait error, this remembers current position of
197  the multi-value field, before which the values have been inserted */
199 
200  ulint magic_n;
201 };
202 
203 #define INS_NODE_MAGIC_N 15849075
204 
205 /* Insert node types */
206 #define INS_SEARCHED 0 /* INSERT INTO ... SELECT ... */
207 #define INS_VALUES 1 /* INSERT INTO ... VALUES ... */
208 #define INS_DIRECT \
209  2 /* this is for internal use in dict0crea: \
210  insert the row directly */
211 
212 /* Node execution states */
213 #define INS_NODE_SET_IX_LOCK 1 /* we should set an IX lock on table */
214 #define INS_NODE_ALLOC_ROW_ID 2 /* row id should be allocated */
215 #define INS_NODE_INSERT_ENTRIES \
216  3 /* index entries should be built and \
217  inserted */
218 
219 #include "row0ins.ic"
220 
221 #endif
dtuple_t
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:716
ins_node_t::entry_sys_heap
mem_heap_t * entry_sys_heap
Definition: row0ins.h:190
ins_node_t::ins_type
ulint ins_type
Definition: row0ins.h:172
dict0types.h
row_ins_clust_index_entry_low
dberr_t row_ins_clust_index_entry_low(ulint flags, ulint mode, dict_index_t *index, ulint n_uniq, dtuple_t *entry, ulint n_ext, que_thr_t *thr, bool dup_chk_only)
Tries to insert an entry into a clustered index, ignoring foreign key constraints.
Definition: row0ins.cc:2329
UT_LIST_BASE_NODE_T
#define UT_LIST_BASE_NODE_T(TYPE)
Definition: innodb_utility.h:46
ins_node_t::row
dtuple_t * row
row to insert
Definition: row0ins.h:173
trx_id_t
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:148
ins_node_t::row_id_buf
byte * row_id_buf
Definition: row0ins.h:186
dict_foreign_t
Data structure for a foreign key constraint; an example: FOREIGN KEY (A, B) REFERENCES TABLE2 (C,...
Definition: dict0mem.h:1277
ins_node_t::state
ulint state
node execution state
Definition: row0ins.h:178
dict_index_t
Data structure for an index.
Definition: dict0mem.h:869
ins_node_t
Definition: row0ins.h:170
row_ins_step
que_thr_t * row_ins_step(que_thr_t *thr)
Inserts a row to a table.
Definition: row0ins.cc:3589
ins_node_t::values_list
que_node_t * values_list
Definition: row0ins.h:176
row_prebuilt_t::table
dict_table_t * table
Innobase table handle.
Definition: row0mysql.h:544
dberr_t
dberr_t
Definition: db0err.h:38
dict_table_t
Data structure for a database table.
Definition: dict0mem.h:1510
row_ins_index_entry_set_vals
dberr_t row_ins_index_entry_set_vals(const dict_index_t *index, dtuple_t *entry, const dtuple_t *row)
Sets the values of the dtuple fields in entry from the values of appropriate columns in row.
Definition: row0ins.cc:3336
row_ins_clust_index_entry
dberr_t row_ins_clust_index_entry(dict_index_t *index, dtuple_t *entry, que_thr_t *thr, ulint n_ext, bool dup_chk_only)
Inserts an entry into a clustered index.
Definition: row0ins.cc:3053
que0types.h
mem_block_info_t
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:337
ins_node_t::common
que_common_t common
node type: QUE_NODE_INSERT
Definition: row0ins.h:171
row_prebuilt_t::heap
mem_heap_t * heap
memory heap from which these auxiliary structures are allocated when needed
Definition: row0mysql.h:616
ins_node_t::ins_multi_val_pos
uint32_t ins_multi_val_pos
When there is a lock wait error, this remembers current position of the multi-value field,...
Definition: row0ins.h:198
row0types.h
ins_node_t::trx_id
trx_id_t trx_id
trx id or the last trx which executed the node
Definition: row0ins.h:187
row_ins_sec_index_entry
dberr_t row_ins_sec_index_entry(dict_index_t *index, dtuple_t *entry, que_thr_t *thr, bool dup_chk_only)
Inserts an entry into a secondary index.
Definition: row0ins.cc:3140
ins_node_t::table
dict_table_t * table
table where to insert
Definition: row0ins.h:174
que_node_t
void que_node_t
Definition: que0types.h:40
trx0types.h
que_common_t
Definition: que0types.h:50
row_ins_check_foreign_constraint
dberr_t row_ins_check_foreign_constraint(ibool check_ref, dict_foreign_t *foreign, dict_table_t *table, dtuple_t *entry, que_thr_t *thr)
Checks if foreign key constraint fails for an index entry.
Definition: row0ins.cc:1343
_entry
Definition: completion_hash.h:34
ins_node_t::index
dict_index_t * index
NULL, or the next index where the index entry should be inserted.
Definition: row0ins.h:179
ins_node_set_new_row
void ins_node_set_new_row(ins_node_t *node, dtuple_t *row)
Sets a new row to insert for an INS_DIRECT node.
Definition: row0ins.cc:190
sel_node_t
Select statement node.
Definition: row0sel.h:337
row_prebuilt_t::trx_id
trx_id_t trx_id
The table->def_trx_id when ins_graph was built.
Definition: row0mysql.h:643
ins_node_t::select
sel_node_t * select
select in searched insert
Definition: row0ins.h:175
row_ins_sec_index_entry_low
dberr_t row_ins_sec_index_entry_low(ulint flags, ulint mode, dict_index_t *index, mem_heap_t *offsets_heap, mem_heap_t *heap, dtuple_t *entry, trx_id_t trx_id, que_thr_t *thr, bool dup_chk_only)
Tries to insert an entry into a secondary index.
Definition: row0ins.cc:2771
ins_node_t::entry
dtuple_t * entry
NULL, or entry to insert in the index; after a successful insert of the entry, this should be reset t...
Definition: row0ins.h:181
data0data.h
que_thr_t
Definition: que0que.h:246
ins_node_t::magic_n
ulint magic_n
Definition: row0ins.h:200
ins_node_t::entry_list
entry_list
Definition: row0ins.h:185
index
char * index(const char *, int c)
Definition: mysql.cc:2875
ins_node_create
ins_node_t * ins_node_create(ulint ins_type, dict_table_t *table, mem_heap_t *heap)
Creates an insert node struct.
Definition: row0ins.cc:78
ins_node_t::trx_id_buf
byte * trx_id_buf
Definition: row0ins.h:189
flags
static int flags[50]
Definition: hp_test1.cc:39