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