MySQL 8.0.40
Source Code Documentation
read0types.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/read0types.h
29 Cursor read
30
31 Created 2/16/1997 Heikki Tuuri
32 *******************************************************/
33
34#ifndef read0types_h
35#define read0types_h
36
37#include <algorithm>
38#include "dict0mem.h"
39
40#include "trx0types.h"
41
42// Friend declaration
43class MVCC;
44
45/** Read view lists the trx ids of those transactions for which a consistent
46read should not see the modifications to the database. */
47
48class ReadView {
49 /** This is similar to a std::vector but it is not a drop
50 in replacement. It is specific to ReadView. */
51 class ids_t {
53
54 /**
55 Constructor */
57
58 /**
59 Destructor */
61
62 /** Try and increase the size of the array. Old elements are copied across.
63 It is a no-op if n is < current size.
64 @param n Make space for n elements */
65 void reserve(ulint n);
66
67 /**
68 Resize the array, sets the current element count.
69 @param n new size of the array, in elements */
70 void resize(ulint n) {
71 ut_ad(n <= capacity());
72
73 m_size = n;
74 }
75
76 /**
77 Reset the size to 0 */
78 void clear() { resize(0); }
79
80 /**
81 @return the capacity of the array in elements */
82 ulint capacity() const { return (m_reserved); }
83
84 /**
85 Copy and overwrite the current array contents
86
87 @param start Source array
88 @param end Pointer to end of array */
89 void assign(const value_type *start, const value_type *end);
90
91 /**
92 Insert the value in the correct slot, preserving the order.
93 Doesn't check for duplicates. */
94 void insert(value_type value);
95
96 /**
97 @return the value of the first element in the array */
98 value_type front() const {
99 ut_ad(!empty());
100
101 return (m_ptr[0]);
102 }
103
104 /**
105 @return the value of the last element in the array */
106 value_type back() const {
107 ut_ad(!empty());
108
109 return (m_ptr[m_size - 1]);
110 }
111
112 /**
113 Append a value to the array.
114 @param value the value to append */
115 void push_back(value_type value);
116
117 /**
118 @return a pointer to the start of the array */
119 trx_id_t *data() { return (m_ptr); }
120
121 /**
122 @return a const pointer to the start of the array */
123 const trx_id_t *data() const { return (m_ptr); }
124
125 /**
126 @return the number of elements in the array */
127 ulint size() const { return (m_size); }
128
129 /**
130 @return true if size() == 0 */
131 bool empty() const { return (size() == 0); }
132
133 private:
134 // Prevent copying
135 ids_t(const ids_t &);
137
138 private:
139 /** Memory for the array */
141
142 /** Number of active elements in the array */
144
145 /** Size of m_ptr in elements */
147
148 friend class ReadView;
149 };
150
151 public:
152 ReadView();
153 ~ReadView();
154 /** Check whether transaction id is valid.
155 @param[in] id transaction id to check
156 @param[in] name table name */
157 static void check_trx_id_sanity(trx_id_t id, const table_name_t &name);
158
159 /** Check whether the changes by id are visible.
160 @param[in] id transaction id to check against the view
161 @param[in] name table name
162 @return whether the view sees the modifications of id. */
163 [[nodiscard]] bool changes_visible(trx_id_t id,
164 const table_name_t &name) const {
165 ut_ad(id > 0);
166
167 if (id < m_up_limit_id || id == m_creator_trx_id) {
168 return (true);
169 }
170
172
173 if (id >= m_low_limit_id) {
174 return (false);
175
176 } else if (m_ids.empty()) {
177 return (true);
178 }
179
180 const ids_t::value_type *p = m_ids.data();
181
182 return (!std::binary_search(p, p + m_ids.size(), id));
183 }
184
185 /**
186 @param id transaction to check
187 @return true if view sees transaction id */
188 bool sees(trx_id_t id) const { return (id < m_up_limit_id); }
189
190 /**
191 Mark the view as closed */
192 void close() {
195 }
196
197 /**
198 @return true if the view is closed */
199 bool is_closed() const { return (m_closed); }
200
201 /**
202 Write the limits to the file.
203 @param file file to write to */
204 void print_limits(FILE *file) const {
205 fprintf(file,
206 "Trx read view will not see trx with"
207 " id >= " TRX_ID_FMT ", sees < " TRX_ID_FMT "\n",
209 }
210
211 /** Check and reduce low limit number for read view. Used to
212 block purge till GTID is persisted on disk table.
213 @param[in] trx_no transaction number to check with */
215 if (trx_no < m_low_limit_no) {
216 /* Save low limit number set for Read View for MVCC. */
218 m_low_limit_no = trx_no;
219 }
220 }
221
222 /**
223 @return the low limit no */
225
226 /**
227 @return the low limit id */
229
230 /**
231 @return true if there are no transaction ids in the snapshot */
232 bool empty() const { return (m_ids.empty()); }
233
234#ifdef UNIV_DEBUG
235 /**
236 @return the view low limit number */
238
239 /**
240 @param rhs view to compare with
241 @return truen if this view is less than or equal rhs */
242 bool le(const ReadView *rhs) const {
243 return (m_low_limit_no <= rhs->m_low_limit_no);
244 }
245#endif /* UNIV_DEBUG */
246 private:
247 /**
248 Copy the transaction ids from the source vector */
249 inline void copy_trx_ids(const trx_ids_t &trx_ids);
250
251 /**
252 Opens a read view where exactly the transactions serialized before this
253 point in time are seen in the view.
254 @param id Creator transaction id */
255 inline void prepare(trx_id_t id);
256
257 /**
258 Copy state from another view. Must call copy_complete() to finish.
259 @param other view to copy from */
260 inline void copy_prepare(const ReadView &other);
261
262 /**
263 Complete the copy, insert the creator transaction id into the
264 m_trx_ids too and adjust the m_up_limit_id *, if required */
265 inline void copy_complete();
266
267 /**
268 Set the creator transaction id, existing id must be 0 */
272 }
273
274 friend class MVCC;
275
276 private:
277 // Disable copying
280
281 private:
282 /** The read should not see any transaction with trx id >= this
283 value. In other words, this is the "high water mark". */
285
286 /** The read should see all trx ids which are strictly
287 smaller (<) than this value. In other words, this is the
288 low water mark". */
290
291 /** trx id of creating transaction, set to TRX_ID_MAX for free
292 views. */
294
295 /** Set of RW transactions that was active when this snapshot
296 was taken */
298
299 /** The view does not need to see the undo logs for transactions
300 whose transaction number is strictly smaller (<) than this value:
301 they can be removed in purge if not needed by other views */
303
304#ifdef UNIV_DEBUG
305 /** The low limit number up to which read views don't need to access
306 undo log records for MVCC. This could be higher than m_low_limit_no
307 if purge is blocked for GTID persistence. Currently used for debug
308 variable INNODB_PURGE_VIEW_TRX_ID_AGE. */
310#endif /* UNIV_DEBUG */
311
312 /** AC-NL-RO transaction view that has been "closed". */
314
315 typedef UT_LIST_NODE_T(ReadView) node_t;
316
317 /** List of read views in trx_sys */
318 byte pad1[64 - sizeof(node_t)];
320};
321
322#endif
The MVCC read view manager.
Definition: read0read.h:44
This is similar to a std::vector but it is not a drop in replacement.
Definition: read0types.h:51
ulint m_size
Number of active elements in the array.
Definition: read0types.h:143
const trx_id_t * data() const
Definition: read0types.h:123
value_type * m_ptr
Memory for the array.
Definition: read0types.h:140
trx_ids_t::value_type value_type
Definition: read0types.h:52
void push_back(value_type value)
Append a value to the array.
Definition: read0read.cc:270
ids_t & operator=(const ids_t &)
value_type front() const
Definition: read0types.h:98
~ids_t()
Destructor.
Definition: read0types.h:60
ulint size() const
Definition: read0types.h:127
ids_t()
Constructor.
Definition: read0types.h:56
void insert(value_type value)
Insert the value in the correct slot, preserving the order.
Definition: read0read.cc:283
void reserve(ulint n)
Try and increase the size of the array.
Definition: read0read.cc:217
bool empty() const
Definition: read0types.h:131
value_type back() const
Definition: read0types.h:106
void clear()
Reset the size to 0.
Definition: read0types.h:78
trx_id_t * data()
Definition: read0types.h:119
ulint m_reserved
Size of m_ptr in elements.
Definition: read0types.h:146
void resize(ulint n)
Resize the array, sets the current element count.
Definition: read0types.h:70
void assign(const value_type *start, const value_type *end)
Copy and overwrite the current array contents.
Definition: read0read.cc:248
ids_t(const ids_t &)
ulint capacity() const
Definition: read0types.h:82
Read view lists the trx ids of those transactions for which a consistent read should not see the modi...
Definition: read0types.h:48
void print_limits(FILE *file) const
Write the limits to the file.
Definition: read0types.h:204
~ReadView()
ReadView destructor.
Definition: read0read.cc:327
void copy_prepare(const ReadView &other)
Copy state from another view.
Definition: read0read.cc:624
ReadView()
ReadView constructor.
Definition: read0read.cc:315
trx_id_t m_view_low_limit_no
The low limit number up to which read views don't need to access undo log records for MVCC.
Definition: read0types.h:309
bool le(const ReadView *rhs) const
Definition: read0types.h:242
node_t m_view_list
Definition: read0types.h:319
byte pad1[64 - sizeof(node_t)]
List of read views in trx_sys.
Definition: read0types.h:318
void copy_complete()
Complete the copy, insert the creator transaction id into the m_trx_ids too and adjust the m_up_limit...
Definition: read0read.cc:650
void creator_trx_id(trx_id_t id)
Set the creator transaction id, existing id must be 0.
Definition: read0types.h:269
trx_id_t low_limit_no() const
Definition: read0types.h:224
bool changes_visible(trx_id_t id, const table_name_t &name) const
Check whether the changes by id are visible.
Definition: read0types.h:163
trx_id_t m_low_limit_id
The read should not see any transaction with trx id >= this value.
Definition: read0types.h:284
bool is_closed() const
Definition: read0types.h:199
void reduce_low_limit(trx_id_t trx_no)
Check and reduce low limit number for read view.
Definition: read0types.h:214
typedef UT_LIST_NODE_T(ReadView) node_t
bool sees(trx_id_t id) const
Definition: read0types.h:188
trx_id_t m_up_limit_id
The read should see all trx ids which are strictly smaller (<) than this value.
Definition: read0types.h:289
void close()
Mark the view as closed.
Definition: read0types.h:192
ids_t m_ids
Set of RW transactions that was active when this snapshot was taken.
Definition: read0types.h:297
trx_id_t m_creator_trx_id
trx id of creating transaction, set to TRX_ID_MAX for free views.
Definition: read0types.h:293
bool m_closed
AC-NL-RO transaction view that has been "closed".
Definition: read0types.h:313
trx_id_t view_low_limit_no() const
Definition: read0types.h:237
void copy_trx_ids(const trx_ids_t &trx_ids)
Copy the transaction ids from the source vector.
Definition: read0read.cc:354
void prepare(trx_id_t id)
Opens a read view where exactly the transactions serialized before this point in time are seen in the...
Definition: read0read.cc:447
ReadView & operator=(const ReadView &)
bool empty() const
Definition: read0types.h:232
trx_id_t m_low_limit_no
The view does not need to see the undo logs for transactions whose transaction number is strictly sma...
Definition: read0types.h:302
ReadView(const ReadView &)
static void check_trx_id_sanity(trx_id_t id, const table_name_t &name)
Check whether transaction id is valid.
Definition: trx0sys.cc:63
trx_id_t low_limit_id() const
Definition: read0types.h:228
const char * p
Definition: ctype-mb.cc:1237
Data dictionary memory object creation.
static void start(mysql_harness::PluginFuncEnv *env)
Definition: http_auth_backend_plugin.cc:177
uint16_t value_type
Definition: vt100.h:184
const std::string FILE("FILE")
Definition: os0file.h:86
Cursor end()
A past-the-end Cursor.
Definition: rules_table_service.cc:192
void delete_arr(T *ptr) noexcept
Releases storage which has been dynamically allocated through any of the ut::new_arr*() variants.
Definition: ut0new.h:1110
case opt name
Definition: sslopt-case.h:33
Table name wrapper for pretty-printing.
Definition: dict0mem.h:470
Transaction system global type definitions.
constexpr trx_id_t TRX_ID_MAX
Maximum transaction identifier.
Definition: trx0types.h:145
#define TRX_ID_FMT
printf(3) format used for printing DB_TRX_ID and other system fields
Definition: trx0types.h:49
std::vector< trx_id_t, ut::allocator< trx_id_t > > trx_ids_t
Definition: trx0types.h:633
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:138
unsigned long int ulint
Definition: univ.i:406
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:69
#define ut_d(EXPR)
Debug statement.
Definition: ut0dbg.h:71
unsigned long id[MAX_DEAD]
Definition: xcom_base.cc:510
int n
Definition: xcom_base.cc:509