MySQL 9.0.0
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 /** Capabilities of the performance schema tables. */
72 ulonglong table_flags() const override {
73 /*
74 About HA_FAST_KEY_READ:
75
76 The storage engine ::rnd_pos() method is fast to locate records by key,
77 so HA_FAST_KEY_READ is technically true, but the record content can be
78 overwritten between ::rnd_next() and ::rnd_pos(), because all the P_S
79 data is volatile.
80 The HA_FAST_KEY_READ flag is not advertised, to force the optimizer
81 to cache records instead, to provide more consistent records.
82 For example, consider the following statement:
83 - select * from P_S.EVENTS_WAITS_HISTORY_LONG where THREAD_ID=<n>
84 order by ...
85 With HA_FAST_KEY_READ, it can return records where "THREAD_ID=<n>"
86 is false, because the where clause was evaluated to true after
87 ::rnd_pos(), then the content changed, then the record was fetched by
88 key using ::rnd_pos().
89 Without HA_FAST_KEY_READ, the optimizer reads all columns and never
90 calls ::rnd_pos(), so it is guaranteed to return only thread <n>
91 records.
92 */
96 }
97
98 /**
99 Operations supported by indexes.
100 */
101 ulong index_flags(uint idx, uint part, bool all_parts) const override;
102
104 return HA_KEY_ALG_HASH;
105 }
106
107 uint max_supported_record_length() const override {
108 return HA_MAX_REC_LENGTH;
109 }
110
111 uint max_supported_keys() const override { return MAX_KEY; }
112
113 uint max_supported_key_parts() const override { return MAX_REF_PARTS; }
114
115 uint max_supported_key_length() const override { return MAX_KEY_LENGTH; }
116
118 [[maybe_unused]]) const override {
119 return MAX_KEY_LENGTH;
120 }
121
122 int index_init(uint idx, bool sorted) override;
123 int index_end() override;
124 int index_read(uchar *buf, const uchar *key, uint key_len,
125 enum ha_rkey_function find_flag) override;
126 int index_next(uchar *buf) override;
127 int index_next_same(uchar *buf, const uchar *key, uint keylen) override;
128
130
131 double scan_time() override { return 1.0; }
132
133 /**
134 Open a performance schema table.
135 @param name the table to open
136 @param mode unused
137 @param test_if_locked unused
138 @param table_def unused
139 @return 0 on success
140 */
141 int open(const char *name, int mode, uint test_if_locked,
142 const dd::Table *table_def) override;
143
144 /**
145 Close a table handle.
146 @sa open.
147 */
148 int close() override;
149
150 /**
151 Write a row.
152 @param buf the row to write
153 @return 0 on success
154 */
155 int write_row(uchar *buf) override;
156
157 void use_hidden_primary_key() override;
158
159 /**
160 Update a row.
161 @param old_data the row old values
162 @param new_data the row new values
163 @return 0 on success
164 */
165 int update_row(const uchar *old_data, uchar *new_data) override;
166
167 /**
168 Delete a row.
169 @param buf the row to delete
170 @return 0 on success
171 */
172 int delete_row(const uchar *buf) override;
173
174 int rnd_init(bool scan) override;
175
176 /**
177 Scan end.
178 @sa rnd_init.
179 */
180 int rnd_end() override;
181
182 /**
183 Iterator, fetch the next row.
184 @param[out] buf the row fetched.
185 @return 0 on success
186 */
187 int rnd_next(uchar *buf) override;
188
189 /**
190 Iterator, fetch the row at a given position.
191 @param[out] buf the row fetched.
192 @param pos the row position
193 @return 0 on success
194 */
195 int rnd_pos(uchar *buf, uchar *pos) override;
196
197 /**
198 Read the row current position.
199 @param record the current row
200 */
201 void position(const uchar *record) override;
202
203 int info(uint) override;
204
205 int delete_all_rows() override;
206
207 int truncate(dd::Table *table_def) override;
208
209 int delete_table(const char *from, const dd::Table *table_def) override;
210
211 int rename_table(const char *from, const char *to,
212 const dd::Table *from_table_def,
213 dd::Table *to_table_def) override;
214
215 int create(const char *name, TABLE *table_arg, HA_CREATE_INFO *create_info,
216 dd::Table *table_def) override;
217
219 enum thr_lock_type lock_type) override;
220
221 void print_error(int error, myf errflags) override;
222
223 private:
224 /**
225 Check if the caller is a replication thread or the caller is called
226 by a client thread executing base64 encoded BINLOG statement.
227
228 In theory, performance schema tables are not supposed to be replicated.
229 This is true and enforced starting with MySQL 5.6.10.
230 In practice, in previous versions such as MySQL 5.5 (GA) or earlier 5.6
231 (non GA) DML on performance schema tables could end up written in the
232 binlog,
233 both in STATEMENT and ROW format.
234 While these records are not supposed to be there, they are found when:
235 - performing replication from a 5.5 master to a 5.6 slave during
236 upgrades
237 - performing replication from 5.5 (performance_schema enabled)
238 to a 5.6 slave
239 - performing point in time recovery in 5.6 with old archived logs.
240
241 This API detects when the code calling the performance schema storage
242 engine is a slave thread or whether the code calling is the client thread
243 executing a BINLOG statement.
244
245 This API acts as a late filter for the above mentioned cases.
246
247 For ROW format, @see Rows_log_event::do_apply_event()
248
249 */
250 bool is_executed_by_slave() const;
251
252 /** MySQL lock */
254 /** Performance schema table share for this table handler. */
256 /** Performance schema table cursor. */
258};
259
260/** @} (end of group performance_schema_engine) */
261#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:36
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:1674
ulong index_flags(uint idx, uint part, bool all_parts) const override
Operations supported by indexes.
Definition: ha_perfschema.cc:1896
uint max_supported_record_length() const override
Definition: ha_perfschema.h:107
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:1618
THR_LOCK_DATA m_thr_lock
MySQL lock.
Definition: ha_perfschema.h:253
enum ha_key_alg get_default_index_algorithm() const override
Get default key algorithm for SE.
Definition: ha_perfschema.h:103
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:1834
int index_end() override
Definition: ha_perfschema.cc:1946
PFS_engine_table_share * m_table_share
Performance schema table share for this table handler.
Definition: ha_perfschema.h:255
void position(const uchar *record) override
Read the row current position.
Definition: ha_perfschema.cc:1762
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:1819
int delete_row(const uchar *buf) override
Delete a row.
Definition: ha_perfschema.cc:1701
~ha_perfschema() override
int truncate(dd::Table *table_def) override
Quickly remove all rows from a table.
Definition: ha_perfschema.cc:1817
int delete_all_rows() override
Delete all rows in a table.
Definition: ha_perfschema.cc:1796
ha_rows estimate_rows_upper_bound() override
Return upper bound of current number of records in the table (max.
Definition: ha_perfschema.h:129
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:1961
double scan_time() override
Definition: ha_perfschema.h:131
uint max_supported_key_length() const override
Definition: ha_perfschema.h:115
int rnd_end() override
Scan end.
Definition: ha_perfschema.cc:1735
const char * index_type(uint key_number)
Definition: ha_perfschema.cc:1894
ulonglong table_flags() const override
Capabilities of the performance schema tables.
Definition: ha_perfschema.h:72
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:1840
uint max_supported_key_parts() const override
Definition: ha_perfschema.h:113
int delete_table(const char *from, const dd::Table *table_def) override
Delete a table.
Definition: ha_perfschema.cc:1829
int info(uint) override
General method to gather info from handler.
Definition: ha_perfschema.cc:1784
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:1713
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:2019
uint max_supported_key_part_length(HA_CREATE_INFO *create_info) const override
Definition: ha_perfschema.h:117
int rnd_pos(uchar *buf, uchar *pos) override
Iterator, fetch the row at a given position.
Definition: ha_perfschema.cc:1769
int index_init(uint idx, bool sorted) override
Initializes a handle to use an index.
Definition: ha_perfschema.cc:1922
ha_perfschema(handlerton *hton, TABLE_SHARE *share)
Create a new performance schema table handle on a table.
Definition: ha_perfschema.cc:1613
int update_row(const uchar *old_data, uchar *new_data) override
Update a row.
Definition: ha_perfschema.cc:1684
void print_error(int error, myf errflags) override
Print error that we got from handler function.
Definition: ha_perfschema.cc:1865
int write_row(uchar *buf) override
Write a row.
Definition: ha_perfschema.cc:1657
uint max_supported_keys() const override
Definition: ha_perfschema.h:111
int close() override
Close a table handle.
Definition: ha_perfschema.cc:1642
const char * table_type() const override
The following can be called without an open handler.
Definition: ha_perfschema.h:67
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:1998
int rnd_next(uchar *buf) override
Iterator, fetch the next row.
Definition: ha_perfschema.cc:1743
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:2037
PFS_engine_table * m_table
Performance schema table cursor.
Definition: ha_perfschema.h:257
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4573
A table definition from the master.
Definition: rpl_utility.h:249
const char * pfs_engine_name
Name of the performance schema engine.
Definition: ha_perfschema.cc:1590
This file includes constants used by all storage engines.
ha_key_alg
Definition: my_base.h:98
@ HA_KEY_ALG_HASH
Definition: my_base.h:110
ha_rkey_function
Definition: my_base.h:78
my_off_t ha_rows
Definition: my_base.h:1141
#define HA_POS_ERROR
Definition: my_base.h:1143
#define HA_NULL_PART_KEY
Some key part is nullable.
Definition: my_base.h:497
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:195
Definition: buf0block_hint.cc:30
The version of the current data dictionary table definitions.
Definition: dictionary_client.h:43
mode
Definition: file_handle.h:61
required string key
Definition: replication_asynchronous_connection_failover.proto:60
#define HA_MAX_REC_LENGTH
Definition: handler.h:625
#define HA_PRIMARY_KEY_REQUIRED_FOR_DELETE
Definition: handler.h:305
#define HA_NO_TRANSACTIONS
Definition: handler.h:218
#define HA_NULL_IN_KEY
Definition: handler.h:253
#define HA_NO_AUTO_INCREMENT
Definition: handler.h:322
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:29
Struct to hold information about the table that should be created.
Definition: handler.h:3202
A PERFORMANCE_SCHEMA table share.
Definition: pfs_engine_table.h:358
This structure is shared between different table objects.
Definition: table.h:701
Definition: table.h:1407
Definition: thr_lock.h:124
handlerton is a singleton structure - one instance per storage engine - to provide access to storage ...
Definition: handler.h:2734
thr_lock_type
Definition: thr_lock.h:51