Merge lp:~posulliv/mysql-server/query-rewrite into lp:~mysql/mysql-server/mysql-next-mr
- query-rewrite
- Merge into mysql-next-mr
Status: | Needs review |
---|---|
Proposed branch: | lp:~posulliv/mysql-server/query-rewrite |
Merge into: | lp:~mysql/mysql-server/mysql-next-mr |
Diff against target: |
987 lines (+639/-136) 17 files modified
Makefile.am (+1/-0) include/mysql/plugin.h (+11/-2) include/mysql/plugin_audit.h.pp (+10/-0) include/mysql/plugin_ftparser.h.pp (+10/-0) include/mysql/plugin_query_rewrite.h (+54/-0) include/mysql/plugin_query_rewrite.h.pp (+198/-0) include/probes_mysql_nodtrace.h (+0/-129) plugin/rewrite_lower/CMakeLists.txt (+17/-0) plugin/rewrite_lower/Makefile.am (+32/-0) plugin/rewrite_lower/plug.in (+4/-0) plugin/rewrite_lower/rewrite_lower.cc (+84/-0) sql/CMakeLists.txt (+1/-1) sql/Makefile.am (+2/-2) sql/sql_parse.cc (+4/-0) sql/sql_plugin.cc (+8/-2) sql/sql_query_rewrite.cc (+167/-0) sql/sql_query_rewrite.h (+36/-0) |
To merge this branch: | bzr merge lp:~posulliv/mysql-server/query-rewrite |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Oracle/MySQL Engineering | Pending | ||
Review via email: mp+38560@code.launchpad.net |
Commit message
Description of the change
This branch contains a new plugin type for query rewriting.
Based on discussions on the internals mailing list, I added 2 distinct plugin points where a plugin developer could choose to rewrite a query:
1) pre-parsing
2) post-parsing
In the pre-parsing case, the raw query string is passed to the plugin. If the plugin rewrites the raw query, it returns a new string which is then set as the current query by the MySQL kernel. There is also a callback function for freeing memory allocated for the rewritten query text in the plugin.
In the post-parsing case, the parse tree structure is passed as a parameter to the plugin. A plugin developer can modify the parse tree in place if they wish. MySQL will operate on the parse tree after this function returns.
I also included a simple example query rewriting plugin which simply converts the raw text of a query to lower case.
I logged bug 57459 as a feature request for this since this was suggested on the mailing list.
- 3205. By Padraig O'Sullivan
-
Forgot new method when embedded server is defined.
Unmerged revisions
- 3205. By Padraig O'Sullivan
-
Forgot new method when embedded server is defined.
- 3204. By Padraig O'Sullivan
-
Added another plugin point for query rewrite which allows the parse tree to be rewritten.
- 3203. By Padraig O'Sullivan
-
Removed one call to query rewrite plugin point which is unneeded.
- 3202. By Padraig O'Sullivan
-
Updated query rewrite plugin interface and how query rewrite plugins are called from within the kernel.
- 3201. By Padraig O'Sullivan
-
Modified locations where query rewrite plugin point is to be always before mysql_parse function. This makes sure the rewritten query is placed in the general query log and also ensures the rewritten query is the query that shows up in profiling output.
- 3200. By Padraig O'Sullivan
-
Added functions for initializing and finalizing query rewrite plugins.
- 3199. By Padraig O'Sullivan
-
Update sample rewriting plugin to work with autoconf tools. Added preprocessor generated file for query rewrite interface.
- 3198. By Padraig O'Sullivan
-
Merge trunk.
- 3197. By Padraig O'Sullivan
-
Added simple query rewriting plugin that simply converts a query to lower case.
- 3196. By Padraig O'Sullivan
-
Added files to call into query rewrite plugins.
Preview Diff
1 | === modified file 'Makefile.am' | |||
2 | --- Makefile.am 2010-08-27 07:20:08 +0000 | |||
3 | +++ Makefile.am 2010-10-15 16:16:49 +0000 | |||
4 | @@ -267,6 +267,7 @@ | |||
5 | 267 | 267 | ||
6 | 268 | API_PREPROCESSOR_HEADER = $(top_srcdir)/include/mysql/plugin_audit.h \ | 268 | API_PREPROCESSOR_HEADER = $(top_srcdir)/include/mysql/plugin_audit.h \ |
7 | 269 | $(top_srcdir)/include/mysql/plugin_ftparser.h \ | 269 | $(top_srcdir)/include/mysql/plugin_ftparser.h \ |
8 | 270 | $(top_srcdir)/include/mysql/plugin_query_rewrite.h \ | ||
9 | 270 | $(top_srcdir)/include/mysql.h \ | 271 | $(top_srcdir)/include/mysql.h \ |
10 | 271 | $(top_srcdir)/include/mysql/psi/psi_abi_v1.h \ | 272 | $(top_srcdir)/include/mysql/psi/psi_abi_v1.h \ |
11 | 272 | $(top_srcdir)/include/mysql/psi/psi_abi_v2.h | 273 | $(top_srcdir)/include/mysql/psi/psi_abi_v2.h |
12 | 273 | 274 | ||
13 | === modified file 'include/mysql/plugin.h' | |||
14 | --- include/mysql/plugin.h 2010-09-01 13:06:14 +0000 | |||
15 | +++ include/mysql/plugin.h 2010-10-15 16:16:49 +0000 | |||
16 | @@ -42,10 +42,13 @@ | |||
17 | 42 | 42 | ||
18 | 43 | #ifdef __cplusplus | 43 | #ifdef __cplusplus |
19 | 44 | class THD; | 44 | class THD; |
20 | 45 | class LEX; | ||
21 | 45 | class Item; | 46 | class Item; |
22 | 46 | #define MYSQL_THD THD* | 47 | #define MYSQL_THD THD* |
23 | 48 | #define MYSQL_LEXPTR LEX* | ||
24 | 47 | #else | 49 | #else |
25 | 48 | #define MYSQL_THD void* | 50 | #define MYSQL_THD void* |
26 | 51 | #define MYSQL_LEXPTR void* | ||
27 | 49 | #endif | 52 | #endif |
28 | 50 | 53 | ||
29 | 51 | #include <mysql/services.h> | 54 | #include <mysql/services.h> |
30 | @@ -82,8 +85,9 @@ | |||
31 | 82 | #define MYSQL_DAEMON_PLUGIN 3 /* The daemon/raw plugin type */ | 85 | #define MYSQL_DAEMON_PLUGIN 3 /* The daemon/raw plugin type */ |
32 | 83 | #define MYSQL_INFORMATION_SCHEMA_PLUGIN 4 /* The I_S plugin type */ | 86 | #define MYSQL_INFORMATION_SCHEMA_PLUGIN 4 /* The I_S plugin type */ |
33 | 84 | #define MYSQL_AUDIT_PLUGIN 5 /* The Audit plugin type */ | 87 | #define MYSQL_AUDIT_PLUGIN 5 /* The Audit plugin type */ |
36 | 85 | #define MYSQL_REPLICATION_PLUGIN 6 /* The replication plugin type */ | 88 | #define MYSQL_QUERY_REWRITE_PLUGIN 6 /* The query rewrite plugin type */ |
37 | 86 | #define MYSQL_MAX_PLUGIN_TYPE_NUM 7 /* The number of plugin types */ | 89 | #define MYSQL_REPLICATION_PLUGIN 7 /* The replication plugin type */ |
38 | 90 | #define MYSQL_MAX_PLUGIN_TYPE_NUM 8 /* The number of plugin types */ | ||
39 | 87 | 91 | ||
40 | 88 | /* We use the following strings to define licenses for plugins */ | 92 | /* We use the following strings to define licenses for plugins */ |
41 | 89 | #define PLUGIN_LICENSE_PROPRIETARY 0 | 93 | #define PLUGIN_LICENSE_PROPRIETARY 0 |
42 | @@ -422,6 +426,11 @@ | |||
43 | 422 | #include "plugin_ftparser.h" | 426 | #include "plugin_ftparser.h" |
44 | 423 | 427 | ||
45 | 424 | /************************************************************************* | 428 | /************************************************************************* |
46 | 429 | API for query rewrite plugin. (MYSQL_QUERY_REWRITE_PLUGIN) | ||
47 | 430 | */ | ||
48 | 431 | #include "plugin_query_rewrite.h" | ||
49 | 432 | |||
50 | 433 | /************************************************************************* | ||
51 | 425 | API for Storage Engine plugin. (MYSQL_DAEMON_PLUGIN) | 434 | API for Storage Engine plugin. (MYSQL_DAEMON_PLUGIN) |
52 | 426 | */ | 435 | */ |
53 | 427 | 436 | ||
54 | 428 | 437 | ||
55 | === modified file 'include/mysql/plugin_audit.h.pp' | |||
56 | --- include/mysql/plugin_audit.h.pp 2010-08-30 14:07:40 +0000 | |||
57 | +++ include/mysql/plugin_audit.h.pp 2010-10-15 16:16:49 +0000 | |||
58 | @@ -143,6 +143,16 @@ | |||
59 | 143 | int (*init)(MYSQL_FTPARSER_PARAM *param); | 143 | int (*init)(MYSQL_FTPARSER_PARAM *param); |
60 | 144 | int (*deinit)(MYSQL_FTPARSER_PARAM *param); | 144 | int (*deinit)(MYSQL_FTPARSER_PARAM *param); |
61 | 145 | }; | 145 | }; |
62 | 146 | #include "plugin_query_rewrite.h" | ||
63 | 147 | #include <stdint.h> | ||
64 | 148 | #include "plugin.h" | ||
65 | 149 | struct st_mysql_query_rewrite | ||
66 | 150 | { | ||
67 | 151 | int interface_version; | ||
68 | 152 | char* (*rewrite_query)(const char* schema, size_t schema_len, const char* query, size_t orig_query_len, size_t* rewritten_query_len); | ||
69 | 153 | void (*free_rewritten_query)(char* query); | ||
70 | 154 | void (*rewrite_parse_tree)(void* thd, void* parse_tree); | ||
71 | 155 | }; | ||
72 | 146 | struct st_mysql_daemon | 156 | struct st_mysql_daemon |
73 | 147 | { | 157 | { |
74 | 148 | int interface_version; | 158 | int interface_version; |
75 | 149 | 159 | ||
76 | === modified file 'include/mysql/plugin_ftparser.h.pp' | |||
77 | --- include/mysql/plugin_ftparser.h.pp 2010-08-30 14:07:40 +0000 | |||
78 | +++ include/mysql/plugin_ftparser.h.pp 2010-10-15 16:16:49 +0000 | |||
79 | @@ -96,6 +96,16 @@ | |||
80 | 96 | void * __reserved1; | 96 | void * __reserved1; |
81 | 97 | }; | 97 | }; |
82 | 98 | #include "plugin_ftparser.h" | 98 | #include "plugin_ftparser.h" |
83 | 99 | #include "plugin_query_rewrite.h" | ||
84 | 100 | #include <stdint.h> | ||
85 | 101 | #include "plugin.h" | ||
86 | 102 | struct st_mysql_query_rewrite | ||
87 | 103 | { | ||
88 | 104 | int interface_version; | ||
89 | 105 | char* (*rewrite_query)(const char* schema, size_t schema_len, const char* query, size_t orig_query_len, size_t* rewritten_query_len); | ||
90 | 106 | void (*free_rewritten_query)(char* query); | ||
91 | 107 | void (*rewrite_parse_tree)(void* thd, void* parse_tree); | ||
92 | 108 | }; | ||
93 | 99 | struct st_mysql_daemon | 109 | struct st_mysql_daemon |
94 | 100 | { | 110 | { |
95 | 101 | int interface_version; | 111 | int interface_version; |
96 | 102 | 112 | ||
97 | === added file 'include/mysql/plugin_query_rewrite.h' | |||
98 | --- include/mysql/plugin_query_rewrite.h 1970-01-01 00:00:00 +0000 | |||
99 | +++ include/mysql/plugin_query_rewrite.h 2010-10-15 16:16:49 +0000 | |||
100 | @@ -0,0 +1,54 @@ | |||
101 | 1 | /* Copyright (C) 2010 Akiban Technologies | ||
102 | 2 | |||
103 | 3 | This program is free software; you can redistribute it and/or modify | ||
104 | 4 | it under the terms of the GNU General Public License as published by | ||
105 | 5 | the Free Software Foundation; version 2 of the License. | ||
106 | 6 | |||
107 | 7 | This program is distributed in the hope that it will be useful, | ||
108 | 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
109 | 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
110 | 10 | GNU General Public License for more details. | ||
111 | 11 | |||
112 | 12 | You should have received a copy of the GNU General Public License | ||
113 | 13 | along with this program; if not, write to the Free Software | ||
114 | 14 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ | ||
115 | 15 | |||
116 | 16 | #ifndef _my_query_rewrite_h | ||
117 | 17 | #define _my_query_rewrite_h | ||
118 | 18 | |||
119 | 19 | #include <stdint.h> | ||
120 | 20 | |||
121 | 21 | /************************************************************************* | ||
122 | 22 | API for query rewrite plugin. (MYSQL_QUERY_REWRITE_PLUGIN) | ||
123 | 23 | */ | ||
124 | 24 | |||
125 | 25 | #include "plugin.h" | ||
126 | 26 | |||
127 | 27 | #define MYSQL_QUERY_REWRITE_INTERFACE_VERSION 0x0200 | ||
128 | 28 | |||
129 | 29 | /************************************************************************* | ||
130 | 30 | Here we define the descriptor structure, that is referred from | ||
131 | 31 | st_mysql_plugin. | ||
132 | 32 | |||
133 | 33 | rewrite_query() is invoked before a query is parsed allowing a plugin | ||
134 | 34 | the opporunity to rewrite the query string passed as a parameter | ||
135 | 35 | to the function | ||
136 | 36 | |||
137 | 37 | free_rewritten_query() is invoked only if a plugin rewrote the text of a query. | ||
138 | 38 | It frees any memory a plugin allocated for the rewritten query. | ||
139 | 39 | |||
140 | 40 | rewrite_parse_tree() is invoked after a query is parsed by MySQL. It | ||
141 | 41 | gives a rewriting plugin the opportunity to modify the parse tree | ||
142 | 42 | generated by MySQL. This allows a plugin developer to rewrite a query | ||
143 | 43 | without having to worry about parsing a query. | ||
144 | 44 | */ | ||
145 | 45 | struct st_mysql_query_rewrite | ||
146 | 46 | { | ||
147 | 47 | int interface_version; | ||
148 | 48 | char* (*rewrite_query)(const char* schema, size_t schema_len, const char* query, size_t orig_query_len, size_t* rewritten_query_len); | ||
149 | 49 | void (*free_rewritten_query)(char* query); | ||
150 | 50 | void (*rewrite_parse_tree)(MYSQL_THD thd, MYSQL_LEXPTR parse_tree); | ||
151 | 51 | }; | ||
152 | 52 | |||
153 | 53 | |||
154 | 54 | #endif /* _my_query_rewrite_h */ | ||
155 | 0 | 55 | ||
156 | === added file 'include/mysql/plugin_query_rewrite.h.pp' | |||
157 | --- include/mysql/plugin_query_rewrite.h.pp 1970-01-01 00:00:00 +0000 | |||
158 | +++ include/mysql/plugin_query_rewrite.h.pp 2010-10-15 16:16:49 +0000 | |||
159 | @@ -0,0 +1,198 @@ | |||
160 | 1 | #include <stdint.h> | ||
161 | 2 | #include "plugin.h" | ||
162 | 3 | #include <mysql/services.h> | ||
163 | 4 | #include <mysql/service_my_snprintf.h> | ||
164 | 5 | extern struct my_snprintf_service_st { | ||
165 | 6 | size_t (*my_snprintf_type)(char*, size_t, const char*, ...); | ||
166 | 7 | size_t (*my_vsnprintf_type)(char *, size_t, const char*, va_list); | ||
167 | 8 | } *my_snprintf_service; | ||
168 | 9 | size_t my_snprintf(char* to, size_t n, const char* fmt, ...); | ||
169 | 10 | size_t my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap); | ||
170 | 11 | #include <mysql/service_thd_alloc.h> | ||
171 | 12 | struct st_mysql_lex_string | ||
172 | 13 | { | ||
173 | 14 | char *str; | ||
174 | 15 | size_t length; | ||
175 | 16 | }; | ||
176 | 17 | typedef struct st_mysql_lex_string MYSQL_LEX_STRING; | ||
177 | 18 | extern struct thd_alloc_service_st { | ||
178 | 19 | void *(*thd_alloc_func)(void*, unsigned int); | ||
179 | 20 | void *(*thd_calloc_func)(void*, unsigned int); | ||
180 | 21 | char *(*thd_strdup_func)(void*, const char *); | ||
181 | 22 | char *(*thd_strmake_func)(void*, const char *, unsigned int); | ||
182 | 23 | void *(*thd_memdup_func)(void*, const void*, unsigned int); | ||
183 | 24 | MYSQL_LEX_STRING *(*thd_make_lex_string_func)(void*, MYSQL_LEX_STRING *, | ||
184 | 25 | const char *, unsigned int, int); | ||
185 | 26 | } *thd_alloc_service; | ||
186 | 27 | void *thd_alloc(void* thd, unsigned int size); | ||
187 | 28 | void *thd_calloc(void* thd, unsigned int size); | ||
188 | 29 | char *thd_strdup(void* thd, const char *str); | ||
189 | 30 | char *thd_strmake(void* thd, const char *str, unsigned int size); | ||
190 | 31 | void *thd_memdup(void* thd, const void* str, unsigned int size); | ||
191 | 32 | MYSQL_LEX_STRING *thd_make_lex_string(void* thd, MYSQL_LEX_STRING *lex_str, | ||
192 | 33 | const char *str, unsigned int size, | ||
193 | 34 | int allocate_lex_string); | ||
194 | 35 | #include <mysql/service_thd_wait.h> | ||
195 | 36 | typedef enum _thd_wait_type_e { | ||
196 | 37 | THD_WAIT_MUTEX= 1, | ||
197 | 38 | THD_WAIT_DISKIO= 2, | ||
198 | 39 | THD_WAIT_ROW_TABLE_LOCK= 3, | ||
199 | 40 | THD_WAIT_GLOBAL_LOCK= 4 | ||
200 | 41 | } thd_wait_type; | ||
201 | 42 | extern struct thd_wait_service_st { | ||
202 | 43 | void (*thd_wait_begin_func)(void*, thd_wait_type); | ||
203 | 44 | void (*thd_wait_end_func)(void*); | ||
204 | 45 | } *thd_wait_service; | ||
205 | 46 | void thd_wait_begin(void* thd, thd_wait_type wait_type); | ||
206 | 47 | void thd_wait_end(void* thd); | ||
207 | 48 | #include <mysql/service_thread_scheduler.h> | ||
208 | 49 | struct scheduler_functions; | ||
209 | 50 | extern struct my_thread_scheduler_service { | ||
210 | 51 | int (*set)(struct scheduler_functions *scheduler); | ||
211 | 52 | int (*reset)(); | ||
212 | 53 | } *my_thread_scheduler_service; | ||
213 | 54 | int my_thread_scheduler_set(struct scheduler_functions *scheduler); | ||
214 | 55 | int my_thread_scheduler_reset(); | ||
215 | 56 | struct st_mysql_xid { | ||
216 | 57 | long formatID; | ||
217 | 58 | long gtrid_length; | ||
218 | 59 | long bqual_length; | ||
219 | 60 | char data[128]; | ||
220 | 61 | }; | ||
221 | 62 | typedef struct st_mysql_xid MYSQL_XID; | ||
222 | 63 | enum enum_mysql_show_type | ||
223 | 64 | { | ||
224 | 65 | SHOW_UNDEF, SHOW_BOOL, SHOW_INT, SHOW_LONG, | ||
225 | 66 | SHOW_LONGLONG, SHOW_CHAR, SHOW_CHAR_PTR, | ||
226 | 67 | SHOW_ARRAY, SHOW_FUNC, SHOW_DOUBLE, | ||
227 | 68 | SHOW_always_last | ||
228 | 69 | }; | ||
229 | 70 | struct st_mysql_show_var { | ||
230 | 71 | const char *name; | ||
231 | 72 | char *value; | ||
232 | 73 | enum enum_mysql_show_type type; | ||
233 | 74 | }; | ||
234 | 75 | typedef int (*mysql_show_var_func)(void*, struct st_mysql_show_var*, char *); | ||
235 | 76 | struct st_mysql_sys_var; | ||
236 | 77 | struct st_mysql_value; | ||
237 | 78 | typedef int (*mysql_var_check_func)(void* thd, | ||
238 | 79 | struct st_mysql_sys_var *var, | ||
239 | 80 | void *save, struct st_mysql_value *value); | ||
240 | 81 | typedef void (*mysql_var_update_func)(void* thd, | ||
241 | 82 | struct st_mysql_sys_var *var, | ||
242 | 83 | void *var_ptr, const void *save); | ||
243 | 84 | struct st_mysql_plugin | ||
244 | 85 | { | ||
245 | 86 | int type; | ||
246 | 87 | void *info; | ||
247 | 88 | const char *name; | ||
248 | 89 | const char *author; | ||
249 | 90 | const char *descr; | ||
250 | 91 | int license; | ||
251 | 92 | int (*init)(void *); | ||
252 | 93 | int (*deinit)(void *); | ||
253 | 94 | unsigned int version; | ||
254 | 95 | struct st_mysql_show_var *status_vars; | ||
255 | 96 | struct st_mysql_sys_var **system_vars; | ||
256 | 97 | void * __reserved1; | ||
257 | 98 | }; | ||
258 | 99 | #include "plugin_ftparser.h" | ||
259 | 100 | #include "plugin.h" | ||
260 | 101 | enum enum_ftparser_mode | ||
261 | 102 | { | ||
262 | 103 | MYSQL_FTPARSER_SIMPLE_MODE= 0, | ||
263 | 104 | MYSQL_FTPARSER_WITH_STOPWORDS= 1, | ||
264 | 105 | MYSQL_FTPARSER_FULL_BOOLEAN_INFO= 2 | ||
265 | 106 | }; | ||
266 | 107 | enum enum_ft_token_type | ||
267 | 108 | { | ||
268 | 109 | FT_TOKEN_EOF= 0, | ||
269 | 110 | FT_TOKEN_WORD= 1, | ||
270 | 111 | FT_TOKEN_LEFT_PAREN= 2, | ||
271 | 112 | FT_TOKEN_RIGHT_PAREN= 3, | ||
272 | 113 | FT_TOKEN_STOPWORD= 4 | ||
273 | 114 | }; | ||
274 | 115 | typedef struct st_mysql_ftparser_boolean_info | ||
275 | 116 | { | ||
276 | 117 | enum enum_ft_token_type type; | ||
277 | 118 | int yesno; | ||
278 | 119 | int weight_adjust; | ||
279 | 120 | char wasign; | ||
280 | 121 | char trunc; | ||
281 | 122 | char prev; | ||
282 | 123 | char *quot; | ||
283 | 124 | } MYSQL_FTPARSER_BOOLEAN_INFO; | ||
284 | 125 | typedef struct st_mysql_ftparser_param | ||
285 | 126 | { | ||
286 | 127 | int (*mysql_parse)(struct st_mysql_ftparser_param *, | ||
287 | 128 | char *doc, int doc_len); | ||
288 | 129 | int (*mysql_add_word)(struct st_mysql_ftparser_param *, | ||
289 | 130 | char *word, int word_len, | ||
290 | 131 | MYSQL_FTPARSER_BOOLEAN_INFO *boolean_info); | ||
291 | 132 | void *ftparser_state; | ||
292 | 133 | void *mysql_ftparam; | ||
293 | 134 | struct charset_info_st *cs; | ||
294 | 135 | char *doc; | ||
295 | 136 | int length; | ||
296 | 137 | int flags; | ||
297 | 138 | enum enum_ftparser_mode mode; | ||
298 | 139 | } MYSQL_FTPARSER_PARAM; | ||
299 | 140 | struct st_mysql_ftparser | ||
300 | 141 | { | ||
301 | 142 | int interface_version; | ||
302 | 143 | int (*parse)(MYSQL_FTPARSER_PARAM *param); | ||
303 | 144 | int (*init)(MYSQL_FTPARSER_PARAM *param); | ||
304 | 145 | int (*deinit)(MYSQL_FTPARSER_PARAM *param); | ||
305 | 146 | }; | ||
306 | 147 | #include "plugin_query_rewrite.h" | ||
307 | 148 | struct st_mysql_daemon | ||
308 | 149 | { | ||
309 | 150 | int interface_version; | ||
310 | 151 | }; | ||
311 | 152 | struct st_mysql_information_schema | ||
312 | 153 | { | ||
313 | 154 | int interface_version; | ||
314 | 155 | }; | ||
315 | 156 | struct st_mysql_storage_engine | ||
316 | 157 | { | ||
317 | 158 | int interface_version; | ||
318 | 159 | }; | ||
319 | 160 | struct handlerton; | ||
320 | 161 | struct Mysql_replication { | ||
321 | 162 | int interface_version; | ||
322 | 163 | }; | ||
323 | 164 | struct st_mysql_value | ||
324 | 165 | { | ||
325 | 166 | int (*value_type)(struct st_mysql_value *); | ||
326 | 167 | const char *(*val_str)(struct st_mysql_value *, char *buffer, int *length); | ||
327 | 168 | int (*val_real)(struct st_mysql_value *, double *realbuf); | ||
328 | 169 | int (*val_int)(struct st_mysql_value *, long long *intbuf); | ||
329 | 170 | int (*is_unsigned)(struct st_mysql_value *); | ||
330 | 171 | }; | ||
331 | 172 | int thd_in_lock_tables(const void* thd); | ||
332 | 173 | int thd_tablespace_op(const void* thd); | ||
333 | 174 | long long thd_test_options(const void* thd, long long test_options); | ||
334 | 175 | int thd_sql_command(const void* thd); | ||
335 | 176 | const char *thd_proc_info(void* thd, const char *info); | ||
336 | 177 | void **thd_ha_data(const void* thd, const struct handlerton *hton); | ||
337 | 178 | void thd_storage_lock_wait(void* thd, long long value); | ||
338 | 179 | int thd_tx_isolation(const void* thd); | ||
339 | 180 | char *thd_security_context(void* thd, char *buffer, unsigned int length, | ||
340 | 181 | unsigned int max_query_len); | ||
341 | 182 | void thd_inc_row_count(void* thd); | ||
342 | 183 | int mysql_tmpfile(const char *prefix); | ||
343 | 184 | int thd_killed(const void* thd); | ||
344 | 185 | unsigned long thd_get_thread_id(const void* thd); | ||
345 | 186 | void thd_get_xid(const void* thd, MYSQL_XID *xid); | ||
346 | 187 | void mysql_query_cache_invalidate4(void* thd, | ||
347 | 188 | const char *key, unsigned int key_length, | ||
348 | 189 | int using_trx); | ||
349 | 190 | void *thd_get_ha_data(const void* thd, const struct handlerton *hton); | ||
350 | 191 | void thd_set_ha_data(void* thd, const struct handlerton *hton, | ||
351 | 192 | const void *ha_data); | ||
352 | 193 | struct st_mysql_query_rewrite | ||
353 | 194 | { | ||
354 | 195 | int interface_version; | ||
355 | 196 | char* (*rewrite_query)(const char* schema, size_t schema_len, const char* query, size_t orig_query_len, size_t* rewritten_query_len); | ||
356 | 197 | void (*free_rewritten_query)(char* query); | ||
357 | 198 | }; | ||
358 | 0 | 199 | ||
359 | === removed file 'include/probes_mysql_nodtrace.h' | |||
360 | --- include/probes_mysql_nodtrace.h 2010-03-01 00:06:27 +0000 | |||
361 | +++ include/probes_mysql_nodtrace.h 1970-01-01 00:00:00 +0000 | |||
362 | @@ -1,129 +0,0 @@ | |||
363 | 1 | /* | ||
364 | 2 | * Generated by dheadgen(1). | ||
365 | 3 | */ | ||
366 | 4 | |||
367 | 5 | #ifndef _PROBES_MYSQL_D | ||
368 | 6 | #define _PROBES_MYSQL_D | ||
369 | 7 | |||
370 | 8 | #ifdef __cplusplus | ||
371 | 9 | extern "C" { | ||
372 | 10 | #endif | ||
373 | 11 | |||
374 | 12 | #define MYSQL_CONNECTION_START(arg0, arg1, arg2) | ||
375 | 13 | #define MYSQL_CONNECTION_START_ENABLED() (0) | ||
376 | 14 | #define MYSQL_CONNECTION_DONE(arg0, arg1) | ||
377 | 15 | #define MYSQL_CONNECTION_DONE_ENABLED() (0) | ||
378 | 16 | #define MYSQL_COMMAND_START(arg0, arg1, arg2, arg3) | ||
379 | 17 | #define MYSQL_COMMAND_START_ENABLED() (0) | ||
380 | 18 | #define MYSQL_COMMAND_DONE(arg0) | ||
381 | 19 | #define MYSQL_COMMAND_DONE_ENABLED() (0) | ||
382 | 20 | #define MYSQL_QUERY_START(arg0, arg1, arg2, arg3, arg4) | ||
383 | 21 | #define MYSQL_QUERY_START_ENABLED() (0) | ||
384 | 22 | #define MYSQL_QUERY_DONE(arg0) | ||
385 | 23 | #define MYSQL_QUERY_DONE_ENABLED() (0) | ||
386 | 24 | #define MYSQL_QUERY_PARSE_START(arg0) | ||
387 | 25 | #define MYSQL_QUERY_PARSE_START_ENABLED() (0) | ||
388 | 26 | #define MYSQL_QUERY_PARSE_DONE(arg0) | ||
389 | 27 | #define MYSQL_QUERY_PARSE_DONE_ENABLED() (0) | ||
390 | 28 | #define MYSQL_QUERY_CACHE_HIT(arg0, arg1) | ||
391 | 29 | #define MYSQL_QUERY_CACHE_HIT_ENABLED() (0) | ||
392 | 30 | #define MYSQL_QUERY_CACHE_MISS(arg0) | ||
393 | 31 | #define MYSQL_QUERY_CACHE_MISS_ENABLED() (0) | ||
394 | 32 | #define MYSQL_QUERY_EXEC_START(arg0, arg1, arg2, arg3, arg4, arg5) | ||
395 | 33 | #define MYSQL_QUERY_EXEC_START_ENABLED() (0) | ||
396 | 34 | #define MYSQL_QUERY_EXEC_DONE(arg0) | ||
397 | 35 | #define MYSQL_QUERY_EXEC_DONE_ENABLED() (0) | ||
398 | 36 | #define MYSQL_INSERT_ROW_START(arg0, arg1) | ||
399 | 37 | #define MYSQL_INSERT_ROW_START_ENABLED() (0) | ||
400 | 38 | #define MYSQL_INSERT_ROW_DONE(arg0) | ||
401 | 39 | #define MYSQL_INSERT_ROW_DONE_ENABLED() (0) | ||
402 | 40 | #define MYSQL_UPDATE_ROW_START(arg0, arg1) | ||
403 | 41 | #define MYSQL_UPDATE_ROW_START_ENABLED() (0) | ||
404 | 42 | #define MYSQL_UPDATE_ROW_DONE(arg0) | ||
405 | 43 | #define MYSQL_UPDATE_ROW_DONE_ENABLED() (0) | ||
406 | 44 | #define MYSQL_DELETE_ROW_START(arg0, arg1) | ||
407 | 45 | #define MYSQL_DELETE_ROW_START_ENABLED() (0) | ||
408 | 46 | #define MYSQL_DELETE_ROW_DONE(arg0) | ||
409 | 47 | #define MYSQL_DELETE_ROW_DONE_ENABLED() (0) | ||
410 | 48 | #define MYSQL_READ_ROW_START(arg0, arg1, arg2) | ||
411 | 49 | #define MYSQL_READ_ROW_START_ENABLED() (0) | ||
412 | 50 | #define MYSQL_READ_ROW_DONE(arg0) | ||
413 | 51 | #define MYSQL_READ_ROW_DONE_ENABLED() (0) | ||
414 | 52 | #define MYSQL_INDEX_READ_ROW_START(arg0, arg1) | ||
415 | 53 | #define MYSQL_INDEX_READ_ROW_START_ENABLED() (0) | ||
416 | 54 | #define MYSQL_INDEX_READ_ROW_DONE(arg0) | ||
417 | 55 | #define MYSQL_INDEX_READ_ROW_DONE_ENABLED() (0) | ||
418 | 56 | #define MYSQL_HANDLER_RDLOCK_START(arg0, arg1) | ||
419 | 57 | #define MYSQL_HANDLER_RDLOCK_START_ENABLED() (0) | ||
420 | 58 | #define MYSQL_HANDLER_WRLOCK_START(arg0, arg1) | ||
421 | 59 | #define MYSQL_HANDLER_WRLOCK_START_ENABLED() (0) | ||
422 | 60 | #define MYSQL_HANDLER_UNLOCK_START(arg0, arg1) | ||
423 | 61 | #define MYSQL_HANDLER_UNLOCK_START_ENABLED() (0) | ||
424 | 62 | #define MYSQL_HANDLER_RDLOCK_DONE(arg0) | ||
425 | 63 | #define MYSQL_HANDLER_RDLOCK_DONE_ENABLED() (0) | ||
426 | 64 | #define MYSQL_HANDLER_WRLOCK_DONE(arg0) | ||
427 | 65 | #define MYSQL_HANDLER_WRLOCK_DONE_ENABLED() (0) | ||
428 | 66 | #define MYSQL_HANDLER_UNLOCK_DONE(arg0) | ||
429 | 67 | #define MYSQL_HANDLER_UNLOCK_DONE_ENABLED() (0) | ||
430 | 68 | #define MYSQL_FILESORT_START(arg0, arg1) | ||
431 | 69 | #define MYSQL_FILESORT_START_ENABLED() (0) | ||
432 | 70 | #define MYSQL_FILESORT_DONE(arg0, arg1) | ||
433 | 71 | #define MYSQL_FILESORT_DONE_ENABLED() (0) | ||
434 | 72 | #define MYSQL_SELECT_START(arg0) | ||
435 | 73 | #define MYSQL_SELECT_START_ENABLED() (0) | ||
436 | 74 | #define MYSQL_SELECT_DONE(arg0, arg1) | ||
437 | 75 | #define MYSQL_SELECT_DONE_ENABLED() (0) | ||
438 | 76 | #define MYSQL_INSERT_START(arg0) | ||
439 | 77 | #define MYSQL_INSERT_START_ENABLED() (0) | ||
440 | 78 | #define MYSQL_INSERT_DONE(arg0, arg1) | ||
441 | 79 | #define MYSQL_INSERT_DONE_ENABLED() (0) | ||
442 | 80 | #define MYSQL_INSERT_SELECT_START(arg0) | ||
443 | 81 | #define MYSQL_INSERT_SELECT_START_ENABLED() (0) | ||
444 | 82 | #define MYSQL_INSERT_SELECT_DONE(arg0, arg1) | ||
445 | 83 | #define MYSQL_INSERT_SELECT_DONE_ENABLED() (0) | ||
446 | 84 | #define MYSQL_UPDATE_START(arg0) | ||
447 | 85 | #define MYSQL_UPDATE_START_ENABLED() (0) | ||
448 | 86 | #define MYSQL_UPDATE_DONE(arg0, arg1, arg2) | ||
449 | 87 | #define MYSQL_UPDATE_DONE_ENABLED() (0) | ||
450 | 88 | #define MYSQL_MULTI_UPDATE_START(arg0) | ||
451 | 89 | #define MYSQL_MULTI_UPDATE_START_ENABLED() (0) | ||
452 | 90 | #define MYSQL_MULTI_UPDATE_DONE(arg0, arg1, arg2) | ||
453 | 91 | #define MYSQL_MULTI_UPDATE_DONE_ENABLED() (0) | ||
454 | 92 | #define MYSQL_DELETE_START(arg0) | ||
455 | 93 | #define MYSQL_DELETE_START_ENABLED() (0) | ||
456 | 94 | #define MYSQL_DELETE_DONE(arg0, arg1) | ||
457 | 95 | #define MYSQL_DELETE_DONE_ENABLED() (0) | ||
458 | 96 | #define MYSQL_MULTI_DELETE_START(arg0) | ||
459 | 97 | #define MYSQL_MULTI_DELETE_START_ENABLED() (0) | ||
460 | 98 | #define MYSQL_MULTI_DELETE_DONE(arg0, arg1) | ||
461 | 99 | #define MYSQL_MULTI_DELETE_DONE_ENABLED() (0) | ||
462 | 100 | #define MYSQL_NET_READ_START() | ||
463 | 101 | #define MYSQL_NET_READ_START_ENABLED() (0) | ||
464 | 102 | #define MYSQL_NET_READ_DONE(arg0, arg1) | ||
465 | 103 | #define MYSQL_NET_READ_DONE_ENABLED() (0) | ||
466 | 104 | #define MYSQL_NET_WRITE_START(arg0) | ||
467 | 105 | #define MYSQL_NET_WRITE_START_ENABLED() (0) | ||
468 | 106 | #define MYSQL_NET_WRITE_DONE(arg0) | ||
469 | 107 | #define MYSQL_NET_WRITE_DONE_ENABLED() (0) | ||
470 | 108 | #define MYSQL_KEYCACHE_READ_START(arg0, arg1, arg2, arg3) | ||
471 | 109 | #define MYSQL_KEYCACHE_READ_START_ENABLED() (0) | ||
472 | 110 | #define MYSQL_KEYCACHE_READ_BLOCK(arg0) | ||
473 | 111 | #define MYSQL_KEYCACHE_READ_BLOCK_ENABLED() (0) | ||
474 | 112 | #define MYSQL_KEYCACHE_READ_HIT() | ||
475 | 113 | #define MYSQL_KEYCACHE_READ_HIT_ENABLED() (0) | ||
476 | 114 | #define MYSQL_KEYCACHE_READ_MISS() | ||
477 | 115 | #define MYSQL_KEYCACHE_READ_MISS_ENABLED() (0) | ||
478 | 116 | #define MYSQL_KEYCACHE_READ_DONE(arg0, arg1) | ||
479 | 117 | #define MYSQL_KEYCACHE_READ_DONE_ENABLED() (0) | ||
480 | 118 | #define MYSQL_KEYCACHE_WRITE_START(arg0, arg1, arg2, arg3) | ||
481 | 119 | #define MYSQL_KEYCACHE_WRITE_START_ENABLED() (0) | ||
482 | 120 | #define MYSQL_KEYCACHE_WRITE_BLOCK(arg0) | ||
483 | 121 | #define MYSQL_KEYCACHE_WRITE_BLOCK_ENABLED() (0) | ||
484 | 122 | #define MYSQL_KEYCACHE_WRITE_DONE(arg0, arg1) | ||
485 | 123 | #define MYSQL_KEYCACHE_WRITE_DONE_ENABLED() (0) | ||
486 | 124 | |||
487 | 125 | #ifdef __cplusplus | ||
488 | 126 | } | ||
489 | 127 | #endif | ||
490 | 128 | |||
491 | 129 | #endif /* _PROBES_MYSQL_D */ | ||
492 | 130 | 0 | ||
493 | === added directory 'plugin/rewrite_lower' | |||
494 | === added file 'plugin/rewrite_lower/CMakeLists.txt' | |||
495 | --- plugin/rewrite_lower/CMakeLists.txt 1970-01-01 00:00:00 +0000 | |||
496 | +++ plugin/rewrite_lower/CMakeLists.txt 2010-10-15 16:16:49 +0000 | |||
497 | @@ -0,0 +1,17 @@ | |||
498 | 1 | # Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. | ||
499 | 2 | # | ||
500 | 3 | # This program is free software; you can redistribute it and/or modify | ||
501 | 4 | # it under the terms of the GNU General Public License as published by | ||
502 | 5 | # the Free Software Foundation; version 2 of the License. | ||
503 | 6 | # | ||
504 | 7 | # This program is distributed in the hope that it will be useful, | ||
505 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
506 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
507 | 10 | # GNU General Public License for more details. | ||
508 | 11 | # | ||
509 | 12 | # You should have received a copy of the GNU General Public License | ||
510 | 13 | # along with this program; if not, write to the Free Software | ||
511 | 14 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
512 | 15 | |||
513 | 16 | MYSQL_ADD_PLUGIN(rewrite_lower rewrite_lower.cc | ||
514 | 17 | MODULE_ONLY MODULE_OUTPUT_NAME "rewrite_lower") | ||
515 | 0 | 18 | ||
516 | === added file 'plugin/rewrite_lower/Makefile.am' | |||
517 | --- plugin/rewrite_lower/Makefile.am 1970-01-01 00:00:00 +0000 | |||
518 | +++ plugin/rewrite_lower/Makefile.am 2010-10-15 16:16:49 +0000 | |||
519 | @@ -0,0 +1,32 @@ | |||
520 | 1 | # Copyright (C) 2006 MySQL AB | ||
521 | 2 | # | ||
522 | 3 | # This program is free software; you can redistribute it and/or modify | ||
523 | 4 | # it under the terms of the GNU General Public License as published by | ||
524 | 5 | # the Free Software Foundation; version 2 of the License. | ||
525 | 6 | # | ||
526 | 7 | # This program is distributed in the hope that it will be useful, | ||
527 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
528 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
529 | 10 | # GNU General Public License for more details. | ||
530 | 11 | # | ||
531 | 12 | # You should have received a copy of the GNU General Public License | ||
532 | 13 | # along with this program; if not, write to the Free Software | ||
533 | 14 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
534 | 15 | |||
535 | 16 | ## Makefile.am for query rewrite plugin that converts a query to lower case | ||
536 | 17 | |||
537 | 18 | pkgplugindir = $(pkglibdir)/plugin | ||
538 | 19 | INCLUDES = -I$(top_srcdir)/include \ | ||
539 | 20 | -I$(top_srcdir)/sql \ | ||
540 | 21 | -I$(top_srcdir)/regex \ | ||
541 | 22 | -I$(srcdir) | ||
542 | 23 | |||
543 | 24 | #noinst_HEADERS = rewrite_lower.h | ||
544 | 25 | |||
545 | 26 | pkgplugin_LTLIBRARIES = rewrite_lower.la | ||
546 | 27 | rewrite_lower_la_LDFLAGS = -module -rpath $(pkgplugindir) -L$(top_builddir)/libservices -lmysqlservices -lstdc++ | ||
547 | 28 | rewrite_lower_la_CXXFLAGS= $(AM_CXXFLAGS) -DMYSQL_DYNAMIC_PLUGIN | ||
548 | 29 | rewrite_lower_la_CFLAGS = $(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN | ||
549 | 30 | rewrite_lower_la_SOURCES = rewrite_lower.cc | ||
550 | 31 | |||
551 | 32 | EXTRA_DIST= plugin.in CMakeLists.txt | ||
552 | 0 | 33 | ||
553 | === added file 'plugin/rewrite_lower/plug.in' | |||
554 | --- plugin/rewrite_lower/plug.in 1970-01-01 00:00:00 +0000 | |||
555 | +++ plugin/rewrite_lower/plug.in 2010-10-15 16:16:49 +0000 | |||
556 | @@ -0,0 +1,4 @@ | |||
557 | 1 | MYSQL_PLUGIN(rewrite_lower,[Convert query to lower-case Query Rewriting Plugin], | ||
558 | 2 | [Example query rewriting plugin.]) | ||
559 | 3 | MYSQL_PLUGIN_DYNAMIC(rewrite_lower, [rewrite_lower.la]) | ||
560 | 4 | MYSQL_PLUGIN_STATIC(rewrite_lower, [librewritelower.a]) | ||
561 | 0 | 5 | ||
562 | === added file 'plugin/rewrite_lower/rewrite_lower.cc' | |||
563 | --- plugin/rewrite_lower/rewrite_lower.cc 1970-01-01 00:00:00 +0000 | |||
564 | +++ plugin/rewrite_lower/rewrite_lower.cc 2010-10-15 16:16:49 +0000 | |||
565 | @@ -0,0 +1,84 @@ | |||
566 | 1 | /* Copyright (C) 2010 Akiban Technologies | ||
567 | 2 | |||
568 | 3 | This program is free software; you can redistribute it and/or modify | ||
569 | 4 | it under the terms of the GNU General Public License as published by | ||
570 | 5 | the Free Software Foundation; version 2 of the License. | ||
571 | 6 | |||
572 | 7 | This program is distributed in the hope that it will be useful, | ||
573 | 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
574 | 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
575 | 10 | GNU General Public License for more details. | ||
576 | 11 | |||
577 | 12 | You should have received a copy of the GNU General Public License | ||
578 | 13 | along with this program; if not, write to the Free Software | ||
579 | 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ | ||
580 | 15 | |||
581 | 16 | #include <ctype.h> | ||
582 | 17 | #include <string.h> | ||
583 | 18 | |||
584 | 19 | #include <mysql/plugin.h> | ||
585 | 20 | #include <mysql/plugin_query_rewrite.h> | ||
586 | 21 | |||
587 | 22 | using namespace std; | ||
588 | 23 | |||
589 | 24 | static char* rewrite_lower(const char*, | ||
590 | 25 | size_t, | ||
591 | 26 | const char* query, | ||
592 | 27 | size_t original_query_len, | ||
593 | 28 | size_t* rewritten_query_len) | ||
594 | 29 | { | ||
595 | 30 | char* rewritten_query= new char[original_query_len]; | ||
596 | 31 | memcpy(rewritten_query, query, original_query_len); | ||
597 | 32 | while (*rewritten_query++ = tolower(*rewritten_query)); | ||
598 | 33 | *rewritten_query_len= original_query_len; | ||
599 | 34 | return (rewritten_query - (original_query_len + 1)); | ||
600 | 35 | } | ||
601 | 36 | |||
602 | 37 | |||
603 | 38 | static void free_rewritten_query(char* query) | ||
604 | 39 | { | ||
605 | 40 | delete [] query; | ||
606 | 41 | } | ||
607 | 42 | |||
608 | 43 | |||
609 | 44 | static void null_parse_rewrite(MYSQL_THD, MYSQL_LEXPTR) | ||
610 | 45 | { | ||
611 | 46 | } | ||
612 | 47 | |||
613 | 48 | |||
614 | 49 | static int rewrite_lower_plugin_init(void *) | ||
615 | 50 | { | ||
616 | 51 | return 0; | ||
617 | 52 | } | ||
618 | 53 | |||
619 | 54 | static int rewrite_lower_plugin_deinit(void *) | ||
620 | 55 | { | ||
621 | 56 | return 0; | ||
622 | 57 | } | ||
623 | 58 | |||
624 | 59 | static struct st_mysql_query_rewrite rewrite_lower_descriptor= { | ||
625 | 60 | MYSQL_QUERY_REWRITE_INTERFACE_VERSION, /* interface version */ | ||
626 | 61 | rewrite_lower, /* rewrite function */ | ||
627 | 62 | free_rewritten_query, /* free allocated memory for rewritten query */ | ||
628 | 63 | null_parse_rewrite /* rewrite the parse tree (do nothing) */ | ||
629 | 64 | }; | ||
630 | 65 | |||
631 | 66 | /* | ||
632 | 67 | Plugin library descriptor | ||
633 | 68 | */ | ||
634 | 69 | mysql_declare_plugin(rewrite_lower) | ||
635 | 70 | { | ||
636 | 71 | MYSQL_QUERY_REWRITE_PLUGIN, | ||
637 | 72 | &rewrite_lower_descriptor, | ||
638 | 73 | "rewrite_lower", | ||
639 | 74 | "Padraig O'Sullivan", | ||
640 | 75 | "Simple example query rewriting plugin", | ||
641 | 76 | PLUGIN_LICENSE_GPL, | ||
642 | 77 | rewrite_lower_plugin_init, /* Plugin Init */ | ||
643 | 78 | rewrite_lower_plugin_deinit, /* Plugin Deinit */ | ||
644 | 79 | 0x0100 /* 1.0 */, | ||
645 | 80 | NULL, /* status variables */ | ||
646 | 81 | NULL, /* system variables */ | ||
647 | 82 | NULL /* config options */ | ||
648 | 83 | } | ||
649 | 84 | mysql_declare_plugin_end; | ||
650 | 0 | 85 | ||
651 | === modified file 'sql/CMakeLists.txt' | |||
652 | --- sql/CMakeLists.txt 2010-09-28 15:30:47 +0000 | |||
653 | +++ sql/CMakeLists.txt 2010-10-15 16:16:49 +0000 | |||
654 | @@ -67,7 +67,7 @@ | |||
655 | 67 | event_queue.cc event_db_repository.cc | 67 | event_queue.cc event_db_repository.cc |
656 | 68 | sql_tablespace.cc events.cc ../sql-common/my_user.c | 68 | sql_tablespace.cc events.cc ../sql-common/my_user.c |
657 | 69 | partition_info.cc sql_locale.cc | 69 | partition_info.cc sql_locale.cc |
659 | 70 | sql_servers.cc sql_audit.cc | 70 | sql_servers.cc sql_audit.cc sql_query_rewrite.cc |
660 | 71 | sql_connect.cc scheduler.cc | 71 | sql_connect.cc scheduler.cc |
661 | 72 | sql_profile.cc event_parse_data.cc | 72 | sql_profile.cc event_parse_data.cc |
662 | 73 | sql_bootstrap.cc | 73 | sql_bootstrap.cc |
663 | 74 | 74 | ||
664 | === modified file 'sql/Makefile.am' | |||
665 | --- sql/Makefile.am 2010-08-20 09:15:16 +0000 | |||
666 | +++ sql/Makefile.am 2010-10-15 16:16:49 +0000 | |||
667 | @@ -130,7 +130,7 @@ | |||
668 | 130 | sql_plugin.h authors.h event_parse_data.h \ | 130 | sql_plugin.h authors.h event_parse_data.h \ |
669 | 131 | event_data_objects.h event_scheduler.h \ | 131 | event_data_objects.h event_scheduler.h \ |
670 | 132 | sql_partition.h partition_info.h partition_element.h \ | 132 | sql_partition.h partition_info.h partition_element.h \ |
672 | 133 | sql_audit.h sql_alter.h sql_partition_admin.h \ | 133 | sql_audit.h sql_query_rewrite.h sql_alter.h sql_partition_admin.h \ |
673 | 134 | contributors.h sql_servers.h sql_signal.h records.h \ | 134 | contributors.h sql_servers.h sql_signal.h records.h \ |
674 | 135 | sql_prepare.h rpl_handler.h replication.h mdl.h \ | 135 | sql_prepare.h rpl_handler.h replication.h mdl.h \ |
675 | 136 | sql_cmd.h \ | 136 | sql_cmd.h \ |
676 | @@ -176,7 +176,7 @@ | |||
677 | 176 | sql_plugin.cc \ | 176 | sql_plugin.cc \ |
678 | 177 | sql_builtin.cc sql_tablespace.cc partition_info.cc \ | 177 | sql_builtin.cc sql_tablespace.cc partition_info.cc \ |
679 | 178 | sql_servers.cc event_parse_data.cc sql_signal.cc \ | 178 | sql_servers.cc event_parse_data.cc sql_signal.cc \ |
681 | 179 | mdl.cc transaction.cc sql_audit.cc \ | 179 | mdl.cc transaction.cc sql_audit.cc sql_query_rewrite.cc \ |
682 | 180 | sha2.cc \ | 180 | sha2.cc \ |
683 | 181 | sql_alter.cc \ | 181 | sql_alter.cc \ |
684 | 182 | sql_partition_admin.cc | 182 | sql_partition_admin.cc |
685 | 183 | 183 | ||
686 | === modified file 'sql/sql_parse.cc' | |||
687 | --- sql/sql_parse.cc 2010-09-01 22:59:33 +0000 | |||
688 | +++ sql/sql_parse.cc 2010-10-15 16:16:49 +0000 | |||
689 | @@ -99,6 +99,7 @@ | |||
690 | 99 | #include "probes_mysql.h" | 99 | #include "probes_mysql.h" |
691 | 100 | #include "set_var.h" | 100 | #include "set_var.h" |
692 | 101 | #include "sql_bootstrap.h" | 101 | #include "sql_bootstrap.h" |
693 | 102 | #include "sql_query_rewrite.h" | ||
694 | 102 | 103 | ||
695 | 103 | #define FLAGSTR(V,F) ((V)&(F)?#F" ":"") | 104 | #define FLAGSTR(V,F) ((V)&(F)?#F" ":"") |
696 | 104 | 105 | ||
697 | @@ -556,6 +557,7 @@ | |||
698 | 556 | mode we have only one thread. | 557 | mode we have only one thread. |
699 | 557 | */ | 558 | */ |
700 | 558 | thd->set_time(); | 559 | thd->set_time(); |
701 | 560 | mysql_rewrite_raw_query(thd); | ||
702 | 559 | Parser_state parser_state; | 561 | Parser_state parser_state; |
703 | 560 | if (parser_state.init(thd, thd->query(), length)) | 562 | if (parser_state.init(thd, thd->query(), length)) |
704 | 561 | { | 563 | { |
705 | @@ -1118,6 +1120,7 @@ | |||
706 | 1118 | char *packet_end= thd->query() + thd->query_length(); | 1120 | char *packet_end= thd->query() + thd->query_length(); |
707 | 1119 | /* 'b' stands for 'buffer' parameter', special for 'my_snprintf' */ | 1121 | /* 'b' stands for 'buffer' parameter', special for 'my_snprintf' */ |
708 | 1120 | 1122 | ||
709 | 1123 | mysql_rewrite_raw_query(thd); | ||
710 | 1121 | general_log_write(thd, command, thd->query(), thd->query_length()); | 1124 | general_log_write(thd, command, thd->query(), thd->query_length()); |
711 | 1122 | DBUG_PRINT("query",("%-.4096s",thd->query())); | 1125 | DBUG_PRINT("query",("%-.4096s",thd->query())); |
712 | 1123 | #if defined(ENABLED_PROFILING) | 1126 | #if defined(ENABLED_PROFILING) |
713 | @@ -5559,6 +5562,7 @@ | |||
714 | 5559 | { | 5562 | { |
715 | 5560 | if (! thd->is_error()) | 5563 | if (! thd->is_error()) |
716 | 5561 | { | 5564 | { |
717 | 5565 | mysql_rewrite_parse_tree(thd); | ||
718 | 5562 | const char *found_semicolon= parser_state->m_lip.found_semicolon; | 5566 | const char *found_semicolon= parser_state->m_lip.found_semicolon; |
719 | 5563 | /* | 5567 | /* |
720 | 5564 | Binlog logs a string starting from thd->query and having length | 5568 | Binlog logs a string starting from thd->query and having length |
721 | 5565 | 5569 | ||
722 | === modified file 'sql/sql_plugin.cc' | |||
723 | --- sql/sql_plugin.cc 2010-09-21 21:27:43 +0000 | |||
724 | +++ sql/sql_plugin.cc 2010-10-15 16:16:49 +0000 | |||
725 | @@ -64,6 +64,7 @@ | |||
726 | 64 | { C_STRING_WITH_LEN("DAEMON") }, | 64 | { C_STRING_WITH_LEN("DAEMON") }, |
727 | 65 | { C_STRING_WITH_LEN("INFORMATION SCHEMA") }, | 65 | { C_STRING_WITH_LEN("INFORMATION SCHEMA") }, |
728 | 66 | { C_STRING_WITH_LEN("AUDIT") }, | 66 | { C_STRING_WITH_LEN("AUDIT") }, |
729 | 67 | { C_STRING_WITH_LEN("QUERY REWRITE") }, | ||
730 | 67 | { C_STRING_WITH_LEN("REPLICATION") }, | 68 | { C_STRING_WITH_LEN("REPLICATION") }, |
731 | 68 | }; | 69 | }; |
732 | 69 | 70 | ||
733 | @@ -73,6 +74,9 @@ | |||
734 | 73 | extern int initialize_audit_plugin(st_plugin_int *plugin); | 74 | extern int initialize_audit_plugin(st_plugin_int *plugin); |
735 | 74 | extern int finalize_audit_plugin(st_plugin_int *plugin); | 75 | extern int finalize_audit_plugin(st_plugin_int *plugin); |
736 | 75 | 76 | ||
737 | 77 | extern int initialize_query_rewrite_plugin(st_plugin_int *plugin); | ||
738 | 78 | extern int finalize_query_rewrite_plugin(st_plugin_int *plugin); | ||
739 | 79 | |||
740 | 76 | /* | 80 | /* |
741 | 77 | The number of elements in both plugin_type_initialize and | 81 | The number of elements in both plugin_type_initialize and |
742 | 78 | plugin_type_deinitialize should equal to the number of plugins | 82 | plugin_type_deinitialize should equal to the number of plugins |
743 | @@ -81,13 +85,13 @@ | |||
744 | 81 | plugin_type_init plugin_type_initialize[MYSQL_MAX_PLUGIN_TYPE_NUM]= | 85 | plugin_type_init plugin_type_initialize[MYSQL_MAX_PLUGIN_TYPE_NUM]= |
745 | 82 | { | 86 | { |
746 | 83 | 0,ha_initialize_handlerton,0,0,initialize_schema_table, | 87 | 0,ha_initialize_handlerton,0,0,initialize_schema_table, |
748 | 84 | initialize_audit_plugin | 88 | initialize_audit_plugin,initialize_query_rewrite_plugin |
749 | 85 | }; | 89 | }; |
750 | 86 | 90 | ||
751 | 87 | plugin_type_init plugin_type_deinitialize[MYSQL_MAX_PLUGIN_TYPE_NUM]= | 91 | plugin_type_init plugin_type_deinitialize[MYSQL_MAX_PLUGIN_TYPE_NUM]= |
752 | 88 | { | 92 | { |
753 | 89 | 0,ha_finalize_handlerton,0,0,finalize_schema_table, | 93 | 0,ha_finalize_handlerton,0,0,finalize_schema_table, |
755 | 90 | finalize_audit_plugin | 94 | finalize_audit_plugin,finalize_query_rewrite_plugin |
756 | 91 | }; | 95 | }; |
757 | 92 | 96 | ||
758 | 93 | #ifdef HAVE_DLOPEN | 97 | #ifdef HAVE_DLOPEN |
759 | @@ -110,6 +114,7 @@ | |||
760 | 110 | MYSQL_DAEMON_INTERFACE_VERSION, | 114 | MYSQL_DAEMON_INTERFACE_VERSION, |
761 | 111 | MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION, | 115 | MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION, |
762 | 112 | MYSQL_AUDIT_INTERFACE_VERSION, | 116 | MYSQL_AUDIT_INTERFACE_VERSION, |
763 | 117 | MYSQL_QUERY_REWRITE_INTERFACE_VERSION, | ||
764 | 113 | MYSQL_REPLICATION_INTERFACE_VERSION | 118 | MYSQL_REPLICATION_INTERFACE_VERSION |
765 | 114 | }; | 119 | }; |
766 | 115 | static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]= | 120 | static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]= |
767 | @@ -120,6 +125,7 @@ | |||
768 | 120 | MYSQL_DAEMON_INTERFACE_VERSION, | 125 | MYSQL_DAEMON_INTERFACE_VERSION, |
769 | 121 | MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION, | 126 | MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION, |
770 | 122 | MYSQL_AUDIT_INTERFACE_VERSION, | 127 | MYSQL_AUDIT_INTERFACE_VERSION, |
771 | 128 | MYSQL_QUERY_REWRITE_INTERFACE_VERSION, | ||
772 | 123 | MYSQL_REPLICATION_INTERFACE_VERSION | 129 | MYSQL_REPLICATION_INTERFACE_VERSION |
773 | 124 | }; | 130 | }; |
774 | 125 | 131 | ||
775 | 126 | 132 | ||
776 | === added file 'sql/sql_query_rewrite.cc' | |||
777 | --- sql/sql_query_rewrite.cc 1970-01-01 00:00:00 +0000 | |||
778 | +++ sql/sql_query_rewrite.cc 2010-10-15 16:16:49 +0000 | |||
779 | @@ -0,0 +1,167 @@ | |||
780 | 1 | /* Copyright (c) 2010, Akiban Technologies. All rights reserved. | ||
781 | 2 | |||
782 | 3 | This program is free software; you can redistribute it and/or modify | ||
783 | 4 | it under the terms of the GNU General Public License as published by | ||
784 | 5 | the Free Software Foundation; version 2 of the License. | ||
785 | 6 | |||
786 | 7 | This program is distributed in the hope that it will be useful, | ||
787 | 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
788 | 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
789 | 10 | GNU General Public License for more details. | ||
790 | 11 | |||
791 | 12 | You should have received a copy of the GNU General Public License | ||
792 | 13 | along with this program; if not, write to the Free Software Foundation, | ||
793 | 14 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ | ||
794 | 15 | |||
795 | 16 | #include "sql_priv.h" | ||
796 | 17 | #include "sql_parse.h" | ||
797 | 18 | #include "sql_query_rewrite.h" | ||
798 | 19 | |||
799 | 20 | extern int initialize_query_rewrite_plugin(st_plugin_int *plugin); | ||
800 | 21 | extern int finalize_query_rewrite_plugin(st_plugin_int *plugin); | ||
801 | 22 | |||
802 | 23 | #ifndef EMBEDDED_LIBRARY | ||
803 | 24 | |||
804 | 25 | /** | ||
805 | 26 | Rewrites a query by invoking the plugin's query_rewrite method. | ||
806 | 27 | |||
807 | 28 | @param[in] thd | ||
808 | 29 | @param[in] plugin | ||
809 | 30 | @param[in] arg | ||
810 | 31 | |||
811 | 32 | @retval FALSE always | ||
812 | 33 | */ | ||
813 | 34 | static my_bool query_text_rewrite(THD *thd, | ||
814 | 35 | plugin_ref plugin, | ||
815 | 36 | void *) | ||
816 | 37 | { | ||
817 | 38 | st_mysql_query_rewrite *data= plugin_data(plugin, struct st_mysql_query_rewrite *); | ||
818 | 39 | |||
819 | 40 | /* rewrite the query */ | ||
820 | 41 | if (data) | ||
821 | 42 | { | ||
822 | 43 | size_t rewritten_query_len= 0; | ||
823 | 44 | char *rewritten_query= data->rewrite_query(thd->db, thd->db_length, thd->query(), thd->query_length(), &rewritten_query_len); | ||
824 | 45 | if (rewritten_query != NULL && rewritten_query_len > 0) | ||
825 | 46 | { | ||
826 | 47 | alloc_query(thd, rewritten_query, rewritten_query_len); | ||
827 | 48 | data->free_rewritten_query(rewritten_query); | ||
828 | 49 | } | ||
829 | 50 | } | ||
830 | 51 | |||
831 | 52 | return 0; | ||
832 | 53 | } | ||
833 | 54 | |||
834 | 55 | |||
835 | 56 | /** | ||
836 | 57 | Rewrites a query by invoking the plugin's rewrite_parse_tree method. | ||
837 | 58 | |||
838 | 59 | @param[in] thd | ||
839 | 60 | @param[in] plugin | ||
840 | 61 | @param[in] arg | ||
841 | 62 | |||
842 | 63 | @retval FALSE always | ||
843 | 64 | */ | ||
844 | 65 | static my_bool parse_tree_rewrite(THD *thd, | ||
845 | 66 | plugin_ref plugin, | ||
846 | 67 | void *) | ||
847 | 68 | { | ||
848 | 69 | st_mysql_query_rewrite *data= plugin_data(plugin, struct st_mysql_query_rewrite *); | ||
849 | 70 | |||
850 | 71 | /* rewrite the parse tree */ | ||
851 | 72 | if (data) | ||
852 | 73 | { | ||
853 | 74 | data->rewrite_parse_tree(thd, thd->lex); | ||
854 | 75 | } | ||
855 | 76 | |||
856 | 77 | return 0; | ||
857 | 78 | } | ||
858 | 79 | |||
859 | 80 | |||
860 | 81 | void mysql_rewrite_raw_query(THD *thd) | ||
861 | 82 | { | ||
862 | 83 | plugin_foreach(thd, | ||
863 | 84 | query_text_rewrite, | ||
864 | 85 | MYSQL_QUERY_REWRITE_PLUGIN, | ||
865 | 86 | NULL); | ||
866 | 87 | } | ||
867 | 88 | |||
868 | 89 | |||
869 | 90 | void mysql_rewrite_parse_tree(THD *thd) | ||
870 | 91 | { | ||
871 | 92 | plugin_foreach(thd, | ||
872 | 93 | parse_tree_rewrite, | ||
873 | 94 | MYSQL_QUERY_REWRITE_PLUGIN, | ||
874 | 95 | NULL); | ||
875 | 96 | } | ||
876 | 97 | |||
877 | 98 | /** | ||
878 | 99 | Initialize a query rewrite plug-in | ||
879 | 100 | |||
880 | 101 | @param[in] plugin | ||
881 | 102 | |||
882 | 103 | @retval FALSE OK | ||
883 | 104 | @retval TRUE There was an error. | ||
884 | 105 | */ | ||
885 | 106 | int initialize_query_rewrite_plugin(st_plugin_int *plugin) | ||
886 | 107 | { | ||
887 | 108 | if (plugin->plugin->init && plugin->plugin->init(NULL)) | ||
888 | 109 | { | ||
889 | 110 | sql_print_error("Plugin '%s' init function returned error.", | ||
890 | 111 | plugin->name.str); | ||
891 | 112 | return 1; | ||
892 | 113 | } | ||
893 | 114 | |||
894 | 115 | /* Make the interface info more easily accessible */ | ||
895 | 116 | plugin->data= plugin->plugin->info; | ||
896 | 117 | |||
897 | 118 | return 0; | ||
898 | 119 | } | ||
899 | 120 | |||
900 | 121 | |||
901 | 122 | /** | ||
902 | 123 | Finalize a query rewrite plug-in | ||
903 | 124 | |||
904 | 125 | @param[in] plugin | ||
905 | 126 | |||
906 | 127 | @retval FALSE OK | ||
907 | 128 | @retval TRUE There was an error. | ||
908 | 129 | */ | ||
909 | 130 | int finalize_query_rewrite_plugin(st_plugin_int *plugin) | ||
910 | 131 | { | ||
911 | 132 | if (plugin->plugin->deinit && plugin->plugin->deinit(NULL)) | ||
912 | 133 | { | ||
913 | 134 | DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.", | ||
914 | 135 | plugin->name.str)); | ||
915 | 136 | DBUG_EXECUTE("finalize_query_rewrite_plugin", return 1; ); | ||
916 | 137 | } | ||
917 | 138 | |||
918 | 139 | plugin->data= NULL; | ||
919 | 140 | return 0; | ||
920 | 141 | } | ||
921 | 142 | |||
922 | 143 | #else /* EMBEDDED_LIBRARY */ | ||
923 | 144 | |||
924 | 145 | |||
925 | 146 | void mysql_rewrite_raw_query(THD *thd) | ||
926 | 147 | { | ||
927 | 148 | } | ||
928 | 149 | |||
929 | 150 | |||
930 | 151 | void mysql_rewrite_parse_tree(THD *thd) | ||
931 | 152 | { | ||
932 | 153 | } | ||
933 | 154 | |||
934 | 155 | |||
935 | 156 | int initialize_query_rewrite_plugin(st_plugin_int *plugin) | ||
936 | 157 | { | ||
937 | 158 | return 1; | ||
938 | 159 | } | ||
939 | 160 | |||
940 | 161 | |||
941 | 162 | int finalize_query_rewrite_plugin(st_plugin_int *plugin) | ||
942 | 163 | { | ||
943 | 164 | return 1; | ||
944 | 165 | } | ||
945 | 166 | |||
946 | 167 | #endif /* EMBEDDED_LIBRARY */ | ||
947 | 0 | 168 | ||
948 | === added file 'sql/sql_query_rewrite.h' | |||
949 | --- sql/sql_query_rewrite.h 1970-01-01 00:00:00 +0000 | |||
950 | +++ sql/sql_query_rewrite.h 2010-10-15 16:16:49 +0000 | |||
951 | @@ -0,0 +1,36 @@ | |||
952 | 1 | #ifndef SQL_QUERY_REWRITE_INCLUDED | ||
953 | 2 | #define SQL_QUERY_REWRITE_INCLUDED | ||
954 | 3 | |||
955 | 4 | /* Copyright (c) 2010, Akiban Technologies. All rights reserved. | ||
956 | 5 | |||
957 | 6 | This program is free software; you can redistribute it and/or modify | ||
958 | 7 | it under the terms of the GNU General Public License as published by | ||
959 | 8 | the Free Software Foundation; version 2 of the License. | ||
960 | 9 | |||
961 | 10 | This program is distributed in the hope that it will be useful, | ||
962 | 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
963 | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
964 | 13 | GNU General Public License for more details. | ||
965 | 14 | |||
966 | 15 | You should have received a copy of the GNU General Public License | ||
967 | 16 | along with this program; if not, write to the Free Software Foundation, | ||
968 | 17 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ | ||
969 | 18 | |||
970 | 19 | |||
971 | 20 | #include <mysql/plugin_query_rewrite.h> | ||
972 | 21 | #include "sql_class.h" | ||
973 | 22 | |||
974 | 23 | /** | ||
975 | 24 | Call query rewrite plugins on raw query text | ||
976 | 25 | @param[in] thd thread with the query to be rewritten | ||
977 | 26 | */ | ||
978 | 27 | void mysql_rewrite_raw_query(THD *thd); | ||
979 | 28 | |||
980 | 29 | |||
981 | 30 | /** | ||
982 | 31 | Call query rewrite plugins on the parse tree | ||
983 | 32 | @param[in] thd thread with the parse tree to be rewritten | ||
984 | 33 | */ | ||
985 | 34 | void mysql_rewrite_parse_tree(THD *thd); | ||
986 | 35 | |||
987 | 36 | #endif /* SQL_QUERY_REWRITE_INCLUDED */ |