MySQL 8.4.2
Source Code Documentation
pfs_example_employee_name.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef PLUGIN_PFS_TABLE_PLUGIN_pfs_example_employee_name_H_
25#define PLUGIN_PFS_TABLE_PLUGIN_pfs_example_employee_name_H_
26
29#include <mysql/plugin.h>
30
31/* Service handle */
32extern SERVICE_TYPE(pfs_plugin_column_integer_v1) * col_int_svc;
33extern SERVICE_TYPE(pfs_plugin_column_string_v2) * col_string_svc;
34
35/* Global share pointer for pfs_example_employee_name table */
37
38/* Number of characters * max multibyte length */
39#define EMPLOYEE_NAME_LEN 20 * 4
40
41/* Maximum number of rows in the table */
42#define EMPLOYEEE_NAME_MAX_ROWS 100
43
44/* A mutex instance to protect:
45 * - ename_rows_in_table
46 * - ename_next_available_index
47 * - ename_records_array
48 */
50
51/* A structure to denote a single row of the table. */
53 public:
56 unsigned int f_name_length;
58 unsigned int l_name_length;
59
60 /* If there is a value in this row */
61 bool m_exist;
62};
63
64/**
65 * An array to keep rows of the tables.
66 * When a row is inserted in plugin table, it will be stored here.
67 * When a row is queried from plugin table, it will be fetched from here.
68 */
70
71/* A class to define position of cursor in table. */
72class Ename_POS {
73 private:
74 unsigned int m_index;
75
76 public:
77 ~Ename_POS() = default;
78 Ename_POS() { m_index = 0; }
79
80 bool has_more() {
81 if (m_index < EMPLOYEEE_NAME_MAX_ROWS) return true;
82 return false;
83 }
84 void next() { m_index++; }
85
86 void reset() { m_index = 0; }
87
88 unsigned int get_index() { return m_index; }
89
90 void set_at(unsigned int index) { m_index = index; }
91
92 void set_at(Ename_POS *pos) { m_index = pos->m_index; }
93
94 void set_after(Ename_POS *pos) { m_index = pos->m_index + 1; }
95};
96
98 public:
99 virtual ~Ename_index() = default;
100 virtual bool match(Ename_Record *record) = 0;
101};
102
103/* And index on Employee Number */
105 public:
107
108 bool match(Ename_Record *record) override {
109 return col_int_svc->match_key(false, record->e_number.val, &m_emp_num);
110 }
111};
112
113/* An index on Employee First Name */
115 public:
118
119 bool match(Ename_Record *record) override {
121 false, record->f_name, record->f_name_length, &m_emp_fname);
122 }
123};
124
125/* A structure to define a handle for table in plugin/component code. */
127 /* Current position instance */
129 /* Next position instance */
131
132 /* Current row for the table */
134
135 /* Index on table */
138
139 /* Index indicator */
140 unsigned int index_num;
141};
142
146int ename_rnd_init(PSI_table_handle *h, bool scan);
148int ename_index_init(PSI_table_handle *handle, uint idx, bool sorted,
149 PSI_index_handle **index);
151 unsigned int idx, int find_flag);
155 uint index);
158 unsigned int index);
161 unsigned int index);
163int ename_delete_all_rows(void);
164unsigned long long ename_get_row_count(void);
166
167#endif /* PLUGIN_PFS_TABLE_PLUGIN_pfs_example_employee_name_H_ */
Definition: pfs_example_employee_name.h:72
void set_at(Ename_POS *pos)
Definition: pfs_example_employee_name.h:92
unsigned int get_index()
Definition: pfs_example_employee_name.h:88
unsigned int m_index
Definition: pfs_example_employee_name.h:74
void set_at(unsigned int index)
Definition: pfs_example_employee_name.h:90
void next()
Definition: pfs_example_employee_name.h:84
bool has_more()
Definition: pfs_example_employee_name.h:80
Ename_POS()
Definition: pfs_example_employee_name.h:78
void set_after(Ename_POS *pos)
Definition: pfs_example_employee_name.h:94
void reset()
Definition: pfs_example_employee_name.h:86
~Ename_POS()=default
Definition: pfs_example_employee_name.h:114
bool match(Ename_Record *record) override
Definition: pfs_example_employee_name.h:119
PSI_plugin_key_string m_emp_fname
Definition: pfs_example_employee_name.h:116
char m_emp_fname_buffer[EMPLOYEE_NAME_LEN]
Definition: pfs_example_employee_name.h:117
Definition: pfs_example_employee_name.h:104
PSI_plugin_key_integer m_emp_num
Definition: pfs_example_employee_name.h:106
bool match(Ename_Record *record) override
Definition: pfs_example_employee_name.h:108
Definition: pfs_example_employee_name.h:97
virtual bool match(Ename_Record *record)=0
virtual ~Ename_index()=default
static int record
Definition: mysqltest.cc:195
static int handle(int sql_errno, const char *sqlstate, const char *message, void *state)
Bridge function between the C++ API offered by this module and the C API of the parser service.
Definition: services.cc:64
int ename_delete_all_rows(void)
Definition: pfs_example_employee_name.cc:381
#define EMPLOYEEE_NAME_MAX_ROWS
Definition: pfs_example_employee_name.h:42
int ename_write_row_values(PSI_table_handle *handle)
Definition: pfs_example_employee_name.cc:249
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:64
int ename_rnd_init(PSI_table_handle *h, bool scan)
Definition: pfs_example_employee_name.cc:111
int ename_read_column_value(PSI_table_handle *handle, PSI_field *field, uint index)
Definition: pfs_example_employee_name.cc:224
int ename_update_row_values(PSI_table_handle *handle)
Definition: pfs_example_employee_name.cc:319
PFS_engine_table_share_proxy ename_st_share
Definition: pfs_example_employee_name.cc:28
const mysql_service_pfs_plugin_column_integer_v1_t * col_int_svc
Definition: pfs_example_plugin_employee.cc:90
unsigned long long ename_get_row_count(void)
Definition: pfs_example_employee_name.cc:391
int ename_update_column_value(PSI_table_handle *handle, PSI_field *field, unsigned int index)
Definition: pfs_example_employee_name.cc:338
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:78
const mysql_service_pfs_plugin_column_string_v2_t * col_string_svc
Definition: pfs_example_plugin_employee.cc:92
void init_ename_share(PFS_engine_table_share_proxy *share)
Definition: pfs_example_employee_name.cc:393
Ename_Record ename_records_array[EMPLOYEEE_NAME_MAX_ROWS]
An array to keep rows of the tables.
Definition: pfs_example_employee_name.cc:37
void ename_reset_position(PSI_table_handle *handle)
Definition: pfs_example_employee_name.cc:216
int ename_write_column_value(PSI_table_handle *handle, PSI_field *field, unsigned int index)
Definition: pfs_example_employee_name.cc:291
int ename_index_next(PSI_table_handle *handle)
Definition: pfs_example_employee_name.cc:184
int ename_delete_row_values(PSI_table_handle *handle)
Definition: pfs_example_employee_name.cc:366
int ename_rnd_pos(PSI_table_handle *handle)
Definition: pfs_example_employee_name.cc:117
int ename_index_init(PSI_table_handle *handle, uint idx, bool sorted, PSI_index_handle **index)
Definition: pfs_example_employee_name.cc:130
#define EMPLOYEE_NAME_LEN
Definition: pfs_example_employee_name.h:39
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
int ename_rnd_next(PSI_table_handle *handle)
Definition: pfs_example_employee_name.cc:94
mysql_mutex_t LOCK_ename_records_array
Definition: pfs_example_employee_name.cc:29
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:97
struct PSI_pos PSI_pos
This is an opaque structure to denote cursor position in plugin/component code.
Definition: pfs_plugin_table_service.h:102
#define PSI_int
Definition: pfs_plugin_table_service.h:148
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:106
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:110
struct PSI_field PSI_field
This is an opaque structure to denote filed in plugin/component code.
Definition: pfs_plugin_table_service.h:93
#define SERVICE_TYPE(name)
Generates the standard Service type name.
Definition: service.h:76
Specifies macros to define Service Implementations.
Definition: pfs_example_employee_name.h:52
char l_name[EMPLOYEE_NAME_LEN]
Definition: pfs_example_employee_name.h:57
unsigned int l_name_length
Definition: pfs_example_employee_name.h:58
bool m_exist
Definition: pfs_example_employee_name.h:61
PSI_int e_number
Definition: pfs_example_employee_name.h:54
char f_name[EMPLOYEE_NAME_LEN]
Definition: pfs_example_employee_name.h:55
unsigned int f_name_length
Definition: pfs_example_employee_name.h:56
Definition: pfs_example_employee_name.h:126
Ename_POS m_next_pos
Definition: pfs_example_employee_name.h:130
Ename_index_by_emp_fname m_emp_fname_index
Definition: pfs_example_employee_name.h:137
Ename_POS m_pos
Definition: pfs_example_employee_name.h:128
Ename_index_by_emp_num m_emp_num_index
Definition: pfs_example_employee_name.h:136
Ename_Record current_row
Definition: pfs_example_employee_name.h:133
unsigned int index_num
Definition: pfs_example_employee_name.h:140
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:462
A structure to denote a key of type long in an index.
Definition: pfs_plugin_table_service.h:160
A structure to denote a key of type string in an index.
Definition: pfs_plugin_table_service.h:226
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:50
bool(* match_key)(bool record_null, long record_value, PSI_plugin_key_integer *key)
Definition: pfs_plugin_table_service.h:569
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:623