2009-02-17 09:36:44 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2009-05-25 09:52:29 +00:00
|
|
|
/**************************************************//**
|
|
|
|
@file include/row0upd.ic
|
2005-10-27 07:29:40 +00:00
|
|
|
Update of a row
|
|
|
|
|
|
|
|
Created 12/27/1996 Heikki Tuuri
|
|
|
|
*******************************************************/
|
|
|
|
|
|
|
|
#include "mtr0log.h"
|
2009-03-23 14:21:34 +00:00
|
|
|
#ifndef UNIV_HOTBACKUP
|
|
|
|
# include "trx0trx.h"
|
|
|
|
# include "trx0undo.h"
|
|
|
|
# include "row0row.h"
|
|
|
|
# include "btr0sea.h"
|
|
|
|
#endif /* !UNIV_HOTBACKUP */
|
2005-10-27 11:48:10 +00:00
|
|
|
#include "page0zip.h"
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2009-05-25 09:52:29 +00:00
|
|
|
/*********************************************************************//**
|
2009-05-25 05:30:14 +00:00
|
|
|
Creates an update vector object.
|
|
|
|
@return own: update vector object */
|
2005-10-27 07:29:40 +00:00
|
|
|
UNIV_INLINE
|
|
|
|
upd_t*
|
|
|
|
upd_create(
|
|
|
|
/*=======*/
|
2009-05-25 05:30:14 +00:00
|
|
|
ulint n, /*!< in: number of fields */
|
|
|
|
mem_heap_t* heap) /*!< in: heap from which memory allocated */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
|
|
|
upd_t* update;
|
|
|
|
|
2007-08-01 10:38:07 +00:00
|
|
|
update = (upd_t*) mem_heap_alloc(heap, sizeof(upd_t));
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
update->info_bits = 0;
|
|
|
|
update->n_fields = n;
|
2007-08-01 10:38:07 +00:00
|
|
|
update->fields = (upd_field_t*)
|
|
|
|
mem_heap_alloc(heap, sizeof(upd_field_t) * n);
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
return(update);
|
|
|
|
}
|
|
|
|
|
2009-05-25 09:52:29 +00:00
|
|
|
/*********************************************************************//**
|
2005-10-27 07:29:40 +00:00
|
|
|
Returns the number of fields in the update vector == number of columns
|
2009-05-25 05:30:14 +00:00
|
|
|
to be updated by an update vector.
|
|
|
|
@return number of fields */
|
2005-10-27 07:29:40 +00:00
|
|
|
UNIV_INLINE
|
|
|
|
ulint
|
|
|
|
upd_get_n_fields(
|
|
|
|
/*=============*/
|
2009-05-25 05:30:14 +00:00
|
|
|
const upd_t* update) /*!< in: update vector */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
|
|
|
ut_ad(update);
|
|
|
|
|
|
|
|
return(update->n_fields);
|
|
|
|
}
|
|
|
|
|
2007-06-19 12:44:45 +00:00
|
|
|
#ifdef UNIV_DEBUG
|
2009-05-25 09:52:29 +00:00
|
|
|
/*********************************************************************//**
|
2009-05-25 05:30:14 +00:00
|
|
|
Returns the nth field of an update vector.
|
|
|
|
@return update vector field */
|
2005-10-27 07:29:40 +00:00
|
|
|
UNIV_INLINE
|
|
|
|
upd_field_t*
|
|
|
|
upd_get_nth_field(
|
|
|
|
/*==============*/
|
2009-05-25 05:30:14 +00:00
|
|
|
const upd_t* update, /*!< in: update vector */
|
|
|
|
ulint n) /*!< in: field position in update vector */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
|
|
|
ut_ad(update);
|
|
|
|
ut_ad(n < update->n_fields);
|
|
|
|
|
2007-06-19 12:44:45 +00:00
|
|
|
return((upd_field_t*) update->fields + n);
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2007-06-19 12:44:45 +00:00
|
|
|
#endif /* UNIV_DEBUG */
|
2005-10-27 07:29:40 +00:00
|
|
|
|
2009-03-23 14:21:34 +00:00
|
|
|
#ifndef UNIV_HOTBACKUP
|
2009-05-25 09:52:29 +00:00
|
|
|
/*********************************************************************//**
|
2005-10-27 07:29:40 +00:00
|
|
|
Sets an index field number to be updated by an update vector field. */
|
|
|
|
UNIV_INLINE
|
|
|
|
void
|
|
|
|
upd_field_set_field_no(
|
|
|
|
/*===================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
upd_field_t* upd_field, /*!< in: update vector field */
|
|
|
|
ulint field_no, /*!< in: field number in a clustered
|
2005-10-27 07:29:40 +00:00
|
|
|
index */
|
2009-05-25 05:30:14 +00:00
|
|
|
dict_index_t* index, /*!< in: index */
|
|
|
|
trx_t* trx) /*!< in: transaction */
|
2006-02-23 19:25:29 +00:00
|
|
|
{
|
2005-10-27 07:29:40 +00:00
|
|
|
upd_field->field_no = field_no;
|
2008-01-23 13:46:45 +00:00
|
|
|
upd_field->orig_len = 0;
|
2005-10-27 07:29:40 +00:00
|
|
|
|
|
|
|
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",
|
2006-08-29 09:30:31 +00:00
|
|
|
(ulong) dict_index_get_n_fields(index));
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2006-09-19 10:14:07 +00:00
|
|
|
dict_col_copy_type(dict_index_get_nth_col(index, field_no),
|
2008-01-23 13:46:45 +00:00
|
|
|
dfield_get_type(&upd_field->new_val));
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
|
|
|
|
2009-05-25 09:52:29 +00:00
|
|
|
/*********************************************************************//**
|
2009-05-25 05:30:14 +00:00
|
|
|
Returns a field of an update vector by field_no.
|
|
|
|
@return update vector field, or NULL */
|
2008-03-13 12:49:34 +00:00
|
|
|
UNIV_INLINE
|
|
|
|
const upd_field_t*
|
|
|
|
upd_get_field_by_field_no(
|
|
|
|
/*======================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
const upd_t* update, /*!< in: update vector */
|
|
|
|
ulint no) /*!< in: field_no */
|
2008-03-13 12:49:34 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-05-25 09:52:29 +00:00
|
|
|
/*********************************************************************//**
|
2005-10-27 07:29:40 +00:00
|
|
|
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(
|
|
|
|
/*===================*/
|
2009-05-25 05:30:14 +00:00
|
|
|
rec_t* rec, /*!< in/out: record */
|
|
|
|
page_zip_des_t* page_zip,/*!< in/out: compressed page whose
|
2006-02-10 15:06:17 +00:00
|
|
|
uncompressed part will be updated, or NULL */
|
2009-05-25 05:30:14 +00:00
|
|
|
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 */
|
2005-10-27 07:29:40 +00:00
|
|
|
{
|
2006-03-09 17:26:02 +00:00
|
|
|
ut_ad(dict_index_is_clust(index));
|
2005-10-27 07:29:40 +00:00
|
|
|
ut_ad(rec_offs_validate(rec, index, offsets));
|
|
|
|
#ifdef UNIV_SYNC_DEBUG
|
2006-10-30 16:18:23 +00:00
|
|
|
if (!rw_lock_own(&btr_search_latch, RW_LOCK_EX)) {
|
|
|
|
ut_ad(!buf_block_align(rec)->is_hashed);
|
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
#endif /* UNIV_SYNC_DEBUG */
|
|
|
|
|
2006-02-10 15:06:17 +00:00
|
|
|
if (UNIV_LIKELY_NULL(page_zip)) {
|
2006-03-09 17:26:02 +00:00
|
|
|
ulint pos = dict_index_get_sys_col_pos(index, DATA_TRX_ID);
|
|
|
|
page_zip_write_trx_id_and_roll_ptr(page_zip, rec, offsets,
|
2006-08-29 09:30:31 +00:00
|
|
|
pos, trx->id, roll_ptr);
|
2006-02-22 13:02:40 +00:00
|
|
|
} else {
|
|
|
|
ulint offset = index->trx_id_offset;
|
|
|
|
|
|
|
|
if (!offset) {
|
|
|
|
offset = row_get_trx_id_offset(rec, index, offsets);
|
|
|
|
}
|
|
|
|
|
2006-03-09 17:26:02 +00:00
|
|
|
#if DATA_TRX_ID + 1 != DATA_ROLL_PTR
|
|
|
|
# error "DATA_TRX_ID + 1 != DATA_ROLL_PTR"
|
|
|
|
#endif
|
2006-02-22 13:02:40 +00:00
|
|
|
trx_write_trx_id(rec + offset, trx->id);
|
|
|
|
trx_write_roll_ptr(rec + offset + DATA_TRX_ID_LEN, roll_ptr);
|
2006-02-10 15:06:17 +00:00
|
|
|
}
|
2005-10-27 07:29:40 +00:00
|
|
|
}
|
2009-03-23 14:21:34 +00:00
|
|
|
#endif /* !UNIV_HOTBACKUP */
|