1 /* Copyright (c) 2010, 2021, Oracle and/or its affiliates.
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 Foundation,
21   51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
22 
23 #ifndef TABLE_EVENTS_TRANSACTIONS_H
24 #define TABLE_EVENTS_TRANSACTIONS_H
25 
26 /**
27   @file storage/perfschema/table_events_HA_ERR_WRONG_COMMAND.h
28   Table EVENTS_TRANSACTIONS_xxx (declarations).
29 */
30 
31 #include "pfs_column_types.h"
32 #include "pfs_engine_table.h"
33 #include "pfs_events_transactions.h"
34 #include "table_helper.h"
35 #include "rpl_gtid.h"
36 
37 struct PFS_thread;
38 
39 /**
40   @addtogroup Performance_schema_tables
41   @{
42 */
43 
44 /** A row of table_events_transactions_common. */
45 struct row_events_transactions
46 {
47   /** Column THREAD_ID. */
48   ulonglong m_thread_internal_id;
49   /** Column EVENT_ID. */
50   ulonglong m_event_id;
51   /** Column END_EVENT_ID. */
52   ulonglong m_end_event_id;
53   /** Column NESTING_EVENT_ID. */
54   ulonglong m_nesting_event_id;
55   /** Column NESTING_EVENT_TYPE. */
56   enum_event_type m_nesting_event_type;
57   /** Column EVENT_NAME. */
58   const char *m_name;
59   /** Length in bytes of @c m_name. */
60   uint m_name_length;
61   /** Column TIMER_START. */
62   ulonglong m_timer_start;
63   /** Column TIMER_END. */
64   ulonglong m_timer_end;
65   /** Column TIMER_WAIT. */
66   ulonglong m_timer_wait;
67   /** Column SOURCE. */
68   char m_source[COL_SOURCE_SIZE];
69   /** Length in bytes of @c m_source. */
70   uint m_source_length;
71   /** InnoDB transaction id. */
72   ulonglong m_trxid;
73   /** Transaction state. */
74   enum_transaction_state m_state;
75   /** Global Transaction ID. */
76   char m_gtid[Gtid_specification::MAX_TEXT_LENGTH + 1];
77   /** GTID length in bytes*/
78   int m_gtid_length;
79   /** XA transaction ID. */
80   PSI_xid m_xid;
81   /** XA transaction state. */
82   enum_xa_transaction_state m_xa_state;
83   /** True if XA transaction. */
84   bool m_xa;
85   /** True if autocommit transaction. */
86   bool m_autocommit;
87   /** Isolation level. */
88   enum_isolation_level m_isolation_level;
89   /** True if read-only, read-write otherwise. */
90   bool m_read_only;
91   /** Column NUMBER_OF_SAVEPOINTS. */
92   ulonglong m_savepoint_count;
93   /** Column NUMBER_OF_ROLLBACK_TO_SAVEPOINT. */
94   ulonglong m_rollback_to_savepoint_count;
95   /** Column NUMBER_OF_RELEASE_SAVEPOINT. */
96   ulonglong m_release_savepoint_count;
97 };
98 
99 /**
100   Position of a cursor on PERFORMANCE_SCHEMA.EVENTS_TRANSACTIONS_HISTORY.
101   Index 1 on thread (0 based)
102   Index 2 on transaction event record in thread history (0 based)
103 */
104 struct pos_events_transactions_history : public PFS_double_index
105 {
pos_events_transactions_historypos_events_transactions_history106   pos_events_transactions_history()
107     : PFS_double_index(0, 0)
108   {}
109 
resetpos_events_transactions_history110   inline void reset(void)
111   {
112     m_index_1= 0;
113     m_index_2= 0;
114   }
115 
next_threadpos_events_transactions_history116   inline void next_thread(void)
117   {
118     m_index_1++;
119     m_index_2= 0;
120   }
121 };
122 
123 /**
124   Adapter, for table sharing the structure of
125   PERFORMANCE_SCHEMA.EVENTS_TRANSACTIONS_CURRENT.
126 */
127 class table_events_transactions_common : public PFS_engine_table
128 {
129 protected:
130   virtual int read_row_values(TABLE *table,
131                               unsigned char *buf,
132                               Field **fields,
133                               bool read_all);
134 
135   table_events_transactions_common(const PFS_engine_table_share *share, void *pos);
136 
~table_events_transactions_common()137   ~table_events_transactions_common()
138   {}
139 
140   void make_row(PFS_events_transactions *statement);
141 
142   /** Current row. */
143   row_events_transactions m_row;
144   /** True if the current row exists. */
145   bool m_row_exists;
146 };
147 
148 /** Table PERFORMANCE_SCHEMA.EVENTS_TRANSACTIONS_CURRENT. */
149 class table_events_transactions_current : public table_events_transactions_common
150 {
151 public:
152   /** Table share */
153   static PFS_engine_table_share m_share;
154   static PFS_engine_table* create();
155   static int delete_all_rows();
156   static ha_rows get_row_count();
157 
158   virtual int rnd_init(bool scan);
159   virtual int rnd_next();
160   virtual int rnd_pos(const void *pos);
161   virtual void reset_position(void);
162 
163 protected:
164   table_events_transactions_current();
165 
166 public:
~table_events_transactions_current()167   ~table_events_transactions_current()
168   {}
169 
170 private:
171   friend class table_events_transactions_history;
172   friend class table_events_transactions_history_long;
173 
174   /** Table share lock. */
175   static THR_LOCK m_table_lock;
176   /**
177     Fields definition.
178     Also used by table_events_transactions_history
179     and table_events_transactions_history_long.
180   */
181   static TABLE_FIELD_DEF m_field_def;
182 
183   /** Current position. */
184   PFS_simple_index m_pos;
185   /** Next position. */
186   PFS_simple_index m_next_pos;
187 };
188 
189 /** Table PERFORMANCE_SCHEMA.EVENTS_TRANSACTIONS_HISTORY. */
190 class table_events_transactions_history : public table_events_transactions_common
191 {
192 public:
193   /** Table share */
194   static PFS_engine_table_share m_share;
195   static PFS_engine_table* create();
196   static int delete_all_rows();
197   static ha_rows get_row_count();
198 
199   virtual int rnd_init(bool scan);
200   virtual int rnd_next();
201   virtual int rnd_pos(const void *pos);
202   virtual void reset_position(void);
203 
204 protected:
205   table_events_transactions_history();
206 
207 public:
~table_events_transactions_history()208   ~table_events_transactions_history()
209   {}
210 
211 private:
212   /** Table share lock. */
213   static THR_LOCK m_table_lock;
214 
215   /** Current position. */
216   pos_events_transactions_history m_pos;
217   /** Next position. */
218   pos_events_transactions_history m_next_pos;
219 };
220 
221 /** Table PERFORMANCE_SCHEMA.EVENTS_TRANSACTIONS_HISTORY_LONG. */
222 class table_events_transactions_history_long : public table_events_transactions_common
223 {
224 public:
225   /** Table share */
226   static PFS_engine_table_share m_share;
227   static PFS_engine_table* create();
228   static int delete_all_rows();
229   static ha_rows get_row_count();
230 
231   virtual int rnd_init(bool scan);
232   virtual int rnd_next();
233   virtual int rnd_pos(const void *pos);
234   virtual void reset_position(void);
235 
236 protected:
237   table_events_transactions_history_long();
238 
239 public:
~table_events_transactions_history_long()240   ~table_events_transactions_history_long()
241   {}
242 
243 private:
244   /** Table share lock. */
245   static THR_LOCK m_table_lock;
246 
247   /** Current position. */
248   PFS_simple_index m_pos;
249   /** Next position. */
250   PFS_simple_index m_next_pos;
251 };
252 
253 /** @} */
254 #endif
255