~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to storage/innodb_plugin/include/row0ins.h

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 
 
3
Copyright (c) 1996, 2009, Innobase Oy. 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 as published by the Free Software
 
7
Foundation; version 2 of the License.
 
8
 
 
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.
 
12
 
 
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., 59 Temple
 
15
Place, Suite 330, Boston, MA 02111-1307 USA
 
16
 
 
17
*****************************************************************************/
 
18
 
 
19
/**************************************************//**
 
20
@file include/row0ins.h
 
21
Insert into a table
 
22
 
 
23
Created 4/20/1996 Heikki Tuuri
 
24
*******************************************************/
 
25
 
 
26
#ifndef row0ins_h
 
27
#define row0ins_h
 
28
 
 
29
#include "univ.i"
 
30
#include "data0data.h"
 
31
#include "que0types.h"
 
32
#include "dict0types.h"
 
33
#include "trx0types.h"
 
34
#include "row0types.h"
 
35
 
 
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 */
 
42
UNIV_INTERN
 
43
ulint
 
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 */
 
59
UNIV_INTERN
 
60
ins_node_t*
 
61
ins_node_create(
 
62
/*============*/
 
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. */
 
70
UNIV_INTERN
 
71
void
 
72
ins_node_set_new_row(
 
73
/*=================*/
 
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
 
80
record.
 
81
@return DB_SUCCESS, DB_LOCK_WAIT, DB_DUPLICATE_KEY, or some other error code */
 
82
UNIV_INTERN
 
83
ulint
 
84
row_ins_index_entry(
 
85
/*================*/
 
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
 
93
SQL execution graphs.
 
94
@return query thread to run next or NULL */
 
95
UNIV_INTERN
 
96
que_thr_t*
 
97
row_ins_step(
 
98
/*=========*/
 
99
        que_thr_t*      thr);   /*!< in: query thread */
 
100
/***********************************************************//**
 
101
Creates an entry template for each index of a table. */
 
102
UNIV_INTERN
 
103
void
 
104
ins_node_create_entry_list(
 
105
/*=======================*/
 
106
        ins_node_t*     node);  /*!< in: row insert node */
 
107
 
 
108
/* Insert node structure */
 
109
 
 
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
 
128
                                node */
 
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 */
 
135
        ulint           magic_n;
 
136
};
 
137
 
 
138
#define INS_NODE_MAGIC_N        15849075
 
139
 
 
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 */
 
145
 
 
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
 
150
                                        inserted */
 
151
 
 
152
#ifndef UNIV_NONINL
 
153
#include "row0ins.ic"
 
154
#endif
 
155
 
 
156
#endif