1 /* Copyright (c) 2014, 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, Suite 500, Boston, MA 02110-1335 USA */
22 
23 #ifndef TABLE_PREPARED_STMT_INSTANCES
24 #define TABLE_PREPARED_STMT_INSTANCES
25 
26 /**
27   @file storage/perfschema/table_prepared_stmt_instances.h
28   Table PREPARED_STATEMENT_INSTANCE(declarations).
29 */
30 
31 #include "table_helper.h"
32 #include "pfs_prepared_stmt.h"
33 
34 /**
35   @addtogroup Performance_schema_tables
36   @{
37 */
38 
39 /**
40   A row of table
41   PERFORMANCE_SCHEMA.PREPARED_STATEMENT_INSTANCES.
42 */
43 struct row_prepared_stmt_instances
44 {
45   /** Column OBJECT_INSTANCE_BEGIN. */
46   const void *m_identity;
47 
48   /** Column STMT_ID. */
49   ulonglong m_stmt_id;
50 
51   /** Column STMT_NAME. */
52   char m_stmt_name[COL_INFO_SIZE];
53   int m_stmt_name_length;
54 
55   /** Column SQL_TEXT. */
56   char m_sql_text[COL_INFO_SIZE];
57   int m_sql_text_length;
58 
59   /** Column OWNER_THREAD_ID. */
60   ulonglong m_owner_thread_id;
61 
62   /** Column OWNER_EVENT_ID. */
63   ulonglong m_owner_event_id;
64 
65   /** Column OWNER_OBJECT_TYPE. */
66   enum_object_type m_owner_object_type;
67 
68   /** Column OWNER_OBJECT_SCHEMA */
69   char m_owner_object_schema[COL_OBJECT_SCHEMA_SIZE];
70   int m_owner_object_schema_length;
71 
72   /** Column OWNER_OBJECT_NAME */
73   char m_owner_object_name[COL_OBJECT_NAME_SIZE];
74   int m_owner_object_name_length;
75 
76   /** Columns TIMER_PREPARE. */
77   PFS_stat_row m_prepare_stat;
78 
79   /** Columns COUNT_REPREPARE. */
80   PFS_stat_row m_reprepare_stat;
81 
82   /** Columns COUNT_STAR...SUM_NO_GOOD_INDEX_USED. */
83   PFS_statement_stat_row m_execute_stat;
84 };
85 
86 /** Table PERFORMANCE_SCHEMA.PREPARED_STATEMENT_INSTANCES. */
87 class table_prepared_stmt_instances : public PFS_engine_table
88 {
89 public:
90   /** Table share */
91   static PFS_engine_table_share m_share;
92   static PFS_engine_table* create();
93   static int delete_all_rows();
94   static ha_rows get_row_count();
95 
96   virtual int rnd_next();
97   virtual int rnd_pos(const void *pos);
98   virtual void reset_position(void);
99 
100 protected:
101   virtual int read_row_values(TABLE *table,
102                               unsigned char *buf,
103                               Field **fields,
104                               bool read_all);
105 
106   table_prepared_stmt_instances();
107 
108 public:
~table_prepared_stmt_instances()109   ~table_prepared_stmt_instances()
110   {}
111 
112 protected:
113   void make_row(PFS_prepared_stmt*);
114 
115 private:
116   /** Table share lock. */
117   static THR_LOCK m_table_lock;
118   /** Fields definition. */
119   static TABLE_FIELD_DEF m_field_def;
120 
121   /** Current row. */
122   row_prepared_stmt_instances m_row;
123   /** True is the current row exists. */
124   bool m_row_exists;
125   /** Current position. */
126   PFS_simple_index m_pos;
127   /** Next position. */
128   PFS_simple_index m_next_pos;
129 };
130 
131 /** @} */
132 #endif
133