MySQL  8.0.18
Source Code Documentation
mysql_statement.h
Go to the documentation of this file.
1 /* Copyright (c) 2010, 2019, Oracle and/or its affiliates. All rights reserved.
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 #include "my_inttypes.h"
33 #include "mysql/psi/psi_stage.h"
35 #include "pfs_stage_provider.h" // IWYU pragma: keep
36 #include "pfs_statement_provider.h" // IWYU pragma: keep
37 
38 class Diagnostics_area;
39 struct CHARSET_INFO;
40 
41 #ifndef PSI_STATEMENT_CALL
42 #define PSI_STATEMENT_CALL(M) psi_statement_service->M
43 #endif
44 
45 #ifndef PSI_DIGEST_CALL
46 #define PSI_DIGEST_CALL(M) psi_statement_service->M
47 #endif
48 
49 #ifndef PSI_STAGE_CALL
50 #define PSI_STAGE_CALL(M) psi_stage_service->M
51 #endif
52 
53 /**
54  @defgroup psi_api_statement Statement Instrumentation (API)
55  @ingroup psi_api
56  @{
57 */
58 
59 /**
60  @def mysql_statement_register(P1, P2, P3)
61  Statement registration.
62 */
63 #define mysql_statement_register(P1, P2, P3) \
64  inline_mysql_statement_register(P1, P2, P3)
65 
66 #ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
67 #define MYSQL_DIGEST_START(LOCKER) inline_mysql_digest_start(LOCKER)
68 #else
69 #define MYSQL_DIGEST_START(LOCKER) NULL
70 #endif
71 
72 #ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
73 #define MYSQL_DIGEST_END(LOCKER, DIGEST) inline_mysql_digest_end(LOCKER, DIGEST)
74 #else
75 #define MYSQL_DIGEST_END(LOCKER, DIGEST) \
76  do { \
77  } while (0)
78 #endif
79 
80 #ifdef HAVE_PSI_STATEMENT_INTERFACE
81 #define MYSQL_START_STATEMENT(STATE, K, DB, DB_LEN, CS, SPS) \
82  inline_mysql_start_statement(STATE, K, DB, DB_LEN, CS, SPS, __FILE__, \
83  __LINE__)
84 #else
85 #define MYSQL_START_STATEMENT(STATE, K, DB, DB_LEN, CS, SPS) NULL
86 #endif
87 
88 #ifdef HAVE_PSI_STATEMENT_INTERFACE
89 #define MYSQL_REFINE_STATEMENT(LOCKER, K) \
90  inline_mysql_refine_statement(LOCKER, K)
91 #else
92 #define MYSQL_REFINE_STATEMENT(LOCKER, K) NULL
93 #endif
94 
95 #ifdef HAVE_PSI_STATEMENT_INTERFACE
96 #define MYSQL_SET_STATEMENT_TEXT(LOCKER, P1, P2) \
97  inline_mysql_set_statement_text(LOCKER, P1, P2)
98 #else
99 #define MYSQL_SET_STATEMENT_TEXT(LOCKER, P1, P2) \
100  do { \
101  } while (0)
102 #endif
103 
104 #ifdef HAVE_PSI_STATEMENT_INTERFACE
105 #define MYSQL_SET_STATEMENT_QUERY_ID(LOCKER, P1) \
106  inline_mysql_set_statement_query_id(LOCKER, P1)
107 #else
108 #define MYSQL_SET_STATEMENT_QUERY_ID(LOCKER, P1) \
109  do { \
110  } while (0)
111 #endif
112 
113 #ifdef HAVE_PSI_STATEMENT_INTERFACE
114 #define MYSQL_SET_STATEMENT_LOCK_TIME(LOCKER, P1) \
115  inline_mysql_set_statement_lock_time(LOCKER, P1)
116 #else
117 #define MYSQL_SET_STATEMENT_LOCK_TIME(LOCKER, P1) \
118  do { \
119  } while (0)
120 #endif
121 
122 #ifdef HAVE_PSI_STATEMENT_INTERFACE
123 #define MYSQL_SET_STATEMENT_ROWS_SENT(LOCKER, P1) \
124  inline_mysql_set_statement_rows_sent(LOCKER, P1)
125 #else
126 #define MYSQL_SET_STATEMENT_ROWS_SENT(LOCKER, P1) \
127  do { \
128  } while (0)
129 #endif
130 
131 #ifdef HAVE_PSI_STATEMENT_INTERFACE
132 #define MYSQL_SET_STATEMENT_ROWS_EXAMINED(LOCKER, P1) \
133  inline_mysql_set_statement_rows_examined(LOCKER, P1)
134 #else
135 #define MYSQL_SET_STATEMENT_ROWS_EXAMINED(LOCKER, P1) \
136  do { \
137  } while (0)
138 #endif
139 
140 #ifdef HAVE_PSI_STATEMENT_INTERFACE
141 #define MYSQL_END_STATEMENT(LOCKER, DA) inline_mysql_end_statement(LOCKER, DA)
142 #else
143 #define MYSQL_END_STATEMENT(LOCKER, DA) \
144  do { \
145  } while (0)
146 #endif
147 
150  const char *category, PSI_statement_info *info, int count
151 #else
152  const char *category MY_ATTRIBUTE((unused)),
153  void *info MY_ATTRIBUTE((unused)), int count MY_ATTRIBUTE((unused))
154 #endif
155 ) {
156 #ifdef HAVE_PSI_STATEMENT_INTERFACE
157  PSI_STATEMENT_CALL(register_statement)(category, info, count);
158 #endif
159 }
160 
161 #ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
163  PSI_statement_locker *locker) {
164  PSI_digest_locker *digest_locker = NULL;
165 
166  if (likely(locker != NULL)) {
167  digest_locker = PSI_DIGEST_CALL(digest_start)(locker);
168  }
169  return digest_locker;
170 }
171 #endif
172 
173 #ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
174 static inline void inline_mysql_digest_end(PSI_digest_locker *locker,
175  const sql_digest_storage *digest) {
176  if (likely(locker != NULL)) {
177  PSI_DIGEST_CALL(digest_end)(locker, digest);
178  }
179 }
180 #endif
181 
182 #ifdef HAVE_PSI_STATEMENT_INTERFACE
184  PSI_statement_locker_state *state, PSI_statement_key key, const char *db,
185  uint db_len, const CHARSET_INFO *charset, PSI_sp_share *sp_share,
186  const char *src_file, int src_line) {
187  PSI_statement_locker *locker;
188  locker = PSI_STATEMENT_CALL(get_thread_statement_locker)(state, key, charset,
189  sp_share);
190  if (likely(locker != NULL)) {
191  PSI_STATEMENT_CALL(start_statement)(locker, db, db_len, src_file, src_line);
192  }
193  return locker;
194 }
195 
198  if (likely(locker != NULL)) {
199  locker = PSI_STATEMENT_CALL(refine_statement)(locker, key);
200  }
201  return locker;
202 }
203 
205  const char *text,
206  uint text_len) {
207  if (likely(locker != NULL)) {
208  PSI_STATEMENT_CALL(set_statement_text)(locker, text, text_len);
209  }
210 }
211 
213  PSI_statement_locker *locker, ulonglong id) {
214  if (likely(locker != NULL)) {
215  PSI_STATEMENT_CALL(set_statement_query_id)(locker, id);
216  }
217 }
218 
221  if (likely(locker != NULL)) {
222  PSI_STATEMENT_CALL(set_statement_lock_time)(locker, count);
223  }
224 }
225 
228  if (likely(locker != NULL)) {
229  PSI_STATEMENT_CALL(set_statement_rows_sent)(locker, count);
230  }
231 }
232 
235  if (likely(locker != NULL)) {
236  PSI_STATEMENT_CALL(set_statement_rows_examined)(locker, count);
237  }
238 }
239 
240 static inline void inline_mysql_end_statement(
241  struct PSI_statement_locker *locker, Diagnostics_area *stmt_da) {
242 #ifdef HAVE_PSI_STAGE_INTERFACE
243  PSI_STAGE_CALL(end_stage)();
244 #endif /* HAVE_PSI_STAGE_INTERFACE */
245  if (likely(locker != NULL)) {
246  PSI_STATEMENT_CALL(end_statement)(locker, stmt_da);
247  }
248 }
249 #endif
250 
251 /** @} (end of group psi_api_statement) */
252 
253 #endif
unsigned long long int ulonglong
Definition: my_inttypes.h:55
ssize_t count
Definition: memcached.c:386
Some integer typedefs for easier portability.
State data storage for get_thread_statement_locker_v1_t, get_thread_statement_locker_v1_t.
Definition: psi_statement_bits.h:136
unsigned long id[MAX_DEAD]
Definition: xcom_base.c:426
#define PSI_STAGE_CALL(M)
Definition: psi_stage.h:31
Performance schema instrumentation (declarations).
static void inline_mysql_end_statement(struct PSI_statement_locker *locker, Diagnostics_area *stmt_da)
Definition: mysql_statement.h:240
struct PSI_sp_share PSI_sp_share
Definition: psi_statement_bits.h:94
struct PSI_digest_locker PSI_digest_locker
Definition: psi_statement_bits.h:87
#define PSI_STATEMENT_CALL(M)
Definition: psi_statement.h:31
static void inline_mysql_digest_end(PSI_digest_locker *locker, const sql_digest_storage *digest)
Definition: mysql_statement.h:174
Performance schema instrumentation interface.
static void inline_mysql_set_statement_lock_time(PSI_statement_locker *locker, ulonglong count)
Definition: mysql_statement.h:219
Stores status of the currently executed statement.
Definition: sql_error.h:268
Header for compiler-dependent features.
Statement instrument information.
Definition: psi_statement_bits.h:108
#define PSI_DIGEST_CALL(M)
Definition: pfs_statement_provider.h:49
static void inline_mysql_set_statement_rows_sent(PSI_statement_locker *locker, ulonglong count)
Definition: mysql_statement.h:226
unsigned int uint
Definition: uca-dump.cc:29
Performance schema instrumentation (declarations).
Performance schema instrumentation interface.
#define HAVE_PSI_STATEMENT_INTERFACE
Definition: my_psi_config.h:141
static struct PSI_statement_locker * inline_mysql_refine_statement(PSI_statement_locker *locker, PSI_statement_key key)
Definition: mysql_statement.h:196
Definition: m_ctype.h:359
bool likely(bool expr)
Definition: my_compiler.h:64
struct PSI_statement_locker PSI_statement_locker
Definition: psi_statement_bits.h:73
static const char * key
Definition: suite_stubs.c:14
static const char * category
Definition: sha2_password.cc:166
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:183
static void inline_mysql_statement_register(const char *category, PSI_statement_info *info, int count)
Definition: mysql_statement.h:148
unsigned int PSI_statement_key
Instrumented statement key.
Definition: psi_statement_bits.h:45
Structure to store token count/array for a statement on which digest is to be calculated.
Definition: sql_digest.h:97
static void inline_mysql_set_statement_rows_examined(PSI_statement_locker *locker, ulonglong count)
Definition: mysql_statement.h:233
#define NULL
Definition: types.h:55
Log info(cout, "NOTE")
static void inline_mysql_set_statement_query_id(PSI_statement_locker *locker, ulonglong id)
Definition: mysql_statement.h:212
static void inline_mysql_set_statement_text(PSI_statement_locker *locker, const char *text, uint text_len)
Definition: mysql_statement.h:204
static struct PSI_digest_locker * inline_mysql_digest_start(PSI_statement_locker *locker)
Definition: mysql_statement.h:162