MySQL 8.0.39
Source Code Documentation
mysql_statement.h
Go to the documentation of this file.
1/* Copyright (c) 2010, 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 MYSQL_STATEMENT_H
25#define MYSQL_STATEMENT_H
26
27/**
28 @file include/mysql/psi/mysql_statement.h
29 Instrumentation helpers for statements.
30*/
31
32#include "my_compiler.h"
33
34/* HAVE_PSI_*_INTERFACE */
35#include "my_psi_config.h" // IWYU pragma: keep
36
37#include "my_inttypes.h"
38#include "mysql/psi/psi_stage.h"
40
41#if defined(MYSQL_SERVER) || defined(PFS_DIRECT_CALL)
42/* PSI_STATEMENT_CALL() as direct call. */
43/* PSI_DIGEST_CALL() as direct call. */
44#include "pfs_statement_provider.h" // IWYU pragma: keep
45/* PSI_STAGE_CALL() as direct call. */
46#include "pfs_stage_provider.h" // IWYU pragma: keep
47#endif
48
50struct CHARSET_INFO;
51
52#ifndef PSI_STATEMENT_CALL
53#define PSI_STATEMENT_CALL(M) psi_statement_service->M
54#endif
55
56#ifndef PSI_DIGEST_CALL
57#define PSI_DIGEST_CALL(M) psi_statement_service->M
58#endif
59
60#ifndef PSI_STAGE_CALL
61#define PSI_STAGE_CALL(M) psi_stage_service->M
62#endif
63
64/**
65 @defgroup psi_api_statement Statement Instrumentation (API)
66 @ingroup psi_api
67 @{
68*/
69
70/**
71 @def mysql_statement_register(P1, P2, P3)
72 Statement registration.
73*/
74#define mysql_statement_register(P1, P2, P3) \
75 inline_mysql_statement_register(P1, P2, P3)
76
77#ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
78#define MYSQL_DIGEST_START(LOCKER) inline_mysql_digest_start(LOCKER)
79#else
80#define MYSQL_DIGEST_START(LOCKER) NULL
81#endif
82
83#ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
84#define MYSQL_DIGEST_END(LOCKER, DIGEST) inline_mysql_digest_end(LOCKER, DIGEST)
85#else
86#define MYSQL_DIGEST_END(LOCKER, DIGEST) \
87 do { \
88 } while (0)
89#endif
90
91#ifdef HAVE_PSI_STATEMENT_INTERFACE
92#define MYSQL_START_STATEMENT(STATE, K, DB, DB_LEN, CS, SPS) \
93 inline_mysql_start_statement(STATE, K, DB, DB_LEN, CS, SPS, __FILE__, \
94 __LINE__)
95#else
96#define MYSQL_START_STATEMENT(STATE, K, DB, DB_LEN, CS, SPS) NULL
97#endif
98
99#ifdef HAVE_PSI_STATEMENT_INTERFACE
100#define MYSQL_REFINE_STATEMENT(LOCKER, K) \
101 inline_mysql_refine_statement(LOCKER, K)
102#else
103#define MYSQL_REFINE_STATEMENT(LOCKER, K) NULL
104#endif
105
106#ifdef HAVE_PSI_STATEMENT_INTERFACE
107#define MYSQL_SET_STATEMENT_TEXT(LOCKER, P1, P2) \
108 inline_mysql_set_statement_text(LOCKER, P1, P2)
109#else
110#define MYSQL_SET_STATEMENT_TEXT(LOCKER, P1, P2) \
111 do { \
112 } while (0)
113#endif
114
115#ifdef HAVE_PSI_STATEMENT_INTERFACE
116#define MYSQL_SET_STATEMENT_QUERY_ID(LOCKER, P1) \
117 inline_mysql_set_statement_query_id(LOCKER, P1)
118#else
119#define MYSQL_SET_STATEMENT_QUERY_ID(LOCKER, P1) \
120 do { \
121 } while (0)
122#endif
123
124#ifdef HAVE_PSI_STATEMENT_INTERFACE
125#define MYSQL_SET_STATEMENT_LOCK_TIME(LOCKER, P1) \
126 inline_mysql_set_statement_lock_time(LOCKER, P1)
127#else
128#define MYSQL_SET_STATEMENT_LOCK_TIME(LOCKER, P1) \
129 do { \
130 } while (0)
131#endif
132
133#ifdef HAVE_PSI_STATEMENT_INTERFACE
134#define MYSQL_SET_STATEMENT_ROWS_SENT(LOCKER, P1) \
135 inline_mysql_set_statement_rows_sent(LOCKER, P1)
136#else
137#define MYSQL_SET_STATEMENT_ROWS_SENT(LOCKER, P1) \
138 do { \
139 } while (0)
140#endif
141
142#ifdef HAVE_PSI_STATEMENT_INTERFACE
143#define MYSQL_SET_STATEMENT_ROWS_EXAMINED(LOCKER, P1) \
144 inline_mysql_set_statement_rows_examined(LOCKER, P1)
145#else
146#define MYSQL_SET_STATEMENT_ROWS_EXAMINED(LOCKER, P1) \
147 do { \
148 } while (0)
149#endif
150
151#ifdef HAVE_PSI_STATEMENT_INTERFACE
152#define MYSQL_NOTIFY_STATEMENT_QUERY_ATTRIBUTES(LOCKER, P1) \
153 inline_mysql_notify_statement_query_attributes(LOCKER, P1)
154#else
155#define MYSQL_NOTIFY_STATEMENT_QUERY_ATTRIBUTES(LOCKER, P1) \
156 do { \
157 } while (0)
158#endif
159
160#ifdef HAVE_PSI_STATEMENT_INTERFACE
161#define MYSQL_END_STATEMENT(LOCKER, DA) inline_mysql_end_statement(LOCKER, DA)
162#else
163#define MYSQL_END_STATEMENT(LOCKER, DA) \
164 do { \
165 } while (0)
166#endif
167
170 const char *category, PSI_statement_info *info, int count
171#else
172 const char *category [[maybe_unused]], void *info [[maybe_unused]],
173 int count [[maybe_unused]]
174#endif
175) {
176#ifdef HAVE_PSI_STATEMENT_INTERFACE
177 PSI_STATEMENT_CALL(register_statement)(category, info, count);
178#endif
179}
180
181#ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
183 PSI_statement_locker *locker) {
184 PSI_digest_locker *digest_locker = nullptr;
185
186 if (likely(locker != nullptr)) {
187 digest_locker = PSI_DIGEST_CALL(digest_start)(locker);
188 }
189 return digest_locker;
190}
191#endif
192
193#ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
195 const sql_digest_storage *digest) {
196 if (likely(locker != nullptr)) {
197 PSI_DIGEST_CALL(digest_end)(locker, digest);
198 }
199}
200#endif
201
202#ifdef HAVE_PSI_STATEMENT_INTERFACE
204 PSI_statement_locker_state *state, PSI_statement_key key, const char *db,
205 uint db_len, const CHARSET_INFO *charset, PSI_sp_share *sp_share,
206 const char *src_file, int src_line) {
207 PSI_statement_locker *locker;
208 locker = PSI_STATEMENT_CALL(get_thread_statement_locker)(state, key, charset,
209 sp_share);
210 if (likely(locker != nullptr)) {
211 PSI_STATEMENT_CALL(start_statement)(locker, db, db_len, src_file, src_line);
212 }
213 return locker;
214}
215
218 if (likely(locker != nullptr)) {
219 locker = PSI_STATEMENT_CALL(refine_statement)(locker, key);
220 }
221 return locker;
222}
223
225 const char *text,
226 uint text_len) {
227 if (likely(locker != nullptr)) {
228 PSI_STATEMENT_CALL(set_statement_text)(locker, text, text_len);
229 }
230}
231
233 PSI_statement_locker *locker, ulonglong id) {
234 if (likely(locker != nullptr)) {
235 PSI_STATEMENT_CALL(set_statement_query_id)(locker, id);
236 }
237}
238
241 if (likely(locker != nullptr)) {
242 PSI_STATEMENT_CALL(set_statement_lock_time)(locker, count);
243 }
244}
245
248 if (likely(locker != nullptr)) {
249 PSI_STATEMENT_CALL(set_statement_rows_sent)(locker, count);
250 }
251}
252
255 if (likely(locker != nullptr)) {
256 PSI_STATEMENT_CALL(set_statement_rows_examined)(locker, count);
257 }
258}
259
261 PSI_statement_locker *locker, bool with_query_attributes) {
262 if (likely(locker != nullptr)) {
263 PSI_STATEMENT_CALL(notify_statement_query_attributes)
264 (locker, with_query_attributes);
265 }
266}
267
268static inline void inline_mysql_end_statement(
269 struct PSI_statement_locker *locker, Diagnostics_area *stmt_da) {
270#ifdef HAVE_PSI_STAGE_INTERFACE
271 PSI_STAGE_CALL(end_stage)();
272#endif /* HAVE_PSI_STAGE_INTERFACE */
273 if (likely(locker != nullptr)) {
274 PSI_STATEMENT_CALL(end_statement)(locker, stmt_da);
275 }
276}
277#endif /* HAVE_PSI_STATEMENT_INTERFACE */
278
280 PSI_statement_locker *locker [[maybe_unused]],
281 bool secondary [[maybe_unused]]) {
282#ifdef HAVE_PSI_STATEMENT_INTERFACE
283 if (likely(locker != nullptr)) {
284 PSI_STATEMENT_CALL(set_statement_secondary_engine)(locker, secondary);
285 }
286#endif /* HAVE_PSI_STATEMENT_INTERFACE */
287}
288
289/** @} (end of group psi_api_statement) */
290
291#endif
Stores status of the currently executed statement.
Definition: sql_error.h:269
#define PSI_STAGE_CALL(M)
Definition: psi_stage.h:36
#define PSI_STATEMENT_CALL(M)
Definition: psi_statement.h:36
struct PSI_digest_locker PSI_digest_locker
Definition: psi_statement_bits.h:112
unsigned int PSI_statement_key
Instrumented statement key.
Definition: psi_statement_bits.h:49
struct PSI_sp_share PSI_sp_share
Definition: psi_statement_bits.h:119
struct PSI_statement_locker PSI_statement_locker
Definition: psi_statement_bits.h:98
static void inline_mysql_set_statement_query_id(PSI_statement_locker *locker, ulonglong id)
Definition: mysql_statement.h:232
static struct PSI_statement_locker * inline_mysql_refine_statement(PSI_statement_locker *locker, PSI_statement_key key)
Definition: mysql_statement.h:216
static void inline_mysql_set_statement_rows_examined(PSI_statement_locker *locker, ulonglong count)
Definition: mysql_statement.h:253
static void inline_mysql_set_statement_text(PSI_statement_locker *locker, const char *text, uint text_len)
Definition: mysql_statement.h:224
static void inline_mysql_digest_end(PSI_digest_locker *locker, const sql_digest_storage *digest)
Definition: mysql_statement.h:194
static struct PSI_digest_locker * inline_mysql_digest_start(PSI_statement_locker *locker)
Definition: mysql_statement.h:182
static void mysql_statement_set_secondary_engine(PSI_statement_locker *locker, bool secondary)
Definition: mysql_statement.h:279
static void inline_mysql_statement_register(const char *category, PSI_statement_info *info, int count)
Definition: mysql_statement.h:168
static void inline_mysql_end_statement(struct PSI_statement_locker *locker, Diagnostics_area *stmt_da)
Definition: mysql_statement.h:268
static void inline_mysql_set_statement_rows_sent(PSI_statement_locker *locker, ulonglong count)
Definition: mysql_statement.h:246
static void inline_mysql_notify_statement_query_attributes(PSI_statement_locker *locker, bool with_query_attributes)
Definition: mysql_statement.h:260
static struct PSI_statement_locker * inline_mysql_start_statement(PSI_statement_locker_state *state, PSI_statement_key key, const char *db, uint db_len, const CHARSET_INFO *charset, PSI_sp_share *sp_share, const char *src_file, int src_line)
Definition: mysql_statement.h:203
static void inline_mysql_set_statement_lock_time(PSI_statement_locker *locker, ulonglong count)
Definition: mysql_statement.h:239
Header for compiler-dependent features.
constexpr bool likely(bool expr)
Definition: my_compiler.h:55
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
#define HAVE_PSI_STATEMENT_INTERFACE
Definition: my_psi_config.h:144
static int count
Definition: myisam_ftdump.cc:43
Log info(cout, "NOTE")
const std::string charset("charset")
static const char * category
Definition: sha2_password.cc:170
Performance schema instrumentation (declarations).
Performance schema instrumentation (declarations).
#define PSI_DIGEST_CALL(M)
Definition: pfs_statement_provider.h:51
Performance schema instrumentation interface.
Performance schema instrumentation interface.
required string key
Definition: replication_asynchronous_connection_failover.proto:60
Definition: m_ctype.h:385
Statement instrument information.
Definition: psi_statement_bits.h:133
State data storage for get_thread_statement_locker_v5_t.
Definition: psi_statement_bits.h:166
Structure to store token count/array for a statement on which digest is to be calculated.
Definition: sql_digest.h:98
unsigned int uint
Definition: uca9-dump.cc:75
unsigned long id[MAX_DEAD]
Definition: xcom_base.cc:510