1 /*****************************************************************************
2 
3 Copyright (c) 1997, 2009, Oracle and/or its affiliates. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License, version 2.0,
7 as published by the Free Software Foundation.
8 
9 This program is also distributed with certain software (including
10 but not limited to OpenSSL) that is licensed under separate terms,
11 as designated in a particular file or component or in included license
12 documentation.  The authors of MySQL hereby grant you an additional
13 permission to link the program and your derivative works with the
14 separately licensed software that they have included with MySQL.
15 
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 GNU General Public License, version 2.0, for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
24 
25 *****************************************************************************/
26 
27 /**************************************************//**
28 @file include/row0undo.h
29 Row undo
30 
31 Created 1/8/1997 Heikki Tuuri
32 *******************************************************/
33 
34 #ifndef row0undo_h
35 #define row0undo_h
36 
37 #include "univ.i"
38 #include "mtr0mtr.h"
39 #include "trx0sys.h"
40 #include "btr0types.h"
41 #include "btr0pcur.h"
42 #include "dict0types.h"
43 #include "trx0types.h"
44 #include "que0types.h"
45 #include "row0types.h"
46 
47 /********************************************************************//**
48 Creates a row undo node to a query graph.
49 @return	own: undo node */
50 UNIV_INTERN
51 undo_node_t*
52 row_undo_node_create(
53 /*=================*/
54 	trx_t*		trx,	/*!< in: transaction */
55 	que_thr_t*	parent,	/*!< in: parent node, i.e., a thr node */
56 	mem_heap_t*	heap);	/*!< in: memory heap where created */
57 /***********************************************************//**
58 Looks for the clustered index record when node has the row reference.
59 The pcur in node is used in the search. If found, stores the row to node,
60 and stores the position of pcur, and detaches it. The pcur must be closed
61 by the caller in any case.
62 @return TRUE if found; NOTE the node->pcur must be closed by the
63 caller, regardless of the return value */
64 UNIV_INTERN
65 ibool
66 row_undo_search_clust_to_pcur(
67 /*==========================*/
68 	undo_node_t*	node);	/*!< in: row undo node */
69 /***********************************************************//**
70 Undoes a row operation in a table. This is a high-level function used
71 in SQL execution graphs.
72 @return	query thread to run next or NULL */
73 UNIV_INTERN
74 que_thr_t*
75 row_undo_step(
76 /*==========*/
77 	que_thr_t*	thr);	/*!< in: query thread */
78 
79 /* A single query thread will try to perform the undo for all successive
80 versions of a clustered index record, if the transaction has modified it
81 several times during the execution which is rolled back. It may happen
82 that the task is transferred to another query thread, if the other thread
83 is assigned to handle an undo log record in the chain of different versions
84 of the record, and the other thread happens to get the x-latch to the
85 clustered index record at the right time.
86 	If a query thread notices that the clustered index record it is looking
87 for is missing, or the roll ptr field in the record doed not point to the
88 undo log record the thread was assigned to handle, then it gives up the undo
89 task for that undo log record, and fetches the next. This situation can occur
90 just in the case where the transaction modified the same record several times
91 and another thread is currently doing the undo for successive versions of
92 that index record. */
93 
94 /** Execution state of an undo node */
95 enum undo_exec {
96 	UNDO_NODE_FETCH_NEXT = 1,	/*!< we should fetch the next
97 					undo log record */
98 	UNDO_NODE_INSERT,		/*!< undo a fresh insert of a
99 					row to a table */
100 	UNDO_NODE_MODIFY		/*!< undo a modify operation
101 					(DELETE or UPDATE) on a row
102 					of a table */
103 };
104 
105 /** Undo node structure */
106 struct undo_node_t{
107 	que_common_t	common;	/*!< node type: QUE_NODE_UNDO */
108 	enum undo_exec	state;	/*!< node execution state */
109 	trx_t*		trx;	/*!< trx for which undo is done */
110 	roll_ptr_t	roll_ptr;/*!< roll pointer to undo log record */
111 	trx_undo_rec_t*	undo_rec;/*!< undo log record */
112 	undo_no_t	undo_no;/*!< undo number of the record */
113 	ulint		rec_type;/*!< undo log record type: TRX_UNDO_INSERT_REC,
114 				... */
115 	trx_id_t	new_trx_id; /*!< trx id to restore to clustered index
116 				record */
117 	btr_pcur_t	pcur;	/*!< persistent cursor used in searching the
118 				clustered index record */
119 	dict_table_t*	table;	/*!< table where undo is done */
120 	ulint		cmpl_info;/*!< compiler analysis of an update */
121 	upd_t*		update;	/*!< update vector for a clustered index
122 				record */
123 	dtuple_t*	ref;	/*!< row reference to the next row to handle */
124 	dtuple_t*	row;	/*!< a copy (also fields copied to heap) of the
125 				row to handle */
126 	row_ext_t*	ext;	/*!< NULL, or prefixes of the externally
127 				stored columns of the row */
128 	dtuple_t*	undo_row;/*!< NULL, or the row after undo */
129 	row_ext_t*	undo_ext;/*!< NULL, or prefixes of the externally
130 				stored columns of undo_row */
131 	dict_index_t*	index;	/*!< the next index whose record should be
132 				handled */
133 	mem_heap_t*	heap;	/*!< memory heap used as auxiliary storage for
134 				row; this must be emptied after undo is tried
135 				on a row */
136 };
137 
138 
139 #ifndef UNIV_NONINL
140 #include "row0undo.ic"
141 #endif
142 
143 #endif
144