1 /*****************************************************************************
2 
3 Copyright (c) 1997, 2019, Oracle and/or its affiliates. All Rights Reserved.
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 also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 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 St, Fifth Floor, Boston, MA 02110-1301  USA
24 
25 *****************************************************************************/
26 
27 /** @file include/row0purge.h
28  Purge obsolete records
29 
30  Created 3/14/1997 Heikki Tuuri
31  *******************************************************/
32 
33 #ifndef row0purge_h
34 #define row0purge_h
35 
36 #include "univ.i"
37 
38 #include "btr0pcur.h"
39 #include "btr0types.h"
40 #include "data0data.h"
41 #include "dict0types.h"
42 #include "que0types.h"
43 #include "row0types.h"
44 #include "trx0types.h"
45 #include "ut0vec.h"
46 
47 /** Create a purge node to a query graph.
48 @param[in]	parent	parent node, i.e., a thr node
49 @param[in]	heap	memory heap where created
50 @return own: purge node */
51 purge_node_t *row_purge_node_create(que_thr_t *parent, mem_heap_t *heap)
52     MY_ATTRIBUTE((warn_unused_result));
53 
54 /** Determines if it is possible to remove a secondary index entry.
55  Removal is possible if the secondary index entry does not refer to any
56  not delete marked version of a clustered index record where DB_TRX_ID
57  is newer than the purge view.
58 
59  NOTE: This function should only be called by the purge thread, only
60  while holding a latch on the leaf page of the secondary index entry
61  (or keeping the buffer pool watch on the page).  It is possible that
62  this function first returns true and then false, if a user transaction
63  inserts a record that the secondary index entry would refer to.
64  However, in that case, the user transaction would also re-insert the
65  secondary index entry after purge has removed it and released the leaf
66  page latch.
67  @return true if the secondary index record can be purged */
68 bool row_purge_poss_sec(purge_node_t *node,    /*!< in/out: row purge node */
69                         dict_index_t *index,   /*!< in: secondary index */
70                         const dtuple_t *entry) /*!< in: secondary index entry */
71     MY_ATTRIBUTE((warn_unused_result));
72 /***************************************************************
73 Does the purge operation for a single undo log record. This is a high-level
74 function used in an SQL execution graph.
75 @return query thread to run next or NULL */
76 que_thr_t *row_purge_step(que_thr_t *thr) /*!< in: query thread */
77     MY_ATTRIBUTE((warn_unused_result));
78 
79 /* Purge node structure */
80 
81 struct purge_node_t {
82   /** Info required to purge a record */
83   struct rec_t {
84     /** Record to purge */
85     trx_undo_rec_t *undo_rec;
86 
87     /** File pointer to UNDO record */
88     roll_ptr_t roll_ptr;
89 
90     /** Trx that created this undo record */
91     trx_id_t modifier_trx_id;
92   };
93 
94   using Recs = std::list<rec_t, mem_heap_allocator<rec_t>>;
95 
96   /** node type: QUE_NODE_PURGE */
97   que_common_t common;
98 
99   /* Local storage for this graph node */
100 
101   /** roll pointer to undo log record */
102   roll_ptr_t roll_ptr;
103 
104   /** undo number of the record */
105   undo_no_t undo_no;
106 
107   /** undo log record type: TRX_UNDO_INSERT_REC, ... */
108   ulint rec_type;
109 
110   /** table where purge is done */
111   dict_table_t *table;
112 
113   /** MDL ticket for the table name */
114   MDL_ticket *mdl;
115 
116   /** parent table for an FTS AUX TABLE */
117   dict_table_t *parent;
118 
119   /** MDL ticket for the parent table of an FTS AUX TABLE */
120   MDL_ticket *parent_mdl;
121 
122   /** MySQL table instance */
123   TABLE *mysql_table;
124 
125   /** compiler analysis info of an update */
126   ulint cmpl_info;
127 
128   /** update vector for a clustered index record */
129   upd_t *update;
130 
131   /** NULL, or row reference to the next row to handle */
132   dtuple_t *ref;
133 
134   /** NULL, or a copy (also fields copied to heap) of the indexed
135   fields of the row to handle */
136   dtuple_t *row;
137 
138   /** NULL, or the next index whose record should be handled */
139   dict_index_t *index;
140 
141   /** The heap is owned by purge_sys and is reset after a purge
142   batch has completed. */
143   mem_heap_t *heap;
144 
145   /** true if the clustered index record determined by ref was
146   found in the clustered index, and we were able to position pcur on it */
147   bool found_clust;
148 
149   /** persistent cursor used in searching the clustered index record */
150   btr_pcur_t pcur;
151 
152   /** Debug flag */
153   bool done;
154 
155   /** trx id for this purging record */
156   trx_id_t trx_id;
157 
158   /** trx id for this purging record */
159   trx_id_t modifier_trx_id;
160 
161   /** Undo recs to purge */
162   Recs *recs;
163 
164   /** Check if undo records of given table_id is there in this purge node.
165   @param[in]	table_id	look for undo records of this table id.
166   @return true if undo records of table id exists, false otherwise. */
167   bool is_table_id_exists(table_id_t table_id) const;
168 
169 #ifdef UNIV_DEBUG
170   /** Check if there are more than one undo record with same (trx_id, undo_no)
171   combination.
172   @return true when no duplicates are found, false otherwise. */
173   bool check_duplicate_undo_no() const;
174 #endif /* UNIV_DEBUG */
175 
176   trx_rseg_t *rseg;
177 #ifdef UNIV_DEBUG
178   /**   Validate the persisent cursor. The purge node has two references
179      to the clustered index record - one via the ref member, and the
180      other via the persistent cursor.  These two references must match
181      each other if the found_clust flag is set.
182      @return true if the persistent cursor is consistent with
183      the ref member.*/
184   bool validate_pcur();
185 #endif
186 };
187 
188 #endif
189