MySQL 8.0.31
Source Code Documentation
row0purge.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1997, 2022, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 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[[nodiscard]] purge_node_t *row_purge_node_create(que_thr_t *parent,
52 mem_heap_t *heap);
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[[nodiscard]] bool row_purge_poss_sec(
69 purge_node_t *node, /*!< in/out: row purge node */
70 dict_index_t *index, /*!< in: secondary index */
71 const dtuple_t *entry); /*!< in: secondary index entry */
72/***************************************************************
73Does the purge operation for a single undo log record. This is a high-level
74function used in an SQL execution graph.
75@return query thread to run next or NULL */
76[[nodiscard]] que_thr_t *row_purge_step(
77 que_thr_t *thr); /*!< in: query thread */
78
79using Page_free_tuple = std::tuple<index_id_t, page_id_t, table_id_t>;
80
82 bool operator()(const Page_free_tuple &lhs,
83 const Page_free_tuple &rhs) const {
84 const page_id_t &lpage_id = std::get<1>(lhs);
85 const page_id_t &rpage_id = std::get<1>(rhs);
86 return (lpage_id < rpage_id);
87 }
88};
89
90/* Purge node structure */
91
93 /** Info required to purge a record */
94 struct rec_t {
95 /** Record to purge */
97
98 /** File pointer to UNDO record */
100
101 /** Trx that created this undo record */
103 };
104
105 using Recs = std::list<rec_t, mem_heap_allocator<rec_t>>;
106
107 /** node type: QUE_NODE_PURGE */
109
110 /* Local storage for this graph node */
111
112 /** roll pointer to undo log record */
114
115 /** undo number of the record */
117
118 /** undo log record type: TRX_UNDO_INSERT_REC, ... */
120
121 /** table where purge is done */
123
124 /** MDL ticket for the table name */
126
127 /** parent table for an FTS AUX TABLE */
129
130 /** MDL ticket for the parent table of an FTS AUX TABLE */
132
133 /** MySQL table instance */
135
136 /** compiler analysis info of an update */
138
139 /** update vector for a clustered index record */
141
142 /** NULL, or row reference to the next row to handle */
144
145 /** NULL, or a copy (also fields copied to heap) of the indexed
146 fields of the row to handle */
148
149 /** NULL, or the next index whose record should be handled */
151
152 /** The heap is owned by purge_sys and is reset after a purge
153 batch has completed. */
155
156 /** true if the clustered index record determined by ref was
157 found in the clustered index, and we were able to position pcur on it */
159
160 /** persistent cursor used in searching the clustered index record */
162
163 /** Debug flag */
164 bool done;
165
166 /** trx id for this purging record */
168
169 /** trx id for this purging record */
171
172 /** Undo recs to purge */
174
175 void init() { new (&m_lob_pages) LOB_free_set(); }
176 void deinit() {
178 m_lob_pages.~LOB_free_set();
179 }
180
181 /** Add an LOB page to the list of pages that will be freed at the end of a
182 purge batch.
183 @param[in] index the clust index to which the LOB belongs.
184 @param[in] page_id the page_id of the first page of the LOB. */
185 void add_lob_page(dict_index_t *index, const page_id_t &page_id);
186
187 /** Free the LOB first pages at end of purge batch. Since this function
188 acquires shared MDL table locks, the caller should not hold any latches. */
189 void free_lob_pages();
190
191 /** Check if undo records of given table_id is there in this purge node.
192 @param[in] table_id look for undo records of this table id.
193 @return true if undo records of table id exists, false otherwise. */
194 bool is_table_id_exists(table_id_t table_id) const;
195
196#ifdef UNIV_DEBUG
197 /** Check if there are more than one undo record with same (trx_id, undo_no)
198 combination.
199 @return true when no duplicates are found, false otherwise. */
200 bool check_duplicate_undo_no() const;
201#endif /* UNIV_DEBUG */
202
204#ifdef UNIV_DEBUG
205 /** Validate the persistent cursor. The purge node has two references
206 to the clustered index record - one via the ref member, and the
207 other via the persistent cursor. These two references must match
208 each other if the found_clust flag is set.
209 @return true if the persistent cursor is consistent with
210 the ref member.*/
211 bool validate_pcur();
212#endif
213
214 private:
217
218 /** Set of LOB first pages that are to be freed. */
220};
221
222#endif
The index tree persistent cursor.
The index tree general types.
A granted metadata lock.
Definition: mdl.h:984
Page identifier.
Definition: buf0types.h:206
Allocator that allows std::* containers to manage their memory through ut::malloc* and ut::free libra...
Definition: ut0new.h:2179
SQL data field and tuple.
Data dictionary global types.
ib_id_t table_id_t
Table or partition identifier (unique within an InnoDB instance).
Definition: dict0types.h:217
static void mem_heap_free(mem_heap_t *heap)
Frees the space occupied by a memory heap.
std::set< Key, Compare, ut::allocator< Key > > set
Specialization of set which uses ut_allocator.
Definition: ut0new.h:2863
Query graph global types.
purge_node_t * row_purge_node_create(que_thr_t *parent, mem_heap_t *heap)
Create a purge node to a query graph.
Definition: row0purge.cc:80
bool row_purge_poss_sec(purge_node_t *node, dict_index_t *index, const dtuple_t *entry)
Determines if it is possible to remove a secondary index entry.
Definition: row0purge.cc:274
que_thr_t * row_purge_step(que_thr_t *thr)
in: query thread
Definition: row0purge.cc:1211
std::tuple< index_id_t, page_id_t, table_id_t > Page_free_tuple
Definition: row0purge.h:79
Row operation global types.
Definition: row0purge.h:81
bool operator()(const Page_free_tuple &lhs, const Page_free_tuple &rhs) const
Definition: row0purge.h:82
Definition: table.h:1396
Definition: completion_hash.h:34
Definition: btr0pcur.h:98
Data structure for an index.
Definition: dict0mem.h:1021
Data structure for a database table.
Definition: dict0mem.h:1884
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:681
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:299
Info required to purge a record.
Definition: row0purge.h:94
roll_ptr_t roll_ptr
File pointer to UNDO record.
Definition: row0purge.h:99
trx_id_t modifier_trx_id
Trx that created this undo record.
Definition: row0purge.h:102
trx_undo_rec_t * undo_rec
Record to purge.
Definition: row0purge.h:96
Definition: row0purge.h:92
que_common_t common
node type: QUE_NODE_PURGE
Definition: row0purge.h:108
bool found_clust
true if the clustered index record determined by ref was found in the clustered index,...
Definition: row0purge.h:158
dtuple_t * row
NULL, or a copy (also fields copied to heap) of the indexed fields of the row to handle.
Definition: row0purge.h:147
void free_lob_pages()
Free the LOB first pages at end of purge batch.
Definition: row0purge.cc:1346
dict_index_t * index
NULL, or the next index whose record should be handled.
Definition: row0purge.h:150
bool done
Debug flag.
Definition: row0purge.h:164
Recs * recs
Undo recs to purge.
Definition: row0purge.h:173
btr_pcur_t pcur
persistent cursor used in searching the clustered index record
Definition: row0purge.h:161
dict_table_t * parent
parent table for an FTS AUX TABLE
Definition: row0purge.h:128
void deinit()
Definition: row0purge.h:176
ulint cmpl_info
compiler analysis info of an update
Definition: row0purge.h:137
dict_table_t * table
table where purge is done
Definition: row0purge.h:122
void init()
Definition: row0purge.h:175
LOB_free_set m_lob_pages
Set of LOB first pages that are to be freed.
Definition: row0purge.h:219
bool is_table_id_exists(table_id_t table_id) const
Check if undo records of given table_id is there in this purge node.
Definition: row0purge.cc:1300
MDL_ticket * mdl
MDL ticket for the table name.
Definition: row0purge.h:125
std::list< rec_t, mem_heap_allocator< rec_t > > Recs
Definition: row0purge.h:105
trx_id_t trx_id
trx id for this purging record
Definition: row0purge.h:167
dtuple_t * ref
NULL, or row reference to the next row to handle.
Definition: row0purge.h:143
ulint rec_type
undo log record type: TRX_UNDO_INSERT_REC, ...
Definition: row0purge.h:119
bool validate_pcur()
Validate the persistent cursor.
Definition: row0purge.cc:1260
std::set< Page_free_tuple, Compare_page_free_tuple, ut::allocator< Page_free_tuple > > LOB_free_set
Definition: row0purge.h:216
undo_no_t undo_no
undo number of the record
Definition: row0purge.h:116
MDL_ticket * parent_mdl
MDL ticket for the parent table of an FTS AUX TABLE.
Definition: row0purge.h:131
mem_heap_t * heap
The heap is owned by purge_sys and is reset after a purge batch has completed.
Definition: row0purge.h:154
upd_t * update
update vector for a clustered index record
Definition: row0purge.h:140
roll_ptr_t roll_ptr
roll pointer to undo log record
Definition: row0purge.h:113
void add_lob_page(dict_index_t *index, const page_id_t &page_id)
Add an LOB page to the list of pages that will be freed at the end of a purge batch.
Definition: row0purge.cc:1339
bool check_duplicate_undo_no() const
Check if there are more than one undo record with same (trx_id, undo_no) combination.
Definition: row0purge.cc:1318
trx_rseg_t * rseg
Definition: row0purge.h:203
trx_id_t modifier_trx_id
trx id for this purging record
Definition: row0purge.h:170
TABLE * mysql_table
MySQL table instance.
Definition: row0purge.h:134
Definition: que0types.h:50
Definition: que0que.h:241
The rollback segment memory object.
Definition: trx0types.h:176
Definition: row0upd.h:564
Transaction system global type definitions.
byte trx_undo_rec_t
Undo log record.
Definition: trx0types.h:166
ib_id_t undo_no_t
Undo number.
Definition: trx0types.h:141
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:137
ib_id_t roll_ptr_t
Rollback pointer (DB_ROLL_PTR, DATA_ROLL_PTR)
Definition: trx0types.h:139
Version control for database, common definitions, and include files.
unsigned long int ulint
Definition: univ.i:407
A vector of pointers to data items.