MySQL 8.4.2
Source Code Documentation
row0log.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2011, 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#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] path Where to create temporary file.
62@retval true if success, false if not */
63bool row_log_allocate(dict_index_t *index, dict_table_t *table, bool same_pk,
64 const dtuple_t *add_cols, const ulint *col_map,
65 const char *path);
66
67/** Free the row log for an index that was being created online. */
68void row_log_free(row_log_t *&log); /*!< in,own: row log */
69
70#ifndef UNIV_HOTBACKUP
71/** Free the row log for an index on which online creation was aborted. */
72static inline void row_log_abort_sec(
73 dict_index_t *index); /*!< in/out: index (x-latched) */
74
75/** Try to log an operation to a secondary index that is (or was) being created.
76@param[in,out] index Index, S- or X-latched.
77@param[in] tuple Index tuple.
78@param[in] trx_id Transaction ID for insert, or 0 for delete.
79@retval true if the operation was logged or can be ignored
80@retval false if online index creation is not taking place */
81[[nodiscard]] static inline bool row_log_online_op_try(dict_index_t *index,
82 const dtuple_t *tuple,
83 trx_id_t trx_id);
84#endif /* !UNIV_HOTBACKUP */
85/** Logs an operation to a secondary index that is (or was) being created. */
87 dict_index_t *index, /*!< in/out: index, S or X latched */
88 const dtuple_t *tuple, /*!< in: index tuple */
89 trx_id_t trx_id) /*!< in: transaction ID for insert,
90 or 0 for delete */
92
93/** Gets the error status of the online index rebuild log.
94 @return DB_SUCCESS or error code */
96 const dict_index_t *index); /*!< in: clustered index of a table
97 that is being rebuilt online */
98
99/** Check whether a virtual column is indexed in the new table being
100created during alter table
101@param[in] index cluster index
102@param[in] v_no virtual column number
103@return true if it is indexed, else false */
104bool row_log_col_is_indexed(const dict_index_t *index, ulint v_no);
105
106/** Logs a delete operation to a table that is being rebuilt.
107 This will be merged in row_log_table_apply_delete(). */
109 const rec_t *rec, /*!< in: clustered index leaf page record,
110 page X-latched */
111 const dtuple_t *ventry, /*!< in: dtuple holding virtual column info */
112 dict_index_t *index, /*!< in/out: clustered index, S-latched
113 or X-latched */
114 const ulint *offsets, /*!< in: rec_get_offsets(rec,index) */
115 const byte *sys) /*!< in: DB_TRX_ID,DB_ROLL_PTR that should
116 be logged, or NULL to use those in rec */
117 UNIV_COLD;
118
119/** Logs an update operation to a table that is being rebuilt.
120 This will be merged in row_log_table_apply_update(). */
122 const rec_t *rec, /*!< in: clustered index leaf page record,
123 page X-latched */
124 dict_index_t *index, /*!< in/out: clustered index, S-latched
125 or X-latched */
126 const ulint *offsets, /*!< in: rec_get_offsets(rec,index) */
127 const dtuple_t *old_pk, /*!< in: row_log_table_get_pk()
128 before the update */
129 const dtuple_t *new_v_row, /*!< in: dtuple contains the new virtual
130 columns */
131 const dtuple_t *old_v_row) /*!< in: dtuple contains the old virtual
132 columns */
133 UNIV_COLD;
134
135/** Constructs the old PRIMARY KEY and DB_TRX_ID,DB_ROLL_PTR
136 of a table that is being rebuilt.
137 @return tuple of PRIMARY KEY,DB_TRX_ID,DB_ROLL_PTR in the rebuilt table,
138 or NULL if the PRIMARY KEY definition does not change */
139[[nodiscard]] const dtuple_t *row_log_table_get_pk(
140 const rec_t *rec, /*!< in: clustered index leaf page record,
141 page X-latched */
142 dict_index_t *index, /*!< in/out: clustered index, S-latched
143 or X-latched */
144 const ulint *offsets, /*!< in: rec_get_offsets(rec,index),
145 or NULL */
146 byte *sys, /*!< out: DB_TRX_ID,DB_ROLL_PTR for
147 row_log_table_delete(), or NULL */
148 mem_heap_t **heap) /*!< in/out: memory heap where allocated */
149 UNIV_COLD;
150
151/** Logs an insert to a table that is being rebuilt.
152 This will be merged in row_log_table_apply_insert(). */
154 const rec_t *rec, /*!< in: clustered index leaf page record,
155 page X-latched */
156 const dtuple_t *ventry, /*!< in: dtuple holding virtual column info */
157 dict_index_t *index, /*!< in/out: clustered index, S-latched
158 or X-latched */
159 const ulint *offsets) /*!< in: rec_get_offsets(rec,index) */
160 UNIV_COLD;
161/** Notes that a BLOB is being freed during online ALTER TABLE. */
163 dict_index_t *index, /*!< in/out: clustered index, X-latched */
164 page_no_t page_no) /*!< in: starting page number of the BLOB */
165 UNIV_COLD;
166/** Notes that a BLOB is being allocated during online ALTER TABLE. */
168 dict_index_t *index, /*!< in/out: clustered index, X-latched */
169 page_no_t page_no) /*!< in: starting page number of the BLOB */
170 UNIV_COLD;
171
172/** Apply the row_log_table log to a table upon completing rebuild.
173@param[in] thr query graph
174@param[in] old_table old table
175@param[in,out] table MySQL table (for reporting duplicates)
176@param[in,out] stage performance schema accounting object, used by
177ALTER TABLE. stage->begin_phase_log_table() will be called initially and then
178stage->inc() will be called for each block of log that is applied.
179@return DB_SUCCESS, or error code on failure */
180[[nodiscard]] dberr_t row_log_table_apply(que_thr_t *thr,
181 dict_table_t *old_table,
182 struct TABLE *table,
183 Alter_stage *stage);
184
185/** Get the latest transaction ID that has invoked row_log_online_op()
186 during online creation.
187 @return latest transaction ID, or 0 if nothing was logged */
188[[nodiscard]] trx_id_t row_log_get_max_trx(
189 dict_index_t *index); /*!< in: index, must be locked */
190
191/** Apply the row log to the index upon completing index creation.
192@param[in] trx transaction (for checking if the operation was
193interrupted)
194@param[in,out] index secondary index
195@param[in,out] table MySQL table (for reporting duplicates)
196@param[in,out] stage performance schema accounting object, used by
197ALTER TABLE. stage->begin_phase_log_index() will be called initially and then
198stage->inc() will be called for each block of log that is applied.
199@return DB_SUCCESS, or error code on failure */
200[[nodiscard]] dberr_t row_log_apply(const trx_t *trx, dict_index_t *index,
201 struct TABLE *table, Alter_stage *stage);
202
203#ifdef HAVE_PSI_STAGE_INTERFACE
204/** Estimate how much work is to be done by the log apply phase
205of an ALTER TABLE for this index.
206@param[in] index index whose log to assess
207@return work to be done by log-apply in abstract units
208*/
210#endif /* HAVE_PSI_STAGE_INTERFACE */
211
212#include "row0log.ic"
213
214#endif /* row0log.h */
uint32_t page_no_t
Page number.
Definition: api0api.h:45
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:149
static PFS_engine_table_share_proxy table
Definition: pfs.cc:61
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:990
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:3798
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:3158
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:1312
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:1259
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:1093
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:278
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:1271
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:519
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 char *path)
Allocate the row log for an index and flag the index for online creation.
Definition: row0log.cc:3093
void row_log_free(row_log_t *&log)
Free the row log for an index that was being created online.
Definition: row0log.cc:3143
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:3056
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:2700
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:409
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:526
Modification log for online index creation and online table rebuild.
Row operation global types.
Definition: table.h:1406
Data structure for an index.
Definition: dict0mem.h:1046
Data structure for a database table.
Definition: dict0mem.h:1909
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:682
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:302
Definition: que0que.h:242
Buffer for logging modifications during online index creation.
Definition: row0log.cc:184
Definition: trx0trx.h:684
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:267
unsigned long int ulint
Definition: univ.i:406