~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/innobase/include/row0row.h

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-03-18 12:12:31 UTC
  • Revision ID: james.westby@ubuntu.com-20100318121231-k6g1xe6cshbwa0f8
Tags: upstream-2010.03.1347
ImportĀ upstreamĀ versionĀ 2010.03.1347

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/row0row.h
 
21
General row routines
 
22
 
 
23
Created 4/20/1996 Heikki Tuuri
 
24
*******************************************************/
 
25
 
 
26
#ifndef row0row_h
 
27
#define row0row_h
 
28
 
 
29
#include "univ.i"
 
30
#include "data0data.h"
 
31
#include "dict0types.h"
 
32
#include "trx0types.h"
 
33
#include "que0types.h"
 
34
#include "mtr0mtr.h"
 
35
#include "rem0types.h"
 
36
#include "read0types.h"
 
37
#include "row0types.h"
 
38
#include "btr0types.h"
 
39
 
 
40
/*********************************************************************//**
 
41
Gets the offset of the trx id field, in bytes relative to the origin of
 
42
a clustered index record.
 
43
@return offset of DATA_TRX_ID */
 
44
UNIV_INTERN
 
45
ulint
 
46
row_get_trx_id_offset(
 
47
/*==================*/
 
48
        const rec_t*    rec,    /*!< in: record */
 
49
        dict_index_t*   index,  /*!< in: clustered index */
 
50
        const ulint*    offsets);/*!< in: rec_get_offsets(rec, index) */
 
51
/*********************************************************************//**
 
52
Reads the trx id field from a clustered index record.
 
53
@return value of the field */
 
54
UNIV_INLINE
 
55
trx_id_t
 
56
row_get_rec_trx_id(
 
57
/*===============*/
 
58
        const rec_t*    rec,    /*!< in: record */
 
59
        dict_index_t*   index,  /*!< in: clustered index */
 
60
        const ulint*    offsets);/*!< in: rec_get_offsets(rec, index) */
 
61
/*********************************************************************//**
 
62
Reads the roll pointer field from a clustered index record.
 
63
@return value of the field */
 
64
UNIV_INLINE
 
65
roll_ptr_t
 
66
row_get_rec_roll_ptr(
 
67
/*=================*/
 
68
        const rec_t*    rec,    /*!< in: record */
 
69
        dict_index_t*   index,  /*!< in: clustered index */
 
70
        const ulint*    offsets);/*!< in: rec_get_offsets(rec, index) */
 
71
/*****************************************************************//**
 
72
When an insert or purge to a table is performed, this function builds
 
73
the entry to be inserted into or purged from an index on the table.
 
74
@return index entry which should be inserted or purged, or NULL if the
 
75
externally stored columns in the clustered index record are
 
76
unavailable and ext != NULL */
 
77
UNIV_INTERN
 
78
dtuple_t*
 
79
row_build_index_entry(
 
80
/*==================*/
 
81
        const dtuple_t* row,    /*!< in: row which should be
 
82
                                inserted or purged */
 
83
        row_ext_t*      ext,    /*!< in: externally stored column prefixes,
 
84
                                or NULL */
 
85
        dict_index_t*   index,  /*!< in: index on the table */
 
86
        mem_heap_t*     heap);  /*!< in: memory heap from which the memory for
 
87
                                the index entry is allocated */
 
88
/*******************************************************************//**
 
89
An inverse function to row_build_index_entry. Builds a row from a
 
90
record in a clustered index.
 
91
@return own: row built; see the NOTE below! */
 
92
UNIV_INTERN
 
93
dtuple_t*
 
94
row_build(
 
95
/*======*/
 
96
        ulint                   type,   /*!< in: ROW_COPY_POINTERS or
 
97
                                        ROW_COPY_DATA; the latter
 
98
                                        copies also the data fields to
 
99
                                        heap while the first only
 
100
                                        places pointers to data fields
 
101
                                        on the index page, and thus is
 
102
                                        more efficient */
 
103
        const dict_index_t*     index,  /*!< in: clustered index */
 
104
        const rec_t*            rec,    /*!< in: record in the clustered
 
105
                                        index; NOTE: in the case
 
106
                                        ROW_COPY_POINTERS the data
 
107
                                        fields in the row will point
 
108
                                        directly into this record,
 
109
                                        therefore, the buffer page of
 
110
                                        this record must be at least
 
111
                                        s-latched and the latch held
 
112
                                        as long as the row dtuple is used! */
 
113
        const ulint*            offsets,/*!< in: rec_get_offsets(rec,index)
 
114
                                        or NULL, in which case this function
 
115
                                        will invoke rec_get_offsets() */
 
116
        const dict_table_t*     col_table,
 
117
                                        /*!< in: table, to check which
 
118
                                        externally stored columns
 
119
                                        occur in the ordering columns
 
120
                                        of an index, or NULL if
 
121
                                        index->table should be
 
122
                                        consulted instead; the user
 
123
                                        columns in this table should be
 
124
                                        the same columns as in index->table */
 
125
        row_ext_t**             ext,    /*!< out, own: cache of
 
126
                                        externally stored column
 
127
                                        prefixes, or NULL */
 
128
        mem_heap_t*             heap);  /*!< in: memory heap from which
 
129
                                        the memory needed is allocated */
 
