Below is the list of changes that have just been committed into a local
5.1 repository of brianm. When brianm does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html
ChangeSet@stripped, 2007-09-26 17:07:51-05:00, brianm@lcane.(none) +19 -0
SQL and parse rewrite
BitKeeper/etc/ignore@stripped, 2007-09-26 17:06:47-05:00, brianm@lcane.(none) +1 -0
Added sc to the ignore list
CMakeLists.txt@stripped, 2007-09-26 17:06:44-05:00, brianm@lcane.(none) +11 -1
SQL and parse rewrite
include/mysql/plugin.h@stripped, 2007-09-26 17:06:44-05:00, brianm@lcane.(none) +10 -2
SQL and parse rewrite
include/mysql/rewrite_plugin.h@stripped, 2007-09-26 17:06:46-05:00, brianm@lcane.(none) +63 -0
SQL and parse rewrite
include/mysql/rewrite_plugin.h@stripped, 2007-09-26 17:06:46-05:00, brianm@lcane.(none) +0 -0
plugin/sql_filter_example/CMakeLists.txt@stripped, 2007-09-26 17:06:46-05:00, brianm@lcane.(none) +23 -0
SQL and parse rewrite
plugin/sql_filter_example/CMakeLists.txt@stripped, 2007-09-26 17:06:46-05:00, brianm@lcane.(none) +0 -0
plugin/sql_filter_example/Makefile.am@stripped, 2007-09-26 17:06:46-05:00, brianm@lcane.(none) +40 -0
SQL and parse rewrite
plugin/sql_filter_example/Makefile.am@stripped, 2007-09-26 17:06:46-05:00, brianm@lcane.(none) +0 -0
plugin/sql_filter_example/NEWS@stripped, 2007-09-26 17:06:46-05:00, brianm@lcane.(none) +2 -0
SQL and parse rewrite
plugin/sql_filter_example/NEWS@stripped, 2007-09-26 17:06:46-05:00, brianm@lcane.(none) +0 -0
plugin/sql_filter_example/README@stripped, 2007-09-26 17:06:46-05:00, brianm@lcane.(none) +49 -0
SQL and parse rewrite
plugin/sql_filter_example/README@stripped, 2007-09-26 17:06:46-05:00, brianm@lcane.(none) +0 -0
plugin/sql_filter_example/configure.in@stripped, 2007-09-26 17:06:46-05:00, brianm@lcane.(none) +7 -0
SQL and parse rewrite
plugin/sql_filter_example/configure.in@stripped, 2007-09-26 17:06:46-05:00, brianm@lcane.(none) +0 -0
plugin/sql_filter_example/plug.in@stripped, 2007-09-26 17:06:46-05:00, brianm@lcane.(none) +4 -0
SQL and parse rewrite
plugin/sql_filter_example/plug.in@stripped, 2007-09-26 17:06:46-05:00, brianm@lcane.(none) +0 -0
plugin/sql_filter_example/sql_filter_example.cc@stripped, 2007-09-26 17:06:46-05:00, brianm@lcane.(none) +194 -0
SQL and parse rewrite
plugin/sql_filter_example/sql_filter_example.cc@stripped, 2007-09-26 17:06:46-05:00, brianm@lcane.(none) +0 -0
sql/CMakeLists.txt@stripped, 2007-09-26 17:06:45-05:00, brianm@lcane.(none) +3 -0
SQL and parse rewrite
sql/Makefile.am@stripped, 2007-09-26 17:06:45-05:00, brianm@lcane.(none) +2 -2
SQL and parse rewrite
sql/sql_parse.cc@stripped, 2007-09-26 17:06:45-05:00, brianm@lcane.(none) +33 -3
SQL and parse rewrite
sql/sql_plugin.cc@stripped, 2007-09-26 17:06:45-05:00, brianm@lcane.(none) +12 -5
SQL and parse rewrite
sql/sql_rewrite.cc@stripped, 2007-09-26 17:06:46-05:00, brianm@lcane.(none) +175 -0
SQL and parse rewrite
sql/sql_rewrite.cc@stripped, 2007-09-26 17:06:46-05:00, brianm@lcane.(none) +0 -0
sql/sql_rewrite.h@stripped, 2007-09-26 17:06:46-05:00, brianm@lcane.(none) +57 -0
SQL and parse rewrite
sql/sql_rewrite.h@stripped, 2007-09-26 17:06:46-05:00, brianm@lcane.(none) +0 -0
sql/sql_select.cc@stripped, 2007-09-26 17:06:45-05:00, brianm@lcane.(none) +13 -0
SQL and parse rewrite
win/configure.js@stripped, 2007-09-26 17:06:46-05:00, brianm@lcane.(none) +1 -0
SQL and parse rewrite
diff -Nrup a/BitKeeper/etc/ignore b/BitKeeper/etc/ignore
--- a/BitKeeper/etc/ignore 2007-08-03 20:44:42 -05:00
+++ b/BitKeeper/etc/ignore 2007-09-26 17:06:47 -05:00
@@ -3001,3 +3001,4 @@ win/vs71cache.txt
win/vs8cache.txt
zlib/*.ds?
zlib/*.vcproj
+sc
diff -Nrup a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt 2007-08-06 16:14:46 -05:00
+++ b/CMakeLists.txt 2007-09-26 17:06:44 -05:00
@@ -74,7 +74,13 @@ IF(WITH_FEDERATED_STORAGE_ENGINE)
SET (mysql_plugin_defs "${mysql_plugin_defs},builtin_federated_plugin")
ENDIF(WITH_FEDERATED_STORAGE_ENGINE)
-CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/sql/sql_builtin.cc.in
+IF(WITH_SQL_FILTER_EXAMPLE_PLUGIN)
+ ADD_DEFINITIONS(-D WITH_SQL_FILTER_EXAMPLE_PLUGIN)
+ SET (mysql_plugin_defs "${mysql_plugin_defs},
+ builtin_sql_filter_example_plugin")
+ENDIF(WITH_SQL_FILTER_EXAMPLE_PLUGIN)
+
+CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/sql/sql_builtin.cc.in
${CMAKE_SOURCE_DIR}/sql/sql_builtin.cc @ONLY)
SET(localstatedir "C:\\mysql\\data")
@@ -234,6 +240,10 @@ ENDIF(WITH_FEDERATED_STORAGE_ENGINE)
IF(WITH_INNOBASE_STORAGE_ENGINE)
ADD_SUBDIRECTORY(storage/innobase)
ENDIF(WITH_INNOBASE_STORAGE_ENGINE)
+IF(WITH_SQL_FILTER_EXAMPLE_PLUGIN)
+ ADD_SUBDIRECTORY(plugin/sql_filter)
+ENDIF(WITH_SQL_FILTER_EXAMPLE_PLUGIN)
+
ADD_SUBDIRECTORY(sql)
ADD_SUBDIRECTORY(server-tools/instance-manager)
ADD_SUBDIRECTORY(libmysql)
diff -Nrup a/include/mysql/plugin.h b/include/mysql/plugin.h
--- a/include/mysql/plugin.h 2007-07-30 03:33:41 -05:00
+++ b/include/mysql/plugin.h 2007-09-26 17:06:44 -05:00
@@ -64,8 +64,9 @@ typedef struct st_mysql_xid MYSQL_XID;
#define MYSQL_STORAGE_ENGINE_PLUGIN 1 /* Storage Engine */
#define MYSQL_FTPARSER_PLUGIN 2 /* Full-text parser plugin */
#define MYSQL_DAEMON_PLUGIN 3 /* The daemon/raw plugin type */
-#define MYSQL_INFORMATION_SCHEMA_PLUGIN 4 /* The I_S plugin type */
-#define MYSQL_MAX_PLUGIN_TYPE_NUM 5 /* The number of plugin types */
+#define MYSQL_INFORMATION_SCHEMA_PLUGIN 4 /* The I_S plugin type */
+#define MYSQL_SQL_REWRITE_PLUGIN 5 /* The sql rewrite filter type */
+#define MYSQL_MAX_PLUGIN_TYPE_NUM 6 /* The number of plugin types */
/* We use the following strings to define licenses for plugins */
#define PLUGIN_LICENSE_PROPRIETARY 0
@@ -599,6 +600,13 @@ struct st_mysql_ftparser
/* handlertons of different MySQL releases are incompatible */
#define MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
+
+/*************************************************************************
+ API for SQL Filter plugin. (MYSQL_SQL_REWRITE_PLUGIN)
+*/
+
+/* handlertons of different MySQL releases are incompatible */
+#define MYSQL_SQL_REWRITE_INTERFACE_VERSION (MYSQL_VERSION_ID << 8)
/*************************************************************************
API for Storage Engine plugin. (MYSQL_STORAGE_ENGINE_PLUGIN)
diff -Nrup a/include/mysql/rewrite_plugin.h b/include/mysql/rewrite_plugin.h
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/include/mysql/rewrite_plugin.h 2007-09-26 17:06:46 -05:00
@@ -0,0 +1,63 @@
+/* Copyright (C) 2005 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef _rewrite_plugin_h
+#define _rewrite_plugin_h
+
+class THD ;
+
+typedef struct st_mysql_sql_rewrite_param
+{
+ THD* thd ;
+ char** in_str_ptr ;
+ char* in_str ;
+ uint* in_str_length_ptr ;
+ uint in_str_length ;
+ char* out_str ;
+ uint out_str_length ;
+ void* user_ptr ;
+} MYSQL_SQL_REWRITE_PARAM;
+
+class JOIN ;
+
+typedef struct st_mysql_ptree_rewrite_param
+{
+ JOIN* join ;
+ void* userdata ;
+} MYSQL_PTREE_REWRITE_PARAM ;
+
+typedef int (*SQL_REWRITE_FILTER)(MYSQL_SQL_REWRITE_PARAM *param);
+
+typedef int (*SQL_REWRITE_RESTORE)(MYSQL_SQL_REWRITE_PARAM *param);
+
+typedef int (*PTREE_REWRITE)(MYSQL_PTREE_REWRITE_PARAM *param) ;
+
+/*
+ SQL Filter descriptor.
+
+ interface_version is, e.g., MYSQL_SQL_REWRITE_INTERFACE_VERSION.
+*/
+
+struct st_mysql_sql_rewrite
+{
+ int interface_version;
+ SQL_REWRITE_FILTER sql_rewrite_filter ;
+ SQL_REWRITE_RESTORE sql_rewrite_restore ;
+ PTREE_REWRITE ptree_rewrite ;
+};
+
+
+#endif
+
diff -Nrup a/plugin/sql_filter_example/CMakeLists.txt b/plugin/sql_filter_example/CMakeLists.txt
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/plugin/sql_filter_example/CMakeLists.txt 2007-09-26 17:06:46 -05:00
@@ -0,0 +1,23 @@
+# Copyright (C) 2006 MySQL AB
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
+SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DSAFEMALLOC -DSAFE_MUTEX")
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/sql
+ ${CMAKE_SOURCE_DIR}/regex
+ ${CMAKE_SOURCE_DIR}/extra/yassl/include)
+ADD_LIBRARY(sql_filter_example sql_filter_example.cc)
+
diff -Nrup a/plugin/sql_filter_example/Makefile.am b/plugin/sql_filter_example/Makefile.am
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/plugin/sql_filter_example/Makefile.am 2007-09-26 17:06:46 -05:00
@@ -0,0 +1,40 @@
+# Copyright (C) 2006 MySQL AB
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+#Makefile.am example for a daemon
+MYSQLDATAdir = $(localstatedir)
+MYSQLSHAREdir = $(pkgdatadir)
+MYSQLBASEdir= $(prefix)
+MYSQLLIBdir= $(pkglibdir)
+INCLUDES = -I$(top_srcdir)/include -I$(top_builddir)/include \
+ -I$(top_srcdir)/regex \
+ -I$(top_srcdir)/sql \
+ -I$(srcdir) @ZLIB_INCLUDES@
+
+DEFS = @DEFS@
+
+EXTRA_LTLIBRARIES = sql_filter_example.la
+pkglib_LTLIBRARIES = @plugin_sql_filter_example_shared_target@
+sql_filter_example_la_LDFLAGS = -module -rpath $(MYSQLLIBdir)
+sql_filter_example_la_CXXFLAGS= $(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN
+sql_filter_example_la_CFLAGS = $(AM_CFLAGS) -DMYSQL_DYNAMIC_PLUGIN
+sql_filter_example_la_SOURCES = sql_filter_example.cc
+
+
+EXTRA_LIBRARIES = libsql_filter_example.a
+noinst_LIBRARIES = @plugin_sql_filter_example_static_target@
+libsql_filter_example_a_CXXFLAGS = $(AM_CFLAGS)
+libsql_filter_example_a_CFLAGS = $(AM_CFLAGS)
+libsql_filter_example_a_SOURCES= sql_filter_example.cc
diff -Nrup a/plugin/sql_filter_example/NEWS b/plugin/sql_filter_example/NEWS
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/plugin/sql_filter_example/NEWS 2007-09-26 17:06:46 -05:00
@@ -0,0 +1,2 @@
+0.1 - Thu Mar 8 18:34:38 CST 2007
+ * Created SQL Filter example
diff -Nrup a/plugin/sql_filter_example/README b/plugin/sql_filter_example/README
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/plugin/sql_filter_example/README 2007-09-26 17:06:46 -05:00
@@ -0,0 +1,49 @@
+Hi!
+
+This is an example of an SQL Filter plugin. It simply replaces
+the string abc with 'select * from test.t1;'.
+
+To test it:
+
+Create a t1 table in test:
+create table t1 ( x int, y int) ;
+
+Insert some data into it:
+insert into t1 values (1,1),(2,2),(3,3) ;
+
+Now install the plug in:
+
+INSTALL plugin SQL_FILTER_EXAMPLE soname 'sql_filter_example.so' ;
+
+(the file sql_filter_example.so will be in <dist>/lib/mysql.)
+
+Type in the query:
+
+abc ; (Or anythign else that start with abc)
+
+You should get:
+
+mysql> use test ;
+Database changed
+
+mysql> create table t1 ( y int, x int ) ;
+Query OK, 0 rows affected (0.03 sec)
+
+mysql> insert into t1 values (1,1),(2,2),(3,3) ;
+Query OK, 3 rows affected (0.00 sec)
+Records: 3 Duplicates: 0 Warnings: 0
+
+mysql> INSTALL plugin SQL_FILTER_EXAMPLE soname 'sql_filter_example.so' ;
+Query OK, 0 rows affected (0.00 sec)
+
+mysql> abc ;
++------+------+
+| y | x |
++------+------+
+| 1 | 1 |
+| 2 | 2 |
+| 3 | 3 |
++------+------+
+3 rows in set (0.00 sec)
+
+
diff -Nrup a/plugin/sql_filter_example/configure.in b/plugin/sql_filter_example/configure.in
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/plugin/sql_filter_example/configure.in 2007-09-26 17:06:46 -05:00
@@ -0,0 +1,7 @@
+# configure.in example for sql_filter_example
+
+AC_INIT(sql_filter_example, 0.1)
+AM_INIT_AUTOMAKE
+AC_PROG_LIBTOOL
+AC_CONFIG_FILES([Makefile])
+AC_OUTPUT
diff -Nrup a/plugin/sql_filter_example/plug.in b/plugin/sql_filter_example/plug.in
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/plugin/sql_filter_example/plug.in 2007-09-26 17:06:46 -05:00
@@ -0,0 +1,4 @@
+MYSQL_PLUGIN(sql_filter_example, [SQL Filter Example Plugin],
+ [This is an example plugin SQL filter.])
+MYSQL_PLUGIN_DYNAMIC(sql_filter_example, [sql_filter_example.la])
+MYSQL_PLUGIN_STATIC(sql_filter_example, [libsql_filter_example.a])
diff -Nrup a/plugin/sql_filter_example/sql_filter_example.cc b/plugin/sql_filter_example/sql_filter_example.cc
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/plugin/sql_filter_example/sql_filter_example.cc 2007-09-26 17:06:46 -05:00
@@ -0,0 +1,194 @@
+/* Copyright (C) 2006 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
+
+#include <mysql_priv.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <mysql_version.h>
+#include <mysql/plugin.h>
+#include <mysql/rewrite_plugin.h>
+#include <my_global.h>
+#include <my_dir.h>
+
+/*
+ Disable __attribute__() on non-gcc compilers.
+*/
+#if !defined(__attribute__) && !defined(__GNUC__)
+#define __attribute__(A)
+#endif
+
+
+/*
+ Initialize the sql_rewrite example at server start or plugin installation.
+
+ SYNOPSIS
+ sql_rewrite_example_plugin_init()
+
+ DESCRIPTION
+
+ RETURN VALUE
+ 0 success
+ 1 failure (cannot happen)
+*/
+
+static int sql_rewrite_example_plugin_init(void *p)
+{
+
+ DBUG_ENTER("sql_rewrite_example_plugin_init");
+ DBUG_RETURN(0);
+}
+
+
+/*
+ Deinit the sql_rewrite, nothing to do here.
+
+ SYNOPSIS
+ sql_rewrite_example_plugin_deinit()
+ Does nothing.
+
+ RETURN VALUE
+ 0 success
+ 1 failure (cannot happen)
+
+*/
+
+static int sql_rewrite_example_plugin_deinit(void *p)
+{
+ DBUG_ENTER("sql_rewrite_example_plugin_deinit");
+ DBUG_RETURN(0);
+}
+
+/*
+
+ The "rewrite" function is the primary function for the SQL rewrite
+ example. The function is called just prior to the codes that checks
+ to see if teh passed in query is cached int eh MySQL query cache.
+ The function can filter ot modify the original query before it is
+ executed.
+
+ SYNOPSIS
+ int sql_rewrite_example_filter(MYSQL_SQL_REWRITE_PARAM *param)
+
+
+typedef struct st_mysql_sql_rewrite_param
+{
+ THD* thd ;
+ A pointer the the thread object for the current executing thread
+
+ char** in_str_ptr ;
+ A pointer to the char* variable that points to the string containing
+ the query that will be parsed and executed.
+ You must set *in_str_ptr to point to the new string. Use this
+ pointer to set the new 'filtered' value of the string.
+
+ char* in_str ;
+ A pointer to the original string. This is set so it can be reused
+ in the restore function if needed.
+
+ uint* in_str_length_ptr ;
+ A pointer the variable containing the length of the original
+ query string.
+
+ uint in_str_length ;
+ The length of the original query string. This is saved so that it can
+ be restored in teh restore function if needed.
+
+ char* out_str ;
+ A pointer to the new filterd string. This must be set by the plugin
+ if needed.
+
+ uint out_str_length ;
+ The length of the new 'filtered' string. This must be set by the
+ plugin if needed.
+
+ void* user_ptr ;
+ A void pointer for the plugin to use hoowever it needs.
+
+} MYSQL_SQL_REWRITE_PARAM;
+
+ RETURN VALUE
+ 0 Success
+ 1 Failure
+
+*/
+
+static int sql_rewrite_example_filter(MYSQL_SQL_REWRITE_PARAM *param)
+{
+ DBUG_ENTER("sql_rewrite_example_filter");
+
+ if(param->in_str[0]=='a'&¶m->in_str[1]=='b'¶m->in_str[2]=='c' )
+ {
+ *(param->in_str_ptr) = param->out_str = "select * from test.t1 ;" ;
+ *(param->in_str_length_ptr) = param->out_str_length = strlen(param->out_str) ;
+ }
+ DBUG_RETURN(0);
+}
+
+static int sql_rewrite_example_restore(MYSQL_SQL_REWRITE_PARAM *param)
+{
+ DBUG_ENTER("sql_rewrite_example_restore");
+
+ /*
+ Note that the restore will be called near the end of the
+ call that install the plugin. In this case the param value
+ will be NULL.
+ */
+
+ if(param)
+ {
+ *(param->in_str_ptr) = param->in_str ;
+ *(param->in_str_length_ptr) = param->in_str_length ;
+ }
+
+ DBUG_RETURN(0);
+}
+
+
+static int sql_ptree_rewrite_example( MYSQL_PTREE_REWRITE_PARAM *param )
+{
+ DBUG_ENTER("ptree_rewrite_example");
+
+ DBUG_RETURN(0);
+
+}
+
+struct st_mysql_sql_rewrite sql_filter_example_plugin=
+{
+ MYSQL_SQL_REWRITE_INTERFACE_VERSION,
+ sql_rewrite_example_filter,
+ sql_rewrite_example_restore,
+ sql_ptree_rewrite_example
+};
+
+/*
+ Plugin library descriptor
+*/
+
+mysql_declare_plugin(sql_filter_example)
+{
+ MYSQL_SQL_REWRITE_PLUGIN,
+ &sql_filter_example_plugin,
+ "sql_filter_example",
+ "Brian Miezejewski",
+ "SQL Filter example TBD",
+ PLUGIN_LICENSE_GPL,
+ sql_rewrite_example_plugin_init, /* Plugin Init */
+ sql_rewrite_example_plugin_deinit, /* Plugin Deinit */
+ 0x0100 /* 1.0 */,
+ NULL, /* status variables */
+ NULL, /* system variables */
+ NULL /* config options */
+}
+mysql_declare_plugin_end;
diff -Nrup a/sql/CMakeLists.txt b/sql/CMakeLists.txt
--- a/sql/CMakeLists.txt 2007-08-06 16:14:47 -05:00
+++ b/sql/CMakeLists.txt 2007-09-26 17:06:45 -05:00
@@ -118,6 +118,9 @@ ENDIF(WITH_FEDERATED_STORAGE_ENGINE)
IF(WITH_INNOBASE_STORAGE_ENGINE)
TARGET_LINK_LIBRARIES(mysqld innobase)
ENDIF(WITH_INNOBASE_STORAGE_ENGINE)
+IF(WITH_SQL_FILTER_EXAMPLE_ENGINE)
+ TARGET_LINK_LIBRARIES(mysqld sql_filter_example)
+ENDIF(WITH_SQL_FILTER_EXAMPLE_ENGINE)
ADD_DEPENDENCIES(mysqld GenError)
diff -Nrup a/sql/Makefile.am b/sql/Makefile.am
--- a/sql/Makefile.am 2007-07-04 15:06:26 -05:00
+++ b/sql/Makefile.am 2007-09-26 17:06:45 -05:00
@@ -74,7 +74,7 @@ noinst_HEADERS = item.h item_func.h item
sql_plugin.h authors.h \
event_data_objects.h event_scheduler.h \
sql_partition.h partition_info.h partition_element.h \
- contributors.h sql_servers.h
+ contributors.h sql_servers.h sql_rewrite.h
mysqld_SOURCES = sql_lex.cc sql_handler.cc sql_partition.cc \
item.cc item_sum.cc item_buff.cc item_func.cc \
@@ -117,7 +117,7 @@ mysqld_SOURCES = sql_lex.cc sql_handler.
event_queue.cc event_db_repository.cc events.cc \
sql_plugin.cc sql_binlog.cc \
sql_builtin.cc sql_tablespace.cc partition_info.cc \
- sql_servers.cc
+ sql_servers.cc sql_rewrite.cc
libndb_la_CPPFLAGS= @ndbcluster_includes@
libndb_la_SOURCES= ha_ndbcluster.cc \
diff -Nrup a/sql/sql_parse.cc b/sql/sql_parse.cc
--- a/sql/sql_parse.cc 2007-08-03 10:15:20 -05:00
+++ b/sql/sql_parse.cc 2007-09-26 17:06:45 -05:00
@@ -21,6 +21,7 @@
#include <m_ctype.h>
#include <myisam.h>
#include <my_dir.h>
+#include "sql_rewrite.h"
#include "sp_head.h"
#include "sp.h"
@@ -37,7 +38,6 @@
(LP)->sql_command == SQLCOM_SHOW_CREATE_FUNC || \
(LP)->sql_command == SQLCOM_DROP_FUNCTION ? \
"FUNCTION" : "PROCEDURE")
-
static bool execute_sqlcom_select(THD *thd, TABLE_LIST *all_tables);
static bool check_show_create_table_access(THD *thd, TABLE_LIST *table);
@@ -5346,6 +5346,7 @@ void create_select_for_variable(const ch
var->set_name(buff, end-buff, system_charset_info);
add_item_to_list(thd, var);
}
+
DBUG_VOID_RETURN;
}
@@ -5383,6 +5384,12 @@ void mysql_parse(THD *thd, const char *i
DBUG_ENTER("mysql_parse");
DBUG_EXECUTE_IF("parser_debug", turn_parser_debug_on(););
+
+ /* rewrite_param is used to hold the data used by the sql_rewrite
+ * plugin portion of the rewrite plugin.
+ */
+
+ MYSQL_SQL_REWRITE_PARAM* rewrite_param = NULL ;
/*
Warning.
@@ -5403,6 +5410,23 @@ void mysql_parse(THD *thd, const char *i
lex_start(thd);
mysql_reset_thd_for_next_command(thd);
+ /*
+ * The following code is for the sql rewrite plugin. There is a
+ * matching section of code below to cleanup anything allowcated
+ * in the plugin.
+ */
+
+ if( mysql_rewrite_start_fptr )
+ {
+ /* All errors are handled in the called function. An error
+ * will cause the fucntion to return with no changes to anything.
+ * The returned value may be NULL if there is an error or if the plugin
+ * declines to make any changes.
+ */
+
+ rewrite_param = mysql_rewrite_start_fptr( thd, &inBuf, &length ) ;
+ }
+
if (query_cache_send_result_to_client(thd, (char*) inBuf, length) <= 0)
{
LEX *lex= thd->lex;
@@ -5473,7 +5497,12 @@ void mysql_parse(THD *thd, const char *i
*found_semicolon= NULL;
}
- DBUG_VOID_RETURN;
+ if( mysql_rewrite_end_fptr )
+ {
+ mysql_rewrite_end_fptr(rewrite_param) ;
+ }
+
+ DBUG_VOID_RETURN;
}
@@ -7157,7 +7186,6 @@ bool check_string_byte_length(LEX_STRING
return TRUE;
}
-
/*
Check that char length of a string does not exceed some limit.
@@ -7241,3 +7269,5 @@ bool parse_sql(THD *thd,
return err_status;
}
+
+
diff -Nrup a/sql/sql_plugin.cc b/sql/sql_plugin.cc
--- a/sql/sql_plugin.cc 2007-08-13 08:11:13 -05:00
+++ b/sql/sql_plugin.cc 2007-09-26 17:06:45 -05:00
@@ -14,6 +14,7 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "mysql_priv.h"
+#include <mysql/rewrite_plugin.h>
#include <my_pthread.h>
#include <my_getopt.h>
#define REPORT_TO_LOG 1
@@ -42,12 +43,16 @@ const LEX_STRING plugin_type_names[MYSQL
{ C_STRING_WITH_LEN("STORAGE ENGINE") },
{ C_STRING_WITH_LEN("FTPARSER") },
{ C_STRING_WITH_LEN("DAEMON") },
- { C_STRING_WITH_LEN("INFORMATION SCHEMA") }
+ { C_STRING_WITH_LEN("INFORMATION SCHEMA") },
+ { C_STRING_WITH_LEN("SQL REWRITE") }
};
extern int initialize_schema_table(st_plugin_int *plugin);
extern int finalize_schema_table(st_plugin_int *plugin);
+extern int initialize_sql_rewrite(st_plugin_int *plugin);
+extern int finalize_sql_rewrite(st_plugin_int *plugin);
+
/*
The number of elements in both plugin_type_initialize and
plugin_type_deinitialize should equal to the number of plugins
@@ -55,12 +60,12 @@ extern int finalize_schema_table(st_plug
*/
plugin_type_init plugin_type_initialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
{
- 0,ha_initialize_handlerton,0,0,initialize_schema_table
+ 0,ha_initialize_handlerton,0,0,initialize_schema_table,initialize_sql_rewrite
};
plugin_type_init plugin_type_deinitialize[MYSQL_MAX_PLUGIN_TYPE_NUM]=
{
- 0,ha_finalize_handlerton,0,0,finalize_schema_table
+ 0,ha_finalize_handlerton,0,0,finalize_schema_table,finalize_sql_rewrite
};
#ifdef HAVE_DLOPEN
@@ -81,7 +86,8 @@ static int min_plugin_info_interface_ver
MYSQL_HANDLERTON_INTERFACE_VERSION,
MYSQL_FTPARSER_INTERFACE_VERSION,
MYSQL_DAEMON_INTERFACE_VERSION,
- MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION
+ MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION,
+ MYSQL_SQL_REWRITE_INTERFACE_VERSION
};
static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]=
{
@@ -89,7 +95,8 @@ static int cur_plugin_info_interface_ver
MYSQL_HANDLERTON_INTERFACE_VERSION,
MYSQL_FTPARSER_INTERFACE_VERSION,
MYSQL_DAEMON_INTERFACE_VERSION,
- MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION
+ MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION,
+ MYSQL_SQL_REWRITE_INTERFACE_VERSION
};
static bool initialized= 0;
diff -Nrup a/sql/sql_rewrite.cc b/sql/sql_rewrite.cc
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/sql/sql_rewrite.cc 2007-09-26 17:06:46 -05:00
@@ -0,0 +1,175 @@
+/* Copyright (C) 2000-2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#define SQL_REWRITE_CC
+#include "mysql_priv.h"
+#include <m_ctype.h>
+#include <myisam.h>
+#include <my_dir.h>
+
+#include "sql_rewrite.h"
+
+/**********************************************************************/
+/* */
+/* Code to support the parse tree rewrite part of the rewrite */
+/* plugin. */
+/* */
+/**********************************************************************/
+
+void ptree_rewrite( JOIN* join ) {
+ MYSQL_PTREE_REWRITE_PARAM *param ;
+ param = (MYSQL_PTREE_REWRITE_PARAM*)
+ my_malloc(sizeof(MYSQL_PTREE_REWRITE_PARAM),MYF(MY_ZEROFILL));
+
+ param->join = join ;
+
+ ptree_rewrite_fptr( param );
+}
+
+/**********************************************************************/
+/* */
+/* Code to support the sql_rewrite part of the rewrite */
+/* plugin. */
+/* */
+/**********************************************************************/
+
+
+MYSQL_SQL_REWRITE_PARAM* mysql_rewrite_sql_start(
+ THD *thd,
+ const char **inBuf,
+ uint *length )
+{
+ DBUG_ENTER("mysql_rewrite_sql_start");
+
+ MYSQL_SQL_REWRITE_PARAM* sql_rewrite_param_ptr = NULL ;
+ int sql_rewrite_result = 0 ;
+
+ /*
+ * Allocate the struct to hold to current values and to
+ * pass in pointers to the local vars so they can be
+ * modified in the plugin. The plugin cleanup will automatically
+ * reset all of the strustures to their original values.
+ */
+ sql_rewrite_param_ptr = (MYSQL_SQL_REWRITE_PARAM*)
+ my_malloc(sizeof(MYSQL_SQL_REWRITE_PARAM),MYF(MY_ZEROFILL));
+ sql_rewrite_param_ptr->in_str_ptr = (char**) inBuf ;
+ sql_rewrite_param_ptr->in_str = *(char**)inBuf ;
+ sql_rewrite_param_ptr->in_str_length_ptr = length ;
+ sql_rewrite_param_ptr->in_str_length = *length ;
+ sql_rewrite_param_ptr->thd = thd ;
+
+ if( sql_rewrite_filter_fptr(sql_rewrite_param_ptr) )
+ {
+ my_free(sql_rewrite_param_ptr,MYF(MY_ALLOW_ZERO_PTR));
+ sql_rewrite_param_ptr = NULL ;
+ }
+
+ DBUG_RETURN(sql_rewrite_param_ptr);
+
+}
+
+void sql_rewrite_sql_end( MYSQL_SQL_REWRITE_PARAM* rewrite_pram )
+{
+ DBUG_ENTER("mysql_rewrite_sql_end");
+
+ /*
+ This is the code for the SQL Filter clenup call if needed.
+ A plugin does not need to define this call if it is not needed.
+ */
+
+ if(sql_rewrite_restore_fptr)
+ {
+ sql_rewrite_restore_fptr(rewrite_pram) ;
+ }
+
+ if(rewrite_pram)
+ {
+ my_free(rewrite_pram,MYF(MY_ALLOW_ZERO_PTR));
+ }
+
+ DBUG_VOID_RETURN ;
+
+}
+
+/*
+ Code to support the SQL Filter plugin.
+*/
+
+int initialize_sql_rewrite(st_plugin_int *plugin) {
+
+ DBUG_ENTER("initialize_sql_rewrite") ;
+
+ if (plugin->plugin->init)
+ {
+ if (plugin->plugin->init(plugin))
+ {
+ sql_print_error("Plugin '%s' init function returned error.",
+ plugin->name.str);
+ goto err;
+ } else {
+
+ sql_rewrite_filter_fptr = ((st_mysql_sql_rewrite*)(plugin->plugin->info))
+ ->sql_rewrite_filter ;
+ sql_rewrite_restore_fptr = ((st_mysql_sql_rewrite*)(plugin->plugin->info))
+ ->sql_rewrite_restore ;
+ ptree_rewrite_fptr = ((st_mysql_sql_rewrite*)(plugin->plugin->info))
+ ->ptree_rewrite ;
+
+
+ if( sql_rewrite_filter_fptr )
+ {
+ mysql_rewrite_start_fptr = mysql_rewrite_sql_start ;
+ }
+ if( sql_rewrite_restore_fptr )
+ {
+ mysql_rewrite_end_fptr = sql_rewrite_sql_end ;
+ }
+ if( ptree_rewrite_fptr )
+ {
+ mysql_ptree_rewrite_fptr = ptree_rewrite ;
+ }
+ }
+ }
+
+ DBUG_RETURN(0) ;
+err:
+ /* Error code */
+ DBUG_RETURN(1) ;
+}
+
+int finalize_sql_rewrite(st_plugin_int *plugin) {
+ DBUG_ENTER("finalize_sql_rewrite") ;
+ int retval = 0 ;
+
+ if (plugin->plugin->deinit)
+ {
+ if (plugin->plugin->deinit(plugin))
+ {
+ DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.",
+ plugin->name.str));
+ retval = 1 ;
+ }
+ }
+
+ sql_rewrite_filter_fptr = NULL ;
+ sql_rewrite_restore_fptr = NULL ;
+ mysql_rewrite_start_fptr = NULL;
+ mysql_rewrite_end_fptr = NULL ;
+
+ mysql_ptree_rewrite_fptr = NULL ;
+
+ DBUG_RETURN(retval) ;
+}
+
diff -Nrup a/sql/sql_rewrite.h b/sql/sql_rewrite.h
--- /dev/null Wed Dec 31 16:00:00 196900
+++ b/sql/sql_rewrite.h 2007-09-26 17:06:46 -05:00
@@ -0,0 +1,57 @@
+/* Copyright (C) 2000-2003 MySQL AB
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; version 2 of the License.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
+
+#ifndef SQL_REWRITE_H
+#define SQL_REWRITE_H
+
+#include <mysql/rewrite_plugin.h>
+
+class THD ;
+class JOIN ;
+
+typedef MYSQL_SQL_REWRITE_PARAM* (*SQL_REWRITE_START_FPTR)(
+ THD *thd,
+ const char **inBuf,
+ uint *length ) ;
+
+typedef void (*SQL_REWRITE_END_FPTR)(
+ MYSQL_SQL_REWRITE_PARAM* rewrite_pram );
+
+typedef void (*PTREE_REWRITE_START_FPTR)( JOIN *join ) ;
+
+#ifdef SQL_REWRITE_CC
+
+/* Declration of the SQL rewrite function calls. */
+
+SQL_REWRITE_FILTER sql_rewrite_filter_fptr = NULL ;
+SQL_REWRITE_RESTORE sql_rewrite_restore_fptr = NULL ;
+PTREE_REWRITE ptree_rewrite_fptr = NULL ;
+
+SQL_REWRITE_START_FPTR mysql_rewrite_start_fptr = NULL ;
+SQL_REWRITE_END_FPTR mysql_rewrite_end_fptr = NULL ;
+PTREE_REWRITE_START_FPTR mysql_ptree_rewrite_fptr = NULL ;
+
+#else
+
+extern SQL_REWRITE_START_FPTR mysql_rewrite_start_fptr ;
+extern SQL_REWRITE_END_FPTR mysql_rewrite_end_fptr ;
+
+extern PTREE_REWRITE_START_FPTR mysql_ptree_rewrite_fptr ;
+
+#endif /* #ifdef SQL_REWRITE_CC */
+
+
+
+#endif /* #ifndef SQL_REWRITE_H */
diff -Nrup a/sql/sql_select.cc b/sql/sql_select.cc
--- a/sql/sql_select.cc 2007-09-25 17:45:18 -05:00
+++ b/sql/sql_select.cc 2007-09-26 17:06:45 -05:00
@@ -24,6 +24,9 @@
#include "sql_select.h"
#include "sql_cursor.h"
+#include "sql_rewrite.h"
+
+
#include <m_ctype.h>
#include <hash.h>
#include <ft_global.h>
@@ -822,6 +825,16 @@ JOIN::optimize()
}
}
+ /*
+ * Call to the hook for the parse tree rewrite plugin
+ */
+
+ if( ( mysql_ptree_rewrite_fptr ) && (join_list->elements != 0 ) )
+ {
+ mysql_ptree_rewrite_fptr(this) ;
+ }
+
+
#ifdef WITH_PARTITION_STORAGE_ENGINE
{
TABLE_LIST *tbl;
diff -Nrup a/win/configure.js b/win/configure.js
--- a/win/configure.js 2007-08-06 16:14:47 -05:00
+++ b/win/configure.js 2007-09-26 17:06:46 -05:00
@@ -41,6 +41,7 @@ try
case "WITH_ARCHIVE_STORAGE_ENGINE":
case "WITH_BLACKHOLE_STORAGE_ENGINE":
case "WITH_EXAMPLE_STORAGE_ENGINE":
+ case "WITH_SQL_FILTER_EXAMPLE_PLUGIN":
case "WITH_FEDERATED_STORAGE_ENGINE":
case "WITH_INNOBASE_STORAGE_ENGINE":
case "WITH_PARTITION_STORAGE_ENGINE":
| Thread |
|---|
| • bk commit into 5.1 tree (brianm:1.2568) | bmiezejewski | 27 Sep |