1 /******************************************************
6 Created 1/8/1997 Heikki Tuuri
7 *******************************************************/
15 #include "btr0types.h"
17 #include "dict0types.h"
18 #include "trx0types.h"
19 #include "que0types.h"
20 #include "row0types.h"
22 /************************************************************************
23 Creates a row undo node to a query graph. */
28 /* out, own: undo node */
29 trx_t
* trx
, /* in: transaction */
30 que_thr_t
* parent
, /* in: parent node, i.e., a thr node */
31 mem_heap_t
* heap
); /* in: memory heap where created */
32 /***************************************************************
33 Looks for the clustered index record when node has the row reference.
34 The pcur in node is used in the search. If found, stores the row to node,
35 and stores the position of pcur, and detaches it. The pcur must be closed
36 by the caller in any case. */
39 row_undo_search_clust_to_pcur(
40 /*==========================*/
41 /* out: TRUE if found; NOTE the node->pcur
42 must be closed by the caller, regardless of
44 undo_node_t
* node
); /* in: row undo node */
45 /***************************************************************
46 Undoes a row operation in a table. This is a high-level function used
47 in SQL execution graphs. */
52 /* out: query thread to run next or NULL */
53 que_thr_t
* thr
); /* in: query thread */
55 /* A single query thread will try to perform the undo for all successive
56 versions of a clustered index record, if the transaction has modified it
57 several times during the execution which is rolled back. It may happen
58 that the task is transferred to another query thread, if the other thread
59 is assigned to handle an undo log record in the chain of different versions
60 of the record, and the other thread happens to get the x-latch to the
61 clustered index record at the right time.
62 If a query thread notices that the clustered index record it is looking
63 for is missing, or the roll ptr field in the record doed not point to the
64 undo log record the thread was assigned to handle, then it gives up the undo
65 task for that undo log record, and fetches the next. This situation can occur
66 just in the case where the transaction modified the same record several times
67 and another thread is currently doing the undo for successive versions of
70 /* Undo node structure */
72 struct undo_node_struct
{
73 que_common_t common
; /* node type: QUE_NODE_UNDO */
74 ulint state
; /* node execution state */
75 trx_t
* trx
; /* trx for which undo is done */
76 dulint roll_ptr
;/* roll pointer to undo log record */
77 trx_undo_rec_t
* undo_rec
;/* undo log record */
78 dulint undo_no
;/* undo number of the record */
79 ulint rec_type
;/* undo log record type: TRX_UNDO_INSERT_REC,
81 dulint new_trx_id
; /* trx id to restore to clustered index
83 btr_pcur_t pcur
; /* persistent cursor used in searching the
84 clustered index record */
85 dict_table_t
* table
; /* table where undo is done */
86 ulint cmpl_info
;/* compiler analysis of an update */
87 upd_t
* update
; /* update vector for a clustered index
89 dtuple_t
* ref
; /* row reference to the next row to handle */
90 dtuple_t
* row
; /* a copy (also fields copied to heap) of the
92 dict_index_t
* index
; /* the next index whose record should be
94 mem_heap_t
* heap
; /* memory heap used as auxiliary storage for
95 row; this must be emptied after undo is tried
99 /* Execution states for an undo node */
100 #define UNDO_NODE_FETCH_NEXT 1 /* we should fetch the next undo log
102 #define UNDO_NODE_INSERT 2
103 #define UNDO_NODE_MODIFY 3
107 #include "row0undo.ic"