MySQL 9.1.0
Source Code Documentation
row0purge.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 1997, 2024, 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 designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26*****************************************************************************/
27
28/** @file include/row0purge.h
29 Purge obsolete records
30
31 Created 3/14/1997 Heikki Tuuri
32 *******************************************************/
33
34#ifndef row0purge_h
35#define row0purge_h
36
37#include "univ.i"
38
39#include "btr0pcur.h"
40#include "btr0types.h"
41#include "data0data.h"
42#include "dict0types.h"
43#include "que0types.h"
44#include "row0types.h"
45#include "trx0types.h"
46#include "ut0vec.h"
47
48/** Create a purge node to a query graph.
49@param[in] parent parent node, i.e., a thr node
50@param[in] heap memory heap where created
51@return own: purge node */
52[[nodiscard]] purge_node_t *row_purge_node_create(que_thr_t *parent,
53 mem_heap_t *heap);
54
55/** Determines if it is possible to remove a secondary index entry.
56 Removal is possible if the secondary index entry does not refer to any
57 not delete marked version of a clustered index record where DB_TRX_ID
58 is newer than the purge view.
59
60 NOTE: This function should only be called by the purge thread, only
61 while holding a latch on the leaf page of the secondary index entry
62 (or keeping the buffer pool watch on the page). It is possible that
63 this function first returns true and then false, if a user transaction
64 inserts a record that the secondary index entry would refer to.
65 However, in that case, the user transaction would also re-insert the
66 secondary index entry after purge has removed it and released the leaf
67 page latch.
68 @return true if the secondary index record can be purged */
69[[nodiscard]] bool row_purge_poss_sec(
70 purge_node_t *node, /*!< in/out: row purge node */
71 dict_index_t *index, /*!< in: secondary index */
72 const dtuple_t *entry); /*!< in: secondary index entry */
73/***************************************************************
74Does the purge operation for a single undo log record. This is a high-level
75function used in an SQL execution graph.
76@return query thread to run next or NULL */
77[[nodiscard]] que_thr_t *row_purge_step(
78 que_thr_t *thr); /*!< in: query thread */
79
80using Page_free_tuple = std::tuple<index_id_t, page_id_t, table_id_t>;
81
83 bool operator()(const Page_free_tuple &lhs,
84 const Page_free_tuple &rhs) const {
85 const page_id_t &lpage_id = std::get<1>(lhs);
86 const page_id_t &rpage_id = std::get<1>(rhs);
87 return (lpage_id < rpage_id);
88 }
89};
90
91/* Purge node structure */
92
94 /** Info required to purge a record */
95 struct rec_t {
96 /** Record to purge */
98
99 /** File pointer to UNDO record */
101
102 /** Trx that created this undo record */
104 };
105
106 using Recs = std::list<rec_t, mem_heap_allocator<rec_t>>;
107
108 /** node type: QUE_NODE_PURGE */
110
111 /* Local storage for this graph node */
112
113 /** roll pointer to undo log record */
115
116 /** undo number of the record */
118
119 /** undo log record type: TRX_UNDO_INSERT_REC, ... */
121
122 /** table where purge is done */
124
125 /** MDL ticket for the table name */
127
128 /** parent table for an FTS AUX TABLE */
130
131 /** MDL ticket for the parent table of an FTS AUX TABLE */
133
134 /** MySQL table instance */
136
137 /** compiler analysis info of an update */
139
140 /** update vector for a clustered index record */
142
143 /** NULL, or row reference to the next row to handle */
145
146 /** NULL, or a copy (also fields copied to heap) of the indexed
147 fields of the row to handle */
149
150 /** NULL, or the next index whose record should be handled */
152
153 /** The heap is owned by purge_sys and is reset after a purge
154 batch has completed. */
156
157 /** true if the clustered index record determined by ref was
158 found in the clustered index, and we were able to position pcur on it */
160
161 /** persistent cursor used in searching the clustered index record */
163
164 /** Debug flag */
165 bool done;
166
167 /** trx id for this purging record */
169
170 /** trx id for this purging record */
172
173 /** Undo recs to purge */
175
176 void init() { new (&m_lob_pages) LOB_free_set(); }
177 void deinit() {
179 m_lob_pages.~LOB_free_set();
180 }
181
182 /** Add an LOB page to the list of pages that will be freed at the end of a
183 purge batch.
184 @param[in] index the clust index to which the LOB belongs.
185 @param[in] page_id the page_id of the first page of the LOB. */
186 void add_lob_page(dict_index_t *index, const page_id_t &page_id);
187
188 /** Free the LOB first pages at end of purge batch. Since this function
189 acquires shared MDL table locks, the caller should not hold any latches. */
190 void free_lob_pages();
191
192 /** Check if undo records of given table_id is there in this purge node.
193 @param[in] table_id look for undo records of this table id.
194 @return true if undo records of table id exists, false otherwise. */
195 bool is_table_id_exists(table_id_t table_id) const;
196
197#ifdef UNIV_DEBUG
198 /** Check if there are more than one undo record with same (trx_id, undo_no)
199 combination.
200 @return true when no duplicates are found, false otherwise. */
201 bool check_duplicate_undo_no() const;
202#endif /* UNIV_DEBUG */
203
205#ifdef UNIV_DEBUG
206 /** Validate the persistent cursor. The purge node has two references
207 to the clustered index record - one via the ref member, and the
208 other via the persistent cursor. These two references must match
209 each other if the found_clust flag is set.
210 @return true if the persistent cursor is consistent with
211 the ref member.*/
212 bool validate_pcur();
213#endif
214
215 private:
218
219 /** Set of LOB first pages that are to be freed. */
221};
222
223#endif
The index tree persistent cursor.
The index tree general types.
A granted metadata lock.
Definition: mdl.h:986
Page identifier.
Definition: buf0types.h:207
Allocator that allows std::* containers to manage their memory through ut::malloc* and ut::free libra...
Definition: ut0new.h:2183
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:232
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:2884
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:82
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:276
que_thr_t * row_purge_step(que_thr_t *thr)
in: query thread
Definition: row0purge.cc:1213
std::tuple< index_id_t, page_id_t, table_id_t > Page_free_tuple
Definition: row0purge.h:80
Row operation global types.
Definition: row0purge.h:82
bool operator()(const Page_free_tuple &lhs, const Page_free_tuple &rhs) const
Definition: row0purge.h:83
Definition: table.h:1421
Definition: completion_hash.h:35
Definition: btr0pcur.h:99
Data structure for an index.
Definition: dict0mem.h:1041
Data structure for a database table.
Definition: dict0mem.h:1904
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:696
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:302
Info required to purge a record.
Definition: row0purge.h:95
roll_ptr_t roll_ptr
File pointer to UNDO record.
Definition: row0purge.h:100
trx_id_t modifier_trx_id
Trx that created this undo record.
Definition: row0purge.h:103
trx_undo_rec_t * undo_rec
Record to purge.
Definition: row0purge.h:97
Definition: row0purge.h:93
que_common_t common
node type: QUE_NODE_PURGE
Definition: row0purge.h:109
bool found_clust
true if the clustered index record determined by ref was found in the clustered index,...
Definition: row0purge.h:159
dtuple_t * row
NULL, or a copy (also fields copied to heap) of the indexed fields of the row to handle.
Definition: row0purge.h:148
void free_lob_pages()
Free the LOB first pages at end of purge batch.
Definition: row0purge.cc:1348
dict_index_t * index
NULL, or the next index whose record should be handled.
Definition: row0purge.h:151
bool done
Debug flag.
Definition: row0purge.h:165
Recs * recs
Undo recs to purge.
Definition: row0purge.h:174
btr_pcur_t pcur
persistent cursor used in searching the clustered index record
Definition: row0purge.h:162
dict_table_t * parent
parent table for an FTS AUX TABLE
Definition: row0purge.h:129
void deinit()
Definition: row0purge.h:177
ulint cmpl_info
compiler analysis info of an update
Definition: row0purge.h:138
dict_table_t * table
table where purge is done
Definition: row0purge.h:123
void init()
Definition: row0purge.h:176
LOB_free_set m_lob_pages
Set of LOB first pages that are to be freed.
Definition: row0purge.h:220
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:1302
MDL_ticket * mdl
MDL ticket for the table name.
Definition: row0purge.h:126
std::list< rec_t, mem_heap_allocator< rec_t > > Recs
Definition: row0purge.h:106
trx_id_t trx_id
trx id for this purging record
Definition: row0purge.h:168
dtuple_t * ref
NULL, or row reference to the next row to handle.
Definition: row0purge.h:144
ulint rec_type
undo log record type: TRX_UNDO_INSERT_REC, ...
Definition: row0purge.h:120
bool validate_pcur()
Validate the persistent cursor.
Definition: row0purge.cc:1262
std::set< Page_free_tuple, Compare_page_free_tuple, ut::allocator< Page_free_tuple > > LOB_free_set
Definition: row0purge.h:217
undo_no_t undo_no
undo number of the record
Definition: row0purge.h:117
MDL_ticket * parent_mdl
MDL ticket for the parent table of an FTS AUX TABLE.
Definition: row0purge.h:132
mem_heap_t * heap
The heap is owned by purge_sys and is reset after a purge batch has completed.
Definition: row0purge.h:155
upd_t * update
update vector for a clustered index record
Definition: row0purge.h:141
roll_ptr_t roll_ptr
roll pointer to undo log record
Definition: row0purge.h:114
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:1341
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:1320
trx_rseg_t * rseg
Definition: row0purge.h:204
trx_id_t modifier_trx_id
trx id for this purging record
Definition: row0purge.h:171
TABLE * mysql_table
MySQL table instance.
Definition: row0purge.h:135
Definition: que0types.h:51
Definition: que0que.h:242
The rollback segment memory object.
Definition: trx0types.h:214
Definition: row0upd.h:565
Transaction system global type definitions.
byte trx_undo_rec_t
Undo log record.
Definition: trx0types.h:167
ib_id_t undo_no_t
Undo number.
Definition: trx0types.h:142
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:138
ib_id_t roll_ptr_t
Rollback pointer (DB_ROLL_PTR, DATA_ROLL_PTR)
Definition: trx0types.h:140
Version control for database, common definitions, and include files.
unsigned long int ulint
Definition: univ.i:406
A vector of pointers to data items.