MySQL 8.0.39
Source Code Documentation
ha_perfschema.h
Go to the documentation of this file.
1/* Copyright (c) 2008, 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 HA_PERFSCHEMA_H
25#define HA_PERFSCHEMA_H
26
27#include <sys/types.h>
28
29#include "my_base.h"
30#include "my_inttypes.h"
31#include "sql/handler.h" /* class handler */
32#include "sql/sql_const.h"
33#include "thr_lock.h"
34
36class THD;
37namespace dd {
38class Table;
39} // namespace dd
40/**
41 @file storage/perfschema/ha_perfschema.h
42 Performance schema storage engine (declarations).
43
44 @defgroup performance_schema_engine Performance Schema Engine
45 @ingroup performance_schema_implementation
46 @{
47*/
49struct TABLE;
50struct TABLE_SHARE;
51
52/** Name of the performance schema engine. */
53extern const char *pfs_engine_name;
54
55/** A handler for a PERFORMANCE_SCHEMA table. */
56class ha_perfschema : public handler {
57 public:
58 /**
59 Create a new performance schema table handle on a table.
60 @param hton storage engine handler singleton
61 @param share table share
62 */
64
65 ~ha_perfschema() override;
66
67 const char *table_type() const override { return pfs_engine_name; }
68
69 const char *index_type(uint key_number);
70
71 const char **bas_ext() const;
72
73 /** Capabilities of the performance schema tables. */
74 ulonglong table_flags() const override {
75 /*
76 About HA_FAST_KEY_READ:
77
78 The storage engine ::rnd_pos() method is fast to locate records by key,
79 so HA_FAST_KEY_READ is technically true, but the record content can be
80 overwritten between ::rnd_next() and ::rnd_pos(), because all the P_S
81 data is volatile.
82 The HA_FAST_KEY_READ flag is not advertised, to force the optimizer
83 to cache records instead, to provide more consistent records.
84 For example, consider the following statement:
85 - select * from P_S.EVENTS_WAITS_HISTORY_LONG where THREAD_ID=<n>
86 order by ...
87 With HA_FAST_KEY_READ, it can return records where "THREAD_ID=<n>"
88 is false, because the where clause was evaluated to true after
89 ::rnd_pos(), then the content changed, then the record was fetched by
90 key using ::rnd_pos().
91 Without HA_FAST_KEY_READ, the optimizer reads all columns and never
92 calls ::rnd_pos(), so it is guaranteed to return only thread <n>
93 records.
94 */
98 }
99
100 /**
101 Operations supported by indexes.
102 */
103 ulong index_flags(uint idx, uint part, bool all_parts) const override;
104
106 return HA_KEY_ALG_HASH;
107 }
108
110 return HA_MAX_REC_LENGTH;
111 }
112
113 uint max_supported_keys() const override { return MAX_KEY; }
114
115 uint max_supported_key_parts() const override { return MAX_REF_PARTS; }
116
117 uint max_supported_key_length() const override { return MAX_KEY_LENGTH; }
118
120 [[maybe_unused]]) const override {
121 return MAX_KEY_LENGTH;
122 }
123
124 int index_init(uint idx, bool sorted) override;
125 int index_end() override;
126 int index_read(uchar *buf, const uchar *key, uint key_len,
127 enum ha_rkey_function find_flag) override;
128 int index_next(uchar *buf) override;
129 int index_next_same(uchar *buf, const uchar *key, uint keylen) override;
130
132
133 double scan_time() override { return 1.0; }
134
135 /**
136 Open a performance schema table.
137 @param name the table to open
138 @param mode unused
139 @param test_if_locked unused
140 @param table_def unused
141 @return 0 on success
142 */
143 int open(const char *name, int mode, uint test_if_locked,
144 const dd::Table *table_def) override;
145
146 /**
147 Close a table handle.
148 @sa open.
149 */
150 int close() override;
151
152 /**
153 Write a row.
154 @param buf the row to write
155 @return 0 on success
156 */
157 int write_row(uchar *buf) override;
158
159 void use_hidden_primary_key() override;
160
161 /**
162 Update a row.
163 @param old_data the row old values
164 @param new_data the row new values
165 @return 0 on success
166 */
167 int update_row(const uchar *old_data, uchar *new_data) override;
168
169 /**
170 Delete a row.
171 @param buf the row to delete
172 @return 0 on success
173 */
174 int delete_row(const uchar *buf) override;
175
176 int rnd_init(bool scan) override;
177
178 /**
179 Scan end.
180 @sa rnd_init.
181 */
182 int rnd_end() override;
183
184 /**
185 Iterator, fetch the next row.
186 @param[out] buf the row fetched.
187 @return 0 on success
188 */
189 int rnd_next(uchar *buf) override;
190
191 /**
192 Iterator, fetch the row at a given position.
193 @param[out] buf the row fetched.
194 @param pos the row position
195 @return 0 on success
196 */
197 int rnd_pos(uchar *buf, uchar *pos) override;
198
199 /**
200 Read the row current position.
201 @param record the current row
202 */
203 void position(const uchar *record) override;
204
205 int info(uint) override;
206
207 int delete_all_rows() override;
208
209 int truncate(dd::Table *table_def) override;
210
211 int delete_table(const char *from, const dd::Table *table_def) override;
212
213 int rename_table(const char *from, const char *to,
214 const dd::Table *from_table_def,
215 dd::Table *to_table_def) override;
216
217 int create(const char *name, TABLE *table_arg, HA_CREATE_INFO *create_info,
218 dd::Table *table_def) override;
219
221 enum thr_lock_type lock_type) override;
222
223 void print_error(int error, myf errflags) override;
224
225 private:
226 /**
227 Check if the caller is a replication thread or the caller is called
228 by a client thread executing base64 encoded BINLOG statement.
229
230 In theory, performance schema tables are not supposed to be replicated.
231 This is true and enforced starting with MySQL 5.6.10.
232 In practice, in previous versions such as MySQL 5.5 (GA) or earlier 5.6
233 (non GA) DML on performance schema tables could end up written in the
234 binlog,
235 both in STATEMENT and ROW format.
236 While these records are not supposed to be there, they are found when:
237 - performing replication from a 5.5 master to a 5.6 slave during
238 upgrades
239 - performing replication from 5.5 (performance_schema enabled)
240 to a 5.6 slave
241 - performing point in time recovery in 5.6 with old archived logs.
242
243 This API detects when the code calling the performance schema storage
244 engine is a slave thread or whether the code calling is the client thread
245 executing a BINLOG statement.
246
247 This API acts as a late filter for the above mentioned cases.
248
249 For ROW format, @see Rows_log_event::do_apply_event()
250
251 */
252 bool is_executed_by_slave() const;
253
254 /** MySQL lock */
256 /** Performance schema table share for this table handler. */
258 /** Performance schema table cursor. */
260};
261
262/** @} (end of group performance_schema_engine) */
263#endif
app_data_ptr new_data(u_int n, char *val, cons_type consensus)
An abstract PERFORMANCE_SCHEMA table.
Definition: pfs_engine_table.h:70
For each client connection we create a separate thread with THD serving as a thread/connection descri...
Definition: sql_lexer_thd.h:34
Definition: table.h:47
A handler for a PERFORMANCE_SCHEMA table.
Definition: ha_perfschema.h:56
void use_hidden_primary_key() override
use_hidden_primary_key() is called in case of an update/delete when (table_flags() and HA_PRIMARY_KEY...
Definition: ha_perfschema.cc:1645
ulong index_flags(uint idx, uint part, bool all_parts) const override
Operations supported by indexes.
Definition: ha_perfschema.cc:1867
uint max_supported_record_length() const override
Definition: ha_perfschema.h:109
int open(const char *name, int mode, uint test_if_locked, const dd::Table *table_def) override
Open a performance schema table.
Definition: ha_perfschema.cc:1589
THR_LOCK_DATA m_thr_lock
MySQL lock.
Definition: ha_perfschema.h:255
enum ha_key_alg get_default_index_algorithm() const override
Get default key algorithm for SE.
Definition: ha_perfschema.h:105
int rename_table(const char *from, const char *to, const dd::Table *from_table_def, dd::Table *to_table_def) override
Default rename_table() and delete_table() rename/delete files with a given name and extensions from h...
Definition: ha_perfschema.cc:1805
int index_end() override
Definition: ha_perfschema.cc:1917
PFS_engine_table_share * m_table_share
Performance schema table share for this table handler.
Definition: ha_perfschema.h:257
void position(const uchar *record) override
Read the row current position.
Definition: ha_perfschema.cc:1733
THR_LOCK_DATA ** store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type) override
Is not invoked for non-transactional temporary tables.
Definition: ha_perfschema.cc:1790
int delete_row(const uchar *buf) override
Delete a row.
Definition: ha_perfschema.cc:1672
~ha_perfschema() override
int truncate(dd::Table *table_def) override
Quickly remove all rows from a table.
Definition: ha_perfschema.cc:1788
int delete_all_rows() override
Delete all rows in a table.
Definition: ha_perfschema.cc:1767
ha_rows estimate_rows_upper_bound() override
Return upper bound of current number of records in the table (max.
Definition: ha_perfschema.h:131
int index_read(uchar *buf, const uchar *key, uint key_len, enum ha_rkey_function find_flag) override
Positions an index cursor to the index specified in the handle.
Definition: ha_perfschema.cc:1932
double scan_time() override
Definition: ha_perfschema.h:133
uint max_supported_key_length() const override
Definition: ha_perfschema.h:117
int rnd_end() override
Scan end.
Definition: ha_perfschema.cc:1706
const char * index_type(uint key_number)
Definition: ha_perfschema.cc:1865
ulonglong table_flags() const override
Capabilities of the performance schema tables.
Definition: ha_perfschema.h:74
int create(const char *name, TABLE *table_arg, HA_CREATE_INFO *create_info, dd::Table *table_def) override
Create table (implementation).
Definition: ha_perfschema.cc:1811
uint max_supported_key_parts() const override
Definition: ha_perfschema.h:115
int delete_table(const char *from, const dd::Table *table_def) override
Delete a table.
Definition: ha_perfschema.cc:1800
int info(uint) override
General method to gather info from handler.
Definition: ha_perfschema.cc:1755
int rnd_init(bool scan) override
rnd_init() can be called two times without rnd_end() in between (it only makes sense if scan=1).
Definition: ha_perfschema.cc:1684
int index_next_same(uchar *buf, const uchar *key, uint keylen) override
Reads the next row matching the given key value.
Definition: ha_perfschema.cc:1990
uint max_supported_key_part_length(HA_CREATE_INFO *create_info) const override
Definition: ha_perfschema.h:119
int rnd_pos(uchar *buf, uchar *pos) override
Iterator, fetch the row at a given position.
Definition: ha_perfschema.cc:1740
int index_init(uint idx, bool sorted) override
Initializes a handle to use an index.
Definition: ha_perfschema.cc:1893
ha_perfschema(handlerton *hton, TABLE_SHARE *share)
Create a new performance schema table handle on a table.
Definition: ha_perfschema.cc:1584
int update_row(const uchar *old_data, uchar *new_data) override
Update a row.
Definition: ha_perfschema.cc:1655
void print_error(int error, myf errflags) override
Print error that we got from handler function.
Definition: ha_perfschema.cc:1836
int write_row(uchar *buf) override
Write a row.
Definition: ha_perfschema.cc:1628
uint max_supported_keys() const override
Definition: ha_perfschema.h:113
int close() override
Close a table handle.
Definition: ha_perfschema.cc:1613
const char * table_type() const override
The following can be called without an open handler.
Definition: ha_perfschema.h:67
const char ** bas_ext() const
int index_next(uchar *buf) override
Reads the next row from a cursor, which must have previously been positioned by index_read.
Definition: ha_perfschema.cc:1969
int rnd_next(uchar *buf) override
Iterator, fetch the next row.
Definition: ha_perfschema.cc:1714
bool is_executed_by_slave() const
Check if the caller is a replication thread or the caller is called by a client thread executing base...
Definition: ha_perfschema.cc:2008
PFS_engine_table * m_table
Performance schema table cursor.
Definition: ha_perfschema.h:259
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4414
A table definition from the master.
Definition: rpl_utility.h:248
const char * pfs_engine_name
Name of the performance schema engine.
Definition: ha_perfschema.cc:1561
This file includes constants used by all storage engines.
ha_key_alg
Definition: my_base.h:97
@ HA_KEY_ALG_HASH
Definition: my_base.h:109
ha_rkey_function
Definition: my_base.h:78
my_off_t ha_rows
Definition: my_base.h:1140
#define HA_POS_ERROR
Definition: my_base.h:1142
#define HA_NULL_PART_KEY
Some key part is nullable.
Definition: my_base.h:496
Some integer typedefs for easier portability.
int myf
Definition: my_inttypes.h:94
unsigned long long int ulonglong
Definition: my_inttypes.h:56
unsigned char uchar
Definition: my_inttypes.h:52
static int record
Definition: mysqltest.cc:188
Definition: buf0block_hint.cc:30
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
mode
Definition: file_handle.h:60
required string key
Definition: replication_asynchronous_connection_failover.proto:60
#define HA_MAX_REC_LENGTH
Definition: handler.h:617
#define HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Definition: handler.h:297
#define HA_NO_TRANSACTIONS
Definition: handler.h:210
#define HA_NULL_IN_KEY
Definition: handler.h:245
#define HA_NO_AUTO_INCREMENT
Definition: handler.h:314
File containing constants that can be used throughout the server.
constexpr const unsigned int MAX_KEY
Definition: sql_const.h:46
constexpr const unsigned int MAX_REF_PARTS
Definition: sql_const.h:47
constexpr const unsigned int MAX_KEY_LENGTH
Definition: sql_const.h:48
case opt name
Definition: sslopt-case.h:33
Struct to hold information about the table that should be created.
Definition: handler.h:3045
A PERFORMANCE_SCHEMA table share.
Definition: pfs_engine_table.h:358
This structure is shared between different table objects.
Definition: table.h:690
Definition: table.h:1399
Definition: thr_lock.h:124
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2622
thr_lock_type
Definition: thr_lock.h:51
unsigned int uint
Definition: uca9-dump.cc:75