1 /***************************************************************************** 2 3 Copyright (c) 1997, 2016, Oracle and/or its affiliates. All Rights Reserved. 4 Copyright (c) 2017, 2019, MariaDB Corporation. 5 6 This program is free software; you can redistribute it and/or modify it under 7 the terms of the GNU General Public License as published by the Free Software 8 Foundation; version 2 of the License. 9 10 This program is distributed in the hope that it will be useful, but WITHOUT 11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 12 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License along with 15 this program; if not, write to the Free Software Foundation, Inc., 16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335 USA 17 18 *****************************************************************************/ 19 20 /**************************************************//** 21 @file include/row0purge.h 22 Purge obsolete records 23 24 Created 3/14/1997 Heikki Tuuri 25 *******************************************************/ 26 27 #ifndef row0purge_h 28 #define row0purge_h 29 30 #include "que0types.h" 31 #include "btr0types.h" 32 #include "btr0pcur.h" 33 #include "trx0types.h" 34 #include "row0types.h" 35 #include "ut0vec.h" 36 #include "row0mysql.h" 37 38 /** Determines if it is possible to remove a secondary index entry. 39 Removal is possible if the secondary index entry does not refer to any 40 not delete marked version of a clustered index record where DB_TRX_ID 41 is newer than the purge view. 42 43 NOTE: This function should only be called by the purge thread, only 44 while holding a latch on the leaf page of the secondary index entry 45 (or keeping the buffer pool watch on the page). It is possible that 46 this function first returns true and then false, if a user transaction 47 inserts a record that the secondary index entry would refer to. 48 However, in that case, the user transaction would also re-insert the 49 secondary index entry after purge has removed it and released the leaf 50 page latch. 51 @param[in,out] node row purge node 52 @param[in] index secondary index 53 @param[in] entry secondary index entry 54 @param[in,out] sec_pcur secondary index cursor or NULL 55 if it is called for purge buffering 56 operation. 57 @param[in,out] sec_mtr mini-transaction which holds 58 secondary index entry or NULL if it is 59 called for purge buffering operation. 60 @param[in] is_tree true=pessimistic purge, 61 false=optimistic (leaf-page only) 62 @return true if the secondary index record can be purged */ 63 bool 64 row_purge_poss_sec( 65 purge_node_t* node, 66 dict_index_t* index, 67 const dtuple_t* entry, 68 btr_pcur_t* sec_pcur=NULL, 69 mtr_t* sec_mtr=NULL, 70 bool is_tree=false); 71 72 /*************************************************************** 73 Does the purge operation for a single undo log record. This is a high-level 74 function used in an SQL execution graph. 75 @return query thread to run next or NULL */ 76 que_thr_t* 77 row_purge_step( 78 /*===========*/ 79 que_thr_t* thr) /*!< in: query thread */ 80 MY_ATTRIBUTE((nonnull, warn_unused_result)); 81 82 /* Purge node structure */ 83 84 struct purge_node_t{ 85 que_common_t common; /*!< node type: QUE_NODE_PURGE */ 86 /*----------------------*/ 87 /* Local storage for this graph node */ 88 roll_ptr_t roll_ptr;/* roll pointer to undo log record */ 89 ib_vector_t* undo_recs;/*!< Undo recs to purge */ 90 91 undo_no_t undo_no;/*!< undo number of the record */ 92 93 ulint rec_type;/*!< undo log record type: TRX_UNDO_INSERT_REC, 94 ... */ 95 private: 96 /** latest unavailable table ID (do not bother looking up again) */ 97 table_id_t unavailable_table_id; 98 /** the latest modification of the table definition identified by 99 unavailable_table_id, or TRX_ID_MAX */ 100 trx_id_t def_trx_id; 101 public: 102 dict_table_t* table; /*!< table where purge is done */ 103 104 ulint cmpl_info;/* compiler analysis info of an update */ 105 106 upd_t* update; /*!< update vector for a clustered index 107 record */ 108 const dtuple_t* ref; /*!< NULL, or row reference to the next row to 109 handle */ 110 dtuple_t* row; /*!< NULL, or a copy (also fields copied to 111 heap) of the indexed fields of the row to 112 handle */ 113 dict_index_t* index; /*!< NULL, or the next index whose record should 114 be handled */ 115 mem_heap_t* heap; /*!< memory heap used as auxiliary storage for 116 row; this must be emptied after a successful 117 purge of a row */ 118 ibool found_clust;/*!< whether the clustered index record 119 determined by ref was found in the clustered 120 index, and we were able to position pcur on 121 it */ 122 btr_pcur_t pcur; /*!< persistent cursor used in searching the 123 clustered index record */ 124 #ifdef UNIV_DEBUG 125 /** whether the operation is in progress */ 126 bool in_progress; 127 #endif 128 trx_id_t trx_id; /*!< trx id for this purging record */ 129 130 /** Virtual column information about opening of MariaDB table. 131 It resets after processing each undo log record. */ 132 purge_vcol_info_t vcol_info; 133 134 /** Constructor */ purge_node_tpurge_node_t135 explicit purge_node_t(que_thr_t* parent) : 136 common(QUE_NODE_PURGE, parent), 137 undo_recs(NULL), 138 unavailable_table_id(0), 139 heap(mem_heap_create(256)), 140 #ifdef UNIV_DEBUG 141 in_progress(false), 142 #endif 143 vcol_info() 144 {} 145 146 #ifdef UNIV_DEBUG 147 /***********************************************************//** 148 Validate the persisent cursor. The purge node has two references 149 to the clustered index record - one via the ref member, and the 150 other via the persistent cursor. These two references must match 151 each other if the found_clust flag is set. 152 @return true if the persistent cursor is consistent with 153 the ref member.*/ 154 bool validate_pcur(); 155 #endif 156 157 /** Whether purge failed to open the maria table for virtual column 158 computation. 159 @return true if the table failed to open. */ vcol_op_failedpurge_node_t160 bool vcol_op_failed() const { return !vcol_info.validate(); } 161 162 /** Determine if a table should be skipped in purge. 163 @param[in] table_id table identifier 164 @return whether to skip the table lookup and processing */ is_skippedpurge_node_t165 bool is_skipped(table_id_t id) const 166 { 167 return id == unavailable_table_id && trx_id <= def_trx_id; 168 } 169 170 /** Remember that a table should be skipped in purge. 171 @param[in] id table identifier 172 @param[in] limit last transaction for which to skip */ skippurge_node_t173 void skip(table_id_t id, trx_id_t limit) 174 { 175 DBUG_ASSERT(limit >= trx_id); 176 unavailable_table_id = id; 177 def_trx_id = limit; 178 } 179 180 /** Start processing an undo log record. */ startpurge_node_t181 void start() 182 { 183 ut_ad(in_progress); 184 DBUG_ASSERT(common.type == QUE_NODE_PURGE); 185 186 table = NULL; 187 row = NULL; 188 ref = NULL; 189 index = NULL; 190 update = NULL; 191 found_clust = FALSE; 192 rec_type = ULINT_UNDEFINED; 193 cmpl_info = ULINT_UNDEFINED; 194 } 195 196 /** Reset the state at end 197 @return the query graph parent */ endpurge_node_t198 que_node_t* end() 199 { 200 DBUG_ASSERT(common.type == QUE_NODE_PURGE); 201 undo_recs = NULL; 202 ut_d(in_progress = false); 203 vcol_info.reset(); 204 mem_heap_empty(heap); 205 return common.parent; 206 } 207 }; 208 209 #endif 210