row0row.ic 5.04 KB
Newer Older
Vadim Tkachenko's avatar
Vadim Tkachenko committed
1 2
/*****************************************************************************

3
Copyright (c) 1996, 2011, Oracle and/or its affiliates. All Rights Reserved.
Vadim Tkachenko's avatar
Vadim Tkachenko committed
4 5 6 7 8 9 10 11 12 13

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
14 15
this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
Vadim Tkachenko's avatar
Vadim Tkachenko committed
16 17 18

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

Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
19 20
/**************************************************//**
@file include/row0row.ic
21 22 23 24 25 26 27 28 29
General row routines

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

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

30
/*********************************************************************//**
31
Gets the offset of the DB_TRX_ID field, in bytes relative to the origin of
32 33 34 35
a clustered index record.
@return	offset of DATA_TRX_ID */
UNIV_INLINE
ulint
36 37
row_get_trx_id_offset(
/*==================*/
38
	const dict_index_t*	index,	/*!< in: clustered index */
39
	const ulint*		offsets)/*!< in: record offsets */
40 41 42 43 44 45
{
	ulint	pos;
	ulint	offset;
	ulint	len;

	ut_ad(dict_index_is_clust(index));
46
	ut_ad(rec_offs_validate(NULL, index, offsets));
47 48 49 50 51 52 53 54 55 56

	pos = dict_index_get_sys_col_pos(index, DATA_TRX_ID);

	offset = rec_get_nth_field_offs(offsets, pos, &len);

	ut_ad(len == DATA_TRX_ID_LEN);

	return(offset);
}

Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
57 58 59
/*********************************************************************//**
Reads the trx id field from a clustered index record.
@return	value of the field */
60
UNIV_INLINE
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
61
trx_id_t
62 63
row_get_rec_trx_id(
/*===============*/
64 65 66
	const rec_t*		rec,	/*!< in: record */
	const dict_index_t*	index,	/*!< in: clustered index */
	const ulint*		offsets)/*!< in: rec_get_offsets(rec, index) */
67 68 69 70 71 72 73 74 75
{
	ulint	offset;

	ut_ad(dict_index_is_clust(index));
	ut_ad(rec_offs_validate(rec, index, offsets));

	offset = index->trx_id_offset;

	if (!offset) {
76
		offset = row_get_trx_id_offset(index, offsets);
77 78 79 80 81
	}

	return(trx_read_trx_id(rec + offset));
}

Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
82 83 84
/*********************************************************************//**
Reads the roll pointer field from a clustered index record.
@return	value of the field */
85
UNIV_INLINE
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
86
roll_ptr_t
87 88
row_get_rec_roll_ptr(
/*=================*/
89 90 91
	const rec_t*		rec,	/*!< in: record */
	const dict_index_t*	index,	/*!< in: clustered index */
	const ulint*		offsets)/*!< in: rec_get_offsets(rec, index) */
92 93 94 95 96 97 98 99 100
{
	ulint	offset;

	ut_ad(dict_index_is_clust(index));
	ut_ad(rec_offs_validate(rec, index, offsets));

	offset = index->trx_id_offset;

	if (!offset) {
101
		offset = row_get_trx_id_offset(index, offsets);
102 103 104 105 106
	}

	return(trx_read_roll_ptr(rec + offset + DATA_TRX_ID_LEN));
}

107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
/*****************************************************************//**
When an insert or purge to a table is performed, this function builds
the entry to be inserted into or purged from an index on the table.
@return index entry which should be inserted or purged, or NULL if the
externally stored columns in the clustered index record are
unavailable and ext != NULL */
UNIV_INLINE
dtuple_t*
row_build_index_entry(
/*==================*/
	const dtuple_t*		row,	/*!< in: row which should be
					inserted or purged */
	const row_ext_t*	ext,	/*!< in: externally stored column
					prefixes, or NULL */
	dict_index_t*		index,	/*!< in: index on the table */
	mem_heap_t*		heap)	/*!< in: memory heap from which
					the memory for the index entry
					is allocated */
{
	dtuple_t*	entry;

	ut_ad(dtuple_check_typed(row));
	entry = row_build_index_entry_low(row, ext, index, heap);
	ut_ad(!entry || dtuple_check_typed(entry));
	return(entry);
}

Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
134
/*******************************************************************//**
135 136 137 138 139 140
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(
/*===================*/
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
141
	dtuple_t*	ref,	/*!< in/out: typed data tuple where the
142
				reference is built */
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
143
	const ulint*	map,	/*!< in: array of field numbers in rec
144 145
				telling how ref should be built from
				the fields of rec */
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
146
	const rec_t*	rec,	/*!< in: record in the index; must be
147 148
				preserved while ref is used, as we do
				not copy field values to heap */
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
149
	const ulint*	offsets)/*!< in: array returned by rec_get_offsets() */
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
{
	dfield_t*	dfield;
	const byte*	field;
	ulint		len;
	ulint		ref_len;
	ulint		field_no;
	ulint		i;

	ut_ad(rec_offs_validate(rec, NULL, offsets));
	ut_ad(!rec_offs_any_extern(offsets));
	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) {

			field = rec_get_nth_field(rec, offsets,
						  field_no, &len);
			dfield_set_data(dfield, field, len);
		}
	}
}