1 /* Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
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_ACCOUNT_BY_EVENT_NAME_H
24 #define TABLE_EWS_BY_ACCOUNT_BY_EVENT_NAME_H
25 
26 /**
27   @file storage/perfschema/table_ews_by_account_by_event_name.h
28   Table EVENTS_WAITS_SUMMARY_BY_ACCOUNT_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_account.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_ACCOUNT_BY_EVENT_NAME.
46 */
47 struct row_ews_by_account_by_event_name
48 {
49   /** Column USER, HOST. */
50   PFS_account_row m_account;
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_ACCOUNT_BY_EVENT_NAME.
60   Index 1 on user@host (0 based)
61   Index 2 on instrument view
62   Index 3 on instrument class (1 based)
63 */
64 struct pos_ews_by_account_by_event_name
65 : public PFS_triple_index, public PFS_instrument_view_constants
66 {
pos_ews_by_account_by_event_namepos_ews_by_account_by_event_name67   pos_ews_by_account_by_event_name()
68     : PFS_triple_index(0, FIRST_VIEW, 1)
69   {}
70 
resetpos_ews_by_account_by_event_name71   inline void reset(void)
72   {
73     m_index_1= 0;
74     m_index_2= VIEW_MUTEX;
75     m_index_3= 1;
76   }
77 
has_more_accountpos_ews_by_account_by_event_name78   inline bool has_more_account(void)
79   { return (m_index_1 < account_max); }
80 
next_accountpos_ews_by_account_by_event_name81   inline void next_account(void)
82   {
83     m_index_1++;
84     m_index_2= FIRST_VIEW;
85     m_index_3= 1;
86   }
87 
has_more_viewpos_ews_by_account_by_event_name88   inline bool has_more_view(void)
89   { return (m_index_2 <= LAST_VIEW); }
90 
next_viewpos_ews_by_account_by_event_name91   inline void next_view(void)
92   {
93     m_index_2++;
94     m_index_3= 1;
95   }
96 };
97 
98 /** Table PERFORMANCE_SCHEMA.EVENTS_WAITS_SUMMARY_BY_ACCOUNT_BY_EVENT_NAME. */
99 class table_ews_by_account_by_event_name : public PFS_engine_table
100 {
101 public:
102   /** Table share */
103   static PFS_engine_table_share m_share;
104   static PFS_engine_table* create();
105   static int delete_all_rows();
106 
107   virtual int rnd_next();
108   virtual int rnd_pos(const void *pos);
109   virtual void reset_position(void);
110 
111 protected:
112   virtual int read_row_values(TABLE *table,
113                               unsigned char *buf,
114                               Field **fields,
115                               bool read_all);
116 
117   table_ews_by_account_by_event_name();
118 
119 public:
~table_ews_by_account_by_event_name()120   ~table_ews_by_account_by_event_name()
121   {}
122 
123 protected:
124   void make_row(PFS_account *account, PFS_instr_class *klass);
125 
126 private:
127   /** Table share lock. */
128   static THR_LOCK m_table_lock;
129   /** Fields definition. */
130   static TABLE_FIELD_DEF m_field_def;
131 
132   /** Current row. */
133   row_ews_by_account_by_event_name m_row;
134   /** True is the current row exists. */
135   bool m_row_exists;
136   /** Current position. */
137   pos_ews_by_account_by_event_name m_pos;
138   /** Next position. */
139   pos_ews_by_account_by_event_name m_next_pos;
140 };
141 
142 /** @} */
143 #endif
144