130
/*******************************************************************//**
 
131
Converts an index record to a typed data tuple.
 
132
@return index entry built; does not set info_bits, and the data fields
 
133
in the entry will point directly to rec */
 
134
UNIV_INTERN
 
135
dtuple_t*
 
136
row_rec_to_index_entry_low(
 
137
/*=======================*/
 
138
        const rec_t*            rec,    /*!< in: record in the index */
 
139
        const dict_index_t*     index,  /*!< in: index */
 
140
        const ulint*            offsets,/*!< in: rec_get_offsets(rec, index) */
 
141
        ulint*                  n_ext,  /*!< out: number of externally
 
142
                                        stored columns */
 
143
        mem_heap_t*             heap);  /*!< in: memory heap from which
 
144
                                        the memory needed is allocated */
 
145
/*******************************************************************//**
 
146
Converts an index record to a typed data tuple. NOTE that externally
 
147
stored (often big) fields are NOT copied to heap.
 
148
@return own: index entry built; see the NOTE below! */
 
149
UNIV_INTERN
 
150
dtuple_t*
 
151
row_rec_to_index_entry(
 
152
/*===================*/
 
153
        ulint                   type,   /*!< in: ROW_COPY_DATA, or
 
154
                                        ROW_COPY_POINTERS: the former
 
155
                                        copies also the data fields to
 
156
                                        heap as the latter only places
 
157
                                        pointers to data fields on the
 
158
                                        index page */
 
159
        const rec_t*            rec,    /*!< in: record in the index;
 
160
                                        NOTE: in the case
 
161
                                        ROW_COPY_POINTERS the data
 
162
                                        fields in the row will point
 
163
                                        directly into this record,
 
164
                                        therefore, the buffer page of
 
165
                                        this record must be at least
 
166
                                        s-latched and the latch held
 
167
                                        as long as the dtuple is used! */
 
168
        const dict_index_t*     index,  /*!< in: index */
 
169
        ulint*                  offsets,/*!< in/out: rec_get_offsets(rec) */
 
170
        ulint*                  n_ext,  /*!< out: number of externally
 
171
                                        stored columns */
 
172
        mem_heap_t*             heap);  /*!< in: memory heap from which
 
173
                                        the memory needed is allocated */
 
174
/*******************************************************************//**
 
175
Builds from a secondary index record a row reference with which we can
 
176
search the clustered index record.
 
177
@return own: row reference built; see the NOTE below! */
 
178
UNIV_INTERN
 
179
dtuple_t*
 
180
row_build_row_ref(
 
181
/*==============*/
 
182
        ulint           type,   /*!< in: ROW_COPY_DATA, or ROW_COPY_POINTERS:
 
183
                                the former copies also the data fields to
 
184
                                heap, whereas the latter only places pointers
 
185
                                to data fields on the index page */
 
186
        dict_index_t*   index,  /*!< in: secondary index */
 
187
        const rec_t*    rec,    /*!< in: record in the index;
 
188
                                NOTE: in the case ROW_COPY_POINTERS
 
189
                                the data fields in the row will point
 
190
                                directly into this record, therefore,
 
191
                                the buffer page of this record must be
 
192
                                at least s-latched and the latch held
 
193
                                as long as the row reference is used! */
 
194
        mem_heap_t*     heap);  /*!< in: memory heap from which the memory
 
195
                                needed is allocated */
 
196
/*******************************************************************//**
 
197
Builds from a secondary index record a row reference with which we can
 
198
search the clustered index record. */
 
199
UNIV_INTERN
 
200
void
 
201
row_build_row_ref_in_tuple(
 
202
/*=======================*/
 
203
        dtuple_t*               ref,    /*!< in/out: row reference built;
 
204
                                        see the NOTE below! */
 
205
        const rec_t*            rec,    /*!< in: record in the index;
 
206
                                        NOTE: the data fields in ref
 
207
                                        will point directly into this
 
208
                                        record, therefore, the buffer
 
209
                                        page of this record must be at
 
210
                                        least s-latched and the latch
 
211
                                        held as long as the row
 
212
                                        reference is used! */
 
213
        const dict_index_t*     index,  /*!< in: secondary index */
 
214
        ulint*                  offsets,/*!< in: rec_get_offsets(rec, index)
 
215
                                        or NULL */
 
216
        trx_t*                  trx);   /*!< in: transaction */
 
