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