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