row0row.ic 3.42 KB
Newer Older
vasil's avatar
vasil committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*****************************************************************************

Copyright (c) 1996, 2009, Innobase Oy. All Rights Reserved.

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; version 2 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA

*****************************************************************************/

osku's avatar
osku committed
19 20 21 22 23 24 25 26 27 28 29 30 31
/******************************************************
General row routines

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

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

/*************************************************************************
Reads the trx id field from a clustered index record. */
UNIV_INLINE
32
trx_id_t
osku's avatar
osku committed
33 34 35
row_get_rec_trx_id(
/*===============*/
				/* out: value of the field */
36
	const rec_t*	rec,	/* in: record */
osku's avatar
osku committed
37 38 39 40 41
	dict_index_t*	index,	/* in: clustered index */
	const ulint*	offsets)/* in: rec_get_offsets(rec, index) */
{
	ulint	offset;

42
	ut_ad(dict_index_is_clust(index));
osku's avatar
osku committed
43 44 45
	ut_ad(rec_offs_validate(rec, index, offsets));

	offset = index->trx_id_offset;
46

47 48
	if (!offset) {
		offset = row_get_trx_id_offset(rec, index, offsets);
osku's avatar
osku committed
49
	}
50 51

	return(trx_read_trx_id(rec + offset));
osku's avatar
osku committed
52 53 54 55 56
}

/*************************************************************************
Reads the roll pointer field from a clustered index record. */
UNIV_INLINE
57
roll_ptr_t
osku's avatar
osku committed
58 59 60
row_get_rec_roll_ptr(
/*=================*/
				/* out: value of the field */
61
	const rec_t*	rec,	/* in: record */
osku's avatar
osku committed
62 63 64 65 66
	dict_index_t*	index,	/* in: clustered index */
	const ulint*	offsets)/* in: rec_get_offsets(rec, index) */
{
	ulint	offset;

67
	ut_ad(dict_index_is_clust(index));
osku's avatar
osku committed
68 69 70
	ut_ad(rec_offs_validate(rec, index, offsets));

	offset = index->trx_id_offset;
71

72 73
	if (!offset) {
		offset = row_get_trx_id_offset(rec, index, offsets);
osku's avatar
osku committed
74 75
	}

76
	return(trx_read_roll_ptr(rec + offset + DATA_TRX_ID_LEN));
osku's avatar
osku committed
77 78 79 80 81 82 83 84 85
}

/***********************************************************************
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(
/*===================*/
marko's avatar
marko committed
86
	dtuple_t*	ref,	/* in/out: typed data tuple where the
osku's avatar
osku committed
87 88 89 90
				reference is built */
	const ulint*	map,	/* in: array of field numbers in rec
				telling how ref should be built from
				the fields of rec */
91
	const rec_t*	rec,	/* in: record in the index; must be
osku's avatar
osku committed
92 93 94 95 96
				preserved while ref is used, as we do
				not copy field values to heap */
	const ulint*	offsets)/* in: array returned by rec_get_offsets() */
{
	dfield_t*	dfield;
97
	const byte*	field;
osku's avatar
osku committed
98 99 100 101
	ulint		len;
	ulint		ref_len;
	ulint		field_no;
	ulint		i;
102

osku's avatar
osku committed
103
	ut_ad(rec_offs_validate(rec, NULL, offsets));
104
	ut_ad(!rec_offs_any_extern(offsets));
osku's avatar
osku committed
105
	ref_len = dtuple_get_n_fields(ref);
106

osku's avatar
osku committed
107
	for (i = 0; i < ref_len; i++) {
108
		dfield = dtuple_get_nth_field(ref, i);
osku's avatar
osku committed
109 110 111 112 113 114

		field_no = *(map + i);

		if (field_no != ULINT_UNDEFINED) {

			field = rec_get_nth_field(rec, offsets,
115
						  field_no, &len);
osku's avatar
osku committed
116 117 118 119
			dfield_set_data(dfield, field, len);
		}
	}
}