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 79 bool row_log_online_op_try( 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. */ 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 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 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(). */ 109 void row_log_table_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(). */ 123 void row_log_table_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 */ 141 const dtuple_t *row_log_table_get_pk( 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(). */ 156 void row_log_table_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. */ 165 void row_log_table_blob_free( 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. */ 170 void row_log_table_blob_alloc( 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 */ 183 dberr_t row_log_table_apply(que_thr_t *thr, dict_table_t *old_table, 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 */ 190 trx_id_t row_log_get_max_trx( 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 */ 219