1
/*****************************************************************************
3
Copyright (C) 1996, 2009, Innobase Oy. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15
St, Fifth Floor, Boston, MA 02110-1301 USA
17
*****************************************************************************/
19
/**************************************************//**
20
@file include/row0upd.ic
23
Created 12/27/1996 Heikki Tuuri
24
*******************************************************/
27
#ifndef UNIV_HOTBACKUP
29
# include "trx0undo.h"
32
#endif /* !UNIV_HOTBACKUP */
35
/*********************************************************************//**
36
Creates an update vector object.
37
@return own: update vector object */
42
ulint n, /*!< in: number of fields */
43
mem_heap_t* heap) /*!< in: heap from which memory allocated */
47
update = (upd_t*) mem_heap_alloc(heap, sizeof(upd_t));
49
update->info_bits = 0;
51
update->fields = (upd_field_t*)
52
mem_heap_alloc(heap, sizeof(upd_field_t) * n);
57
/*********************************************************************//**
58
Returns the number of fields in the update vector == number of columns
59
to be updated by an update vector.
60
@return number of fields */
65
const upd_t* update) /*!< in: update vector */
69
return(update->n_fields);
73
/*********************************************************************//**
74
Returns the nth field of an update vector.
75
@return update vector field */
80
const upd_t* update, /*!< in: update vector */
81
ulint n) /*!< in: field position in update vector */
84
ut_ad(n < update->n_fields);
86
return((upd_field_t*) update->fields + n);
88
#endif /* UNIV_DEBUG */
90
#ifndef UNIV_HOTBACKUP
91
/*********************************************************************//**
92
Sets an index field number to be updated by an update vector field. */
95
upd_field_set_field_no(
96
/*===================*/
97
upd_field_t* upd_field, /*!< in: update vector field */
98
ulint field_no, /*!< in: field number in a clustered
100
dict_index_t* index, /*!< in: index */
101
trx_t* trx) /*!< in: transaction */
103
upd_field->field_no = field_no;
104
upd_field->orig_len = 0;
106
if (UNIV_UNLIKELY(field_no >= dict_index_get_n_fields(index))) {
108
"InnoDB: Error: trying to access field %lu in ",
110
dict_index_name_print(stderr, trx, index);
112
"InnoDB: but index only has %lu fields\n",
113
(ulong) dict_index_get_n_fields(index));
116
dict_col_copy_type(dict_index_get_nth_col(index, field_no),
117
dfield_get_type(&upd_field->new_val));
120
/*********************************************************************//**
121
Returns a field of an update vector by field_no.
122
@return update vector field, or NULL */
125
upd_get_field_by_field_no(
126
/*======================*/
127
const upd_t* update, /*!< in: update vector */
128
ulint no) /*!< in: field_no */
131
for (i = 0; i < upd_get_n_fields(update); i++) {
132
const upd_field_t* uf = upd_get_nth_field(update, i);
134
if (uf->field_no == no) {
143
/*********************************************************************//**
144
Updates the trx id and roll ptr field in a clustered index record when
145
a row is updated or marked deleted. */
148
row_upd_rec_sys_fields(
149
/*===================*/
150
rec_t* rec, /*!< in/out: record */
151
page_zip_des_t* page_zip,/*!< in/out: compressed page whose
152
uncompressed part will be updated, or NULL */
153
dict_index_t* index, /*!< in: clustered index */
154
const ulint* offsets,/*!< in: rec_get_offsets(rec, index) */
155
trx_t* trx, /*!< in: transaction */
156
roll_ptr_t roll_ptr)/*!< in: roll ptr of the undo log record */
158
ut_ad(dict_index_is_clust(index));
159
ut_ad(rec_offs_validate(rec, index, offsets));
160
#ifdef UNIV_SYNC_DEBUG
161
if (!rw_lock_own(&btr_search_latch, RW_LOCK_EX)) {
162
ut_ad(!buf_block_align(rec)->is_hashed);
164
#endif /* UNIV_SYNC_DEBUG */
166
if (UNIV_LIKELY_NULL(page_zip)) {
167
ulint pos = dict_index_get_sys_col_pos(index, DATA_TRX_ID);
168
page_zip_write_trx_id_and_roll_ptr(page_zip, rec, offsets,
169
pos, trx->id, roll_ptr);
171
ulint offset = index->trx_id_offset;
174
offset = row_get_trx_id_offset(rec, index, offsets);
177
#if DATA_TRX_ID + 1 != DATA_ROLL_PTR
178
# error "DATA_TRX_ID + 1 != DATA_ROLL_PTR"
180
trx_write_trx_id(rec + offset, trx->id);
181
trx_write_roll_ptr(rec + offset + DATA_TRX_ID_LEN, roll_ptr);
184
#endif /* !UNIV_HOTBACKUP */