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