217
/*******************************************************************//**
 
218
Builds from a secondary index record a row reference with which we can
 
219
search the clustered index record. */
 
220
UNIV_INLINE
 
221
void
 
222
row_build_row_ref_fast(
 
223
/*===================*/
 
224
        dtuple_t*       ref,    /*!< in/out: typed data tuple where the
 
225
                                reference is built */
 
226
        const ulint*    map,    /*!< in: array of field numbers in rec
 
227
                                telling how ref should be built from
 
228
                                the fields of rec */
 
229
        const rec_t*    rec,    /*!< in: record in the index; must be
 
230
                                preserved while ref is used, as we do
 
231
                                not copy field values to heap */
 
232
        const ulint*    offsets);/*!< in: array returned by rec_get_offsets() */
 
233
/***************************************************************//**
 
234
Searches the clustered index record for a row, if we have the row
 
235
reference.
 
236
@return TRUE if found */
 
237
UNIV_INTERN
 
238
ibool
 
239
row_search_on_row_ref(
 
240
/*==================*/
 
241
        btr_pcur_t*             pcur,   /*!< out: persistent cursor, which must
 
242
                                        be closed by the caller */
 
243
        ulint                   mode,   /*!< in: BTR_MODIFY_LEAF, ... */
 
244
        const dict_table_t*     table,  /*!< in: table */
 
245
        const dtuple_t*         ref,    /*!< in: row reference */
 
246
        mtr_t*                  mtr);   /*!< in/out: mtr */
 
247
/*********************************************************************//**
 
248
Fetches the clustered index record for a secondary index record. The latches
 
249
on the secondary index record are preserved.
 
250
@return record or NULL, if no record found */
 
251
UNIV_INTERN
 
252
rec_t*
 
253
row_get_clust_rec(
 
254
/*==============*/
 
255
        ulint           mode,   /*!< in: BTR_MODIFY_LEAF, ... */
 
256
        const rec_t*    rec,    /*!< in: record in a secondary index */
 
257
        dict_index_t*   index,  /*!< in: secondary index */
 
258
        dict_index_t**  clust_index,/*!< out: clustered index */
 
259
        mtr_t*          mtr);   /*!< in: mtr */
 
260
/***************************************************************//**
 
261
Searches an index record.
 
262
@return TRUE if found */
 
263
UNIV_INTERN
 
264
ibool
 
265
row_search_index_entry(
 
266
/*===================*/
 
267
        dict_index_t*   index,  /*!< in: index */
 
268
        const dtuple_t* entry,  /*!< in: index entry */
 
269
        ulint           mode,   /*!< in: BTR_MODIFY_LEAF, ... */
 
270
        btr_pcur_t*     pcur,   /*!< in/out: persistent cursor, which must
 
271
                                be closed by the caller */
 
272
        mtr_t*          mtr);   /*!< in: mtr */
 
273
 
 
274
 
 
275
#define ROW_COPY_DATA           1
 
276
#define ROW_COPY_POINTERS       2
 
277
 
 
278
/* The allowed latching order of index records is the following:
 
279
(1) a secondary index record ->
 
280
(2) the clustered index record ->
 
281
(3) rollback segment data for the clustered index record.
 
282
 
 
283
No new latches may be obtained while the kernel mutex is reserved.
 
284
However, the kernel mutex can be reserved while latches are owned. */
 
285
 
 
286
/*******************************************************************//**
 
287
Formats the raw data in "data" (in InnoDB on-disk format) using
 
288
"dict_field" and writes the result to "buf".
 
289
Not more than "buf_size" bytes are written to "buf".
 
290
The result is always NUL-terminated (provided buf_size is positive) and the
 
291
number of bytes that were written to "buf" is returned (including the
 
292
terminating NUL).
 
293
@return number of bytes that were written */
 
294
UNIV_INTERN
 
295
ulint
 
296
row_raw_format(
 
297
/*===========*/
 
298
        const char*             data,           /*!< in: raw data */
 
299
        ulint                   data_len,       /*!< in: raw data length
 
300
                                                in bytes */
 
301
        const dict_field_t*     dict_field,     /*!< in: index field */
 
302
        char*                   buf,            /*!< out: output buffer */
 
303
        ulint                   buf_size);      /*!< in: output buffer size
 
304
                                                in bytes */
 
305
 
 
306
#ifndef UNIV_NONINL
 
307
#include "row0row.ic"
 
308
#endif
 
309
 
 
310
#endif