1 /* Copyright (c) 2010, 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 Street, Fifth Floor, Boston, MA 02110-1301, USA */
22 
23 #ifndef TABLE_EWS_BY_HOST_BY_EVENT_NAME_H
24 #define TABLE_EWS_BY_HOST_BY_EVENT_NAME_H
25 
26 /**
27   @file storage/perfschema/table_ews_by_host_by_event_name.h
28   Table EVENTS_WAITS_SUMMARY_BY_HOST_BY_EVENT_NAME (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_host.h"
36 #include "table_helper.h"
37 
38 /**
39   @addtogroup Performance_schema_tables
40   @{
41 */
42 
43 /**
44   A row of table
45   PERFORMANCE_SCHEMA.EVENTS_WAITS_SUMMARY_BY_HOST_BY_EVENT_NAME.
46 */
47 struct row_ews_by_host_by_event_name
48 {
49   /** Column HOST. */
50   PFS_host_row m_host;
51   /** Column EVENT_NAME. */
52   PFS_event_name_row m_event_name;
53   /** Columns COUNT_STAR, SUM/MIN/AVG/MAX TIMER_WAIT. */
54   PFS_stat_row m_stat;
55 };
56 
57 /**
58   Position of a cursor on
59   PERFORMANCE_SCHEMA.EVENTS_WAITS_SUMMARY_BY_HOST_BY_EVENT_NAME.
60   Index 1 on host (0 based)
61   Index 2 on instrument view
62   Index 3 on instrument class (1 based)
63 */
64 struct pos_ews_by_host_by_event_name
65 : public PFS_triple_index, public PFS_instrument_view_constants
66 {
pos_ews_by_host_by_event_namepos_ews_by_host_by_event_name67   pos_ews_by_host_by_event_name()
68     : PFS_triple_index(0, FIRST_VIEW, 1)
69   {}
70 
resetpos_ews_by_host_by_event_name71   inline void reset(void)
72   {
73     m_index_1= 0;
74     m_index_2= FIRST_VIEW;
75     m_index_3= 1;
76   }
77 
next_hostpos_ews_by_host_by_event_name78   inline void next_host(void)
79   {
80     m_index_1++;
81     m_index_2= FIRST_VIEW;
82     m_index_3= 1;
83   }
84 
has_more_viewpos_ews_by_host_by_event_name85   inline bool has_more_view(void)
86   { return (m_index_2 <= LAST_VIEW); }
87 
next_viewpos_ews_by_host_by_event_name88   inline void next_view(void)
89   {
90     m_index_2++;
91     m_index_3= 1;
92   }
93 };
94 
95 /** Table PERFORMANCE_SCHEMA.EVENTS_WAITS_SUMMARY_BY_HOST_BY_EVENT_NAME. */
96 class table_ews_by_host_by_event_name : public PFS_engine_table
97 {
98 public:
99   /** Table share */
100   static PFS_engine_table_share m_share;
101   static PFS_engine_table* create();
102   static int delete_all_rows();
103   static ha_rows get_row_count();
104 
105   virtual int rnd_next();
106   virtual int rnd_pos(const void *pos);
107   virtual void reset_position(void);
108 
109 protected:
110   virtual int read_row_values(TABLE *table,
111                               unsigned char *buf,
112                               Field **fields,
113                               bool read_all);
114 
115   table_ews_by_host_by_event_name();
116 
117 public:
~table_ews_by_host_by_event_name()118   ~table_ews_by_host_by_event_name()
119   {}
120 
121 protected:
122   void make_row(PFS_host *host, PFS_instr_class *klass);
123 
124 private:
125   /** Table share lock. */
126   static THR_LOCK m_table_lock;
127   /** Fields definition. */
128   static TABLE_FIELD_DEF m_field_def;
129 
130   /** Current row. */
131   row_ews_by_host_by_event_name m_row;
132   /** True is the current row exists. */
133   bool m_row_exists;
134   /** Current position. */
135   pos_ews_by_host_by_event_name m_pos;
136   /** Next position. */
137   pos_ews_by_host_by_event_name m_next_pos;
138 };
139 
140 /** @} */
141 #endif
142