| 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/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 |
/*************************************************************** |
| 74 |
Does the purge operation for a single undo log record. This is a high-level |
| 75 |
function 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 |
|
| 80 |
using Page_free_tuple = std::tuple<index_id_t, page_id_t, table_id_t>; |
| 81 |
|
| 82 |
struct Compare_page_free_tuple { |
| 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 |
|
| 93 |
struct purge_node_t { |
| 94 |
/** Info required to purge a record */ |
| 95 |
struct rec_t { |
| 96 |
/** Record to purge */ |
| 97 |
trx_undo_rec_t *undo_rec; |
| 98 |
|
| 99 |
/** File pointer to UNDO record */ |
| 100 |
roll_ptr_t roll_ptr; |
| 101 |
|
| 102 |
/** Trx that created this undo record */ |
| 103 |
trx_id_t modifier_trx_id; |
| 104 |
}; |
| 105 |
|
| 106 |
using Recs = std::list<rec_t, mem_heap_allocator<rec_t>>; |
| 107 |
|
| 108 |
/** node type: QUE_NODE_PURGE */ |
| 109 |
que_common_t common; |
| 110 |
|
| 111 |
/* Local storage for this graph node */ |
| 112 |
|
| 113 |
/** roll pointer to undo log record */ |
| 114 |
roll_ptr_t roll_ptr; |
| 115 |
|
| 116 |
/** undo number of the record */ |
| 117 |
undo_no_t undo_no; |
| 118 |
|
| 119 |
/** undo log record type: TRX_UNDO_INSERT_REC, ... */ |
| 120 |
ulint rec_type; |
| 121 |
|
| 122 |
/** table where purge is done */ |
| 123 |
dict_table_t *table; |
| 124 |
|
| 125 |
/** MDL ticket for the table name */ |
| 126 |
MDL_ticket *mdl; |
| 127 |
|
| 128 |
/** parent table for an FTS AUX TABLE */ |
| 129 |
dict_table_t *parent; |
| 130 |
|
| 131 |
/** MDL ticket for the parent table of an FTS AUX TABLE */ |
| 132 |
MDL_ticket *parent_mdl; |
| 133 |
|
| 134 |
/** MySQL table instance */ |
| 135 |
TABLE *mysql_table; |
| 136 |
|
| 137 |
/** compiler analysis info of an update */ |
| 138 |
ulint cmpl_info; |
| 139 |
|
| 140 |
/** update vector for a clustered index record */ |
| 141 |
upd_t *update; |
| 142 |
|
| 143 |
/** NULL, or row reference to the next row to handle */ |
| 144 |
dtuple_t *ref; |
| 145 |
|
| 146 |
/** NULL, or a copy (also fields copied to heap) of the indexed |
| 147 |
fields of the row to handle */ |
| 148 |
dtuple_t *row; |
| 149 |
|
| 150 |
/** NULL, or the next index whose record should be handled */ |
| 151 |
dict_index_t *index; |
| 152 |
|
| 153 |
/** The heap is owned by purge_sys and is reset after a purge |
| 154 |
batch has completed. */ |
| 155 |
mem_heap_t *heap; |
| 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 */ |
| 159 |
bool found_clust; |
| 160 |
|
| 161 |
/** persistent cursor used in searching the clustered index record */ |
| 162 |
btr_pcur_t pcur; |
| 163 |
|
| 164 |
/** Debug flag */ |
| 165 |
bool done; |
| 166 |
|
| 167 |
/** trx id for this purging record */ |
| 168 |
trx_id_t trx_id; |
| 169 |
|
| 170 |
/** trx id for this purging record */ |
| 171 |
trx_id_t modifier_trx_id; |
| 172 |
|
| 173 |
/** Undo recs to purge */ |
| 174 |
Recs *recs; |
| 175 |
|
| 176 |
void init() { new (&m_lob_pages) LOB_free_set(); } |
| 177 |
void deinit() { |
| 178 |
mem_heap_free(heap); |
| 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 |
|
| 204 |
trx_rseg_t *rseg; |
| 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: |
| 216 |
using LOB_free_set = std::set<Page_free_tuple, Compare_page_free_tuple, |
| 217 |
ut::allocator<Page_free_tuple>>; |
| 218 |
|
| 219 |
/** Set of LOB first pages that are to be freed. */ |
| 220 |
LOB_free_set m_lob_pages; |
| 221 |
}; |
| 222 |
|
| 223 |
#endif |