MySQL 8.4.2
Source Code Documentation
pfs_example_country.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_POC_PLUGIN_COUNTRY_H_
25#define PLUGIN_PFS_TABLE_PLUGIN_POC_PLUGIN_COUNTRY_H_
26
29
31#include "thr_mutex.h"
32
33/* Global share pointer for pfs_example_country table */
35
36/* Maximum number of rows in the table */
37#define COUNTRY_MAX_ROWS 10
38
39/* A mutex instance to protect:
40 * - country_rows_in_table
41 * - country_next_available_index
42 * - country_records_array
43 */
45
46/* A structure to denote a single row of the table. */
48 public:
50 unsigned int name_length;
54 unsigned int country_code_length;
58 /* If there is a value in this row */
59 bool m_exist;
60};
61
62/**
63 * An array to keep rows of the tables.
64 * When a row is inserted in plugin table, it will be stored here.
65 * When a row is queried from plugin table, it will be fetched from here.
66 */
68
69/* A class to define position of cursor in table. */
71 private:
72 unsigned int m_index;
73
74 public:
75 ~Country_POS() = default;
77
78 bool has_more() {
79 if (m_index < COUNTRY_MAX_ROWS) return true;
80 return false;
81 }
82 void next() { m_index++; }
83
84 void reset() { m_index = 0; }
85
86 unsigned int get_index() { return m_index; }
87
88 void set_at(unsigned int index) { m_index = index; }
89
90 void set_at(Country_POS *pos) { m_index = pos->m_index; }
91
92 void set_after(Country_POS *pos) { m_index = pos->m_index + 1; }
93};
94
96 public:
98
99 virtual ~Country_index() = default;
100
101 virtual bool match(Country_record *record) = 0;
102
103 unsigned int m_fields;
104};
105
106/* An index on Country Name */
108 public:
111
114
115 bool match(Country_record *record) override {
116 if (m_fields >= 1) {
118 false, record->name, record->name_length, &m_country_name)) {
119 return false;
120 }
121 }
122
123 if (m_fields >= 2) {
124 if (!pc_string_srv->match_key_string(false, record->continent_name,
125 record->continent_name_length,
127 return false;
128 }
129 }
130
131 return true;
132 }
133};
134
135/* A structure to define a handle for table in plugin/component code. */
137 /* Current position instance */
139 /* Next position instance */
141
142 /* Current row for the table */
144
145 /* Current index for the table */
147
148 /* Index indicator */
149 unsigned int index_num;
150};
151
155int country_rnd_init(PSI_table_handle *h, bool scan);
157int country_index_init(PSI_table_handle *handle, unsigned int idx, bool sorted,
158 PSI_index_handle **index);
160 unsigned int idx, int find_flag);
164 unsigned int index);
167 unsigned int index);
170 unsigned int index);
173unsigned long long country_get_row_count(void);
175
176#endif /* PLUGIN_PFS_TABLE_PLUGIN_POC_PLUGIN_COUNTRY_H_ */
Definition: pfs_example_country.h:70
void set_at(unsigned int index)
Definition: pfs_example_country.h:88
~Country_POS()=default
Country_POS()
Definition: pfs_example_country.h:76
unsigned int m_index
Definition: pfs_example_country.h:72
bool has_more()
Definition: pfs_example_country.h:78
void set_after(Country_POS *pos)
Definition: pfs_example_country.h:92
void set_at(Country_POS *pos)
Definition: pfs_example_country.h:90
void next()
Definition: pfs_example_country.h:82
unsigned int get_index()
Definition: pfs_example_country.h:86
void reset()
Definition: pfs_example_country.h:84
Definition: pfs_example_country.h:107
bool match(Country_record *record) override
Definition: pfs_example_country.h:115
PSI_plugin_key_string m_country_name
Definition: pfs_example_country.h:112
PSI_plugin_key_string m_continent_name
Definition: pfs_example_country.h:109
char m_country_name_buffer[COUNTRY_NAME_LEN]
Definition: pfs_example_country.h:113
char m_continent_name_buffer[CONTINENT_NAME_LEN]
Definition: pfs_example_country.h:110
Definition: pfs_example_country.h:95
Country_index()
Definition: pfs_example_country.h:97
unsigned int m_fields
Definition: pfs_example_country.h:103
virtual bool match(Country_record *record)=0
virtual ~Country_index()=default
Definition: pfs_example_country.h:47
char country_code[COUNTRY_CODE_LEN]
Definition: pfs_example_country.h:53
char name[COUNTRY_NAME_LEN]
Definition: pfs_example_country.h:49
unsigned int continent_name_length
Definition: pfs_example_country.h:52
PSI_year year
Definition: pfs_example_country.h:55
bool m_exist
Definition: pfs_example_country.h:59
PSI_bigint population
Definition: pfs_example_country.h:56
unsigned int country_code_length
Definition: pfs_example_country.h:54
PSI_double growth_factor
Definition: pfs_example_country.h:57
char continent_name[CONTINENT_NAME_LEN]
Definition: pfs_example_country.h:51
unsigned int name_length
Definition: pfs_example_country.h:50
static int record
Definition: mysqltest.cc:195
const mysql_service_pfs_plugin_column_string_v2_t * pc_string_srv
Definition: pfs.cc:44
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
#define COUNTRY_CODE_LEN
Definition: pfs_example_component_population.h:47
#define CONTINENT_NAME_LEN
Definition: pfs_example_component_population.h:46
#define COUNTRY_NAME_LEN
Definition: pfs_example_component_population.h:45
int country_index_read(PSI_index_handle *index, PSI_key_reader *reader, unsigned int idx, int find_flag)
Definition: pfs_example_country.cc:175
native_mutex_t LOCK_country_records_array
Definition: pfs_example_country.cc:30
#define COUNTRY_MAX_ROWS
Definition: pfs_example_country.h:37
int country_delete_all_rows(void)
Definition: pfs_example_country.cc:423
int country_update_row_values(PSI_table_handle *handle)
Definition: pfs_example_country.cc:351
unsigned long long country_get_row_count(void)
Definition: pfs_example_country.cc:433
int country_rnd_next(PSI_table_handle *handle)
Definition: pfs_example_country.cc:109
int country_write_column_value(PSI_table_handle *handle, PSI_field *field, unsigned int index)
Definition: pfs_example_country.cc:311
int country_read_column_value(PSI_table_handle *handle, PSI_field *field, unsigned int index)
Definition: pfs_example_country.cc:234
void init_country_share(PFS_engine_table_share_proxy *share)
Definition: pfs_example_country.cc:435
int country_index_next(PSI_table_handle *handle)
Definition: pfs_example_country.cc:197
int country_rnd_init(PSI_table_handle *h, bool scan)
Definition: pfs_example_country.cc:126
int country_write_row_values(PSI_table_handle *handle)
Definition: pfs_example_country.cc:269
int country_delete_row_values(PSI_table_handle *handle)
Definition: pfs_example_country.cc:408
PFS_engine_table_share_proxy country_st_share
Definition: pfs_example_country.cc:29
PSI_table_handle * country_open_table(PSI_pos **pos)
Instantiate Country_Table_Handle at plugin code when corresponding table in performance schema is ope...
Definition: pfs_example_country.cc:71
void country_close_table(PSI_table_handle *handle)
Destroy the Country_Table_Handle at plugin code when corresponding table in performance schema is clo...
Definition: pfs_example_country.cc:88
void country_reset_position(PSI_table_handle *handle)
Definition: pfs_example_country.cc:226
int country_index_init(PSI_table_handle *handle, unsigned int idx, bool sorted, PSI_index_handle **index)
Definition: pfs_example_country.cc:142
int country_update_column_value(PSI_table_handle *handle, PSI_field *field, unsigned int index)
Definition: pfs_example_country.cc:369
Country_record country_records_array[COUNTRY_MAX_ROWS]
An array to keep rows of the tables.
Definition: pfs_example_country.cc:38
int country_rnd_pos(PSI_table_handle *handle)
Definition: pfs_example_country.cc:129
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_bigint
Definition: pfs_plugin_table_service.h:150
#define PSI_year
Definition: pfs_plugin_table_service.h:152
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
Specifies macros to define Service Implementations.
Definition: pfs_example_country.h:136
Country_POS m_pos
Definition: pfs_example_country.h:138
Country_record current_row
Definition: pfs_example_country.h:143
Country_index_by_name m_index
Definition: pfs_example_country.h:146
unsigned int index_num
Definition: pfs_example_country.h:149
Country_POS m_next_pos
Definition: pfs_example_country.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
Definition: pfs_plugin_table_service.h:136
A structure to denote a key of type string in an index.
Definition: pfs_plugin_table_service.h:226
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
MySQL mutex implementation.
pthread_mutex_t native_mutex_t
Definition: thr_mutex_bits.h:55