row0undo.h 5.32 KB
Newer Older
Vadim Tkachenko's avatar
Vadim Tkachenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
/*****************************************************************************

Copyright (c) 1997, 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

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

Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
19 20
/**************************************************//**
@file include/row0undo.h
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
Row undo

Created 1/8/1997 Heikki Tuuri
*******************************************************/

#ifndef row0undo_h
#define row0undo_h

#include "univ.i"
#include "mtr0mtr.h"
#include "trx0sys.h"
#include "btr0types.h"
#include "btr0pcur.h"
#include "dict0types.h"
#include "trx0types.h"
#include "que0types.h"
#include "row0types.h"

Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
39 40 41
/********************************************************************//**
Creates a row undo node to a query graph.
@return	own: undo node */
42 43 44 45
UNIV_INTERN
undo_node_t*
row_undo_node_create(
/*=================*/
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
46 47 48 49
	trx_t*		trx,	/*!< in: transaction */
	que_thr_t*	parent,	/*!< in: parent node, i.e., a thr node */
	mem_heap_t*	heap);	/*!< in: memory heap where created */
/***********************************************************//**
50 51 52
Looks for the clustered index record when node has the row reference.
The pcur in node is used in the search. If found, stores the row to node,
and stores the position of pcur, and detaches it. The pcur must be closed
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
53 54 55
by the caller in any case.
@return TRUE if found; NOTE the node->pcur must be closed by the
caller, regardless of the return value */
56 57 58 59
UNIV_INTERN
ibool
row_undo_search_clust_to_pcur(
/*==========================*/
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
60 61
	undo_node_t*	node);	/*!< in: row undo node */
/***********************************************************//**
62
Undoes a row operation in a table. This is a high-level function used
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
63 64
in SQL execution graphs.
@return	query thread to run next or NULL */
65 66 67 68
UNIV_INTERN
que_thr_t*
row_undo_step(
/*==========*/
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
69
	que_thr_t*	thr);	/*!< in: query thread */
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85

/* A single query thread will try to perform the undo for all successive
versions of a clustered index record, if the transaction has modified it
several times during the execution which is rolled back. It may happen
that the task is transferred to another query thread, if the other thread
is assigned to handle an undo log record in the chain of different versions
of the record, and the other thread happens to get the x-latch to the
clustered index record at the right time.
	If a query thread notices that the clustered index record it is looking
for is missing, or the roll ptr field in the record doed not point to the
undo log record the thread was assigned to handle, then it gives up the undo
task for that undo log record, and fetches the next. This situation can occur
just in the case where the transaction modified the same record several times
and another thread is currently doing the undo for successive versions of
that index record. */

Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
86 87 88 89 90 91 92 93 94 95 96 97 98 99
/** Execution state of an undo node */
enum undo_exec {
	UNDO_NODE_FETCH_NEXT = 1,	/*!< we should fetch the next
					undo log record */
	UNDO_NODE_PREV_VERS,		/*!< the roll ptr to previous
					version of a row is stored in
					node, and undo should be done
					based on it */
	UNDO_NODE_INSERT,		/*!< undo a fresh insert of a
					row to a table */
	UNDO_NODE_MODIFY		/*!< undo a modify operation
					(DELETE or UPDATE) on a row
					of a table */
};
100

Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
101
/** Undo node structure */
102
struct undo_node_struct{
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
103 104 105 106 107 108 109
	que_common_t	common;	/*!< node type: QUE_NODE_UNDO */
	enum undo_exec	state;	/*!< node execution state */
	trx_t*		trx;	/*!< trx for which undo is done */
	roll_ptr_t	roll_ptr;/*!< roll pointer to undo log record */
	trx_undo_rec_t*	undo_rec;/*!< undo log record */
	undo_no_t	undo_no;/*!< undo number of the record */
	ulint		rec_type;/*!< undo log record type: TRX_UNDO_INSERT_REC,
110
				... */
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
111 112
	roll_ptr_t	new_roll_ptr;
				/*!< roll ptr to restore to clustered index
113
				record */
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
114
	trx_id_t	new_trx_id; /*!< trx id to restore to clustered index
115
				record */
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
116
	btr_pcur_t	pcur;	/*!< persistent cursor used in searching the
117
				clustered index record */
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
118 119 120
	dict_table_t*	table;	/*!< table where undo is done */
	ulint		cmpl_info;/*!< compiler analysis of an update */
	upd_t*		update;	/*!< update vector for a clustered index
121
				record */
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
122 123
	dtuple_t*	ref;	/*!< row reference to the next row to handle */
	dtuple_t*	row;	/*!< a copy (also fields copied to heap) of the
124
				row to handle */
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
125
	row_ext_t*	ext;	/*!< NULL, or prefixes of the externally
126
				stored columns of the row */
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
127 128
	dtuple_t*	undo_row;/*!< NULL, or the row after undo */
	row_ext_t*	undo_ext;/*!< NULL, or prefixes of the externally
129
				stored columns of undo_row */
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
130
	dict_index_t*	index;	/*!< the next index whose record should be
131
				handled */
Aleksandr Kuzminsky's avatar
Aleksandr Kuzminsky committed
132
	mem_heap_t*	heap;	/*!< memory heap used as auxiliary storage for
133 134 135 136 137 138 139 140 141 142
				row; this must be emptied after undo is tried
				on a row */
};


#ifndef UNIV_NONINL
#include "row0undo.ic"
#endif

#endif