Merge lp:~posulliv/mysql-server/query-rewrite into lp:~mysql/mysql-server/mysql-next-mr

Proposed by Padraig O'Sullivan
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
Reviewer Review Type Date Requested Status
Oracle/MySQL Engineering Pending
Review via email: mp+38560@code.launchpad.net

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.

To post a comment you must log in.
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

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

Subscribers

People subscribed via source and target branches

to status/vote changes: