MySQL 8.2.0
Source Code Documentation
row0log.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2011, 2023, 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 also distributed with certain software (including but not
10limited to OpenSSL) that is licensed under separate terms, as designated in a
11particular file or component or in included license documentation. The authors
12of MySQL hereby grant you an additional permission to link the program and
13your derivative works with the separately licensed software that they have
14included with MySQL.
15
16This program is distributed in the hope that it will be useful, but WITHOUT
17ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19for more details.
20
21You should have received a copy of the GNU General Public License along with
22this program; if not, write to the Free Software Foundation, Inc.,
2351 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24
25*****************************************************************************/
26
27#include "my_psi_config.h"
28
29/** @file include/row0log.h
30 Modification log for online index creation and online table rebuild
31
32 Created 2011-05-26 Marko Makela
33 *******************************************************/
34
35#ifndef row0log_h
36#define row0log_h
37
38#include "univ.i"
39
40#include "data0types.h"
41#include "dict0types.h"
42#include "mtr0types.h"
43#include "que0types.h"
44#include "rem0types.h"
45#include "row0types.h"
46#include "trx0types.h"
47
48class Alter_stage;
49
50/** Allocate the row log for an index and flag the index
51for online creation.
52@param[in] index Index.
53@param[in] table New table being rebuilt, or NULL when creating a secondary
54index.
55@param[in] same_pk Whether the definition of the PRIMARY KEY has remained the
56same.
57@param[in] add_cols Default values of added columns, or nullptr.
58@param[in] col_map Mapping of old column numbers to new ones, or nullptr if
59!table.
60@param[in] path Where to create temporary file.
61@retval true if success, false if not */
62bool row_log_allocate(dict_index_t *index, dict_table_t *table, bool same_pk,
63 const dtuple_t *add_cols, const ulint *col_map,
64 const char *path);
65
66/** Free the row log for an index that was being created online. */
67void row_log_free(row_log_t *&log); /*!< in,own: row log */
68
69#ifndef UNIV_HOTBACKUP
70/** Free the row log for an index on which online creation was aborted. */
71static inline void row_log_abort_sec(
72 dict_index_t *index); /*!< in/out: index (x-latched) */
73
74/** Try to log an operation to a secondary index that is (or was) being created.
75@param[in,out] index Index, S- or X-latched.
76@param[in] tuple Index tuple.
77@param[in] trx_id Transaction ID for insert, or 0 for delete.
78@retval true if the operation was logged or can be ignored
79@retval false if online index creation is not taking place */
80[[nodiscard]] static inline bool row_log_online_op_try(dict_index_t *index,
81 const dtuple_t *tuple,
82 trx_id_t trx_id);
83#endif /* !UNIV_HOTBACKUP */
84/** Logs an operation to a secondary index that is (or was) being created. */
86 dict_index_t *index, /*!< in/out: index, S or X latched */
87 const dtuple_t *tuple, /*!< in: index tuple */
88 trx_id_t trx_id) /*!< in: transaction ID for insert,
89 or 0 for delete */
91
92/** Gets the error status of the online index rebuild log.
93 @return DB_SUCCESS or error code */
95 const dict_index_t *index); /*!< in: clustered index of a table
96 that is being rebuilt online */
97
98/** Check whether a virtual column is indexed in the new table being
99created during alter table
100@param[in] index cluster index
101@param[in] v_no virtual column number
102@return true if it is indexed, else false */
103bool row_log_col_is_indexed(const dict_index_t *index, ulint v_no);
104
105/** Logs a delete operation to a table that is being rebuilt.
106 This will be merged in row_log_table_apply_delete(). */
108 const rec_t *rec, /*!< in: clustered index leaf page record,
109 page X-latched */
110 const dtuple_t *ventry, /*!< in: dtuple holding virtual column info */
111 dict_index_t *index, /*!< in/out: clustered index, S-latched
112 or X-latched */
113 const ulint *offsets, /*!< in: rec_get_offsets(rec,index) */
114 const byte *sys) /*!< in: DB_TRX_ID,DB_ROLL_PTR that should
115 be logged, or NULL to use those in rec */
116 UNIV_COLD;
117
118/** Logs an update operation to a table that is being rebuilt.
119 This will be merged in row_log_table_apply_update(). */
121 const rec_t *rec, /*!< in: clustered index leaf page record,
122 page X-latched */
123 dict_index_t *index, /*!< in/out: clustered index, S-latched
124 or X-latched */
125 const ulint *offsets, /*!< in: rec_get_offsets(rec,index) */
126 const dtuple_t *old_pk, /*!< in: row_log_table_get_pk()
127 before the update */
128 const dtuple_t *new_v_row, /*!< in: dtuple contains the new virtual
129 columns */
130 const dtuple_t *old_v_row) /*!< in: dtuple contains the old virtual
131 columns */
132 UNIV_COLD;
133
134/** Constructs the old PRIMARY KEY and DB_TRX_ID,DB_ROLL_PTR
135 of a table that is being rebuilt.
136 @return tuple of PRIMARY KEY,DB_TRX_ID,DB_ROLL_PTR in the rebuilt table,
137 or NULL if the PRIMARY KEY definition does not change */
138[[nodiscard]] const dtuple_t *row_log_table_get_pk(
139 const rec_t *rec, /*!< in: clustered index leaf page record,
140 page X-latched */
141 dict_index_t *index, /*!< in/out: clustered index, S-latched
142 or X-latched */
143 const ulint *offsets, /*!< in: rec_get_offsets(rec,index),
144 or NULL */
145 byte *sys, /*!< out: DB_TRX_ID,DB_ROLL_PTR for
146 row_log_table_delete(), or NULL */
147 mem_heap_t **heap) /*!< in/out: memory heap where allocated */
148 UNIV_COLD;
149
150/** Logs an insert to a table that is being rebuilt.
151 This will be merged in row_log_table_apply_insert(). */
153 const rec_t *rec, /*!< in: clustered index leaf page record,
154 page X-latched */
155 const dtuple_t *ventry, /*!< in: dtuple holding virtual column info */
156 dict_index_t *index, /*!< in/out: clustered index, S-latched
157 or X-latched */
158 const ulint *offsets) /*!< in: rec_get_offsets(rec,index) */
159 UNIV_COLD;
160/** Notes that a BLOB is being freed during online ALTER TABLE. */
162 dict_index_t *index, /*!< in/out: clustered index, X-latched */
163 page_no_t page_no) /*!< in: starting page number of the BLOB */
164 UNIV_COLD;
165/** Notes that a BLOB is being allocated during online ALTER TABLE. */
167 dict_index_t *index, /*!< in/out: clustered index, X-latched */
168 page_no_t page_no) /*!< in: starting page number of the BLOB */
169 UNIV_COLD;
170
171/** Apply the row_log_table log to a table upon completing rebuild.
172@param[in] thr query graph
173@param[in] old_table old table
174@param[in,out] table MySQL table (for reporting duplicates)
175@param[in,out] stage performance schema accounting object, used by
176ALTER TABLE. stage->begin_phase_log_table() will be called initially and then
177stage->inc() will be called for each block of log that is applied.
178@return DB_SUCCESS, or error code on failure */
179[[nodiscard]] dberr_t row_log_table_apply(que_thr_t *thr,
180 dict_table_t *old_table,
181 struct TABLE *table,
182 Alter_stage *stage);
183
184/** Get the latest transaction ID that has invoked row_log_online_op()
185 during online creation.
186 @return latest transaction ID, or 0 if nothing was logged */
187[[nodiscard]] trx_id_t row_log_get_max_trx(
188 dict_index_t *index); /*!< in: index, must be locked */
189
190/** Apply the row log to the index upon completing index creation.
191@param[in] trx transaction (for checking if the operation was
192interrupted)
193@param[in,out] index secondary index
194@param[in,out] table MySQL table (for reporting duplicates)
195@param[in,out] stage performance schema accounting object, used by
196ALTER TABLE. stage->begin_phase_log_index() will be called initially and then
197stage->inc() will be called for each block of log that is applied.
198@return DB_SUCCESS, or error code on failure */
199[[nodiscard]] dberr_t row_log_apply(const trx_t *trx, dict_index_t *index,
200 struct TABLE *table, Alter_stage *stage);
201
202#ifdef HAVE_PSI_STAGE_INTERFACE
203/** Estimate how much work is to be done by the log apply phase
204of an ALTER TABLE for this index.
205@param[in] index index whose log to assess
206@return work to be done by log-apply in abstract units
207*/
209#endif /* HAVE_PSI_STAGE_INTERFACE */
210
211#include "row0log.ic"
212
213#endif /* row0log.h */
uint32_t page_no_t
Page number.
Definition: api0api.h:48
Class used to report ALTER TABLE progress via performance_schema.
Definition: ut0stage.h:80
Some type definitions.
dberr_t
Definition: db0err.h:38
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:148
static PFS_engine_table_share_proxy table
Definition: pfs.cc:60
Query graph global types.
Record manager global types.
byte rec_t
Definition: rem0types.h:40
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:989
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:3797
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:3157
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:1311
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:1258
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:1092
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:277
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:1270
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:518
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:3092
void row_log_free(row_log_t *&log)
Free the row log for an index that was being created online.
Definition: row0log.cc:3142
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:3055
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:2699
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:408
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:525
Modification log for online index creation and online table rebuild.
Row operation global types.
Definition: table.h:1396
Data structure for an index.
Definition: dict0mem.h:1045
Data structure for a database table.
Definition: dict0mem.h:1908
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:681
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:301
Definition: que0que.h:241
Buffer for logging modifications during online index creation.
Definition: row0log.cc:183
Definition: trx0trx.h:683
Transaction system global type definitions.
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:137
Version control for database, common definitions, and include files.
#define UNIV_COLD
Definition: univ.i:266
unsigned long int ulint
Definition: univ.i:405