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