MySQL  8.0.22
Source Code Documentation
row0log.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3 Copyright (c) 2011, 2018, Oracle and/or its affiliates. All Rights Reserved.
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 also distributed with certain software (including but not
10 limited to OpenSSL) that is licensed under separate terms, as designated in a
11 particular file or component or in included license documentation. The authors
12 of MySQL hereby grant you an additional permission to link the program and
13 your derivative works with the separately licensed software that they have
14 included with MySQL.
15 
16 This program is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
19 for more details.
20 
21 You should have received a copy of the GNU General Public License along with
22 this program; if not, write to the Free Software Foundation, Inc.,
23 51 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 
48 class ut_stage_alter_t;
49 
50 /** Allocate the row log for an index and flag the index
51  for online creation.
52  @retval true if success, false if not */
53 bool row_log_allocate(
54  dict_index_t *index, /*!< in/out: index */
55  dict_table_t *table, /*!< in/out: new table being rebuilt,
56  or NULL when creating a secondary index */
57  bool same_pk, /*!< in: whether the definition of the
58  PRIMARY KEY has remained the same */
59  const dtuple_t *add_cols,
60  /*!< in: default values of
61  added columns, or NULL */
62  const ulint *col_map, /*!< in: mapping of old column
63  numbers to new ones, or NULL if !table */
64  const char *path) /*!< in: where to create temporary file */
65  MY_ATTRIBUTE((warn_unused_result));
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 /** Free the row log for an index on which online creation was aborted. */
71 UNIV_INLINE
72 void row_log_abort_sec(dict_index_t *index); /*!< in/out: index (x-latched) */
73 
74 /** Try to log an operation to a secondary index that is
75  (or was) being created.
76  @retval true if the operation was logged or can be ignored
77  @retval false if online index creation is not taking place */
78 UNIV_INLINE
80  dict_index_t *index, /*!< in/out: index, S or X latched */
81  const dtuple_t *tuple, /*!< in: index tuple */
82  trx_id_t trx_id) /*!< in: transaction ID for insert,
83  or 0 for delete */
84  MY_ATTRIBUTE((warn_unused_result));
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 */
91  UNIV_COLD;
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  MY_ATTRIBUTE((warn_unused_result));
99 
100 /** Check whether a virtual column is indexed in the new table being
101 created during alter table
102 @param[in] index cluster index
103 @param[in] v_no virtual column number
104 @return true if it is indexed, else false */
105 bool row_log_col_is_indexed(const dict_index_t *index, ulint v_no);
106 
107 /** Logs a delete operation to a table that is being rebuilt.
108  This will be merged in row_log_table_apply_delete(). */
110  trx_t *trx, /*!< in: current transaction. */
111  const rec_t *rec, /*!< in: clustered index leaf page record,
112  page X-latched */
113  const dtuple_t *ventry, /*!< in: dtuple holding virtual column info */
114  dict_index_t *index, /*!< in/out: clustered index, S-latched
115  or X-latched */
116  const ulint *offsets, /*!< in: rec_get_offsets(rec,index) */
117  const byte *sys) /*!< in: DB_TRX_ID,DB_ROLL_PTR that should
118  be logged, or NULL to use those in rec */
119  UNIV_COLD;
120 
121 /** Logs an update operation to a table that is being rebuilt.
122  This will be merged in row_log_table_apply_update(). */
124  const rec_t *rec, /*!< in: clustered index leaf page record,
125  page X-latched */
126  dict_index_t *index, /*!< in/out: clustered index, S-latched
127  or X-latched */
128  const ulint *offsets, /*!< in: rec_get_offsets(rec,index) */
129  const dtuple_t *old_pk, /*!< in: row_log_table_get_pk()
130  before the update */
131  const dtuple_t *new_v_row, /*!< in: dtuple contains the new virtual
132  columns */
133  const dtuple_t *old_v_row) /*!< in: dtuple contains the old virtual
134  columns */
135  UNIV_COLD;
136 
137 /** Constructs the old PRIMARY KEY and DB_TRX_ID,DB_ROLL_PTR
138  of a table that is being rebuilt.
139  @return tuple of PRIMARY KEY,DB_TRX_ID,DB_ROLL_PTR in the rebuilt table,
140  or NULL if the PRIMARY KEY definition does not change */
142  trx_t *trx, /*!< in: the current transaction. */
143  const rec_t *rec, /*!< in: clustered index leaf page record,
144  page X-latched */
145  dict_index_t *index, /*!< in/out: clustered index, S-latched
146  or X-latched */
147  const ulint *offsets, /*!< in: rec_get_offsets(rec,index),
148  or NULL */
149  byte *sys, /*!< out: DB_TRX_ID,DB_ROLL_PTR for
150  row_log_table_delete(), or NULL */
151  mem_heap_t **heap) /*!< in/out: memory heap where allocated */
152  UNIV_COLD MY_ATTRIBUTE((warn_unused_result));
153 
154 /** Logs an insert to a table that is being rebuilt.
155  This will be merged in row_log_table_apply_insert(). */
157  const rec_t *rec, /*!< in: clustered index leaf page record,
158  page X-latched */
159  const dtuple_t *ventry, /*!< in: dtuple holding virtual column info */
160  dict_index_t *index, /*!< in/out: clustered index, S-latched
161  or X-latched */
162  const ulint *offsets) /*!< in: rec_get_offsets(rec,index) */
163  UNIV_COLD;
164 /** Notes that a BLOB is being freed during online ALTER TABLE. */
166  dict_index_t *index, /*!< in/out: clustered index, X-latched */
167  page_no_t page_no) /*!< in: starting page number of the BLOB */
168  UNIV_COLD;
169 /** Notes that a BLOB is being allocated during online ALTER TABLE. */
171  dict_index_t *index, /*!< in/out: clustered index, X-latched */
172  page_no_t page_no) /*!< in: starting page number of the BLOB */
173  UNIV_COLD;
174 
175 /** Apply the row_log_table log to a table upon completing rebuild.
176 @param[in] thr query graph
177 @param[in] old_table old table
178 @param[in,out] table MySQL table (for reporting duplicates)
179 @param[in,out] stage performance schema accounting object, used by
180 ALTER TABLE. stage->begin_phase_log_table() will be called initially and then
181 stage->inc() will be called for each block of log that is applied.
182 @return DB_SUCCESS, or error code on failure */
184  struct TABLE *table, ut_stage_alter_t *stage)
185  MY_ATTRIBUTE((warn_unused_result));
186 
187 /** Get the latest transaction ID that has invoked row_log_online_op()
188  during online creation.
189  @return latest transaction ID, or 0 if nothing was logged */
191  dict_index_t *index) /*!< in: index, must be locked */
192  MY_ATTRIBUTE((warn_unused_result));
193 
194 /** Apply the row log to the index upon completing index creation.
195 @param[in] trx transaction (for checking if the operation was
196 interrupted)
197 @param[in,out] index secondary index
198 @param[in,out] table MySQL table (for reporting duplicates)
199 @param[in,out] stage performance schema accounting object, used by
200 ALTER TABLE. stage->begin_phase_log_index() will be called initially and then
201 stage->inc() will be called for each block of log that is applied.
202 @return DB_SUCCESS, or error code on failure */
203 dberr_t row_log_apply(const trx_t *trx, dict_index_t *index,
204  struct TABLE *table, ut_stage_alter_t *stage)
205  MY_ATTRIBUTE((warn_unused_result));
206 
207 #ifdef HAVE_PSI_STAGE_INTERFACE
208 /** Estimate how much work is to be done by the log apply phase
209 of an ALTER TABLE for this index.
210 @param[in] index index whose log to assess
211 @return work to be done by log-apply in abstract units
212 */
213 ulint row_log_estimate_work(const dict_index_t *index);
214 #endif /* HAVE_PSI_STAGE_INTERFACE */
215 
216 #include "row0log.ic"
217 
218 #endif /* row0log.h */
Record manager global types.
const dtuple_t * row_log_table_get_pk(trx_t *trx, 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:1036
uint32 page_no_t
Page number.
Definition: api0api.h:57
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:3106
Buffer for logging modifications during online index creation.
Definition: row0log.cc:176
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:504
Definition: trx0trx.h:833
UNIV_INLINE void row_log_abort_sec(dict_index_t *index)
Free the row log for an index on which online creation was aborted.
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:939
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:262
Some type definitions.
void row_log_table_delete(trx_t *trx, 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:511
Data structure for a database table.
Definition: dict0mem.h:1532
void row_log_free(row_log_t *&log)
Free the row log for an index that was being created online.
Definition: row0log.cc:3090
The info structure stored at the beginning of a heap block.
Definition: mem0mem.h:349
Definition: table.h:1363
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:1202
Query graph global types.
Data dictionary global types.
UNIV_INLINE 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.
byte rec_t
Definition: rem0types.h:39
Structure for an SQL data tuple of fields (logical record)
Definition: data0data.h:711
dberr_t
Definition: db0err.h:38
static char * path
Definition: mysqldump.cc:131
Row operation global types.
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
Definition: que0que.h:251
Transaction system global type definitions.
dberr_t row_log_table_apply(que_thr_t *thr, dict_table_t *old_table, struct TABLE *table, ut_stage_alter_t *stage)
Apply the row_log_table log to a table upon completing rebuild.
Definition: row0log.cc:2988
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:2635
dberr_t row_log_apply(const trx_t *trx, dict_index_t *index, struct TABLE *table, ut_stage_alter_t *stage)
Apply the row log to the index upon completing index creation.
Definition: row0log.cc:3745
ib_id_t trx_id_t
Transaction identifier (DB_TRX_ID, DATA_TRX_ID)
Definition: trx0types.h:144
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:391
Class used to report ALTER TABLE progress via performance_schema.
Definition: ut0stage.h:77
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:3029
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:1214
unsigned char byte
Blob class.
Definition: common.h:159
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:1254
Mini-transaction buffer global types.
Data structure for an index.
Definition: dict0mem.h:886