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