1
/*****************************************************************************
3
Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/row0ins.h
23
Created 4/20/1996 Heikki Tuuri
24
*******************************************************/
30
#include "data0data.h"
31
#include "que0types.h"
32
#include "dict0types.h"
33
#include "trx0types.h"
34
#include "row0types.h"
36
/***************************************************************//**
37
Checks if foreign key constraint fails for an index entry. Sets shared locks
38
which lock either the success or the failure of the constraint. NOTE that
39
the caller must have a shared latch on dict_foreign_key_check_lock.
40
@return DB_SUCCESS, DB_LOCK_WAIT, DB_NO_REFERENCED_ROW, or
41
DB_ROW_IS_REFERENCED */
44
row_ins_check_foreign_constraint(
45
/*=============================*/
46
ibool check_ref,/*!< in: TRUE If we want to check that
47
the referenced table is ok, FALSE if we
48
want to check the foreign key table */
49
dict_foreign_t* foreign,/*!< in: foreign constraint; NOTE that the
50
tables mentioned in it must be in the
51
dictionary cache if they exist at all */
52
dict_table_t* table, /*!< in: if check_ref is TRUE, then the foreign
53
table, else the referenced table */
54
dtuple_t* entry, /*!< in: index entry for index */
55
que_thr_t* thr); /*!< in: query thread */
56
/*********************************************************************//**
57
Creates an insert node struct.
58
@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
/*********************************************************************//**
67
Sets a new row to insert for an INS_DIRECT node. This function is only used
68
if we have constructed the row separately, which is a rare case; this
69
function is quite slow. */
74
ins_node_t* node, /*!< in: insert node */
75
dtuple_t* row); /*!< in: new row (or first row) for the node */
76
/***************************************************************//**
77
Inserts an index entry to index. Tries first optimistic, then pessimistic
78
descent down the tree. If the entry matches enough to a delete marked record,
79
performs the insert by updating or delete unmarking the delete marked
81
@return DB_SUCCESS, DB_LOCK_WAIT, DB_DUPLICATE_KEY, or some other error code */
86
dict_index_t* index, /*!< in: index */
87
dtuple_t* entry, /*!< in: index entry to insert */
88
ulint n_ext, /*!< in: number of externally stored columns */
89
ibool foreign,/*!< in: TRUE=check foreign key constraints */
90
que_thr_t* thr); /*!< in: query thread */
91
/***********************************************************//**
92
Inserts a row to a table. This is a high-level function used in
94
@return query thread to run next or NULL */
99
que_thr_t* thr); /*!< in: query thread */
100
/***********************************************************//**
101
Creates an entry template for each index of a table. */
104
ins_node_create_entry_list(
105
/*=======================*/
106
ins_node_t* node); /*!< in: row insert node */
108
/* Insert node structure */
110
struct ins_node_struct{
111
que_common_t common; /*!< node type: QUE_NODE_INSERT */
112
ulint ins_type;/* INS_VALUES, INS_SEARCHED, or INS_DIRECT */
113
dtuple_t* row; /*!< row to insert */
114
dict_table_t* table; /*!< table where to insert */
115
sel_node_t* select; /*!< select in searched insert */
116
que_node_t* values_list;/* list of expressions to evaluate and
117
insert in an INS_VALUES insert */
118
ulint state; /*!< node execution state */
119
dict_index_t* index; /*!< NULL, or the next index where the index
120
entry should be inserted */
121
dtuple_t* entry; /*!< NULL, or entry to insert in the index;
122
after a successful insert of the entry,
123
this should be reset to NULL */
124
UT_LIST_BASE_NODE_T(dtuple_t)
125
entry_list;/* list of entries, one for each index */
126
byte* row_id_buf;/* buffer for the row id sys field in row */
127
trx_id_t trx_id; /*!< trx id or the last trx which executed the
129
byte* trx_id_buf;/* buffer for the trx id sys field in row */
130
mem_heap_t* entry_sys_heap;
131
/* memory heap used as auxiliary storage;
132
entry_list and sys fields are stored here;
133
if this is NULL, entry list should be created
134
and buffers for sys fields in row allocated */
138
#define INS_NODE_MAGIC_N 15849075
140
/* Insert node types */
141
#define INS_SEARCHED 0 /* INSERT INTO ... SELECT ... */
142
#define INS_VALUES 1 /* INSERT INTO ... VALUES ... */
143
#define INS_DIRECT 2 /* this is for internal use in dict0crea:
144
insert the row directly */
146
/* Node execution states */
147
#define INS_NODE_SET_IX_LOCK 1 /* we should set an IX lock on table */
148
#define INS_NODE_ALLOC_ROW_ID 2 /* row id should be allocated */
149
#define INS_NODE_INSERT_ENTRIES 3 /* index entries should be built and
153
#include "row0ins.ic"