MySQL 26.10.0
Source Code Documentation
row0log.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2011, 2026, 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#include "my_psi_config.h"
29
30/** @file include/row0log.h
31 Modification log for online index creation and online table rebuild
32
33 Created 2011-05-26 Marko Makela
34 *******************************************************/
35
36#ifndef row0log_h
37#define row0log_h
38
39#include "univ.i"
40
41#include "data0types.h"
42#include "dict0types.h"
43#include "mtr0types.h"
44#include "que0types.h"
45#include "rem0types.h"
46#include "row0types.h"
47#include "trx0types.h"
48
49class Alter_stage;
50
51/** Allocate the row log for an index and flag the index
52for online creation.
53@param[in] index Index.
54@param[in] table New table being rebuilt, or NULL when creating a secondary
55index.
56@param[in] same_pk Whether the definition of the PRIMARY KEY has remained the
57same.
58@param[in] add_cols Default values of added columns, or nullptr.
59@param[in] col_map Mapping of old column numbers to new ones, or nullptr if
60!table.
61@param[in] col_has_compatible_charset_change
62 Per-old-column array; true when the mapped column has a
63 charset/collation change whose existing value bytes can be
64 reused during row-log replay, or nullptr when table is
65 nullptr.
66@param[in] path Where to create temporary file.
67@retval true if success, false if not */
69 const dtuple_t *add_cols, const ulint *col_map,
70 const bool *col_has_compatible_charset_change,
71 const char *path);
72
73/** Free the row log for an index that was being created online. */
74void row_log_free(row_log_t *&log); /*!< in,own: row log */
75
76#ifndef UNIV_HOTBACKUP
77/** Free the row log for an index on which online creation was aborted. */
78static inline void row_log_abort_sec(
79 dict_index_t *index); /*!< in/out: index (x-latched) */
80
81/** Try to log an operation to a secondary index that is (or was) being created.
82@param[in,out] index Index, S- or X-latched.
83@param[in] tuple Index tuple.
84@param[in] trx_id Transaction ID for insert, or 0 for delete.
85@retval true if the operation was logged or can be ignored
86@retval false if online index creation is not taking place */
87[[nodiscard]] static inline bool row_log_online_op_try(dict_index_t *index,
88 const dtuple_t *tuple,
89 trx_id_t trx_id);
90#endif /* !UNIV_HOTBACKUP */
91/** Logs an operation to a secondary index that is (or was) being created. */
93 dict_index_t *index, /*!< in/out: index, S or X latched */
94 const dtuple_t *tuple, /*!< in: index tuple */
95 trx_id_t trx_id) /*!< in: transaction ID for insert,
96 or 0 for delete */
98
99/** Gets the error status of the online index rebuild log.
100 @return DB_SUCCESS or error code */
101[[nodiscard]] dberr_t row_log_table_get_error(
102 const dict_index_t *index); /*!< in: clustered index of a table
103 that is being rebuilt online */
104
105/** Check whether a virtual column is indexed in the new table being
106created during alter table
107@param[in] index cluster index
108@param[in] v_no virtual column number
109@return true if it is indexed, else false */
111
112/** Logs a delete operation to a table that is being rebuilt.
113 This will be merged in row_log_table_apply_delete(). */
115 const rec_t *rec, /*!< in: clustered index leaf page record,
116 page X-latched */
117 const dtuple_t *ventry, /*!< in: dtuple holding virtual column info */
118 dict_index_t *index, /*!< in/out: clustered index, S-latched
119 or X-latched */
120 const ulint *offsets, /*!< in: rec_get_offsets(rec,index) */
121 const byte *sys) /*!< in: DB_TRX_ID,DB_ROLL_PTR that should
122 be logged, or NULL to use those in rec */
123 UNIV_COLD;
124
125/** Logs an update operation to a table that is being rebuilt.
126 This will be merged in row_log_table_apply_update(). */
128 const rec_t *rec, /*!< in: clustered index leaf page record,
129 page X-latched */
130 dict_index_t *index, /*!< in/out: clustered index, S-latched
131 or X-latched */
132 const ulint *offsets, /*!< in: rec_get_offsets(rec,index) */
133 const dtuple_t *old_pk, /*!< in: row_log_table_get_pk()
134 before the update */
135 const dtuple_t *new_v_row, /*!< in: dtuple contains the new virtual
136 columns */
137 const dtuple_t *old_v_row) /*!< in: dtuple contains the old virtual
138 columns */
139 UNIV_COLD;
140
141/** Constructs the old PRIMARY KEY and DB_TRX_ID,DB_ROLL_PTR
142 of a table that is being rebuilt.
143 @return tuple of PRIMARY KEY,DB_TRX_ID,DB_ROLL_PTR in the rebuilt table,
144 or NULL if the PRIMARY KEY definition does not change */
145[[nodiscard]] const dtuple_t *row_log_table_get_pk(
146 const rec_t *rec, /*!< in: clustered index leaf page record,
147 page X-latched */
148 dict_index_t *index, /*!< in/out: clustered index, S-latched
149 or X-latched */
150 const ulint *offsets, /*!< in: rec_get_offsets(rec,index),
151 or NULL */
152 byte *sys, /*!< out: DB_TRX_ID,DB_ROLL_PTR for
153 row_log_table_delete(), or NULL */
154 mem_heap_t **heap) /*!< in/out: memory heap where allocated */
155 UNIV_COLD;
156
157/** Logs an insert to a table that is being rebuilt.
158 This will be merged in row_log_table_apply_insert(). */
160 const rec_t *rec, /*!< in: clustered index leaf page record,
161 page X-latched */
162 const dtuple_t *ventry, /*!< in: dtuple holding virtual column info */
163 dict_index_t *index, /*!< in/out: clustered index, S-latched
164 or X-latched */
165 const ulint *offsets) /*!< in: rec_get_offsets(rec,index) */
166 UNIV_COLD;
167/** Notes that a BLOB is being freed during online ALTER TABLE. */
169 dict_index_t *index, /*!< in/out: clustered index, X-latched */
170 page_no_t page_no) /*!< in: starting page number of the BLOB */
171 UNIV_COLD;
172/** Notes that a BLOB is being allocated during online ALTER TABLE. */
174 dict_index_t *index, /*!< in/out: clustered index, X-latched */
175 page_no_t page_no) /*!< in: starting page number of the BLOB */
176 UNIV_COLD;
177
178/** Apply the row_log_table log to a table upon completing rebuild.
179@param[in] thr query graph
180@param[in] old_table old table
181@param[in,out] table MySQL table (for reporting duplicates)
182@param[in,out] stage performance schema accounting object, used by
183ALTER TABLE. stage->begin_phase_log_table() will be called initially and then
184stage->inc() will be called for each block of log that is applied.
185@return DB_SUCCESS, or error code on failure */
186[[nodiscard]] dberr_t row_log_table_apply(que_thr_t *thr,
187 dict_table_t *old_table,
188 struct TABLE *table,
189 Alter_stage *stage);
190
191/** Get the latest transaction ID that has invoked row_log_online_op()
192 during online creation.
193 @return latest transaction ID, or 0 if nothing was logged */
194[[nodiscard]] trx_id_t row_log_get_max_trx(
195 dict_index_t *index); /*!< in: index, must be locked */
196
197/** Apply the row log to the index upon completing index creation.
198@param[in] trx transaction (for checking if the operation was
199interrupted)
200@param[in,out] index secondary index
201@param[in,out] table MySQL table (for reporting duplicates)
202@param[in,out] stage performance schema accounting object, used by
203ALTER TABLE. stage->begin_phase_log_index() will be called initially and then
204stage->inc() will be called for each block of log that is applied.
205@return DB_SUCCESS, or error code on failure */
206[[nodiscard]] dberr_t row_log_apply(const trx_t *trx, dict_index_t *index,
207 struct TABLE *table, Alter_stage *stage);
208
209#ifdef HAVE_PSI_STAGE_INTERFACE
210/** Estimate how much work is to be done by the log apply phase
211of an ALTER TABLE for this index.
212@param[in] index index whose log to assess
213@return work to be done by log-apply in abstract units
214*/
216#endif /* HAVE_PSI_STAGE_INTERFACE */
217
218#include "row0log.ic"
219
220#endif /* row0log.h */
uint32_t page_no_t
Page number.
Definition: api0api.h:47
Class used to report ALTER TABLE progress via performance_schema.
Definition: ut0stage.h:81
Some type definitions.
dberr_t
Definition: db0err.h:39
Data dictionary global types.
Mini-transaction buffer global types.
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
static char * path
Definition: mysqldump.cc:153
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
bool index(const std::string &value, const String &search_for, uint32_t *idx)
Definition: contains.h:76
Query graph global types.
Record manager global types.
byte rec_t
Definition: rem0types.h:41
void row_log_table_update(const rec_t *rec, dict_index_t *index, const ulint *offsets, const dtuple_t *old_pk, const dtuple_t *new_v_row, const dtuple_t *old_v_row) UNIV_COLD
Logs an update operation to a table that is being rebuilt.
Definition: row0log.cc:997
static void row_log_abort_sec(dict_index_t *index)
Free the row log for an index on which online creation was aborted.
dberr_t row_log_apply(const trx_t *trx, dict_index_t *index, struct TABLE *table, Alter_stage *stage)
Apply the row log to the index upon completing index creation.
Definition: row0log.cc:3845
trx_id_t row_log_get_max_trx(dict_index_t *index)
Get the latest transaction ID that has invoked row_log_online_op() during online creation.
Definition: row0log.cc:3205
void row_log_table_blob_alloc(dict_index_t *index, page_no_t page_no) UNIV_COLD
Notes that a BLOB is being allocated during online ALTER TABLE.
Definition: row0log.cc:1319
void row_log_table_insert(const rec_t *rec, const dtuple_t *ventry, dict_index_t *index, const ulint *offsets) UNIV_COLD
Logs an insert to a table that is being rebuilt.
Definition: row0log.cc:1266
const dtuple_t * row_log_table_get_pk(const rec_t *rec, dict_index_t *index, const ulint *offsets, byte *sys, mem_heap_t **heap) UNIV_COLD
Constructs the old PRIMARY KEY and DB_TRX_ID,DB_ROLL_PTR of a table that is being rebuilt.
Definition: row0log.cc:1100
void row_log_online_op(dict_index_t *index, const dtuple_t *tuple, trx_id_t trx_id) UNIV_COLD
Logs an operation to a secondary index that is (or was) being created.
Definition: row0log.cc:284
void row_log_table_blob_free(dict_index_t *index, page_no_t page_no) UNIV_COLD
Notes that a BLOB is being freed during online ALTER TABLE.
Definition: row0log.cc:1278
static bool row_log_online_op_try(dict_index_t *index, const dtuple_t *tuple, trx_id_t trx_id)
Try to log an operation to a secondary index that is (or was) being created.
bool row_log_col_is_indexed(const dict_index_t *index, ulint v_no)
Check whether a virtual column is indexed in the new table being created during alter table.
Definition: row0log.cc:525
void row_log_free(row_log_t *&log)
Free the row log for an index that was being created online.
Definition: row0log.cc:3190
dberr_t row_log_table_apply(que_thr_t *thr, dict_table_t *old_table, struct TABLE *table, Alter_stage *stage)
Apply the row_log_table log to a table upon completing rebuild.
Definition: row0log.cc:3100
ulint row_log_estimate_work(const dict_index_t *index)
Estimate how much work is to be done by the log apply phase of an ALTER TABLE for this index.
Definition: row0log.cc:2744
bool row_log_allocate(dict_index_t *index, dict_table_t *table, bool same_pk, const dtuple_t *add_cols, const ulint *col_map, const bool *col_has_compatible_charset_change, const char *path)
Allocate the row log for an index and flag the index for online creation.
Definition: row0log.cc:3137
dberr_t row_log_table_get_error(const dict_index_t *index)
Gets the error status of the online index rebuild log.
Definition: row0log.cc:415
void row_log_table_delete(const rec_t *rec, const dtuple_t *ventry, dict_index_t *index, const ulint *offsets, const byte *sys) UNIV_COLD
Logs a delete operation to a table that is being rebuilt.
Definition: row0log.cc:532
Modification log for online index creation and online table rebuild.
Row operation global types.
Definition: table.h:1456
Data structure for an index.
Definition: dict0mem.h:1069
Data structure for a database table.
Definition: dict0mem.h:1927
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:706
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:295
Definition: que0que.h:242
Buffer for logging modifications during online index creation.
Definition: row0log.cc:186
Definition: trx0trx.h:670
Transaction system global type definitions.
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:138
Version control for database, common definitions, and include files.
#define UNIV_COLD
Definition: univ.i:264
unsigned long int ulint
Definition: univ.i:403