1 /* Copyright (c) 2015, 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 21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 22 23 #ifndef TABLE_STATUS_BY_THREAD_H 24 #define TABLE_STATUS_BY_THREAD_H 25 26 /** 27 @file storage/perfschema/table_status_by_thread.h 28 Table STATUS_BY_THREAD (declarations). 29 */ 30 31 #include "pfs_column_types.h" 32 #include "pfs_engine_table.h" 33 #include "pfs_instr_class.h" 34 #include "pfs_instr.h" 35 #include "table_helper.h" 36 #include "pfs_variable.h" 37 #include "pfs_buffer_container.h" 38 /** 39 @addtogroup Performance_schema_tables 40 @{ 41 */ 42 43 /** 44 A row of table 45 PERFORMANCE_SCHEMA.STATUS_BY_THREAD. 46 */ 47 struct row_status_by_thread 48 { 49 /** Column THREAD_ID. */ 50 ulonglong m_thread_internal_id; 51 /** Column VARIABLE_NAME. */ 52 PFS_variable_name_row m_variable_name; 53 /** Column VARIABLE_VALUE. */ 54 PFS_variable_value_row m_variable_value; 55 }; 56 57 /** 58 Position of a cursor on 59 PERFORMANCE_SCHEMA.STATUS_BY_THREAD. 60 Index 1 on thread (0 based) 61 Index 2 on status variable (0 based) 62 */ 63 struct pos_status_by_thread 64 : public PFS_double_index 65 { pos_status_by_threadpos_status_by_thread66 pos_status_by_thread() 67 : PFS_double_index(0, 0) 68 {} 69 resetpos_status_by_thread70 inline void reset(void) 71 { 72 m_index_1= 0; 73 m_index_2= 0; 74 } 75 has_more_threadpos_status_by_thread76 inline bool has_more_thread(void) 77 { return (m_index_1 < global_thread_container.get_row_count()); } 78 next_threadpos_status_by_thread79 inline void next_thread(void) 80 { 81 m_index_1++; 82 m_index_2= 0; 83 } 84 }; 85 86 /** 87 Store and retrieve table state information for queries that reinstantiate 88 the table object. 89 */ 90 class table_status_by_thread_context : public PFS_table_context 91 { 92 public: table_status_by_thread_context(ulonglong current_version,bool restore)93 table_status_by_thread_context(ulonglong current_version, bool restore) : 94 PFS_table_context(current_version, global_thread_container.get_row_count(), restore, THR_PFS_SBT) { } 95 }; 96 97 /** Table PERFORMANCE_SCHEMA.STATUS_BY_THREAD. */ 98 class table_status_by_thread : public PFS_engine_table 99 { 100 typedef pos_status_by_thread pos_t; 101 102 public: 103 /** Table share */ 104 static PFS_engine_table_share m_share; 105 static PFS_engine_table* create(); 106 static int delete_all_rows(); 107 static ha_rows get_row_count(); 108 109 virtual int rnd_init(bool scan); 110 virtual int rnd_next(); 111 virtual int rnd_pos(const void *pos); 112 virtual void reset_position(void); 113 114 protected: 115 virtual int read_row_values(TABLE *table, 116 unsigned char *buf, 117 Field **fields, 118 bool read_all); 119 table_status_by_thread(); 120 121 public: ~table_status_by_thread()122 ~table_status_by_thread() 123 {} 124 125 protected: 126 int materialize(PFS_thread *thread); 127 void make_row(PFS_thread *thread, const Status_variable *status_var); 128 129 private: 130 /** Table share lock. */ 131 static THR_LOCK m_table_lock; 132 /** Fields definition. */ 133 static TABLE_FIELD_DEF m_field_def; 134 135 /** Current THD variables. */ 136 PFS_status_variable_cache m_status_cache; 137 /** Current row. */ 138 row_status_by_thread m_row; 139 /** True if the current row exists. */ 140 bool m_row_exists; 141 /** Current position. */ 142 pos_t m_pos; 143 /** Next position. */ 144 pos_t m_next_pos; 145 146 /** Table context with global status array version and map of materialized threads. */ 147 table_status_by_thread_context *m_context; 148 }; 149 150 /** @} */ 151 #endif 152