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_VARIABLES_H
24 #define TABLE_GLOBAL_VARIABLES_H
25 
26 /**
27   @file storage/perfschema/table_global_variables.h
28   Table GLOBAL_VARIABLES (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   Store and retrieve table state information during queries that reinstantiate
44   the table object.
45 */
46 class table_global_variables_context : public PFS_table_context
47 {
48 public:
table_global_variables_context(ulonglong hash_version,bool restore)49   table_global_variables_context(ulonglong hash_version, bool restore) :
50     PFS_table_context(hash_version, restore, THR_PFS_VG)  {}
51 };
52 
53 /**
54   A row of table
55   PERFORMANCE_SCHEMA.GLOBAL_VARIABLES.
56 */
57 struct row_global_variables
58 {
59   /** Column VARIABLE_NAME. */
60   PFS_variable_name_row m_variable_name;
61   /** Column VARIABLE_VALUE. */
62   PFS_variable_value_row m_variable_value;
63 };
64 
65 /** Table PERFORMANCE_SCHEMA.GLOBAL_VARIABLES. */
66 class table_global_variables : 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 ha_rows get_row_count();
75 
76   virtual int rnd_init(bool scan);
77   virtual int rnd_next();
78   virtual int rnd_pos(const void *pos);
79   virtual void reset_position(void);
80 
81 protected:
82   virtual int read_row_values(TABLE *table,
83                               unsigned char *buf,
84                               Field **fields,
85                               bool read_all);
86   table_global_variables();
87 
88 public:
~table_global_variables()89   ~table_global_variables()
90   {}
91 
92 protected:
93   void make_row(const System_variable *system_var);
94 
95 private:
96   /** Table share lock. */
97   static THR_LOCK m_table_lock;
98   /** Fields definition. */
99   static TABLE_FIELD_DEF m_field_def;
100 
101   /** Current THD variables. */
102   PFS_system_variable_cache m_sysvar_cache;
103   /** Current row. */
104   row_global_variables m_row;
105   /** True if the current row exists. */
106   bool m_row_exists;
107   /** Current position. */
108   pos_t m_pos;
109   /** Next position. */
110   pos_t m_next_pos;
111 
112   /** Table context with system variable hash version. */
113   table_global_variables_context *m_context;
114 };
115 
116 /** @} */
117 #endif
118