Skip to content

Commit 421e513

Browse files
author
Martin Hansson
committed
WL#7589: Query Rewrite Plugins
1 parent 43d8cc9 commit 421e513

File tree

149 files changed

+10926
-88
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+10926
-88
lines changed

cmake/abi_check.cmake

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
22
#
33
# This program is free software; you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License as published by
@@ -44,6 +44,7 @@ IF(CMAKE_COMPILER_IS_GNUCC AND RUN_ABI_CHECK)
4444
${CMAKE_SOURCE_DIR}/include/mysql/psi/psi_abi_v2.h
4545
${CMAKE_SOURCE_DIR}/include/mysql/client_plugin.h
4646
${CMAKE_SOURCE_DIR}/include/mysql/plugin_auth.h
47+
${CMAKE_SOURCE_DIR}/include/mysql/plugin_query_rewrite.h
4748
)
4849

4950
ADD_CUSTOM_TARGET(abi_check ALL

include/little_endian.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
/* Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
1+
#ifndef LITTLE_ENDIAN_INCLUDED
2+
#define LITTLE_ENDIAN_INCLUDED
3+
/* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
24
35
This program is free software; you can redistribute it and/or modify
46
it under the terms of the GNU General Public License as published by
@@ -87,3 +89,5 @@ static inline void longlongstore(uchar *T, longlong V)
8789
{
8890
memcpy((T), &V, sizeof(ulonglong));
8991
}
92+
93+
#endif /* LITTLE_ENDIAN_INCLUDED */

include/my_md5.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef MY_MD5_INCLUDED
22
#define MY_MD5_INCLUDED
33

4-
/* Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
4+
/* Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
55
66
This program is free software; you can redistribute it and/or modify
77
it under the terms of the GNU General Public License as published by
@@ -17,8 +17,7 @@
1717
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
1818

1919
#include "m_string.h"
20-
21-
#define MD5_HASH_SIZE 16 /* Hash size in bytes */
20+
#include "my_md5_size.h"
2221

2322
/*
2423
Wrapper function for MD5 implementation.

include/my_md5_size.h

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef MY_MD5_SIZE_INCLUDED
2+
#define MY_MD5_SIZE_INCLUDED
3+
/* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU General Public License as published by
7+
the Free Software Foundation; version 2 of the License.
8+
9+
This program is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
GNU General Public License for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with this program; if not, write to the Free Software Foundation,
16+
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
17+
18+
/**
19+
@file my_md5_size.h
20+
21+
This is not part of md5.h, so that it can be included using C linkage,
22+
unlike that file.
23+
*/
24+
25+
#define MD5_HASH_SIZE 16 /* Hash size in bytes */
26+
27+
#endif // MY_MD5_SIZE_INCLUDED

include/mysql/plugin.h

+13-3
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@
4444
class THD;
4545
class Item;
4646
#define MYSQL_THD THD*
47+
typedef Item* MYSQL_ITEM;
4748
#else
4849
#define MYSQL_THD void*
50+
typedef void* MYSQL_ITEM;
4951
#endif
5052

5153
typedef void * MYSQL_PLUGIN;
@@ -87,7 +89,9 @@ typedef struct st_mysql_xid MYSQL_XID;
8789
#define MYSQL_REPLICATION_PLUGIN 6 /* The replication plugin type */
8890
#define MYSQL_AUTHENTICATION_PLUGIN 7 /* The authentication plugin type */
8991
#define MYSQL_VALIDATE_PASSWORD_PLUGIN 8 /* validate password plugin type */
90-
#define MYSQL_MAX_PLUGIN_TYPE_NUM 9 /* The number of plugin types */
92+
#define MYSQL_REWRITE_PRE_PARSE_PLUGIN 9 /* Pre-parse query rewrite. */
93+
#define MYSQL_REWRITE_POST_PARSE_PLUGIN 10 /* Post-parse query rewrite. */
94+
#define MYSQL_MAX_PLUGIN_TYPE_NUM 11 /* The number of plugin types */
9195

9296
/* We use the following strings to define licenses for plugins */
9397
#define PLUGIN_LICENSE_PROPRIETARY 0
@@ -454,6 +458,13 @@ struct st_mysql_plugin
454458
*/
455459
#define MYSQL_FTPARSER_INTERFACE_VERSION 0x0101
456460

461+
/*************************************************************************
462+
API for Query Rewrite plugin. (MYSQL_QUERY_REWRITE_PLUGIN)
463+
*/
464+
465+
#define MYSQL_REWRITE_PRE_PARSE_INTERFACE_VERSION 0x0010
466+
#define MYSQL_REWRITE_POST_PARSE_INTERFACE_VERSION 0x0010
467+
457468
/*************************************************************************
458469
API for Storage Engine plugin. (MYSQL_DAEMON_PLUGIN)
459470
*/
@@ -698,5 +709,4 @@ void thd_set_ha_data(MYSQL_THD thd, const struct handlerton *hton,
698709
}
699710
#endif
700711

701-
#endif
702-
712+
#endif /* _my_plugin_h */

include/mysql/plugin_audit.h.pp

+58
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "plugin.h"
2+
typedef void* MYSQL_ITEM;
23
typedef void * MYSQL_PLUGIN;
34
#include <mysql/services.h>
45
#include <mysql/service_my_snprintf.h>
@@ -133,6 +134,63 @@
133134
extern void * my_memdup(PSI_memory_key key, const void *from, size_t length, myf_t flags);
134135
extern char * my_strdup(PSI_memory_key key, const char *from, myf_t flags);
135136
extern char * my_strndup(PSI_memory_key key, const char *from, size_t length, myf_t flags);
137+
#include <mysql/service_parser.h>
138+
#include "my_md5_size.h"
139+
#include <mysql/plugin.h>
140+
typedef
141+
int (*parse_node_visit_function)(MYSQL_ITEM item, unsigned char* arg);
142+
typedef
143+
int (*sql_condition_handler_function)(int sql_errno,
144+
const char* sqlstate,
145+
const char* msg,
146+
void *state);
147+
struct st_my_thread_handle;
148+
extern struct mysql_parser_service_st {
149+
void* (*mysql_current_session)();
150+
void* (*mysql_open_session)();
151+
void (*mysql_start_thread)(void* thd, void *(*callback_fun)(void*),
152+
void *arg,
153+
struct st_my_thread_handle *thread_handle);
154+
void (*mysql_join_thread)(struct st_my_thread_handle *thread_handle);
155+
void (*mysql_set_current_database)(void* thd, const MYSQL_LEX_STRING db);
156+
int (*mysql_parse)(void* thd, const MYSQL_LEX_STRING query,
157+
unsigned char is_prepared,
158+
sql_condition_handler_function handle_condition,
159+
void *condition_handler_state);
160+
int (*mysql_get_statement_digest)(void* thd, unsigned char *digest);
161+
int (*mysql_parser_get_number_params)(void* thd);
162+
int (*mysql_parser_extract_prepared_params)(void* thd, int *positions);
163+
int (*mysql_parser_visit_tree)(void* thd,
164+
parse_node_visit_function processor,
165+
unsigned char* arg);
166+
MYSQL_LEX_STRING (*mysql_parser_item_string)(MYSQL_ITEM item);
167+
void (*mysql_parser_free_string)(MYSQL_LEX_STRING string);
168+
MYSQL_LEX_STRING (*mysql_parser_get_query)(void* thd);
169+
MYSQL_LEX_STRING (*mysql_parser_get_normalized_query)(void* thd);
170+
} *mysql_parser_service;
171+
typedef void *(*callback_function)(void*);
172+
void* mysql_parser_current_session();
173+
void* mysql_parser_open_session();
174+
void mysql_parser_start_thread(void* thd, callback_function fun, void *arg,
175+
struct st_my_thread_handle *thread_handle);
176+
void mysql_parser_join_thread(struct st_my_thread_handle *thread_handle);
177+
void mysql_parser_set_current_database(void* thd,
178+
const MYSQL_LEX_STRING db);
179+
int mysql_parser_parse(void* thd, const MYSQL_LEX_STRING query,
180+
unsigned char is_prepared,
181+
sql_condition_handler_function handle_condition,
182+
void *condition_handler_state);
183+
int mysql_parser_get_statement_type(void* thd);
184+
int mysql_parser_get_statement_digest(void* thd, unsigned char *digest);
185+
int mysql_parser_get_number_params(void* thd);
186+
int mysql_parser_extract_prepared_params(void* thd, int *positions);
187+
int mysql_parser_visit_tree(void* thd,
188+
parse_node_visit_function processor,
189+
unsigned char* arg);
190+
MYSQL_LEX_STRING mysql_parser_item_string(MYSQL_ITEM item);
191+
void mysql_parser_free_string(MYSQL_LEX_STRING string);
192+
MYSQL_LEX_STRING mysql_parser_get_query(void* thd);
193+
MYSQL_LEX_STRING mysql_parser_get_normalized_query(void* thd);
136194
struct st_mysql_xid {
137195
long formatID;
138196
long gtrid_length;

include/mysql/plugin_auth.h.pp

+58
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <mysql/plugin.h>
2+
typedef void* MYSQL_ITEM;
23
typedef void * MYSQL_PLUGIN;
34
#include <mysql/services.h>
45
#include <mysql/service_my_snprintf.h>
@@ -133,6 +134,63 @@
133134
extern void * my_memdup(PSI_memory_key key, const void *from, size_t length, myf_t flags);
134135
extern char * my_strdup(PSI_memory_key key, const char *from, myf_t flags);
135136
extern char * my_strndup(PSI_memory_key key, const char *from, size_t length, myf_t flags);
137+
#include <mysql/service_parser.h>
138+
#include "my_md5_size.h"
139+
#include <mysql/plugin.h>
140+
typedef
141+
int (*parse_node_visit_function)(MYSQL_ITEM item, unsigned char* arg);
142+
typedef
143+
int (*sql_condition_handler_function)(int sql_errno,
144+
const char* sqlstate,
145+
const char* msg,
146+
void *state);
147+
struct st_my_thread_handle;
148+
extern struct mysql_parser_service_st {
149+
void* (*mysql_current_session)();
150+
void* (*mysql_open_session)();
151+
void (*mysql_start_thread)(void* thd, void *(*callback_fun)(void*),
152+
void *arg,
153+
struct st_my_thread_handle *thread_handle);
154+
void (*mysql_join_thread)(struct st_my_thread_handle *thread_handle);
155+
void (*mysql_set_current_database)(void* thd, const MYSQL_LEX_STRING db);
156+
int (*mysql_parse)(void* thd, const MYSQL_LEX_STRING query,
157+
unsigned char is_prepared,
158+
sql_condition_handler_function handle_condition,
159+
void *condition_handler_state);
160+
int (*mysql_get_statement_digest)(void* thd, unsigned char *digest);
161+
int (*mysql_parser_get_number_params)(void* thd);
162+
int (*mysql_parser_extract_prepared_params)(void* thd, int *positions);
163+
int (*mysql_parser_visit_tree)(void* thd,
164+
parse_node_visit_function processor,
165+
unsigned char* arg);
166+
MYSQL_LEX_STRING (*mysql_parser_item_string)(MYSQL_ITEM item);
167+
void (*mysql_parser_free_string)(MYSQL_LEX_STRING string);
168+
MYSQL_LEX_STRING (*mysql_parser_get_query)(void* thd);
169+
MYSQL_LEX_STRING (*mysql_parser_get_normalized_query)(void* thd);
170+
} *mysql_parser_service;
171+
typedef void *(*callback_function)(void*);
172+
void* mysql_parser_current_session();
173+
void* mysql_parser_open_session();
174+
void mysql_parser_start_thread(void* thd, callback_function fun, void *arg,
175+
struct st_my_thread_handle *thread_handle);
176+
void mysql_parser_join_thread(struct st_my_thread_handle *thread_handle);
177+
void mysql_parser_set_current_database(void* thd,
178+
const MYSQL_LEX_STRING db);
179+
int mysql_parser_parse(void* thd, const MYSQL_LEX_STRING query,
180+
unsigned char is_prepared,
181+
sql_condition_handler_function handle_condition,
182+
void *condition_handler_state);
183+
int mysql_parser_get_statement_type(void* thd);
184+
int mysql_parser_get_statement_digest(void* thd, unsigned char *digest);
185+
int mysql_parser_get_number_params(void* thd);
186+
int mysql_parser_extract_prepared_params(void* thd, int *positions);
187+
int mysql_parser_visit_tree(void* thd,
188+
parse_node_visit_function processor,
189+
unsigned char* arg);
190+
MYSQL_LEX_STRING mysql_parser_item_string(MYSQL_ITEM item);
191+
void mysql_parser_free_string(MYSQL_LEX_STRING string);
192+
MYSQL_LEX_STRING mysql_parser_get_query(void* thd);
193+
MYSQL_LEX_STRING mysql_parser_get_normalized_query(void* thd);
136194
struct st_mysql_xid {
137195
long formatID;
138196
long gtrid_length;

include/mysql/plugin_ftparser.h.pp

+58
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "plugin.h"
2+
typedef void* MYSQL_ITEM;
23
typedef void * MYSQL_PLUGIN;
34
#include <mysql/services.h>
45
#include <mysql/service_my_snprintf.h>
@@ -133,6 +134,63 @@
133134
extern void * my_memdup(PSI_memory_key key, const void *from, size_t length, myf_t flags);
134135
extern char * my_strdup(PSI_memory_key key, const char *from, myf_t flags);
135136
extern char * my_strndup(PSI_memory_key key, const char *from, size_t length, myf_t flags);
137+
#include <mysql/service_parser.h>
138+
#include "my_md5_size.h"
139+
#include <mysql/plugin.h>
140+
typedef
141+
int (*parse_node_visit_function)(MYSQL_ITEM item, unsigned char* arg);
142+
typedef
143+
int (*sql_condition_handler_function)(int sql_errno,
144+
const char* sqlstate,
145+
const char* msg,
146+
void *state);
147+
struct st_my_thread_handle;
148+
extern struct mysql_parser_service_st {
149+
void* (*mysql_current_session)();
150+
void* (*mysql_open_session)();
151+
void (*mysql_start_thread)(void* thd, void *(*callback_fun)(void*),
152+
void *arg,
153+
struct st_my_thread_handle *thread_handle);
154+
void (*mysql_join_thread)(struct st_my_thread_handle *thread_handle);
155+
void (*mysql_set_current_database)(void* thd, const MYSQL_LEX_STRING db);
156+
int (*mysql_parse)(void* thd, const MYSQL_LEX_STRING query,
157+
unsigned char is_prepared,
158+
sql_condition_handler_function handle_condition,
159+
void *condition_handler_state);
160+
int (*mysql_get_statement_digest)(void* thd, unsigned char *digest);
161+
int (*mysql_parser_get_number_params)(void* thd);
162+
int (*mysql_parser_extract_prepared_params)(void* thd, int *positions);
163+
int (*mysql_parser_visit_tree)(void* thd,
164+
parse_node_visit_function processor,
165+
unsigned char* arg);
166+
MYSQL_LEX_STRING (*mysql_parser_item_string)(MYSQL_ITEM item);
167+
void (*mysql_parser_free_string)(MYSQL_LEX_STRING string);
168+
MYSQL_LEX_STRING (*mysql_parser_get_query)(void* thd);
169+
MYSQL_LEX_STRING (*mysql_parser_get_normalized_query)(void* thd);
170+
} *mysql_parser_service;
171+
typedef void *(*callback_function)(void*);
172+
void* mysql_parser_current_session();
173+
void* mysql_parser_open_session();
174+
void mysql_parser_start_thread(void* thd, callback_function fun, void *arg,
175+
struct st_my_thread_handle *thread_handle);
176+
void mysql_parser_join_thread(struct st_my_thread_handle *thread_handle);
177+
void mysql_parser_set_current_database(void* thd,
178+
const MYSQL_LEX_STRING db);
179+
int mysql_parser_parse(void* thd, const MYSQL_LEX_STRING query,
180+
unsigned char is_prepared,
181+
sql_condition_handler_function handle_condition,
182+
void *condition_handler_state);
183+
int mysql_parser_get_statement_type(void* thd);
184+
int mysql_parser_get_statement_digest(void* thd, unsigned char *digest);
185+
int mysql_parser_get_number_params(void* thd);
186+
int mysql_parser_extract_prepared_params(void* thd, int *positions);
187+
int mysql_parser_visit_tree(void* thd,
188+
parse_node_visit_function processor,
189+
unsigned char* arg);
190+
MYSQL_LEX_STRING mysql_parser_item_string(MYSQL_ITEM item);
191+
void mysql_parser_free_string(MYSQL_LEX_STRING string);
192+
MYSQL_LEX_STRING mysql_parser_get_query(void* thd);
193+
MYSQL_LEX_STRING mysql_parser_get_normalized_query(void* thd);
136194
struct st_mysql_xid {
137195
long formatID;
138196
long gtrid_length;

0 commit comments

Comments
 (0)