MySQL 8.1.0
Source Code Documentation
pfs_example_employee_name.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2023, 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 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 */
31extern SERVICE_TYPE(pfs_plugin_column_integer_v1) * col_int_svc;
32extern SERVICE_TYPE(pfs_plugin_column_string_v2) * col_string_svc;
33
34/* Global share pointer for pfs_example_employee_name table */
36
37/* Number of characters * max multibyte length */
38#define EMPLOYEE_NAME_LEN 20 * 4
39
40/* Maximum number of rows in the table */
41#define EMPLOYEEE_NAME_MAX_ROWS 100
42
43/* A mutex instance to protect:
44 * - ename_rows_in_table
45 * - ename_next_available_index
46 * - ename_records_array
47 */
49
50/* A structure to denote a single row of the table. */
52 public:
55 unsigned int f_name_length;
57 unsigned int l_name_length;
58
59 /* If there is a value in this row */
60 bool m_exist;
61};
62
63/**
64 * An array to keep rows of the tables.
65 * When a row is inserted in plugin table, it will be stored here.
66 * When a row is queried from plugin table, it will be fetched from here.
67 */
69
70/* A class to define position of cursor in table. */
71class Ename_POS {
72 private:
73 unsigned int m_index;
74
75 public:
76 ~Ename_POS() = default;
77 Ename_POS() { m_index = 0; }
78
79 bool has_more() {
80 if (m_index < EMPLOYEEE_NAME_MAX_ROWS) return true;
81 return false;
82 }
83 void next() { m_index++; }
84
85 void reset() { m_index = 0; }
86
87 unsigned int get_index() { return m_index; }
88
89 void set_at(unsigned int index) { m_index = index; }
90
91 void set_at(Ename_POS *pos) { m_index = pos->m_index; }
92
93 void set_after(Ename_POS *pos) { m_index = pos->m_index + 1; }
94};
95
97 public:
98 virtual ~Ename_index() = default;
99 virtual bool match(Ename_Record *record) = 0;
100};
101
102/* And index on Employee Number */
104 public:
106
107 bool match(Ename_Record *record) override {
108 return col_int_svc->match_key(false, record->e_number.val, &m_emp_num);
109 }
110};
111
112/* An index on Employee First Name */
114 public:
117
118 bool match(Ename_Record *record) override {
120 false, record->f_name, record->f_name_length, &m_emp_fname);
121 }
122};
123
124/* A structure to define a handle for table in plugin/component code. */
126 /* Current position instance */
128 /* Next position instance */
130
131 /* Current row for the table */
133
134 /* Index on table */
137
138 /* Index indicator */
139 unsigned int index_num;
140};
141
145int ename_rnd_init(PSI_table_handle *h, bool scan);
147int ename_index_init(PSI_table_handle *handle, uint idx, bool sorted,
148 PSI_index_handle **index);
150 unsigned int idx, int find_flag);
154 uint index);
157 unsigned int index);
160 unsigned int index);
162int ename_delete_all_rows(void);
163unsigned long long ename_get_row_count(void);
165
166#endif /* PLUGIN_PFS_TABLE_PLUGIN_pfs_example_employee_name_H_ */
Definition: pfs_example_employee_name.h:71
void set_at(Ename_POS *pos)
Definition: pfs_example_employee_name.h:91
unsigned int get_index()
Definition: pfs_example_employee_name.h:87
unsigned int m_index
Definition: pfs_example_employee_name.h:73
void set_at(unsigned int index)
Definition: pfs_example_employee_name.h:89
void next()
Definition: pfs_example_employee_name.h:83
bool has_more()
Definition: pfs_example_employee_name.h:79
Ename_POS()
Definition: pfs_example_employee_name.h:77
void set_after(Ename_POS *pos)
Definition: pfs_example_employee_name.h:93
void reset()
Definition: pfs_example_employee_name.h:85
~Ename_POS()=default
Definition: pfs_example_employee_name.h:113
bool match(Ename_Record *record) override
Definition: pfs_example_employee_name.h:118
PSI_plugin_key_string m_emp_fname
Definition: pfs_example_employee_name.h:115
char m_emp_fname_buffer[EMPLOYEE_NAME_LEN]
Definition: pfs_example_employee_name.h:116
Definition: pfs_example_employee_name.h:103
PSI_plugin_key_integer m_emp_num
Definition: pfs_example_employee_name.h:105
bool match(Ename_Record *record) override
Definition: pfs_example_employee_name.h:107
Definition: pfs_example_employee_name.h:96
virtual bool match(Ename_Record *record)=0
virtual ~Ename_index()=default
static int record
Definition: mysqltest.cc:194
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:63
int ename_delete_all_rows(void)
Definition: pfs_example_employee_name.cc:380
#define EMPLOYEEE_NAME_MAX_ROWS
Definition: pfs_example_employee_name.h:41
int ename_write_row_values(PSI_table_handle *handle)
Definition: pfs_example_employee_name.cc:248
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
int ename_rnd_init(PSI_table_handle *h, bool scan)
Definition: pfs_example_employee_name.cc:110
int ename_read_column_value(PSI_table_handle *handle, PSI_field *field, uint index)
Definition: pfs_example_employee_name.cc:223
int ename_update_row_values(PSI_table_handle *handle)
Definition: pfs_example_employee_name.cc:318
PFS_engine_table_share_proxy ename_st_share
Definition: pfs_example_employee_name.cc:27
const mysql_service_pfs_plugin_column_integer_v1_t * col_int_svc
Definition: pfs_example_plugin_employee.cc:89
unsigned long long ename_get_row_count(void)
Definition: pfs_example_employee_name.cc:390
int ename_update_column_value(PSI_table_handle *handle, PSI_field *field, unsigned int index)
Definition: pfs_example_employee_name.cc:337
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
const mysql_service_pfs_plugin_column_string_v2_t * col_string_svc
Definition: pfs_example_plugin_employee.cc:91
void init_ename_share(PFS_engine_table_share_proxy *share)
Definition: pfs_example_employee_name.cc:392
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 ename_reset_position(PSI_table_handle *handle)
Definition: pfs_example_employee_name.cc:215
int ename_write_column_value(PSI_table_handle *handle, PSI_field *field, unsigned int index)
Definition: pfs_example_employee_name.cc:290
int ename_index_next(PSI_table_handle *handle)
Definition: pfs_example_employee_name.cc:183
int ename_delete_row_values(PSI_table_handle *handle)
Definition: pfs_example_employee_name.cc:365
int ename_rnd_pos(PSI_table_handle *handle)
Definition: pfs_example_employee_name.cc:116
int ename_index_init(PSI_table_handle *handle, uint idx, bool sorted, PSI_index_handle **index)
Definition: pfs_example_employee_name.cc:129
#define EMPLOYEE_NAME_LEN
Definition: pfs_example_employee_name.h:38
int ename_index_read(PSI_index_handle *index, PSI_key_reader *reader, unsigned int idx, int find_flag)
Definition: pfs_example_employee_name.cc:161
int ename_rnd_next(PSI_table_handle *handle)
Definition: pfs_example_employee_name.cc:93
mysql_mutex_t LOCK_ename_records_array
Definition: pfs_example_employee_name.cc:28
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_pos PSI_pos
This is an opaque structure to denote cursor position in plugin/component code.
Definition: pfs_plugin_table_service.h:101
#define PSI_int
Definition: pfs_plugin_table_service.h:147
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
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
struct PSI_field PSI_field
This is an opaque structure to denote filed in plugin/component code.
Definition: pfs_plugin_table_service.h:92
#define SERVICE_TYPE(name)
Generates the standard Service type name.
Definition: service.h:75
Specifies macros to define Service Implementations.
Definition: pfs_example_employee_name.h:51
char l_name[EMPLOYEE_NAME_LEN]
Definition: pfs_example_employee_name.h:56
unsigned int l_name_length
Definition: pfs_example_employee_name.h:57
bool m_exist
Definition: pfs_example_employee_name.h:60
PSI_int e_number
Definition: pfs_example_employee_name.h:53
char f_name[EMPLOYEE_NAME_LEN]
Definition: pfs_example_employee_name.h:54
unsigned int f_name_length
Definition: pfs_example_employee_name.h:55
Definition: pfs_example_employee_name.h:125
Ename_POS m_next_pos
Definition: pfs_example_employee_name.h:129
Ename_index_by_emp_fname m_emp_fname_index
Definition: pfs_example_employee_name.h:136
Ename_POS m_pos
Definition: pfs_example_employee_name.h:127
Ename_index_by_emp_num m_emp_num_index
Definition: pfs_example_employee_name.h:135
Ename_Record current_row
Definition: pfs_example_employee_name.h:132
unsigned int index_num
Definition: pfs_example_employee_name.h:139
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:159
A structure to denote a key of type string in an index.
Definition: pfs_plugin_table_service.h:225
An instrumented mutex structure.
Definition: mysql_mutex_bits.h:49
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