MySQL  8.0.27
Source Code Documentation
mysql_statement.h
Go to the documentation of this file.
1 /* Copyright (c) 2010, 2021, 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 
48 class Diagnostics_area;
49 struct 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_END_STATEMENT(LOCKER, DA) inline_mysql_end_statement(LOCKER, DA)
152 #else
153 #define MYSQL_END_STATEMENT(LOCKER, DA) \
154  do { \
155  } while (0)
156 #endif
157 
160  const char *category, PSI_statement_info *info, int count
161 #else
162  const char *category [[maybe_unused]], void *info [[maybe_unused]],
163  int count [[maybe_unused]]
164 #endif
165 ) {
166 #ifdef HAVE_PSI_STATEMENT_INTERFACE
167  PSI_STATEMENT_CALL(register_statement)(category, info, count);
168 #endif
169 }
170 
171 #ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
173  PSI_statement_locker *locker) {
174  PSI_digest_locker *digest_locker = nullptr;
175 
176  if (likely(locker != nullptr)) {
177  digest_locker = PSI_DIGEST_CALL(digest_start)(locker);
178  }
179  return digest_locker;
180 }
181 #endif
182 
183 #ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
184 static inline void inline_mysql_digest_end(PSI_digest_locker *locker,
185  const sql_digest_storage *digest) {
186  if (likely(locker != nullptr)) {
187  PSI_DIGEST_CALL(digest_end)(locker, digest);
188  }
189 }
190 #endif
191 
192 #ifdef HAVE_PSI_STATEMENT_INTERFACE
194  PSI_statement_locker_state *state, PSI_statement_key key, const char *db,
195  uint db_len, const CHARSET_INFO *charset, PSI_sp_share *sp_share,
196  const char *src_file, int src_line) {
197  PSI_statement_locker *locker;
198  locker = PSI_STATEMENT_CALL(get_thread_statement_locker)(state, key, charset,
199  sp_share);
200  if (likely(locker != nullptr)) {
201  PSI_STATEMENT_CALL(start_statement)(locker, db, db_len, src_file, src_line);
202  }
203  return locker;
204 }
205 
208  if (likely(locker != nullptr)) {
209  locker = PSI_STATEMENT_CALL(refine_statement)(locker, key);
210  }
211  return locker;
212 }
213 
215  const char *text,
216  uint text_len) {
217  if (likely(locker != nullptr)) {
218  PSI_STATEMENT_CALL(set_statement_text)(locker, text, text_len);
219  }
220 }
221 
223  PSI_statement_locker *locker, ulonglong id) {
224  if (likely(locker != nullptr)) {
225  PSI_STATEMENT_CALL(set_statement_query_id)(locker, id);
226  }
227 }
228 
231  if (likely(locker != nullptr)) {
232  PSI_STATEMENT_CALL(set_statement_lock_time)(locker, count);
233  }
234 }
235 
238  if (likely(locker != nullptr)) {
239  PSI_STATEMENT_CALL(set_statement_rows_sent)(locker, count);
240  }
241 }
242 
245  if (likely(locker != nullptr)) {
246  PSI_STATEMENT_CALL(set_statement_rows_examined)(locker, count);
247  }
248 }
249 
250 static inline void inline_mysql_end_statement(
251  struct PSI_statement_locker *locker, Diagnostics_area *stmt_da) {
252 #ifdef HAVE_PSI_STAGE_INTERFACE
253  PSI_STAGE_CALL(end_stage)();
254 #endif /* HAVE_PSI_STAGE_INTERFACE */
255  if (likely(locker != nullptr)) {
256  PSI_STATEMENT_CALL(end_statement)(locker, stmt_da);
257  }
258 }
259 #endif
260 
261 /** @} (end of group psi_api_statement) */
262 
263 #endif
Stores status of the currently executed statement.
Definition: sql_error.h:265
#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:89
unsigned int PSI_statement_key
Instrumented statement key.
Definition: psi_statement_bits.h:47
struct PSI_sp_share PSI_sp_share
Definition: psi_statement_bits.h:96
struct PSI_statement_locker PSI_statement_locker
Definition: psi_statement_bits.h:75
static void inline_mysql_set_statement_query_id(PSI_statement_locker *locker, ulonglong id)
Definition: mysql_statement.h:222
static struct PSI_statement_locker * inline_mysql_refine_statement(PSI_statement_locker *locker, PSI_statement_key key)
Definition: mysql_statement.h:206
static void inline_mysql_set_statement_rows_examined(PSI_statement_locker *locker, ulonglong count)
Definition: mysql_statement.h:243
static void inline_mysql_set_statement_text(PSI_statement_locker *locker, const char *text, uint text_len)
Definition: mysql_statement.h:214
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:193
static void inline_mysql_digest_end(PSI_digest_locker *locker, const sql_digest_storage *digest)
Definition: mysql_statement.h:184
static void inline_mysql_statement_register(const char *category, PSI_statement_info *info, int count)
Definition: mysql_statement.h:158
static void inline_mysql_end_statement(struct PSI_statement_locker *locker, Diagnostics_area *stmt_da)
Definition: mysql_statement.h:250
static void inline_mysql_set_statement_rows_sent(PSI_statement_locker *locker, ulonglong count)
Definition: mysql_statement.h:236
static void inline_mysql_set_statement_lock_time(PSI_statement_locker *locker, ulonglong count)
Definition: mysql_statement.h:229
static struct PSI_digest_locker * inline_mysql_digest_start(PSI_statement_locker *locker)
Definition: mysql_statement.h:172
Header for compiler-dependent features.
bool likely(bool expr)
Definition: my_compiler.h:54
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:142
static int count
Definition: myisam_ftdump.cc:42
Log info(cout, "NOTE")
const std::string charset("charset")
static const char * category
Definition: sha2_password.cc:168
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:354
Statement instrument information.
Definition: psi_statement_bits.h:110
State data storage for get_thread_statement_locker_v1_t, get_thread_statement_locker_v1_t.
Definition: psi_statement_bits.h:138
Structure to store token count/array for a statement on which digest is to be calculated.
Definition: sql_digest.h:97
unsigned int uint
Definition: uca-dump.cc:29
unsigned long id[MAX_DEAD]
Definition: xcom_base.cc:506