MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
mysql_statement.h
Go to the documentation of this file.
1 /* Copyright (c) 2010, 2012, 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 as published by
5  the Free Software Foundation; version 2 of the License.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  GNU General Public License for more details.
11 
12  You should have received a copy of the GNU General Public License
13  along with this program; if not, write to the Free Software
14  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
15 
16 #ifndef MYSQL_STATEMENT_H
17 #define MYSQL_STATEMENT_H
18 
24 #include "mysql/psi/psi.h"
25 
36 #ifdef HAVE_PSI_STATEMENT_INTERFACE
37 #define mysql_statement_register(P1, P2, P3) \
38  inline_mysql_statement_register(P1, P2, P3)
39 #else
40 #define mysql_statement_register(P1, P2, P3) \
41  do {} while (0)
42 #endif
43 
44 #ifdef HAVE_PSI_STATEMENT_INTERFACE
45 #ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
46  #define MYSQL_DIGEST_START(LOCKER) \
47  inline_mysql_digest_start(LOCKER)
48 #else
49  #define MYSQL_DIGEST_START(LOCKER) \
50  NULL
51 #endif
52 #else
53  #define MYSQL_DIGEST_START(LOCKER) \
54  NULL
55 #endif
56 
57 #ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
58  #define MYSQL_ADD_TOKEN(LOCKER, T, Y) \
59  inline_mysql_add_token(LOCKER, T, Y)
60 #else
61  #define MYSQL_ADD_TOKEN(LOCKER, T, Y) \
62  NULL
63 #endif
64 
65 #ifdef HAVE_PSI_STATEMENT_INTERFACE
66  #define MYSQL_START_STATEMENT(STATE, K, DB, DB_LEN, CS) \
67  inline_mysql_start_statement(STATE, K, DB, DB_LEN, CS, __FILE__, __LINE__)
68 #else
69  #define MYSQL_START_STATEMENT(STATE, K, DB, DB_LEN, CS) \
70  NULL
71 #endif
72 
73 #ifdef HAVE_PSI_STATEMENT_INTERFACE
74  #define MYSQL_REFINE_STATEMENT(LOCKER, K) \
75  inline_mysql_refine_statement(LOCKER, K)
76 #else
77  #define MYSQL_REFINE_STATEMENT(LOCKER, K) \
78  NULL
79 #endif
80 
81 #ifdef HAVE_PSI_STATEMENT_INTERFACE
82  #define MYSQL_SET_STATEMENT_TEXT(LOCKER, P1, P2) \
83  inline_mysql_set_statement_text(LOCKER, P1, P2)
84 #else
85  #define MYSQL_SET_STATEMENT_TEXT(LOCKER, P1, P2) \
86  do {} while (0)
87 #endif
88 
89 #ifdef HAVE_PSI_STATEMENT_INTERFACE
90  #define MYSQL_SET_STATEMENT_LOCK_TIME(LOCKER, P1) \
91  inline_mysql_set_statement_lock_time(LOCKER, P1)
92 #else
93  #define MYSQL_SET_STATEMENT_LOCK_TIME(LOCKER, P1) \
94  do {} while (0)
95 #endif
96 
97 #ifdef HAVE_PSI_STATEMENT_INTERFACE
98  #define MYSQL_SET_STATEMENT_ROWS_SENT(LOCKER, P1) \
99  inline_mysql_set_statement_rows_sent(LOCKER, P1)
100 #else
101  #define MYSQL_SET_STATEMENT_ROWS_SENT(LOCKER, P1) \
102  do {} while (0)
103 #endif
104 
105 #ifdef HAVE_PSI_STATEMENT_INTERFACE
106  #define MYSQL_SET_STATEMENT_ROWS_EXAMINED(LOCKER, P1) \
107  inline_mysql_set_statement_rows_examined(LOCKER, P1)
108 #else
109  #define MYSQL_SET_STATEMENT_ROWS_EXAMINED(LOCKER, P1) \
110  do {} while (0)
111 #endif
112 
113 #ifdef HAVE_PSI_STATEMENT_INTERFACE
114  #define MYSQL_END_STATEMENT(LOCKER, DA) \
115  inline_mysql_end_statement(LOCKER, DA)
116 #else
117  #define MYSQL_END_STATEMENT(LOCKER, DA) \
118  do {} while (0)
119 #endif
120 
121 #ifdef HAVE_PSI_STATEMENT_INTERFACE
122 static inline void inline_mysql_statement_register(
123  const char *category, PSI_statement_info *info, int count)
124 {
125  PSI_STATEMENT_CALL(register_statement)(category, info, count);
126 }
127 
128 #ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
129 static inline struct PSI_digest_locker *
130 inline_mysql_digest_start(PSI_statement_locker *locker)
131 {
132  PSI_digest_locker* digest_locker= NULL;
133 
134  if (likely(locker != NULL))
135  digest_locker= PSI_STATEMENT_CALL(digest_start)(locker);
136  return digest_locker;
137 }
138 #endif
139 
140 #ifdef HAVE_PSI_STATEMENT_DIGEST_INTERFACE
141 static inline struct PSI_digest_locker *
142 inline_mysql_add_token(PSI_digest_locker *locker, uint token,
143  void *yylval)
144 {
145  if (likely(locker != NULL))
146  locker= PSI_STATEMENT_CALL(digest_add_token)(locker, token,
147  (OPAQUE_LEX_YYSTYPE*)yylval);
148  return locker;
149 }
150 #endif
151 
152 static inline struct PSI_statement_locker *
153 inline_mysql_start_statement(PSI_statement_locker_state *state,
154  PSI_statement_key key,
155  const char *db, uint db_len,
156  const CHARSET_INFO *charset,
157  const char *src_file, int src_line)
158 {
159  PSI_statement_locker *locker;
160  locker= PSI_STATEMENT_CALL(get_thread_statement_locker)(state, key, charset);
161  if (likely(locker != NULL))
162  PSI_STATEMENT_CALL(start_statement)(locker, db, db_len, src_file, src_line);
163  return locker;
164 }
165 
166 static inline struct PSI_statement_locker *
167 inline_mysql_refine_statement(PSI_statement_locker *locker,
168  PSI_statement_key key)
169 {
170  if (likely(locker != NULL))
171  {
172  locker= PSI_STATEMENT_CALL(refine_statement)(locker, key);
173  }
174  return locker;
175 }
176 
177 static inline void
178 inline_mysql_set_statement_text(PSI_statement_locker *locker,
179  const char *text, uint text_len)
180 {
181  if (likely(locker != NULL))
182  {
183  PSI_STATEMENT_CALL(set_statement_text)(locker, text, text_len);
184  }
185 }
186 
187 static inline void
188 inline_mysql_set_statement_lock_time(PSI_statement_locker *locker,
189  ulonglong count)
190 {
191  if (likely(locker != NULL))
192  {
193  PSI_STATEMENT_CALL(set_statement_lock_time)(locker, count);
194  }
195 }
196 
197 static inline void
198 inline_mysql_set_statement_rows_sent(PSI_statement_locker *locker,
199  ulonglong count)
200 {
201  if (likely(locker != NULL))
202  {
203  PSI_STATEMENT_CALL(set_statement_rows_sent)(locker, count);
204  }
205 }
206 
207 static inline void
208 inline_mysql_set_statement_rows_examined(PSI_statement_locker *locker,
209  ulonglong count)
210 {
211  if (likely(locker != NULL))
212  {
213  PSI_STATEMENT_CALL(set_statement_rows_examined)(locker, count);
214  }
215 }
216 
217 static inline void
218 inline_mysql_end_statement(struct PSI_statement_locker *locker,
219  Diagnostics_area *stmt_da)
220 {
221  PSI_STAGE_CALL(end_stage)();
222  if (likely(locker != NULL))
223  PSI_STATEMENT_CALL(end_statement)(locker, stmt_da);
224 }
225 #endif
226 
229 #endif
230