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_USER_H 24 #define TABLE_STATUS_BY_USER_H 25 26 /** 27 @file storage/perfschema/table_status_by_user.h 28 Table STATUS_BY_USER (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 "pfs_user.h" 36 #include "table_helper.h" 37 #include "pfs_variable.h" 38 #include "pfs_buffer_container.h" 39 40 /** 41 @addtogroup Performance_schema_tables 42 @{ 43 */ 44 45 /** 46 A row of table 47 PERFORMANCE_SCHEMA.STATUS_BY_USER. 48 */ 49 struct row_status_by_user 50 { 51 /** Column USER */ 52 PFS_user_row m_user; 53 /** Column VARIABLE_NAME. */ 54 PFS_variable_name_row m_variable_name; 55 /** Column VARIABLE_VALUE. */ 56 PFS_variable_value_row m_variable_value; 57 }; 58 59 /** 60 Position of a cursor on 61 PERFORMANCE_SCHEMA.STATUS_BY_USER. 62 Index 1 on user (0 based) 63 Index 2 on status variable (0 based) 64 */ 65 struct pos_status_by_user 66 : public PFS_double_index 67 { pos_status_by_userpos_status_by_user68 pos_status_by_user() 69 : PFS_double_index(0, 0) 70 {} 71 resetpos_status_by_user72 inline void reset(void) 73 { 74 m_index_1= 0; 75 m_index_2= 0; 76 } 77 has_more_userpos_status_by_user78 inline bool has_more_user(void) 79 { return (m_index_1 < global_user_container.get_row_count()); } 80 next_userpos_status_by_user81 inline void next_user(void) 82 { 83 m_index_1++; 84 m_index_2= 0; 85 } 86 }; 87 88 /** 89 Store and retrieve table state information for queries that reinstantiate 90 the table object. 91 */ 92 class table_status_by_user_context : public PFS_table_context 93 { 94 public: table_status_by_user_context(ulonglong current_version,bool restore)95 table_status_by_user_context(ulonglong current_version, bool restore) : 96 PFS_table_context(current_version, global_user_container.get_row_count(), restore, THR_PFS_SBU) { } 97 }; 98 99 /** Table PERFORMANCE_SCHEMA.STATUS_BY_USER. */ 100 class table_status_by_user : public PFS_engine_table 101 { 102 typedef pos_status_by_user pos_t; 103 104 public: 105 /** Table share */ 106 static PFS_engine_table_share m_share; 107 static PFS_engine_table* create(); 108 static int delete_all_rows(); 109 static ha_rows get_row_count(); 110 111 virtual int rnd_init(bool scan); 112 virtual int rnd_next(); 113 virtual int rnd_pos(const void *pos); 114 virtual void reset_position(void); 115 116 protected: 117 virtual int read_row_values(TABLE *table, 118 unsigned char *buf, 119 Field **fields, 120 bool read_all); 121 table_status_by_user(); 122 123 public: ~table_status_by_user()124 ~table_status_by_user() { } 125 126 protected: 127 int materialize(PFS_thread *thread); 128 void make_row(PFS_user *user, const Status_variable *status_var); 129 130 private: 131 /** Table share lock. */ 132 static THR_LOCK m_table_lock; 133 /** Fields definition. */ 134 static TABLE_FIELD_DEF m_field_def; 135 136 /** Status variable cache for one user. */ 137 PFS_status_variable_cache m_status_cache; 138 139 /** Current row. */ 140 row_status_by_user m_row; 141 /** True if the current row exists. */ 142 bool m_row_exists; 143 /** Current position. */ 144 pos_t m_pos; 145 /** Next position. */ 146 pos_t m_next_pos; 147 148 /** Table context with global status array version and map of materialized threads. */ 149 table_status_by_user_context *m_context; 150 }; 151 152 /** @} */ 153 #endif 154