~drizzle-trunk/drizzle/development

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"
20
#include "btr0types.h"
21
22
/*************************************************************************
23
Reads the trx id field from a clustered index record. */
24
UNIV_INLINE
25
dulint
26
row_get_rec_trx_id(
27
/*===============*/
28
				/* out: value of the field */
29
	rec_t*		rec,	/* in: record */
30
	dict_index_t*	index,	/* in: clustered index */
31
	const ulint*	offsets);/* in: rec_get_offsets(rec, index) */
32
/*************************************************************************
33
Reads the roll pointer field from a clustered index record. */
34
UNIV_INLINE
35
dulint
36
row_get_rec_roll_ptr(
37
/*=================*/
38
				/* out: value of the field */
39
	rec_t*		rec,	/* in: record */
40
	dict_index_t*	index,	/* in: clustered index */
41
	const ulint*	offsets);/* in: rec_get_offsets(rec, index) */
42
/*************************************************************************
43
Writes the trx id field to a clustered index record. */
44
UNIV_INLINE
45
void
46
row_set_rec_trx_id(
47
/*===============*/
48
	rec_t*		rec,	/* in: record */
49
	dict_index_t*	index,	/* in: clustered index */
50
	const ulint*	offsets,/* in: rec_get_offsets(rec, index) */
51
	dulint		trx_id);/* in: value of the field */
52
/*************************************************************************
53
Sets the roll pointer field in a clustered index record. */
54
UNIV_INLINE
55
void
56
row_set_rec_roll_ptr(
57
/*=================*/
58
	rec_t*		rec,	/* in: record */
59
	dict_index_t*	index,	/* in: clustered index */
60
	const ulint*	offsets,/* in: rec_get_offsets(rec, index) */
61
	dulint		roll_ptr);/* in: value of the field */
62
/*********************************************************************
63
When an insert to a table is performed, this function builds the entry which
64
has to be inserted to an index on the table. */
65
66
dtuple_t*
67
row_build_index_entry(
68
/*==================*/
69
				/* out: index entry which should be inserted */
70
	dtuple_t*	row,	/* in: row which should be inserted to the
71
				table */
72
	dict_index_t*	index,	/* in: index on the table */
73
	mem_heap_t*	heap);	/* in: memory heap from which the memory for
74
				the index entry is allocated */
75
/***********************************************************************
76
An inverse function to dict_row_build_index_entry. Builds a row from a
77
record in a clustered index. */
78
79
dtuple_t*
80
row_build(
81
/*======*/
82
				/* out, own: row built; see the NOTE below! */
83
	ulint		type,	/* in: ROW_COPY_POINTERS or ROW_COPY_DATA;
84
				the latter copies also the data fields to
85
				heap while the first only places pointers to
86
				data fields on the index page, and thus is
87
				more efficient */
88
	dict_index_t*	index,	/* in: clustered index */
89
	rec_t*		rec,	/* in: record in the clustered index;
90
				NOTE: in the case ROW_COPY_POINTERS
91
				the data fields in the row will point
92
				directly into this record, therefore,
93
				the buffer page of this record must be
94
				at least s-latched and the latch held
95
				as long as the row dtuple is used! */
96
	const ulint*	offsets,/* in: rec_get_offsets(rec, index)
97
				or NULL, in which case this function
98
				will invoke rec_get_offsets() */
99
	mem_heap_t*	heap);	/* in: memory heap from which the memory
100
				needed is allocated */
101
/***********************************************************************
102
Converts an index record to a typed data tuple. */
103
104
dtuple_t*
105
row_rec_to_index_entry(
106
/*===================*/
107
				/* out, own: index entry built; see the
108
				NOTE below! */
109
	ulint		type,	/* in: ROW_COPY_DATA, or ROW_COPY_POINTERS:
110
				the former copies also the data fields to
111
				heap as the latter only places pointers to
112
				data fields on the index page */
113
	dict_index_t*	index,	/* in: index */
114
	rec_t*		rec,	/* in: record in the index;
115
				NOTE: in the case ROW_COPY_POINTERS
116
				the data fields in the row will point
117
				directly into this record, therefore,
118
				the buffer page of this record must be
119
				at least s-latched and the latch held
120
				as long as the dtuple is used! */
121
	mem_heap_t*	heap);	/* in: memory heap from which the memory
122
				needed is allocated */
