1 /* Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved. 2 3 This program is free software; you can redistribute it and/or modify 4 it under the terms of the GNU General Public License, version 2.0, 5 as published by the Free Software Foundation. 6 7 This program is also distributed with certain software (including 8 but not limited to OpenSSL) that is licensed under separate terms, 9 as designated in a particular file or component or in included license 10 documentation. The authors of MySQL hereby grant you an additional 11 permission to link the program and your derivative works with the 12 separately licensed software that they have included with MySQL. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License, version 2.0, for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 22 23 #ifndef TABLE_EVENTS_TRANSACTIONS_H 24 #define TABLE_EVENTS_TRANSACTIONS_H 25 26 /** 27 @file storage/perfschema/table_events_transactions.h 28 Table EVENTS_TRANSACTIONS_xxx (declarations). 29 */ 30 31 #include <sys/types.h> 32 33 #include "my_base.h" 34 #include "my_inttypes.h" 35 #include "sql/rpl_gtid.h" 36 #include "storage/perfschema/pfs_column_types.h" 37 #include "storage/perfschema/pfs_engine_table.h" 38 #include "storage/perfschema/pfs_events_transactions.h" 39 #include "storage/perfschema/table_helper.h" 40 41 class Field; 42 class Plugin_table; 43 struct PFS_events; 44 struct PFS_thread; 45 struct TABLE; 46 struct THR_LOCK; 47 48 /** 49 @addtogroup performance_schema_tables 50 @{ 51 */ 52 53 class PFS_index_events_transactions : public PFS_engine_index { 54 public: PFS_index_events_transactions()55 PFS_index_events_transactions() 56 : PFS_engine_index(&m_key_1, &m_key_2), 57 m_key_1("THREAD_ID"), 58 m_key_2("EVENT_ID") {} 59 ~PFS_index_events_transactions()60 ~PFS_index_events_transactions() {} 61 62 bool match(PFS_thread *pfs); 63 bool match(PFS_events *pfs); 64 65 private: 66 PFS_key_thread_id m_key_1; 67 PFS_key_event_id m_key_2; 68 }; 69 70 /** A row of table_events_transactions_common. */ 71 struct row_events_transactions { 72 /** Column THREAD_ID. */ 73 ulonglong m_thread_internal_id; 74 /** Column EVENT_ID. */ 75 ulonglong m_event_id; 76 /** Column END_EVENT_ID. */ 77 ulonglong m_end_event_id; 78 /** Column NESTING_EVENT_ID. */ 79 ulonglong m_nesting_event_id; 80 /** Column NESTING_EVENT_TYPE. */ 81 enum_event_type m_nesting_event_type; 82 /** Column EVENT_NAME. */ 83 const char *m_name; 84 /** Length in bytes of @c m_name. */ 85 uint m_name_length; 86 /** Column TIMER_START. */ 87 ulonglong m_timer_start; 88 /** Column TIMER_END. */ 89 ulonglong m_timer_end; 90 /** Column TIMER_WAIT. */ 91 ulonglong m_timer_wait; 92 /** Column SOURCE. */ 93 char m_source[COL_SOURCE_SIZE]; 94 /** Length in bytes of @c m_source. */ 95 uint m_source_length; 96 /** InnoDB transaction id. */ 97 ulonglong m_trxid; 98 /** Transaction state. */ 99 enum_transaction_state m_state; 100 /** Global Transaction ID. */ 101 char m_gtid[Gtid_specification::MAX_TEXT_LENGTH + 1]; 102 /** GTID length in bytes*/ 103 int m_gtid_length; 104 /** XA transaction ID. */ 105 PSI_xid m_xid; 106 /** XA transaction state. */ 107 enum_xa_transaction_state m_xa_state; 108 /** True if XA transaction. */ 109 bool m_xa; 110 /** True if autocommit transaction. */ 111 bool m_autocommit; 112 /** Isolation level. */ 113 enum_isolation_level m_isolation_level; 114 /** True if read-only, read-write otherwise. */ 115 bool m_read_only; 116 /** Column NUMBER_OF_SAVEPOINTS. */ 117 ulonglong m_savepoint_count; 118 /** Column NUMBER_OF_ROLLBACK_TO_SAVEPOINT. */ 119 ulonglong m_rollback_to_savepoint_count; 120 /** Column NUMBER_OF_RELEASE_SAVEPOINT. */ 121 ulonglong m_release_savepoint_count; 122 }; 123 124 /** 125 Position of a cursor on PERFORMANCE_SCHEMA.EVENTS_TRANSACTIONS_HISTORY. 126 Index 1 on thread (0 based) 127 Index 2 on transaction event record in thread history (0 based) 128 */ 129 struct pos_events_transactions_history : public PFS_double_index { pos_events_transactions_historypos_events_transactions_history130 pos_events_transactions_history() : PFS_double_index(0, 0) {} 131 resetpos_events_transactions_history132 inline void reset(void) { 133 m_index_1 = 0; 134 m_index_2 = 0; 135 } 136 next_threadpos_events_transactions_history137 inline void next_thread(void) { 138 m_index_1++; 139 m_index_2 = 0; 140 } 141 }; 142 143 /** 144 Adapter, for table sharing the structure of 145 PERFORMANCE_SCHEMA.EVENTS_TRANSACTIONS_CURRENT. 146 */ 147 class table_events_transactions_common : public PFS_engine_table { 148 protected: 149 virtual int read_row_values(TABLE *table, unsigned char *buf, Field **fields, 150 bool read_all); 151 152 table_events_transactions_common(const PFS_engine_table_share *share, 153 void *pos); 154 ~table_events_transactions_common()155 ~table_events_transactions_common() {} 156 157 int make_row(PFS_events_transactions *statement); 158 159 /** Current row. */ 160 row_events_transactions m_row; 161 }; 162 163 /** Table PERFORMANCE_SCHEMA.EVENTS_TRANSACTIONS_CURRENT. */ 164 class table_events_transactions_current 165 : public table_events_transactions_common { 166 public: 167 /** Table share */ 168 static PFS_engine_table_share m_share; 169 static PFS_engine_table *create(PFS_engine_table_share *); 170 static int delete_all_rows(); 171 static ha_rows get_row_count(); 172 173 virtual void reset_position(void); 174 175 virtual int rnd_init(bool scan); 176 virtual int rnd_next(); 177 virtual int rnd_pos(const void *pos); 178 179 virtual int index_init(uint idx, bool sorted); 180 virtual int index_next(); 181 182 protected: 183 table_events_transactions_current(); 184 185 public: ~table_events_transactions_current()186 ~table_events_transactions_current() {} 187 188 private: 189 friend class table_events_transactions_history; 190 friend class table_events_transactions_history_long; 191 192 /** Table share lock. */ 193 static THR_LOCK m_table_lock; 194 /** Table definition. */ 195 static Plugin_table m_table_def; 196 197 /** Current position. */ 198 PFS_simple_index m_pos; 199 /** Next position. */ 200 PFS_simple_index m_next_pos; 201 202 PFS_index_events_transactions *m_opened_index; 203 }; 204 205 /** Table PERFORMANCE_SCHEMA.EVENTS_TRANSACTIONS_HISTORY. */ 206 class table_events_transactions_history 207 : public table_events_transactions_common { 208 public: 209 /** Table share */ 210 static PFS_engine_table_share m_share; 211 static PFS_engine_table *create(PFS_engine_table_share *); 212 static int delete_all_rows(); 213 static ha_rows get_row_count(); 214 215 virtual void reset_position(void); 216 217 virtual int rnd_init(bool scan); 218 virtual int rnd_next(); 219 virtual int rnd_pos(const void *pos); 220 221 virtual int index_init(uint idx, bool sorted); 222 virtual int index_next(); 223 224 protected: 225 table_events_transactions_history(); 226 227 public: ~table_events_transactions_history()228 ~table_events_transactions_history() {} 229 230 private: 231 /** Table share lock. */ 232 static THR_LOCK m_table_lock; 233 /** Table definition. */ 234 static Plugin_table m_table_def; 235 236 /** Current position. */ 237 pos_events_transactions_history m_pos; 238 /** Next position. */ 239 pos_events_transactions_history m_next_pos; 240 241 PFS_index_events_transactions *m_opened_index; 242 }; 243 244 /** Table PERFORMANCE_SCHEMA.EVENTS_TRANSACTIONS_HISTORY_LONG. */ 245 class table_events_transactions_history_long 246 : public table_events_transactions_common { 247 public: 248 /** Table share */ 249 static PFS_engine_table_share m_share; 250 static PFS_engine_table *create(PFS_engine_table_share *); 251 static int delete_all_rows(); 252 static ha_rows get_row_count(); 253 254 virtual int rnd_init(bool scan); 255 virtual int rnd_next(); 256 virtual int rnd_pos(const void *pos); 257 virtual void reset_position(void); 258 259 protected: 260 table_events_transactions_history_long(); 261 262 public: ~table_events_transactions_history_long()263 ~table_events_transactions_history_long() {} 264 265 private: 266 /** Table share lock. */ 267 static THR_LOCK m_table_lock; 268 /** Table definition. */ 269 static Plugin_table m_table_def; 270 271 /** Current position. */ 272 PFS_simple_index m_pos; 273 /** Next position. */ 274 PFS_simple_index m_next_pos; 275 }; 276 277 /** @} */ 278 #endif 279