1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 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 175 176 177 178 179 180 181
|
/*****************************************************************************
Copyright (c) 1996, 2011, Oracle and/or its affiliates. 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.,
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
/**************************************************//**
@file include/row0upd.ic
Update of a row
Created 12/27/1996 Heikki Tuuri
*******************************************************/
#include "mtr0log.h"
#ifndef UNIV_HOTBACKUP
# include "trx0trx.h"
# include "trx0undo.h"
# include "row0row.h"
# include "lock0lock.h"
#endif /* !UNIV_HOTBACKUP */
#include "page0zip.h"
/*********************************************************************//**
Creates an update vector object.
@return own: update vector object */
UNIV_INLINE
upd_t*
upd_create(
/*=======*/
ulint n, /*!< in: number of fields */
mem_heap_t* heap) /*!< in: heap from which memory allocated */
{
upd_t* update;
update = (upd_t*) mem_heap_alloc(heap, sizeof(upd_t));
update->info_bits = 0;
update->n_fields = n;
update->fields = (upd_field_t*)
mem_heap_alloc(heap, sizeof(upd_field_t) * n);
return(update);
}
/*********************************************************************//**
Returns the number of fields in the update vector == number of columns
to be updated by an update vector.
@return number of fields */
UNIV_INLINE
ulint
upd_get_n_fields(
/*=============*/
const upd_t* update) /*!< in: update vector */
{
ut_ad(update);
return(update->n_fields);
}
#ifdef UNIV_DEBUG
/*********************************************************************//**
Returns the nth field of an update vector.
@return update vector field */
UNIV_INLINE
upd_field_t*
upd_get_nth_field(
/*==============*/
const upd_t* update, /*!< in: update vector */
ulint n) /*!< in: field position in update vector */
{
ut_ad(update);
ut_ad(n < update->n_fields);
return((upd_field_t*) update->fields + n);
}
#endif /* UNIV_DEBUG */
#ifndef UNIV_HOTBACKUP
/*********************************************************************//**
Sets an index field number to be updated by an update vector field. */
UNIV_INLINE
void
upd_field_set_field_no(
/*===================*/
upd_field_t* upd_field, /*!< in: update vector field */
ulint field_no, /*!< in: field number in a clustered
index */
dict_index_t* index, /*!< in: index */
trx_t* trx) /*!< in: transaction */
{
upd_field->field_no = field_no;
upd_field->orig_len = 0;
if (UNIV_UNLIKELY(field_no >= dict_index_get_n_fields(index))) {
fprintf(stderr,
"InnoDB: Error: trying to access field %lu in ",
(ulong) field_no);
dict_index_name_print(stderr, trx, index);
fprintf(stderr, "\n"
"InnoDB: but index only has %lu fields\n",
(ulong) dict_index_get_n_fields(index));
}
dict_col_copy_type(dict_index_get_nth_col(index, field_no),
dfield_get_type(&upd_field->new_val));
}
/*********************************************************************//**
Returns a field of an update vector by field_no.
@return update vector field, or NULL */
UNIV_INLINE
const upd_field_t*
upd_get_field_by_field_no(
/*======================*/
const upd_t* update, /*!< in: update vector */
ulint no) /*!< in: field_no */
{
ulint i;
for (i = 0; i < upd_get_n_fields(update); i++) {
const upd_field_t* uf = upd_get_nth_field(update, i);
if (uf->field_no == no) {
return(uf);
}
}
return(NULL);
}
/*********************************************************************//**
Updates the trx id and roll ptr field in a clustered index record when
a row is updated or marked deleted. */
UNIV_INLINE
void
row_upd_rec_sys_fields(
/*===================*/
rec_t* rec, /*!< in/out: record */
page_zip_des_t* page_zip,/*!< in/out: compressed page whose
uncompressed part will be updated, or NULL */
dict_index_t* index, /*!< in: clustered index */
const ulint* offsets,/*!< in: rec_get_offsets(rec, index) */
trx_t* trx, /*!< in: transaction */
roll_ptr_t roll_ptr)/*!< in: roll ptr of the undo log record */
{
ut_ad(dict_index_is_clust(index));
ut_ad(rec_offs_validate(rec, index, offsets));
if (UNIV_LIKELY_NULL(page_zip)) {
ulint pos = dict_index_get_sys_col_pos(index, DATA_TRX_ID);
page_zip_write_trx_id_and_roll_ptr(page_zip, rec, offsets,
pos, trx->id, roll_ptr);
} else {
ulint offset = index->trx_id_offset;
if (!offset) {
offset = row_get_trx_id_offset(index, offsets);
}
#if DATA_TRX_ID + 1 != DATA_ROLL_PTR
# error "DATA_TRX_ID + 1 != DATA_ROLL_PTR"
#endif
ut_ad(lock_check_trx_id_sanity(trx_read_trx_id(rec + offset),
rec, index, offsets, FALSE));
trx_write_trx_id(rec + offset, trx->id);
trx_write_roll_ptr(rec + offset + DATA_TRX_ID_LEN, roll_ptr);
}
}
#endif /* !UNIV_HOTBACKUP */
|