MySQL 8.0.32
Source Code Documentation
pfs_example_country.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2022, 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;
55 /* If there is a value in this row */
56 bool m_exist;
57};
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. */
68 private:
69 unsigned int m_index;
70
71 public:
72 ~Country_POS() = default;
74
75 bool has_more() {
76 if (m_index < COUNTRY_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(Country_POS *pos) { m_index = pos->m_index; }
88
89 void set_after(Country_POS *pos) { m_index = pos->m_index + 1; }
90};
91
93 public:
95
96 virtual ~Country_index() = default;
97
98 virtual bool match(Country_record *record) = 0;
99
100 unsigned int m_fields;
101};
102
103/* An index on Country Name */
105 public:
108
111
112 bool match(Country_record *record) override {
113 if (m_fields >= 1) {
114 if (!pc_string_srv->match_key_string(
115 false, record->name, record->name_length, &m_country_name)) {
116 return false;
117 }
118 }
119
120 if (m_fields >= 2) {
121 if (!pc_string_srv->match_key_string(false, record->continent_name,
122 record->continent_name_length,
124 return false;
125 }
126 }
127
128 return true;
129 }
130};
131
132/* A structure to define a handle for table in plugin/component code. */
134 /* Current position instance */
136 /* Next position instance */
138
139 /* Current row for the table */
141
142 /* Current index for the table */
144
145 /* Index indicator */
146 unsigned int index_num;
147};
148
152int country_rnd_init(PSI_table_handle *h, bool scan);
154int country_index_init(PSI_table_handle *handle, unsigned int idx, bool sorted,
155 PSI_index_handle **index);
157 unsigned int idx, int find_flag);
161 unsigned int index);
164 unsigned int index);
167 unsigned int index);
170unsigned long long country_get_row_count(void);
172
173#endif /* PLUGIN_PFS_TABLE_PLUGIN_POC_PLUGIN_COUNTRY_H_ */
Definition: pfs_example_country.h:67
void set_at(unsigned int index)
Definition: pfs_example_country.h:85
~Country_POS()=default
Country_POS()
Definition: pfs_example_country.h:73
unsigned int m_index
Definition: pfs_example_country.h:69
bool has_more()
Definition: pfs_example_country.h:75
void set_after(Country_POS *pos)
Definition: pfs_example_country.h:89
void set_at(Country_POS *pos)
Definition: pfs_example_country.h:87
void next()
Definition: pfs_example_country.h:79
unsigned int get_index()
Definition: pfs_example_country.h:83
void reset()
Definition: pfs_example_country.h:81
Definition: pfs_example_country.h:104
bool match(Country_record *record) override
Definition: pfs_example_country.h:112
PSI_plugin_key_string m_country_name
Definition: pfs_example_country.h:109
PSI_plugin_key_string m_continent_name
Definition: pfs_example_country.h:106
char m_country_name_buffer[COUNTRY_NAME_LEN]
Definition: pfs_example_country.h:110
char m_continent_name_buffer[CONTINENT_NAME_LEN]
Definition: pfs_example_country.h:107
Definition: pfs_example_country.h:92
Country_index()
Definition: pfs_example_country.h:94
unsigned int m_fields
Definition: pfs_example_country.h:100
virtual bool match(Country_record *record)=0
virtual ~Country_index()=default
Definition: pfs_example_country.h:46
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:52
bool m_exist
Definition: pfs_example_country.h:56
PSI_bigint population
Definition: pfs_example_country.h:53
PSI_double growth_factor
Definition: pfs_example_country.h:54
char continent_name[CONTINENT_NAME_LEN]
Definition: pfs_example_country.h:50
unsigned int name_length
Definition: pfs_example_country.h:49
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 CONTINENT_NAME_LEN
Definition: pfs_example_component_population.h:44
#define COUNTRY_NAME_LEN
Definition: pfs_example_component_population.h:43
int country_index_read(PSI_index_handle *index, PSI_key_reader *reader, unsigned int idx, int find_flag)
Definition: pfs_example_country.cc:171
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:405
int country_update_row_values(PSI_table_handle *handle)
Definition: pfs_example_country.cc:338
unsigned long long country_get_row_count(void)
Definition: pfs_example_country.cc:415
int country_rnd_next(PSI_table_handle *handle)
Definition: pfs_example_country.cc:105
int country_write_column_value(PSI_table_handle *handle, PSI_field *field, unsigned int index)
Definition: pfs_example_country.cc:303
int country_read_column_value(PSI_table_handle *handle, PSI_field *field, unsigned int index)
Definition: pfs_example_country.cc:230
void init_country_share(PFS_engine_table_share_proxy *share)
Definition: pfs_example_country.cc:417
int country_index_next(PSI_table_handle *handle)
Definition: pfs_example_country.cc:193
int country_rnd_init(PSI_table_handle *h, bool scan)
Definition: pfs_example_country.cc:122
int country_write_row_values(PSI_table_handle *handle)
Definition: pfs_example_country.cc:261
int country_delete_row_values(PSI_table_handle *handle)
Definition: pfs_example_country.cc:390
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:86
void country_reset_position(PSI_table_handle *handle)
Definition: pfs_example_country.cc:222
int country_index_init(PSI_table_handle *handle, unsigned int idx, bool sorted, PSI_index_handle **index)
Definition: pfs_example_country.cc:138
int country_update_column_value(PSI_table_handle *handle, PSI_field *field, unsigned int index)
Definition: pfs_example_country.cc:356
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:125
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:133
Country_POS m_pos
Definition: pfs_example_country.h:135
Country_record current_row
Definition: pfs_example_country.h:140
Country_index_by_name m_index
Definition: pfs_example_country.h:143
unsigned int index_num
Definition: pfs_example_country.h:146
Country_POS m_next_pos
Definition: pfs_example_country.h:137
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:444
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
Definition: mi_test3.cc:54
MySQL mutex implementation.
pthread_mutex_t native_mutex_t
Definition: thr_mutex_bits.h:54