MySQL  8.0.17
Source Code Documentation
pfs_example_employee_name.h
Go to the documentation of this file.
1 /* Copyright (c) 2017, 2018, 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 St, Fifth Floor, Boston, MA 02110-1301 USA */
22 
23 #ifndef PLUGIN_PFS_TABLE_PLUGIN_pfs_example_employee_name_H_
24 #define PLUGIN_PFS_TABLE_PLUGIN_pfs_example_employee_name_H_
25 
28 #include <mysql/plugin.h>
29 
30 /* Service handle */
31 extern SERVICE_TYPE(pfs_plugin_table) * table_svc;
32 
33 /* Global share pointer for pfs_example_employee_name table */
35 
36 /* Maximum number of rows in the table */
37 #define EMPLOYEEE_NAME_MAX_ROWS 100
38 
39 /* A mutex instance to protect:
40  * - ename_rows_in_table
41  * - ename_next_available_index
42  * - ename_records_array
43  */
45 
46 /* A structure to denote a single row of the table. */
47 struct {
48  public:
50  char f_name[20];
51  unsigned int f_name_length;
52  char l_name[20];
53  unsigned int l_name_length;
54 
55  /* If there is a value in this row */
56  bool m_exist;
57 } typedef Ename_Record;
58 
59 /**
60  * An array to keep rows of the tables.
61  * When a row is inserted in plugin table, it will be stored here.
62  * When a row is queried from plugin table, it will be fetched from here.
63  */
65 
66 /* A class to define position of cursor in table. */
67 class Ename_POS {
68  private:
69  unsigned int m_index;
70 
71  public:
73  Ename_POS() { m_index = 0; }
74 
75  bool has_more() {
76  if (m_index < EMPLOYEEE_NAME_MAX_ROWS) return true;
77  return false;
78  }
79  void next() { m_index++; }
80 
81  void reset() { m_index = 0; }
82 
83  unsigned int get_index() { return m_index; }
84 
85  void set_at(unsigned int index) { m_index = index; }
86 
87  void set_at(Ename_POS *pos) { m_index = pos->m_index; }
88 
89  void set_after(Ename_POS *pos) { m_index = pos->m_index + 1; }
90 };
91 
92 class Ename_index {
93  public:
94  virtual ~Ename_index() {}
95  virtual bool match(Ename_Record *record) = 0;
96 };
97 
98 /* And index on Employee Number */
100  public:
102 
104  return table_svc->match_key_integer(false, record->e_number.val,
105  &m_emp_num);
106  }
107 };
108 
109 /* An index on Employee First Name */
111  public:
114 
116  return table_svc->match_key_string(false, record->f_name,
117  record->f_name_length, &m_emp_fname);
118  }
119 };
120 
121 /* A structure to define a handle for table in plugin/component code. */
122 typedef struct {
123  /* Current position instance */
125  /* Next position instance */
127 
128  /* Current row for the table */
130 
131  /* Index on table */
134 
135  /* Index indicator */
136  unsigned int index_num;
138 
142 int ename_rnd_init(PSI_table_handle *h, bool scan);
144 int ename_index_init(PSI_table_handle *handle, uint idx, bool sorted,
147  unsigned int idx, int find_flag);
151  uint index);
154  unsigned int index);
157  unsigned int index);
159 int ename_delete_all_rows(void);
160 unsigned long long ename_get_row_count(void);
162 
163 #endif /* PLUGIN_PFS_TABLE_PLUGIN_pfs_example_employee_name_H_ */
A share to be initialized by plugin/component code and to be provided to add_table() service method o...
Definition: pfs_plugin_table_service.h:443
int ename_index_next(PSI_table_handle *handle)
Definition: pfs_example_employee_name.cc:184
struct PSI_table_handle PSI_table_handle
This is an opaque structure to denote table handle in plugin/component code.
Definition: pfs_plugin_table_service.h:96
struct PSI_index_handle PSI_index_handle
This is an opaque structure to denote Index Handle in plugin/component code.
Definition: pfs_plugin_table_service.h:109
Definition: pfs_example_employee_name.h:122
t pos
Definition: dbug_analyze.cc:148
char m_emp_fname_buffer[20]
Definition: pfs_example_employee_name.h:113
void set_after(Ename_POS *pos)
Definition: pfs_example_employee_name.h:89
Ename_index_by_emp_fname m_emp_fname_index
Definition: pfs_example_employee_name.h:133
Ename_POS()
Definition: pfs_example_employee_name.h:73
void * handle
Definition: engine_loader.c:19
Ename_POS m_pos
Definition: pfs_example_employee_name.h:124
int ename_index_init(PSI_table_handle *handle, uint idx, bool sorted, PSI_index_handle **index)
Definition: pfs_example_employee_name.cc:129
PFS_engine_table_share_proxy ename_st_share
Definition: pfs_example_employee_name.cc:27
Definition: mi_test3.cc:54
virtual ~Ename_index()
Definition: pfs_example_employee_name.h:94
virtual bool match(Ename_Record *record)=0
int ename_rnd_pos(PSI_table_handle *handle)
Definition: pfs_example_employee_name.cc:116
PSI_plugin_key_string m_emp_fname
Definition: pfs_example_employee_name.h:112
Definition: pfs_example_employee_name.h:99
#define SERVICE_TYPE(name)
PSI_table_handle * ename_open_table(PSI_pos **pos)
Instantiate Ename_Table_Handle at plugin code when corresponding table in performance schema is opene...
Definition: pfs_example_employee_name.cc:63
Definition: pfs_example_employee_name.h:92
struct PSI_pos PSI_pos
This is an opaque structure to denote cursor position in plugin/component code.
Definition: pfs_plugin_table_service.h:101
int ename_read_column_value(PSI_table_handle *handle, PSI_field *field, uint index)
Definition: pfs_example_employee_name.cc:224
int ename_write_column_value(PSI_table_handle *handle, PSI_field *field, unsigned int index)
Definition: pfs_example_employee_name.cc:291
bool match(Ename_Record *record)
Definition: pfs_example_employee_name.h:115
unsigned int f_name_length
Definition: pfs_example_employee_name.h:51
A structure to denote a key of type string in an index.
Definition: pfs_plugin_table_service.h:225
int ename_rnd_next(PSI_table_handle *handle)
Definition: pfs_example_employee_name.cc:93
bool(* match_key_integer)(bool record_null, long record_value, PSI_plugin_key_integer *key)
Definition: pfs_plugin_table_service.h:510
PSI_int e_number
Definition: pfs_example_employee_name.h:49
unsigned int index_num
Definition: pfs_example_employee_name.h:136
char * index(const char *, int c)
Definition: mysql.cc:2847
int ename_write_row_values(PSI_table_handle *handle)
Definition: pfs_example_employee_name.cc:249
void ename_close_table(PSI_table_handle *handle)
Destroy the Ename_Table_Handle at plugin code when corresponding table in performance schema is close...
Definition: pfs_example_employee_name.cc:77
int ename_rnd_init(PSI_table_handle *h, bool scan)
Definition: pfs_example_employee_name.cc:110
unsigned long long ename_get_row_count(void)
Definition: pfs_example_employee_name.cc:391
unsigned int l_name_length
Definition: pfs_example_employee_name.h:53
void set_at(unsigned int index)
Definition: pfs_example_employee_name.h:85
unsigned int uint
Definition: uca-dump.cc:29
void init_ename_share(PFS_engine_table_share_proxy *share)
Definition: pfs_example_employee_name.cc:393
Definition: pfs_example_employee_name.h:47
unsigned int get_index()
Definition: pfs_example_employee_name.h:83
bool has_more()
Definition: pfs_example_employee_name.h:75
int ename_update_column_value(PSI_table_handle *handle, PSI_field *field, unsigned int index)
Definition: pfs_example_employee_name.cc:338
void reset()
Definition: pfs_example_employee_name.h:81
PSI_plugin_key_integer m_emp_num
Definition: pfs_example_employee_name.h:101
~Ename_POS()
Definition: pfs_example_employee_name.h:72
bool(* match_key_string)(bool record_null, const char *record_string_value, unsigned int record_string_length, PSI_plugin_key_string *key)
Definition: pfs_plugin_table_service.h:539
unsigned int m_index
Definition: pfs_example_employee_name.h:69
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
bool m_exist
Definition: pfs_example_employee_name.h:56
const mysql_service_pfs_plugin_table_t * table_svc
Definition: pfs_example_plugin_employee.cc:87
int ename_delete_row_values(PSI_table_handle *handle)
Definition: pfs_example_employee_name.cc:366
Ename_Record ename_records_array[EMPLOYEEE_NAME_MAX_ROWS]
An array to keep rows of the tables.
Definition: pfs_example_employee_name.cc:36
void set_at(Ename_POS *pos)
Definition: pfs_example_employee_name.h:87
struct PSI_field PSI_field
This is an opaque structure to denote filed in plugin/component code.
Definition: pfs_plugin_table_service.h:92
int ename_update_row_values(PSI_table_handle *handle)
Definition: pfs_example_employee_name.cc:319
struct PSI_key_reader PSI_key_reader
This is an opaque structure to denote Key Reader in plugin/component code.
Definition: pfs_plugin_table_service.h:105
void next()
Definition: pfs_example_employee_name.h:79
bool match(Ename_Record *record)
Definition: pfs_example_employee_name.h:103
mysql_mutex_t LOCK_ename_records_array
Definition: pfs_example_employee_name.cc:28
void ename_reset_position(PSI_table_handle *handle)
Definition: pfs_example_employee_name.cc:216
Ename_Record current_row
Definition: pfs_example_employee_name.h:129
A structure to denote a key of type long in an index.
Definition: pfs_plugin_table_service.h:159
Specifies macros to define Service Implementations.
int ename_index_read(PSI_index_handle *index, PSI_key_reader *reader, unsigned int idx, int find_flag)
Definition: pfs_example_employee_name.cc:162
Ename_index_by_emp_num m_emp_num_index
Definition: pfs_example_employee_name.h:132
#define EMPLOYEEE_NAME_MAX_ROWS
Definition: pfs_example_employee_name.h:37
int ename_delete_all_rows(void)
Definition: pfs_example_employee_name.cc:381
Definition: pfs_example_employee_name.h:110
Definition: pfs_example_employee_name.h:67
#define PSI_int
Definition: pfs_plugin_table_service.h:147
Ename_POS m_next_pos
Definition: pfs_example_employee_name.h:126