diff --git a/include/mysql/plugin.h b/include/mysql/plugin.h index a98aeb25a47..660ce49d7ee 100644 --- a/include/mysql/plugin.h +++ b/include/mysql/plugin.h @@ -29,7 +29,8 @@ #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_MAX_PLUGIN_TYPE_NUM 4 /* The number of plugin types */ +#define MYSQL_INFORMATION_SCHEMA_PLUGIN 4 /* The I_S plugin type */ +#define MYSQL_MAX_PLUGIN_TYPE_NUM 5 /* The number of plugin types */ /* We use the following strings to define licenses for plugins */ #define PLUGIN_LICENSE_PROPRIETARY 0 @@ -302,6 +303,13 @@ struct st_mysql_ftparser /* handlertons of different MySQL releases are incompatible */ #define MYSQL_DAEMON_INTERFACE_VERSION (MYSQL_VERSION_ID << 8) +/************************************************************************* + API for I_S plugin. (MYSQL_INFORMATION_SCHEMA_PLUGIN) +*/ + +/* handlertons of different MySQL releases are incompatible */ +#define MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION (MYSQL_VERSION_ID << 8) + /************************************************************************* API for Storage Engine plugin. (MYSQL_STORAGE_ENGINE_PLUGIN) */ @@ -330,5 +338,15 @@ struct st_mysql_daemon int interface_version; }; +/* + Here we define only the descriptor structure, that is referred from + st_mysql_plugin. +*/ + +struct st_mysql_information_schema +{ + int interface_version; +}; + #endif diff --git a/mysql-test/r/archive.result b/mysql-test/r/archive.result index 8ccd2f7e17f..6ba8191e2c3 100644 --- a/mysql-test/r/archive.result +++ b/mysql-test/r/archive.result @@ -12665,4 +12665,4 @@ t6 CREATE TABLE `t6` ( `c` int(11) DEFAULT NULL, KEY `a` (`a`) ) ENGINE=ARCHIVE DEFAULT CHARSET=latin1 -DROP TABLE t1, t2, t4, t5; +DROP TABLE t1, t2, t4, t5, t6; diff --git a/mysql-test/t/archive.test b/mysql-test/t/archive.test index 1f4cf6ea132..b2e720cb900 100644 --- a/mysql-test/t/archive.test +++ b/mysql-test/t/archive.test @@ -1538,5 +1538,5 @@ SHOW CREATE TABLE t6; --disable_warnings -DROP TABLE t1, t2, t4, t5; +DROP TABLE t1, t2, t4, t5, t6; --enable_warnings diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 1d711b7835c..901fe3a1aa8 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -31,17 +31,26 @@ const LEX_STRING plugin_type_names[MYSQL_MAX_PLUGIN_TYPE_NUM]= { C_STRING_WITH_LEN("UDF") }, { C_STRING_WITH_LEN("STORAGE ENGINE") }, { C_STRING_WITH_LEN("FTPARSER") }, - { C_STRING_WITH_LEN("DAEMON") } + { C_STRING_WITH_LEN("DAEMON") }, + { C_STRING_WITH_LEN("INFORMATION SCHEMA") } }; +extern int initialize_schema_table(st_plugin_int *plugin); +extern int finalize_schema_table(st_plugin_int *plugin); + +/* + The number of elements in both plugin_type_initialize and + plugin_type_deinitialize should equal to the number of plugins + defined. +*/ plugin_type_init plugin_type_initialize[MYSQL_MAX_PLUGIN_TYPE_NUM]= { - 0,ha_initialize_handlerton,0,0 + 0,ha_initialize_handlerton,0,0,initialize_schema_table }; plugin_type_init plugin_type_deinitialize[MYSQL_MAX_PLUGIN_TYPE_NUM]= { - 0,ha_finalize_handlerton,0,0 + 0,ha_finalize_handlerton,0,0,finalize_schema_table }; static const char *plugin_interface_version_sym= @@ -58,14 +67,16 @@ static int min_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]= 0x0000, MYSQL_HANDLERTON_INTERFACE_VERSION, MYSQL_FTPARSER_INTERFACE_VERSION, - MYSQL_DAEMON_INTERFACE_VERSION + MYSQL_DAEMON_INTERFACE_VERSION, + MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION }; static int cur_plugin_info_interface_version[MYSQL_MAX_PLUGIN_TYPE_NUM]= { 0x0000, /* UDF: not implemented */ MYSQL_HANDLERTON_INTERFACE_VERSION, MYSQL_FTPARSER_INTERFACE_VERSION, - MYSQL_DAEMON_INTERFACE_VERSION + MYSQL_DAEMON_INTERFACE_VERSION, + MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION }; static DYNAMIC_ARRAY plugin_dl_array; diff --git a/sql/sql_show.cc b/sql/sql_show.cc index c4bb6a8fc92..fd5ca34e974 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -2451,10 +2451,48 @@ int make_db_list(THD *thd, List *files, mysql_data_home, NullS, 1) != FIND_FILES_OK); } +struct st_add_schema_table +{ + List *files; + const char *wild; +}; + +static my_bool add_schema_table(THD *thd, st_plugin_int *plugin, + void* p_data) +{ + st_add_schema_table *data= (st_add_schema_table *)p_data; + List *file_list= data->files; + const char *wild= data->wild; + ST_SCHEMA_TABLE *schema_table= (ST_SCHEMA_TABLE *)plugin->data; + DBUG_ENTER("add_schema_table"); + + if (schema_table->hidden) + DBUG_RETURN(0); + if (wild) + { + if (lower_case_table_names) + { + if (wild_case_compare(files_charset_info, + schema_table->table_name, + wild)) + DBUG_RETURN(0); + } + else if (wild_compare(schema_table->table_name, wild, 0)) + DBUG_RETURN(0); + } + + if (file_list->push_back(thd->strdup(schema_table->table_name))) + DBUG_RETURN(1); + + DBUG_RETURN(0); +} int schema_tables_add(THD *thd, List *files, const char *wild) { ST_SCHEMA_TABLE *tmp_schema_table= schema_tables; + st_add_schema_table add_data; + DBUG_ENTER("schema_tables_add"); + for (; tmp_schema_table->table_name; tmp_schema_table++) { if (tmp_schema_table->hidden) @@ -2472,9 +2510,16 @@ int schema_tables_add(THD *thd, List *files, const char *wild) continue; } if (files->push_back(thd->strdup(tmp_schema_table->table_name))) - return 1; + DBUG_RETURN(1); } - return 0; + + add_data.files= files; + add_data.wild= wild; + if (plugin_foreach(thd, add_schema_table, + MYSQL_INFORMATION_SCHEMA_PLUGIN, &add_data)) + DBUG_RETURN(1); + + DBUG_RETURN(0); } @@ -4511,6 +4556,44 @@ get_referential_constraints_record(THD *thd, struct st_table_list *tables, DBUG_RETURN(0); } +struct schema_table_ref +{ + const char *table_name; + ST_SCHEMA_TABLE *schema_table; +}; + + +/* + Find schema_tables elment by name + + SYNOPSIS + find_schema_table_in_plugin() + thd thread handler + plugin plugin + table_name table name + + RETURN + 0 table not found + 1 found the schema table +*/ +static my_bool find_schema_table_in_plugin(THD *thd, st_plugin_int *plugin, + void* p_table) +{ + schema_table_ref *p_schema_table= (schema_table_ref *)p_table; + const char* table_name= p_schema_table->table_name; + ST_SCHEMA_TABLE *schema_table= (ST_SCHEMA_TABLE *)plugin->data; + DBUG_ENTER("find_schema_table_in_plugin"); + + if (!my_strcasecmp(system_charset_info, + schema_table->table_name, + table_name)) { + p_schema_table->schema_table= schema_table; + DBUG_RETURN(1); + } + + DBUG_RETURN(0); +} + /* Find schema_tables elment by name @@ -4527,15 +4610,24 @@ get_referential_constraints_record(THD *thd, struct st_table_list *tables, ST_SCHEMA_TABLE *find_schema_table(THD *thd, const char* table_name) { + schema_table_ref schema_table_a; ST_SCHEMA_TABLE *schema_table= schema_tables; + DBUG_ENTER("find_schema_table"); + for (; schema_table->table_name; schema_table++) { if (!my_strcasecmp(system_charset_info, schema_table->table_name, table_name)) - return schema_table; + DBUG_RETURN(schema_table); } - return 0; + + schema_table_a.table_name= table_name; + if (plugin_foreach(thd, find_schema_table_in_plugin, + MYSQL_INFORMATION_SCHEMA_PLUGIN, &schema_table_a)) + DBUG_RETURN(schema_table_a.schema_table); + + DBUG_RETURN(NULL); } @@ -5752,3 +5844,54 @@ ST_SCHEMA_TABLE schema_tables[]= template class List_iterator_fast; template class List; #endif + +int initialize_schema_table(st_plugin_int *plugin) +{ + ST_SCHEMA_TABLE *schema_table; + DBUG_ENTER("initialize_schema_table"); + + if (!(schema_table= (ST_SCHEMA_TABLE *)my_malloc(sizeof(ST_SCHEMA_TABLE), + MYF(MY_WME | MY_ZEROFILL)))) + DBUG_RETURN(1); + /* Historical Requirement */ + plugin->data= schema_table; // shortcut for the future + if (plugin->plugin->init) + { + schema_table->create_table= create_schema_table; + schema_table->old_format= make_old_format; + schema_table->idx_field1= -1, + schema_table->idx_field2= -1; + + if (plugin->plugin->init(schema_table)) + { + sql_print_error("Plugin '%s' init function returned error.", + plugin->name.str); + goto err; + } + schema_table->table_name= plugin->name.str; + } + + DBUG_RETURN(0); +err: + my_free((gptr)schema_table, MYF(0)); + DBUG_RETURN(1); +} + +int finalize_schema_table(st_plugin_int *plugin) +{ + ST_SCHEMA_TABLE *schema_table= (ST_SCHEMA_TABLE *)plugin->data; + DBUG_ENTER("finalize_schema_table"); + + if (schema_table && plugin->plugin->deinit) + { + DBUG_PRINT("info", ("Deinitializing plugin: '%s'", plugin->name.str)); + if (plugin->plugin->deinit(NULL)) + { + DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.", + plugin->name.str)); + } + my_free((gptr)schema_table, MYF(0)); + } + + DBUG_RETURN(0); +} diff --git a/storage/archive/ha_archive.cc b/storage/archive/ha_archive.cc index 584de61ca10..50abea9b664 100644 --- a/storage/archive/ha_archive.cc +++ b/storage/archive/ha_archive.cc @@ -629,11 +629,11 @@ int ha_archive::create(const char *name, TABLE *table_arg, */ frm_file= my_open(name_buff, O_RDONLY, MYF(0)); VOID(my_fstat(frm_file, &file_stat, MYF(MY_WME))); - frm_ptr= (char *)my_malloc(sizeof(char) * file_stat.st_size , MYF(0)); + frm_ptr= (byte *)my_malloc(sizeof(byte) * file_stat.st_size , MYF(0)); my_read(frm_file, frm_ptr, file_stat.st_size, MYF(0)); azwrite_frm(&create_stream, (char *)frm_ptr, file_stat.st_size); my_close(frm_file, MYF(0)); - my_free(frm_ptr, MYF(0)); + my_free((gptr)frm_ptr, MYF(0)); if (create_info->comment.str) azwrite_comment(&create_stream, create_info->comment.str,