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_ESMS_BY_USER_BY_EVENT_NAME_H
24 #define TABLE_ESMS_BY_USER_BY_EVENT_NAME_H
25 
26 /**
27   @file storage/perfschema/table_esms_by_user_by_event_name.h
28   Table EVENTS_STATEMENTS_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_STATEMENTS_SUMMARY_BY_USER_BY_EVENT_NAME.
46 */
47 struct row_esms_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_statement_stat_row m_stat;
55 };
56 
57 /**
58   Position of a cursor on
59   PERFORMANCE_SCHEMA.EVENTS_STATEMENTS_SUMMARY_BY_USER_BY_EVENT_NAME.
60   Index 1 on user (0 based)
61   Index 2 on statement class (1 based)
62 */
63 struct pos_esms_by_user_by_event_name
64 : public PFS_double_index
65 {
pos_esms_by_user_by_event_namepos_esms_by_user_by_event_name66   pos_esms_by_user_by_event_name()
67     : PFS_double_index(0, 1)
68   {}
69 
resetpos_esms_by_user_by_event_name70   inline void reset(void)
71   {
72     m_index_1= 0;
73     m_index_2= 1;
74   }
75 
next_userpos_esms_by_user_by_event_name76   inline void next_user(void)
77   {
78     m_index_1++;
79     m_index_2= 1;
80   }
81 };
82 
83 /** Table PERFORMANCE_SCHEMA.EVENTS_STATEMENTS_SUMMARY_BY_USER_BY_EVENT_NAME. */
84 class table_esms_by_user_by_event_name : public PFS_engine_table
85 {
86 public:
87   /** Table share */
88   static PFS_engine_table_share m_share;
89   static PFS_engine_table* create();
90   static int delete_all_rows();
91   static ha_rows get_row_count();
92 
93   virtual int rnd_init(bool scan);
94   virtual int rnd_next();
95   virtual int rnd_pos(const void *pos);
96   virtual void reset_position(void);
97 
98 protected:
99   virtual int read_row_values(TABLE *table,
100                               unsigned char *buf,
101                               Field **fields,
102                               bool read_all);
103 
104   table_esms_by_user_by_event_name();
105 
106 public:
~table_esms_by_user_by_event_name()107   ~table_esms_by_user_by_event_name()
108   {}
109 
110 protected:
111   void make_row(PFS_user *user, PFS_statement_class *klass);
112 
113 private:
114   /** Table share lock. */
115   static THR_LOCK m_table_lock;
116   /** Fields definition. */
117   static TABLE_FIELD_DEF m_field_def;
118 
119   /** Current row. */
120   row_esms_by_user_by_event_name m_row;
121   /** True is the current row exists. */
122   bool m_row_exists;
123   /** Current position. */
124   pos_esms_by_user_by_event_name m_pos;
125   /** Next position. */
126   pos_esms_by_user_by_event_name m_next_pos;
127 };
128 
129 /** @} */
130 #endif
131