123
/***********************************************************************
124
Builds from a secondary index record a row reference with which we can
125
search the clustered index record. */
126
127
dtuple_t*
128
row_build_row_ref(
129
/*==============*/
130
				/* out, own: row reference built; see the
131
				NOTE below! */
132
	ulint		type,	/* in: ROW_COPY_DATA, or ROW_COPY_POINTERS:
133
				the former copies also the data fields to
134
				heap, whereas the latter only places pointers
135
				to data fields on the index page */
136
	dict_index_t*	index,	/* in: index */
137
	rec_t*		rec,	/* in: record in the index;
138
				NOTE: in the case ROW_COPY_POINTERS
139
				the data fields in the row will point
140
				directly into this record, therefore,
141
				the buffer page of this record must be
142
				at least s-latched and the latch held
143
				as long as the row reference is used! */
144
	mem_heap_t*	heap);	/* in: memory heap from which the memory
145
				needed is allocated */
146
/***********************************************************************
147
Builds from a secondary index record a row reference with which we can
148
search the clustered index record. */
149
150
void
151
row_build_row_ref_in_tuple(
152
/*=======================*/
153
	dtuple_t*	ref,	/* in/out: row reference built; see the
154
				NOTE below! */
155
	dict_index_t*	index,	/* in: index */
156
	rec_t*		rec,	/* in: record in the index;
157
				NOTE: the data fields in ref will point
158
				directly into this record, therefore,
159
				the buffer page of this record must be
160
				at least s-latched and the latch held
161
				as long as the row reference is used! */
162
	trx_t*		trx);	/* in: transaction */
163
/***********************************************************************
164
From a row build a row reference with which we can search the clustered
165
index record. */
166
167
void
168
row_build_row_ref_from_row(
169
/*=======================*/
170
	dtuple_t*	ref,	/* in/out: row reference built; see the
171
				NOTE below! ref must have the right number
172
				of fields! */
173
	dict_table_t*	table,	/* in: table */
174
	dtuple_t*	row);	/* in: row
175
				NOTE: the data fields in ref will point
176
				directly into data of this row */
177
/***********************************************************************
178
Builds from a secondary index record a row reference with which we can
179
search the clustered index record. */
180
UNIV_INLINE
181
void
182
row_build_row_ref_fast(
183
/*===================*/
184
	dtuple_t*	ref,	/* in: typed data tuple where the
185
				reference is built */
186
	const ulint*	map,	/* in: array of field numbers in rec
187
				telling how ref should be built from
188
				the fields of rec */
189
	rec_t*		rec,	/* in: record in the index; must be
190
				preserved while ref is used, as we do
191
				not copy field values to heap */
192
	const ulint*	offsets);/* in: array returned by rec_get_offsets() */
193
/*******************************************************************
194
Searches the clustered index record for a row, if we have the row
195
reference. */
196
197
ibool
198
row_search_on_row_ref(
199
/*==================*/
200
				/* out: TRUE if found */
201
	btr_pcur_t*	pcur,	/* in/out: persistent cursor, which must
202
				be closed by the caller */
203
	ulint		mode,	/* in: BTR_MODIFY_LEAF, ... */
204
	dict_table_t*	table,	/* in: table */
205
	dtuple_t*	ref,	/* in: row reference */
206
	mtr_t*		mtr);	/* in: mtr */
207
/*************************************************************************
208
Fetches the clustered index record for a secondary index record. The latches
209
on the secondary index record are preserved. */
210
211
rec_t*
212
row_get_clust_rec(
213
/*==============*/
214
				/* out: record or NULL, if no record found */
215
	ulint		mode,	/* in: BTR_MODIFY_LEAF, ... */
216
	rec_t*		rec,	/* in: record in a secondary index */
217
	dict_index_t*	index,	/* in: secondary index */
218
	dict_index_t**	clust_index,/* out: clustered index */
219
	mtr_t*		mtr);	/* in: mtr */
220
/*******************************************************************
221
Searches an index record. */
222
223
ibool
224
row_search_index_entry(
225
/*===================*/
226
				/* out: TRUE if found */
227
	dict_index_t*	index,	/* in: index */
228
	dtuple_t*	entry,	/* in: index entry */
229
	ulint		mode,	/* in: BTR_MODIFY_LEAF, ... */
230
	btr_pcur_t*	pcur,	/* in/out: persistent cursor, which must
231
				be closed by the caller */
232
	mtr_t*		mtr);	/* in: mtr */
233
234
235
#define ROW_COPY_DATA		1
236
#define ROW_COPY_POINTERS	2
237
238
/* The allowed latching order of index records is the following:
239
(1) a secondary index record ->
240
(2) the clustered index record ->
241
(3) rollback segment data for the clustered index record.
242
243
No new latches may be obtained while the kernel mutex is reserved.
244
However, the kernel mutex can be reserved while latches are owned. */
245
246
#ifndef UNIV_NONINL
247
#include "row0row.ic"
248
#endif
249
250
#endif