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