row0row.ic 4.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/******************************************************
General row routines

(c) 1996 Innobase Oy

Created 4/20/1996 Heikki Tuuri
*******************************************************/

#include "dict0dict.h"
#include "rem0rec.h"
#include "trx0undo.h"

/*************************************************************************
Reads the trx id or roll ptr field from a clustered index record: this function
is slower than the specialized inline functions. */

dulint
row_get_rec_sys_field(
/*==================*/
				/* out: value of the field */
	ulint		type,	/* in: DATA_TRX_ID or DATA_ROLL_PTR */
	rec_t*		rec,	/* in: record */
unknown's avatar
unknown committed
23 24
	dict_index_t*	index,	/* in: clustered index */
	const ulint*	offsets);/* in: rec_get_offsets(rec, index) */
25 26 27 28 29 30 31 32 33 34 35
/*************************************************************************
Sets the trx id or roll ptr field in a clustered index record: this function
is slower than the specialized inline functions. */

void
row_set_rec_sys_field(
/*==================*/
				/* out: value of the field */
	ulint		type,	/* in: DATA_TRX_ID or DATA_ROLL_PTR */
	rec_t*		rec,	/* in: record */
	dict_index_t*	index,	/* in: clustered index */
unknown's avatar
unknown committed
36
	const ulint*	offsets,/* in: rec_get_offsets(rec, index) */
37 38 39 40 41 42 43 44 45 46
	dulint		val);	/* in: value to set */

/*************************************************************************
Reads the trx id field from a clustered index record. */
UNIV_INLINE
dulint
row_get_rec_trx_id(
/*===============*/
				/* out: value of the field */
	rec_t*		rec,	/* in: record */
unknown's avatar
unknown committed
47 48
	dict_index_t*	index,	/* in: clustered index */
	const ulint*	offsets)/* in: rec_get_offsets(rec, index) */
49 50 51 52
{
	ulint	offset;

	ut_ad(index->type & DICT_CLUSTERED);
unknown's avatar
unknown committed
53
	ut_ad(rec_offs_validate(rec, index, offsets));
54 55 56 57 58 59

	offset = index->trx_id_offset;
	
	if (offset) {
		return(trx_read_trx_id(rec + offset));
	} else {
unknown's avatar
unknown committed
60 61
		return(row_get_rec_sys_field(DATA_TRX_ID,
				rec, index, offsets));
62 63 64 65 66 67 68 69 70 71 72
	}
}

/*************************************************************************
Reads the roll pointer field from a clustered index record. */
UNIV_INLINE
dulint
row_get_rec_roll_ptr(
/*=================*/
				/* out: value of the field */
	rec_t*		rec,	/* in: record */
unknown's avatar
unknown committed
73 74
	dict_index_t*	index,	/* in: clustered index */
	const ulint*	offsets)/* in: rec_get_offsets(rec, index) */
75 76 77 78
{
	ulint	offset;

	ut_ad(index->type & DICT_CLUSTERED);
unknown's avatar
unknown committed
79
	ut_ad(rec_offs_validate(rec, index, offsets));
80 81 82 83 84 85

	offset = index->trx_id_offset;
	
	if (offset) {
		return(trx_read_roll_ptr(rec + offset + DATA_TRX_ID_LEN));
	} else {
unknown's avatar
unknown committed
86 87
		return(row_get_rec_sys_field(DATA_ROLL_PTR,
				rec, index, offsets));
88 89 90 91 92 93 94 95 96 97 98
	}
}

/*************************************************************************
Writes the trx id field to a clustered index record. */
UNIV_INLINE
void
row_set_rec_trx_id(
/*===============*/
	rec_t*		rec,	/* in: record */
	dict_index_t*	index,	/* in: clustered index */
unknown's avatar
unknown committed
99
	const ulint*	offsets,/* in: rec_get_offsets(rec, index) */
100 101 102 103 104
	dulint		trx_id)	/* in: value of the field */
{
	ulint	offset;

	ut_ad(index->type & DICT_CLUSTERED);
unknown's avatar
unknown committed
105
	ut_ad(rec_offs_validate(rec, index, offsets));
106 107 108 109 110 111

	offset = index->trx_id_offset;
	
	if (offset) {
		trx_write_trx_id(rec + offset, trx_id);
	} else {
unknown's avatar
unknown committed
112 113
		row_set_rec_sys_field(DATA_TRX_ID,
				rec, index, offsets, trx_id);
114 115 116 117 118 119 120 121 122 123 124
	}
}

/*************************************************************************
Sets the roll pointer field in a clustered index record. */
UNIV_INLINE
void
row_set_rec_roll_ptr(
/*=================*/
	rec_t*		rec,	/* in: record */
	dict_index_t*	index,	/* in: clustered index */
unknown's avatar
unknown committed
125
	const ulint*	offsets,/* in: rec_get_offsets(rec, index) */
126 127 128 129 130
	dulint		roll_ptr)/* in: value of the field */
{
	ulint	offset;

	ut_ad(index->type & DICT_CLUSTERED);
unknown's avatar
unknown committed
131
	ut_ad(rec_offs_validate(rec, index, offsets));
132 133 134 135 136 137

	offset = index->trx_id_offset;
	
	if (offset) {
		trx_write_roll_ptr(rec + offset + DATA_TRX_ID_LEN, roll_ptr);
	} else {
unknown's avatar
unknown committed
138 139
	 	row_set_rec_sys_field(DATA_ROLL_PTR,
				rec, index, offsets, roll_ptr);
140 141 142 143 144 145 146 147 148 149
	}
}

/***********************************************************************
Builds from a secondary index record a row reference with which we can
search the clustered index record. */
UNIV_INLINE
void
row_build_row_ref_fast(
/*===================*/
unknown's avatar
unknown committed
150 151 152 153 154 155 156 157 158
	dtuple_t*	ref,	/* in: typed data tuple where the
				reference is built */
	const ulint*	map,	/* in: array of field numbers in rec
				telling how ref should be built from
				the fields of rec */
	rec_t*		rec,	/* in: record in the index; must be
				preserved while ref is used, as we do
				not copy field values to heap */
	const ulint*	offsets)/* in: array returned by rec_get_offsets() */
159 160 161 162 163 164 165 166
{
	dfield_t*	dfield;
	byte*		field;
	ulint		len;
	ulint		ref_len;
	ulint		field_no;
	ulint		i;
	
unknown's avatar
unknown committed
167
	ut_ad(rec_offs_validate(rec, NULL, offsets));
168 169 170 171 172 173 174 175 176
	ref_len = dtuple_get_n_fields(ref);
	
	for (i = 0; i < ref_len; i++) {
		dfield = dtuple_get_nth_field(ref, i);

		field_no = *(map + i);

		if (field_no != ULINT_UNDEFINED) {

unknown's avatar
unknown committed
177 178
			field = rec_get_nth_field(rec, offsets,
						field_no, &len);
179 180 181 182
			dfield_set_data(dfield, field, len);
		}
	}
}