| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 2011, 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 |
#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 |
|
| 49 |
class Alter_stage; |
| 50 |
|
| 51 |
/** Allocate the row log for an index and flag the index |
| 52 |
for online creation. |
| 53 |
@param[in] index Index. |
| 54 |
@param[in] table New table being rebuilt, or NULL when creating a secondary |
| 55 |
index. |
| 56 |
@param[in] same_pk Whether the definition of the PRIMARY KEY has remained the |
| 57 |
same. |
| 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 */ |
| 63 |
bool 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. */ |
| 68 |
void 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. */ |
| 72 |
static 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. */ |
| 86 |
void row_log_online_op( |
| 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 */ |
| 91 |
UNIV_COLD; |
| 92 |
|
| 93 |
/** Gets the error status of the online index rebuild log. |
| 94 |
@return DB_SUCCESS or error code */ |
| 95 |
[[nodiscard]] dberr_t row_log_table_get_error( |
| 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 |
| 100 |
created 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 */ |
| 104 |
bool 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(). */ |
| 108 |
void row_log_table_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(). */ |
| 121 |
void row_log_table_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(). */ |
| 153 |
void row_log_table_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. */ |
| 162 |
void row_log_table_blob_free( |
| 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. */ |
| 167 |
void row_log_table_blob_alloc( |
| 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 |
| 177 |
ALTER TABLE. stage->begin_phase_log_table() will be called initially and then |
| 178 |
stage->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 |
| 193 |
interrupted) |
| 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 |
| 197 |
ALTER TABLE. stage->begin_phase_log_index() will be called initially and then |
| 198 |
stage->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 |
| 205 |
of 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 |
*/ |
| 209 |
ulint row_log_estimate_work(const dict_index_t *index); |
| 210 |
#endif /* HAVE_PSI_STAGE_INTERFACE */ |
| 211 |
|
| 212 |
#include "row0log.ic" |
| 213 |
|
| 214 |
#endif /* row0log.h */ |