1
/******************************************************
6
Created 4/20/1996 Heikki Tuuri
7
*******************************************************/
13
#include "data0data.h"
14
#include "que0types.h"
15
#include "dict0types.h"
16
#include "trx0types.h"
17
#include "row0types.h"
19
/*******************************************************************
20
Checks if foreign key constraint fails for an index entry. Sets shared locks
21
which lock either the success or the failure of the constraint. NOTE that
22
the caller must have a shared latch on dict_foreign_key_check_lock. */
25
row_ins_check_foreign_constraint(
26
/*=============================*/
27
/* out: DB_SUCCESS, DB_LOCK_WAIT,
29
or DB_ROW_IS_REFERENCED */
30
ibool check_ref,/* in: TRUE If we want to check that
31
the referenced table is ok, FALSE if we
32
want to to check the foreign key table */
33
dict_foreign_t* foreign,/* in: foreign constraint; NOTE that the
34
tables mentioned in it must be in the
35
dictionary cache if they exist at all */
36
dict_table_t* table, /* in: if check_ref is TRUE, then the foreign
37
table, else the referenced table */
38
dtuple_t* entry, /* in: index entry for index */
39
que_thr_t* thr); /* in: query thread */
40
/*************************************************************************
41
Creates an insert node struct. */
46
/* out, own: insert node struct */
47
ulint ins_type, /* in: INS_VALUES, ... */
48
dict_table_t* table, /* in: table where to insert */
49
mem_heap_t* heap); /* in: mem heap where created */
50
/*************************************************************************
51
Sets a new row to insert for an INS_DIRECT node. This function is only used
52
if we have constructed the row separately, which is a rare case; this
53
function is quite slow. */
58
ins_node_t* node, /* in: insert node */
59
dtuple_t* row); /* in: new row (or first row) for the node */
60
/*******************************************************************
61
Inserts an index entry to index. Tries first optimistic, then pessimistic
62
descent down the tree. If the entry matches enough to a delete marked record,
63
performs the insert by updating or delete unmarking the delete marked
69
/* out: DB_SUCCESS, DB_LOCK_WAIT,
70
DB_DUPLICATE_KEY, or some other error code */
71
dict_index_t* index, /* in: index */
72
dtuple_t* entry, /* in: index entry to insert */
73
ulint n_ext, /* in: number of externally stored columns */
74
ibool foreign,/* in: TRUE=check foreign key constraints */
75
que_thr_t* thr); /* in: query thread */
76
/***************************************************************
77
Inserts a row to a table. This is a high-level function used in
78
SQL execution graphs. */
83
/* out: query thread to run next or NULL */
84
que_thr_t* thr); /* in: query thread */
85
/***************************************************************
86
Creates an entry template for each index of a table. */
89
ins_node_create_entry_list(
90
/*=======================*/
91
ins_node_t* node); /* in: row insert node */
93
/* Insert node structure */
95
struct ins_node_struct{
96
que_common_t common; /* node type: QUE_NODE_INSERT */
97
ulint ins_type;/* INS_VALUES, INS_SEARCHED, or INS_DIRECT */
98
dtuple_t* row; /* row to insert */
99
dict_table_t* table; /* table where to insert */
100
sel_node_t* select; /* select in searched insert */
101
que_node_t* values_list;/* list of expressions to evaluate and
102
insert in an INS_VALUES insert */
103
ulint state; /* node execution state */
104
dict_index_t* index; /* NULL, or the next index where the index
105
entry should be inserted */
106
dtuple_t* entry; /* NULL, or entry to insert in the index;
107
after a successful insert of the entry,
108
this should be reset to NULL */
109
UT_LIST_BASE_NODE_T(dtuple_t)
110
entry_list;/* list of entries, one for each index */
111
byte* row_id_buf;/* buffer for the row id sys field in row */
112
dulint trx_id; /* trx id or the last trx which executed the
114
byte* trx_id_buf;/* buffer for the trx id sys field in row */
115
mem_heap_t* entry_sys_heap;
116
/* memory heap used as auxiliary storage;
117
entry_list and sys fields are stored here;
118
if this is NULL, entry list should be created
119
and buffers for sys fields in row allocated */
123
#define INS_NODE_MAGIC_N 15849075
125
/* Insert node types */
126
#define INS_SEARCHED 0 /* INSERT INTO ... SELECT ... */
127
#define INS_VALUES 1 /* INSERT INTO ... VALUES ... */
128
#define INS_DIRECT 2 /* this is for internal use in dict0crea:
129
insert the row directly */
131
/* Node execution states */
132
#define INS_NODE_SET_IX_LOCK 1 /* we should set an IX lock on table */
133
#define INS_NODE_ALLOC_ROW_ID 2 /* row id should be allocated */
134
#define INS_NODE_INSERT_ENTRIES 3 /* index entries should be built and
138
#include "row0ins.ic"