~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
#include "dict0dict.h"
10
#include "rem0rec.h"
11
#include "trx0undo.h"
12
13
/*************************************************************************
14
Reads the trx id or roll ptr field from a clustered index record: this function
15
is slower than the specialized inline functions. */
16
17
dulint
18
row_get_rec_sys_field(
19
/*==================*/
20
				/* out: value of the field */
21
	ulint		type,	/* in: DATA_TRX_ID or DATA_ROLL_PTR */
22
	rec_t*		rec,	/* in: record */
23
	dict_index_t*	index,	/* in: clustered index */
24
	const ulint*	offsets);/* in: rec_get_offsets(rec, index) */
25
/*************************************************************************
26
Sets the trx id or roll ptr field in a clustered index record: this function
27
is slower than the specialized inline functions. */
28
29
void
30
row_set_rec_sys_field(
31
/*==================*/
32
				/* out: value of the field */
33
	ulint		type,	/* in: DATA_TRX_ID or DATA_ROLL_PTR */
34
	rec_t*		rec,	/* in: record */
35
	dict_index_t*	index,	/* in: clustered index */
36
	const ulint*	offsets,/* in: rec_get_offsets(rec, index) */
37
	dulint		val);	/* in: value to set */
38
39
/*************************************************************************
40
Reads the trx id field from a clustered index record. */
41
UNIV_INLINE
42
dulint
43
row_get_rec_trx_id(
44
/*===============*/
45
				/* out: value of the field */
46
	rec_t*		rec,	/* in: record */
47
	dict_index_t*	index,	/* in: clustered index */
48
	const ulint*	offsets)/* in: rec_get_offsets(rec, index) */
49
{
50
	ulint	offset;
51
52
	ut_ad(index->type & DICT_CLUSTERED);
53
	ut_ad(rec_offs_validate(rec, index, offsets));
54
55
	offset = index->trx_id_offset;
56
57
	if (offset) {
58
		return(trx_read_trx_id(rec + offset));
59
	} else {
60
		return(row_get_rec_sys_field(DATA_TRX_ID,
61
					     rec, index, offsets));
62
	}
63
}
64
65
/*************************************************************************
66
Reads the roll pointer field from a clustered index record. */
67
UNIV_INLINE
68
dulint
69
row_get_rec_roll_ptr(
70
/*=================*/
71
				/* out: value of the field */
72
	rec_t*		rec,	/* in: record */
73
	dict_index_t*	index,	/* in: clustered index */
74
	const ulint*	offsets)/* in: rec_get_offsets(rec, index) */
75
{
76
	ulint	offset;
77
78
	ut_ad(index->type & DICT_CLUSTERED);
79
	ut_ad(rec_offs_validate(rec, index, offsets));
80
81
	offset = index->trx_id_offset;
82
83
	if (offset) {
84
		return(trx_read_roll_ptr(rec + offset + DATA_TRX_ID_LEN));
85
	} else {
86
		return(row_get_rec_sys_field(DATA_ROLL_PTR,
87
					     rec, index, offsets));
88
	}
89
}
90
91
/*************************************************************************
92
Writes the trx id field to a clustered index record. */
93
UNIV_INLINE
94
void
95
row_set_rec_trx_id(
96
/*===============*/
97
	rec_t*		rec,	/* in: record */
98
	dict_index_t*	index,	/* in: clustered index */
99
	const ulint*	offsets,/* in: rec_get_offsets(rec, index) */
100
	dulint		trx_id)	/* in: value of the field */
101
{
102
	ulint	offset;
103
104
	ut_ad(index->type & DICT_CLUSTERED);
105
	ut_ad(rec_offs_validate(rec, index, offsets));
106
107
	offset = index->trx_id_offset;
108
109
	if (offset) {
110
		trx_write_trx_id(rec + offset, trx_id);
111
	} else {
112
		row_set_rec_sys_field(DATA_TRX_ID,
113
				      rec, index, offsets, trx_id);
114
	}
115
}
116
117
/*************************************************************************
118
Sets the roll pointer field in a clustered index record. */
119
UNIV_INLINE
120
void
121
row_set_rec_roll_ptr(
122
/*=================*/
123
	rec_t*		rec,	/* in: record */
124
	dict_index_t*	index,	/* in: clustered index */
125
	const ulint*	offsets,/* in: rec_get_offsets(rec, index) */
126
	dulint		roll_ptr)/* in: value of the field */
127
{
128
	ulint	offset;
129
130
	ut_ad(index->type & DICT_CLUSTERED);
131
	ut_ad(rec_offs_validate(rec, index, offsets));
132
133
	offset = index->trx_id_offset;
134
135
	if (offset) {
136
		trx_write_roll_ptr(rec + offset + DATA_TRX_ID_LEN, roll_ptr);
137
	} else {
138
		row_set_rec_sys_field(DATA_ROLL_PTR,
139
				      rec, index, offsets, roll_ptr);
140
	}
141
}
142
143
/***********************************************************************
144
Builds from a secondary index record a row reference with which we can
145
search the clustered index record. */
146
UNIV_INLINE
147
void
148
row_build_row_ref_fast(
149
/*===================*/
150
	dtuple_t*	ref,	/* in: typed data tuple where the
151
				reference is built */
152
	const ulint*	map,	/* in: array of field numbers in rec
153
				telling how ref should be built from
154
				the fields of rec */
155
	rec_t*		rec,	/* in: record in the index; must be
156
				preserved while ref is used, as we do
157
				not copy field values to heap */
158
	const ulint*	offsets)/* in: array returned by rec_get_offsets() */
159
{
160
	dfield_t*	dfield;
161
	byte*		field;
162
	ulint		len;
163
	ulint		ref_len;
164
	ulint		field_no;
165
	ulint		i;
166
167
	ut_ad(rec_offs_validate(rec, NULL, offsets));
168
	ref_len = dtuple_get_n_fields(ref);
169
170
	for (i = 0; i < ref_len; i++) {
171
		dfield = dtuple_get_nth_field(ref, i);
172
173
		field_no = *(map + i);
174
175
		if (field_no != ULINT_UNDEFINED) {
176
177
			field = rec_get_nth_field(rec, offsets,
178
						  field_no, &len);
179
			dfield_set_data(dfield, field, len);
180
		}
181
	}
182
}