1 /***************************************************************************** 2 3 Copyright (c) 1997, 2016, Oracle and/or its affiliates. All Rights Reserved. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License, version 2.0, 7 as published by the Free Software Foundation. 8 9 This program is also distributed 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 included with MySQL. 15 16 This program is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License, version 2.0, 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 Street, Suite 500, Boston, MA 02110-1335 USA 24 25 *****************************************************************************/ 26 27 /**************************************************//** 28 @file include/read0read.h 29 Cursor read 30 31 Created 2/16/1997 Heikki Tuuri 32 *******************************************************/ 33 34 #ifndef read0read_h 35 #define read0read_h 36 37 #include "univ.i" 38 39 40 #include "ut0byte.h" 41 #include "ut0lst.h" 42 #include "btr0types.h" 43 #include "trx0trx.h" 44 #include "trx0sys.h" 45 #include "read0types.h" 46 47 /*********************************************************************//** 48 Opens a read view where exactly the transactions serialized before this 49 point in time are seen in the view. 50 @return own: read view struct */ 51 UNIV_INTERN 52 read_view_t* 53 read_view_open_now( 54 /*===============*/ 55 trx_id_t cr_trx_id, /*!< in: trx_id of creating 56 transaction, or 0 used in purge */ 57 read_view_t*& view); /*!< in,out: pre-allocated view array or 58 NULL if a new one needs to be created */ 59 60 /*********************************************************************//** 61 Clones a read view object. This function will allocate space for two read 62 views contiguously, one identical in size and content as @param view (starting 63 at returned pointer) and another view immediately following the trx_ids array. 64 The second view will have space for an extra trx_id_t element. 65 @return read view struct */ 66 UNIV_INTERN 67 read_view_t* 68 read_view_clone( 69 /*============*/ 70 const read_view_t* view, /*!< in: view to clone */ 71 read_view_t*& prebuilt_clone);/*!< in,out: prebuilt view or 72 NULL */ 73 /*********************************************************************//** 74 Insert the view in the proper order into the trx_sys->view_list. The 75 read view list is ordered by read_view_t::low_limit_no in descending order. */ 76 UNIV_INTERN 77 void 78 read_view_add( 79 /*==========*/ 80 read_view_t* view); /*!< in: view to add to */ 81 /*********************************************************************//** 82 Makes a copy of the oldest existing read view, or opens a new. The view 83 must be closed with ..._close. 84 @return own: read view struct */ 85 UNIV_INTERN 86 read_view_t* 87 read_view_purge_open( 88 /*=================*/ 89 read_view_t*& clone_view, /*!< in,out: pre-allocated view that 90 will be used to clone the oldest view if 91 exists */ 92 read_view_t*& view); /*!< in,out: pre-allocated view array or 93 NULL if a new one needs to be created */ 94 /*********************************************************************//** 95 Remove a read view from the trx_sys->view_list. */ 96 UNIV_INLINE 97 void 98 read_view_remove( 99 /*=============*/ 100 read_view_t* view, /*!< in: read view, can be 0 */ 101 bool own_mutex); /*!< in: true if caller owns the 102 trx_sys_t::mutex */ 103 /*********************************************************************//** 104 Frees memory allocated by a read view. */ 105 UNIV_INTERN 106 void 107 read_view_free( 108 /*===========*/ 109 read_view_t*& view); /*< in,out: read view */ 110 /*********************************************************************//** 111 Closes a consistent read view for MySQL. This function is called at an SQL 112 statement end if the trx isolation level is <= TRX_ISO_READ_COMMITTED. */ 113 UNIV_INTERN 114 void 115 read_view_close_for_mysql( 116 /*======================*/ 117 trx_t* trx); /*!< in: trx which has a read view */ 118 /*********************************************************************//** 119 Checks if a read view sees the specified transaction. 120 @return true if sees */ 121 UNIV_INLINE 122 bool 123 read_view_sees_trx_id( 124 /*==================*/ 125 const read_view_t* view, /*!< in: read view */ 126 trx_id_t trx_id) /*!< in: trx id */ 127 MY_ATTRIBUTE((nonnull, warn_unused_result)); 128 /*********************************************************************//** 129 Prints a read view to file. */ 130 UNIV_INTERN 131 void 132 read_view_print( 133 /*============*/ 134 FILE* file, /*!< in: file to print to */ 135 const read_view_t* view); /*!< in: read view */ 136 /*********************************************************************//** 137 Create a consistent cursor view for mysql to be used in cursors. In this 138 consistent read view modifications done by the creating transaction or future 139 transactions are not visible. */ 140 UNIV_INTERN 141 cursor_view_t* 142 read_cursor_view_create_for_mysql( 143 /*==============================*/ 144 trx_t* cr_trx);/*!< in: trx where cursor view is created */ 145 /*********************************************************************//** 146 Close a given consistent cursor view for mysql and restore global read view 147 back to a transaction read view. */ 148 UNIV_INTERN 149 void 150 read_cursor_view_close_for_mysql( 151 /*=============================*/ 152 trx_t* trx, /*!< in: trx */ 153 cursor_view_t* curview); /*!< in: cursor view to be closed */ 154 /*********************************************************************//** 155 This function sets a given consistent cursor view to a transaction 156 read view if given consistent cursor view is not NULL. Otherwise, function 157 restores a global read view to a transaction read view. */ 158 UNIV_INTERN 159 void 160 read_cursor_set_for_mysql( 161 /*======================*/ 162 trx_t* trx, /*!< in: transaction where cursor is set */ 163 cursor_view_t* curview);/*!< in: consistent cursor view to be set */ 164 165 /** Read view lists the trx ids of those transactions for which a consistent 166 read should not see the modifications to the database. */ 167 168 struct read_view_t{ 169 ulint type; /*!< VIEW_NORMAL, VIEW_HIGH_GRANULARITY */ 170 undo_no_t undo_no;/*!< 0 or if type is 171 VIEW_HIGH_GRANULARITY 172 transaction undo_no when this high-granularity 173 consistent read view was created */ 174 trx_id_t low_limit_no; 175 /*!< The view does not need to see the undo 176 logs for transactions whose transaction number 177 is strictly smaller (<) than this value: they 178 can be removed in purge if not needed by other 179 views */ 180 trx_id_t low_limit_id; 181 /*!< The read should not see any transaction 182 with trx id >= this value. In other words, 183 this is the "high water mark". */ 184 trx_id_t up_limit_id; 185 /*!< The read should see all trx ids which 186 are strictly smaller (<) than this value. 187 In other words, 188 this is the "low water mark". */ 189 ulint n_descr; 190 /*!< Number of cells in the trx_ids array */ 191 ulint max_descr; 192 /*!< Maximum number of cells in the trx_ids 193 array */ 194 trx_id_t* descriptors; 195 /*!< Additional trx ids which the read should 196 not see: typically, these are the read-write 197 active transactions at the time when the read 198 is serialized, except the reading transaction 199 itself; the trx ids in this array are in a 200 ascending order. These trx_ids should be 201 between the "low" and "high" water marks, 202 that is, up_limit_id and low_limit_id. */ 203 trx_id_t creator_trx_id; 204 /*!< trx id of creating transaction, or 205 0 used in purge */ 206 UT_LIST_NODE_T(read_view_t) view_list; 207 /*!< List of read views in trx_sys */ 208 }; 209 210 /** Read view types @{ */ 211 #define VIEW_NORMAL 1 /*!< Normal consistent read view 212 where transaction does not see changes 213 made by active transactions except 214 creating transaction. */ 215 #define VIEW_HIGH_GRANULARITY 2 /*!< High-granularity read view where 216 transaction does not see changes 217 made by active transactions and own 218 changes after a point in time when this 219 read view was created. */ 220 /* @} */ 221 222 /** Implement InnoDB framework to support consistent read views in 223 cursors. This struct holds both heap where consistent read view 224 is allocated and pointer to a read view. */ 225 226 struct cursor_view_t{ 227 mem_heap_t* heap; 228 /*!< Memory heap for the cursor view */ 229 read_view_t* read_view; 230 /*!< Consistent read view of the cursor*/ 231 ulint n_mysql_tables_in_use; 232 /*!< number of Innobase tables used in the 233 processing of this cursor */ 234 }; 235 236 #ifndef UNIV_NONINL 237 #include "read0read.ic" 238 #endif 239 240 #endif 241