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_ESGS_BY_USER_BY_EVENT_NAME_H
24 #define TABLE_ESGS_BY_USER_BY_EVENT_NAME_H
25 
26 /**
27   @file storage/perfschema/table_esgs_by_user_by_event_name.h
28   Table EVENTS_STAGES_SUMMARY_BY_USER_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_user.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_STAGES_SUMMARY_BY_USER_BY_EVENT_NAME.
46 */
47 struct row_esgs_by_user_by_event_name
48 {
49   /** Column USER. */
50   PFS_user_row m_user;
51   /** Column EVENT_NAME. */
52   PFS_event_name_row m_event_name;
53   /** Columns COUNT_STAR, SUM/MIN/AVG/MAX TIMER_WAIT. */
54   PFS_stage_stat_row m_stat;
55 };
56 
57 /**
58   Position of a cursor on
59   PERFORMANCE_SCHEMA.EVENTS_STAGES_SUMMARY_BY_USER_BY_EVENT_NAME.
60   Index 1 on user (0 based)
61   Index 2 on stage class (1 based)
62 */
63 struct pos_esgs_by_user_by_event_name
64 : public PFS_double_index
65 {
pos_esgs_by_user_by_event_namepos_esgs_by_user_by_event_name66   pos_esgs_by_user_by_event_name()
67     : PFS_double_index(0, 1)
68   {}
69 
resetpos_esgs_by_user_by_event_name70   inline void reset(void)
71   {
72     m_index_1= 0;
73     m_index_2= 1;
74   }
75 
next_userpos_esgs_by_user_by_event_name76   inline void next_user(void)
77   {
78     m_index_1++;
79     m_index_2= 1;
80   }
81 
next_stagepos_esgs_by_user_by_event_name82   inline void next_stage(void)
83   {
84     m_index_2++;
85   }
86 };
87 
88 /** Table PERFORMANCE_SCHEMA.EVENTS_STAGES_SUMMARY_BY_USER_BY_EVENT_NAME. */
89 class table_esgs_by_user_by_event_name : public PFS_engine_table
90 {
91 public:
92   /** Table share */
93   static PFS_engine_table_share m_share;
94   static PFS_engine_table* create();
95   static int delete_all_rows();
96   static ha_rows get_row_count();
97 
98   virtual int rnd_init(bool scan);
99   virtual int rnd_next();
100   virtual int rnd_pos(const void *pos);
101   virtual void reset_position(void);
102 
103 protected:
104   virtual int read_row_values(TABLE *table,
105                               unsigned char *buf,
106                               Field **fields,
107                               bool read_all);
108 
109   table_esgs_by_user_by_event_name();
110 
111 public:
~table_esgs_by_user_by_event_name()112   ~table_esgs_by_user_by_event_name()
113   {}
114 
115 protected:
116   void make_row(PFS_user *user, PFS_stage_class *klass);
117 
118 private:
119   /** Table share lock. */
120   static THR_LOCK m_table_lock;
121   /** Fields definition. */
122   static TABLE_FIELD_DEF m_field_def;
123 
124   /** Current row. */
125   row_esgs_by_user_by_event_name m_row;
126   /** True is the current row exists. */
127   bool m_row_exists;
128   /** Current position. */
129   pos_esgs_by_user_by_event_name m_pos;
130   /** Next position. */
131   pos_esgs_by_user_by_event_name m_next_pos;
132 };
133 
134 /** @} */
135 #endif
136