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_GLOBAL_STATUS_H
24 #define TABLE_GLOBAL_STATUS_H
25 
26 /**
27   @file storage/perfschema/table_global_status.h
28   Table global_status (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_variable.h"
36 #include "table_helper.h"
37 /**
38   @addtogroup Performance_schema_tables
39   @{
40 */
41 
42 /**
43   A row of table
44   PERFORMANCE_SCHEMA.GLOBAL_STATUS.
45 */
46 struct row_global_status
47 {
48   /** Column VARIABLE_NAME. */
49   PFS_variable_name_row m_variable_name;
50   /** Column VARIABLE_VALUE. */
51   PFS_variable_value_row m_variable_value;
52 };
53 
54 /**
55   Store and retrieve table state information for queries that reinstantiate
56   the table object.
57 */
58 class table_global_status_context : public PFS_table_context
59 {
60 public:
table_global_status_context(ulonglong current_version,bool restore)61   table_global_status_context(ulonglong current_version, bool restore) :
62     PFS_table_context(current_version, restore, THR_PFS_SG) { }
63 };
64 
65 /** Table PERFORMANCE_SCHEMA.GLOBAL_STATUS. */
66 class table_global_status : public PFS_engine_table
67 {
68   typedef PFS_simple_index pos_t;
69 
70 public:
71   /** Table share */
72   static PFS_engine_table_share m_share;
73   static PFS_engine_table* create();
74   static int delete_all_rows();
75   static ha_rows get_row_count();
76 
77   virtual int rnd_init(bool scan);
78   virtual int rnd_next();
79   virtual int rnd_pos(const void *pos);
80   virtual void reset_position(void);
81 
82 protected:
83   virtual int read_row_values(TABLE *table,
84                               unsigned char *buf,
85                               Field **fields,
86                               bool read_all);
87   table_global_status();
88 
89 public:
~table_global_status()90   ~table_global_status()
91   {}
92 
93 protected:
94   void make_row(const Status_variable *system_var);
95 
96 private:
97   /** Table share lock. */
98   static THR_LOCK m_table_lock;
99   /** Fields definition. */
100   static TABLE_FIELD_DEF m_field_def;
101 
102   /** Current THD variables. */
103   PFS_status_variable_cache m_status_cache;
104   /** Current row. */
105   row_global_status m_row;
106   /** True if the current row exists. */
107   bool m_row_exists;
108   /** Current position. */
109   pos_t m_pos;
110   /** Next position. */
111   pos_t m_next_pos;
112 
113   /** Table context with global status array version. */
114   table_global_status_context *m_context;
115 };
116 
117 /** @} */
118 #endif
119