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