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/out: index entry to insert */
88
ulint n_ext, /*!< in: number of externally stored columns */
89
ibool foreign,/*!< in: TRUE=check foreign key constraints
90
(foreign=FALSE only during CREATE INDEX) */
91
que_thr_t* thr); /*!< in: query thread */
92
/***********************************************************//**
93
Inserts a row to a table. This is a high-level function used in
95
@return query thread to run next or NULL */
100
que_thr_t* thr); /*!< in: query thread */
101
/***********************************************************//**
102
Creates an entry template for each index of a table. */
105
ins_node_create_entry_list(
106
/*=======================*/
107
ins_node_t* node); /*!< in: row insert node */
109
/* Insert node structure */
111
struct ins_node_struct{
112
que_common_t common; /*!< node type: QUE_NODE_INSERT */
113
ulint ins_type;/* INS_VALUES, INS_SEARCHED, or INS_DIRECT */
114
dtuple_t* row; /*!< row to insert */
115
dict_table_t* table; /*!< table where to insert */
116
sel_node_t* select; /*!< select in searched insert */
117
que_node_t* values_list;/* list of expressions to evaluate and
118
insert in an INS_VALUES insert */
119
ulint state; /*!< node execution state */
120
dict_index_t* index; /*!< NULL, or the next index where the index
121
entry should be inserted */
122
dtuple_t* entry; /*!< NULL, or entry to insert in the index;
123
after a successful insert of the entry,
124
this should be reset to NULL */
125
UT_LIST_BASE_NODE_T(dtuple_t)
126
entry_list;/* list of entries, one for each index */
127
byte* row_id_buf;/* buffer for the row id sys field in row */
128
trx_id_t trx_id; /*!< trx id or the last trx which executed the
130
byte* trx_id_buf;/* buffer for the trx id sys field in row */
131
mem_heap_t* entry_sys_heap;
132
/* memory heap used as auxiliary storage;
133
entry_list and sys fields are stored here;
134
if this is NULL, entry list should be created
135
and buffers for sys fields in row allocated */
139
#define INS_NODE_MAGIC_N 15849075
141
/* Insert node types */
142
#define INS_SEARCHED 0 /* INSERT INTO ... SELECT ... */
143
#define INS_VALUES 1 /* INSERT INTO ... VALUES ... */
144
#define INS_DIRECT 2 /* this is for internal use in dict0crea:
145
insert the row directly */
147
/* Node execution states */
148
#define INS_NODE_SET_IX_LOCK 1 /* we should set an IX lock on table */
149
#define INS_NODE_ALLOC_ROW_ID 2 /* row id should be allocated */
150
#define INS_NODE_INSERT_ENTRIES 3 /* index entries should be built and
154
#include "row0ins.ic"