From 42d46376af5e3a3569278381ffeb2a6712e17131 Mon Sep 17 00:00:00 2001 From: Sergey Vojtovich Date: Mon, 27 Sep 2010 16:55:09 +0400 Subject: [PATCH 01/47] WL#5341 - Sticky plugins This patch implements "permanent" load option for plugins as specified by WL#5341. --- mysql-test/r/plugin_load_option.result | 2 ++ mysql-test/t/plugin_load_option-master.opt | 3 ++ mysql-test/t/plugin_load_option.test | 5 +++ sql/share/errmsg-utf8.txt | 2 ++ sql/sql_plugin.cc | 39 +++++++++++++--------- sql/sql_plugin.h | 7 +++- 6 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 mysql-test/r/plugin_load_option.result create mode 100644 mysql-test/t/plugin_load_option-master.opt create mode 100644 mysql-test/t/plugin_load_option.test diff --git a/mysql-test/r/plugin_load_option.result b/mysql-test/r/plugin_load_option.result new file mode 100644 index 00000000000..3e49e3c6b47 --- /dev/null +++ b/mysql-test/r/plugin_load_option.result @@ -0,0 +1,2 @@ +UNINSTALL PLUGIN example; +ERROR HY000: Plugin 'example' is force_plus_permanent and can not be unloaded diff --git a/mysql-test/t/plugin_load_option-master.opt b/mysql-test/t/plugin_load_option-master.opt new file mode 100644 index 00000000000..3be53c3b713 --- /dev/null +++ b/mysql-test/t/plugin_load_option-master.opt @@ -0,0 +1,3 @@ +$EXAMPLE_PLUGIN_OPT +$EXAMPLE_PLUGIN_LOAD +--plugin-example=FORCE_PLUS_PERMANENT diff --git a/mysql-test/t/plugin_load_option.test b/mysql-test/t/plugin_load_option.test new file mode 100644 index 00000000000..604be30b561 --- /dev/null +++ b/mysql-test/t/plugin_load_option.test @@ -0,0 +1,5 @@ +--source include/not_windows_embedded.inc +--source include/have_example_plugin.inc + +--error ER_PLUGIN_IS_PERMANENT +UNINSTALL PLUGIN example; diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index 9e7fdbfeae5..b01b824f236 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -6346,3 +6346,5 @@ ER_STORED_FUNCTION_PREVENTS_SWITCH_SQL_LOG_BIN ER_FAILED_READ_FROM_PAR_FILE eng "Failed to read from the .par file" swe "Misslyckades läsa från .par filen" +ER_PLUGIN_IS_PERMANENT + eng "Plugin '%s' is force_plus_permanent and can not be unloaded" diff --git a/sql/sql_plugin.cc b/sql/sql_plugin.cc index 956be657af2..71e2f844168 100644 --- a/sql/sql_plugin.cc +++ b/sql/sql_plugin.cc @@ -41,9 +41,8 @@ extern struct st_mysql_plugin *mysql_mandatory_plugins[]; @note The order of the enumeration is critical. @see construct_options */ -static const char *global_plugin_typelib_names[]= - { "OFF", "ON", "FORCE", NULL }; -enum enum_plugin_load_policy {PLUGIN_OFF, PLUGIN_ON, PLUGIN_FORCE}; +const char *global_plugin_typelib_names[]= + { "OFF", "ON", "FORCE", "FORCE_PLUS_PERMANENT", NULL }; static TYPELIB global_plugin_typelib= { array_elements(global_plugin_typelib_names)-1, "", global_plugin_typelib_names, NULL }; @@ -796,6 +795,7 @@ static bool plugin_add(MEM_ROOT *tmp_root, tmp.name.length= name_len; tmp.ref_count= 0; tmp.state= PLUGIN_IS_UNINITIALIZED; + tmp.load_option= PLUGIN_ON; if (test_plugin_options(tmp_root, &tmp, argc, argv)) tmp.state= PLUGIN_IS_DISABLED; @@ -1237,7 +1237,7 @@ int plugin_init(int *argc, char **argv, int flags) tmp.name.str= (char *)plugin->name; tmp.name.length= strlen(plugin->name); tmp.state= 0; - tmp.is_mandatory= mandatory; + tmp.load_option= mandatory ? PLUGIN_FORCE : PLUGIN_ON; /* If the performance schema is compiled in, @@ -1256,7 +1256,7 @@ int plugin_init(int *argc, char **argv, int flags) to work, by using '--skip-performance-schema' (the plugin) */ if (!my_strcasecmp(&my_charset_latin1, plugin->name, "PERFORMANCE_SCHEMA")) - tmp.is_mandatory= true; + tmp.load_option= PLUGIN_FORCE; free_root(&tmp_root, MYF(MY_MARK_BLOCKS_FREE)); if (test_plugin_options(&tmp_root, &tmp, argc, argv)) @@ -1334,7 +1334,8 @@ int plugin_init(int *argc, char **argv, int flags) while ((plugin_ptr= *(--reap))) { mysql_mutex_unlock(&LOCK_plugin); - if (plugin_ptr->is_mandatory) + if (plugin_ptr->load_option == PLUGIN_FORCE || + plugin_ptr->load_option == PLUGIN_FORCE_PLUS_PERMANENT) reaped_mandatory_plugin= TRUE; plugin_deinitialize(plugin_ptr, true); mysql_mutex_lock(&LOCK_plugin); @@ -1844,6 +1845,11 @@ bool mysql_uninstall_plugin(THD *thd, const LEX_STRING *name) my_error(ER_SP_DOES_NOT_EXIST, MYF(0), "PLUGIN", name->str); goto err; } + if (plugin->load_option == PLUGIN_FORCE_PLUS_PERMANENT) + { + my_error(ER_PLUGIN_IS_PERMANENT, MYF(0), name->str); + goto err; + } plugin->state= PLUGIN_IS_DELETED; if (plugin->ref_count) @@ -3054,7 +3060,8 @@ static int construct_options(MEM_ROOT *mem_root, struct st_plugin_int *tmp, plugin_dash.length + 1); strxmov(plugin_name_with_prefix_ptr, plugin_dash.str, plugin_name_ptr, NullS); - if (!tmp->is_mandatory) + if (tmp->load_option != PLUGIN_FORCE && + tmp->load_option != PLUGIN_FORCE_PLUS_PERMANENT) { /* support --skip-plugin-foo syntax */ options[0].name= plugin_name_ptr; @@ -3314,7 +3321,7 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp, { struct sys_var_chain chain= { NULL, NULL }; bool disable_plugin; - enum_plugin_load_policy plugin_load_policy= tmp->is_mandatory ? PLUGIN_FORCE : PLUGIN_ON; + enum_plugin_load_option plugin_load_option= tmp->load_option; MEM_ROOT *mem_root= alloc_root_inited(&tmp->mem_root) ? &tmp->mem_root : &plugin_mem_root; @@ -3335,7 +3342,7 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp, */ if (!(my_strcasecmp(&my_charset_latin1, tmp->name.str, "federated") && my_strcasecmp(&my_charset_latin1, tmp->name.str, "ndbcluster"))) - plugin_load_policy= PLUGIN_OFF; + plugin_load_option= PLUGIN_OFF; for (opt= tmp->plugin->system_vars; opt && *opt; opt++) count+= 2; /* --{plugin}-{optname} and --plugin-{plugin}-{optname} */ @@ -3359,8 +3366,9 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp, We adjust the default value to account for the hardcoded exceptions we have set for the federated and ndbcluster storage engines. */ - if (!tmp->is_mandatory) - opts[0].def_value= opts[1].def_value= plugin_load_policy; + if (tmp->load_option != PLUGIN_FORCE && + tmp->load_option != PLUGIN_FORCE_PLUS_PERMANENT) + opts[0].def_value= opts[1].def_value= plugin_load_option; error= handle_options(argc, &argv, opts, NULL); (*argc)++; /* add back one for the program name */ @@ -3375,12 +3383,13 @@ static int test_plugin_options(MEM_ROOT *tmp_root, struct st_plugin_int *tmp, Set plugin loading policy from option value. First element in the option list is always the option value. */ - if (!tmp->is_mandatory) - plugin_load_policy= (enum_plugin_load_policy)*(ulong*)opts[0].value; + if (tmp->load_option != PLUGIN_FORCE && + tmp->load_option != PLUGIN_FORCE_PLUS_PERMANENT) + plugin_load_option= (enum_plugin_load_option) *(ulong*) opts[0].value; } - disable_plugin= (plugin_load_policy == PLUGIN_OFF); - tmp->is_mandatory= (plugin_load_policy == PLUGIN_FORCE); + disable_plugin= (plugin_load_option == PLUGIN_OFF); + tmp->load_option= plugin_load_option; /* If the plugin is disabled it should not be initialized. diff --git a/sql/sql_plugin.h b/sql/sql_plugin.h index 079dc4e6dca..5fa9afb3066 100644 --- a/sql/sql_plugin.h +++ b/sql/sql_plugin.h @@ -32,6 +32,9 @@ class sys_var; enum SHOW_COMP_OPTION { SHOW_OPTION_YES, SHOW_OPTION_NO, SHOW_OPTION_DISABLED}; +enum enum_plugin_load_option { PLUGIN_OFF, PLUGIN_ON, PLUGIN_FORCE, + PLUGIN_FORCE_PLUS_PERMANENT }; +extern const char *global_plugin_typelib_names[]; #include @@ -95,7 +98,7 @@ struct st_plugin_int void *data; /* plugin type specific, e.g. handlerton */ MEM_ROOT mem_root; /* memory for dynamic plugin structures */ sys_var *system_vars; /* server variables for this plugin */ - bool is_mandatory; /* If true then plugin must not fail to load */ + enum enum_plugin_load_option load_option; /* OFF, ON, FORCE, F+PERMANENT */ }; @@ -110,6 +113,7 @@ typedef struct st_plugin_int *plugin_ref; #define plugin_data(pi,cast) ((cast)((pi)->data)) #define plugin_name(pi) (&((pi)->name)) #define plugin_state(pi) ((pi)->state) +#define plugin_load_option(pi) ((pi)->load_option) #define plugin_equals(p1,p2) ((p1) == (p2)) #else typedef struct st_plugin_int **plugin_ref; @@ -118,6 +122,7 @@ typedef struct st_plugin_int **plugin_ref; #define plugin_data(pi,cast) ((cast)((pi)[0]->data)) #define plugin_name(pi) (&((pi)[0]->name)) #define plugin_state(pi) ((pi)[0]->state) +#define plugin_load_option(pi) ((pi)[0]->load_option) #define plugin_equals(p1,p2) ((p1) && (p2) && (p1)[0] == (p2)[0]) #endif From 19463ba4181938e34386e6da9fd41c2e40946502 Mon Sep 17 00:00:00 2001 From: Sergey Vojtovich Date: Mon, 27 Sep 2010 17:03:27 +0400 Subject: [PATCH 02/47] WL#5496 - Plugin LOAD_OPTION in INFORMATION_SCHEMA.PLUGINS This patch implements I_S.PLUGINS.LOAD_OPTION column as specified by WL#5496. --- mysql-test/r/plugin_load_option.result | 5 +++++ mysql-test/suite/funcs_1/r/is_columns_is.result | 2 ++ mysql-test/t/plugin_load_option.test | 3 +++ sql/sql_show.cc | 6 ++++++ 4 files changed, 16 insertions(+) diff --git a/mysql-test/r/plugin_load_option.result b/mysql-test/r/plugin_load_option.result index 3e49e3c6b47..fec41bac8e6 100644 --- a/mysql-test/r/plugin_load_option.result +++ b/mysql-test/r/plugin_load_option.result @@ -1,2 +1,7 @@ UNINSTALL PLUGIN example; ERROR HY000: Plugin 'example' is force_plus_permanent and can not be unloaded +SELECT PLUGIN_NAME, PLUGIN_STATUS, LOAD_OPTION FROM INFORMATION_SCHEMA.PLUGINS +WHERE PLUGIN_NAME IN ('MyISAM', 'EXAMPLE'); +PLUGIN_NAME PLUGIN_STATUS LOAD_OPTION +MyISAM ACTIVE FORCE +EXAMPLE ACTIVE FORCE_PLUS_PERMANENT diff --git a/mysql-test/suite/funcs_1/r/is_columns_is.result b/mysql-test/suite/funcs_1/r/is_columns_is.result index ea13b8619ce..ba64ea0887e 100644 --- a/mysql-test/suite/funcs_1/r/is_columns_is.result +++ b/mysql-test/suite/funcs_1/r/is_columns_is.result @@ -165,6 +165,7 @@ def information_schema PARTITIONS TABLE_NAME 3 NO varchar 64 192 NULL NULL utf8 def information_schema PARTITIONS TABLE_ROWS 13 0 NO bigint NULL NULL 20 0 NULL NULL bigint(21) unsigned select def information_schema PARTITIONS TABLE_SCHEMA 2 NO varchar 64 192 NULL NULL utf8 utf8_general_ci varchar(64) select def information_schema PARTITIONS UPDATE_TIME 20 NULL YES datetime NULL NULL NULL NULL NULL NULL datetime select +def information_schema PLUGINS LOAD_OPTION 11 NO varchar 64 192 NULL NULL utf8 utf8_general_ci varchar(64) select def information_schema PLUGINS PLUGIN_AUTHOR 8 NULL YES varchar 64 192 NULL NULL utf8 utf8_general_ci varchar(64) select def information_schema PLUGINS PLUGIN_DESCRIPTION 9 NULL YES longtext 4294967295 4294967295 NULL NULL utf8 utf8_general_ci longtext select def information_schema PLUGINS PLUGIN_LIBRARY 6 NULL YES varchar 64 192 NULL NULL utf8 utf8_general_ci varchar(64) select @@ -562,6 +563,7 @@ NULL information_schema PARTITIONS CHECKSUM bigint NULL NULL NULL NULL bigint(21 3.0000 information_schema PLUGINS PLUGIN_AUTHOR varchar 64 192 utf8 utf8_general_ci varchar(64) 1.0000 information_schema PLUGINS PLUGIN_DESCRIPTION longtext 4294967295 4294967295 utf8 utf8_general_ci longtext 3.0000 information_schema PLUGINS PLUGIN_LICENSE varchar 80 240 utf8 utf8_general_ci varchar(80) +3.0000 information_schema PLUGINS LOAD_OPTION varchar 64 192 utf8 utf8_general_ci varchar(64) NULL information_schema PROCESSLIST ID bigint NULL NULL NULL NULL bigint(4) 3.0000 information_schema PROCESSLIST USER varchar 16 48 utf8 utf8_general_ci varchar(16) 3.0000 information_schema PROCESSLIST HOST varchar 64 192 utf8 utf8_general_ci varchar(64) diff --git a/mysql-test/t/plugin_load_option.test b/mysql-test/t/plugin_load_option.test index 604be30b561..e49b693b5be 100644 --- a/mysql-test/t/plugin_load_option.test +++ b/mysql-test/t/plugin_load_option.test @@ -3,3 +3,6 @@ --error ER_PLUGIN_IS_PERMANENT UNINSTALL PLUGIN example; + +SELECT PLUGIN_NAME, PLUGIN_STATUS, LOAD_OPTION FROM INFORMATION_SCHEMA.PLUGINS +WHERE PLUGIN_NAME IN ('MyISAM', 'EXAMPLE'); diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 6b24e3db7bc..10b918b2505 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -211,6 +211,11 @@ static my_bool show_plugins(THD *thd, plugin_ref plugin, } table->field[9]->set_notnull(); + table->field[10]->store( + global_plugin_typelib_names[plugin_load_option(plugin)], + strlen(global_plugin_typelib_names[plugin_load_option(plugin)]), + cs); + return schema_table_store_record(thd, table); } @@ -7214,6 +7219,7 @@ ST_FIELD_INFO plugin_fields_info[]= {"PLUGIN_AUTHOR", NAME_CHAR_LEN, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE}, {"PLUGIN_DESCRIPTION", 65535, MYSQL_TYPE_STRING, 0, 1, 0, SKIP_OPEN_TABLE}, {"PLUGIN_LICENSE", 80, MYSQL_TYPE_STRING, 0, 1, "License", SKIP_OPEN_TABLE}, + {"LOAD_OPTION", 64, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE}, {0, 0, MYSQL_TYPE_STRING, 0, 0, 0, SKIP_OPEN_TABLE} }; From c4a18b6af34cee61bcb933f1b0a2597bdfcf098a Mon Sep 17 00:00:00 2001 From: Jon Olav Hauglid Date: Mon, 4 Oct 2010 10:25:04 +0200 Subject: [PATCH 03/47] Bug #51099 Assertion in mysql_multi_delete_prepare() This assert was triggered if DELETE was done on a view that referenced another view which in turn (directly or indirectly) referenced more than one table. Delete from a view referencing more than one table (a join view) is not supported and is supposed to give ER_VIEW_DELETE_MERGE_VIEW error. Before this error was reported from the multi table delete code, an assert verified that the view from the DELETE statement had more than one underlying table. However, this assert did not take into account that the view could refer to another view which in turn referenced the actual tables. This patch fixes the problem by adjusting the assert to take this possibility into account. This problem was only noticeable on debug builds of the server. On release builds, ER_VIEW_DELETE_MERGE_VIEW was correctly reported. Test case added to delete.test. --- mysql-test/r/delete.result | 15 +++++++++++++++ mysql-test/t/delete.test | 26 ++++++++++++++++++++++++++ sql/sql_delete.cc | 4 +--- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/delete.result b/mysql-test/r/delete.result index 702b9348b7d..5e4adbbd6dc 100644 --- a/mysql-test/r/delete.result +++ b/mysql-test/r/delete.result @@ -509,3 +509,18 @@ CREATE TABLE t3 LIKE t1; DELETE FROM t1.*, test.t2.*, a.* USING t1, t2, t3 AS a; DROP TABLE t1, t2, t3; End of 5.1 tests +# +# Bug#51099 Assertion in mysql_multi_delete_prepare() +# +DROP TABLE IF EXISTS t1, t2; +DROP VIEW IF EXISTS v1, v2; +CREATE TABLE t1(a INT); +CREATE TABLE t2(b INT); +CREATE VIEW v1 AS SELECT a, b FROM t1, t2; +CREATE VIEW v2 AS SELECT a FROM v1; +DELETE FROM v2; +ERROR HY000: Can not delete from join view 'test.v2' +DELETE v2 FROM v2; +ERROR HY000: Can not delete from join view 'test.v2' +DROP VIEW v2, v1; +DROP TABLE t1, t2; diff --git a/mysql-test/t/delete.test b/mysql-test/t/delete.test index 15aade73ab7..6a72ae9c38b 100644 --- a/mysql-test/t/delete.test +++ b/mysql-test/t/delete.test @@ -554,3 +554,29 @@ DELETE FROM t1.*, test.t2.*, a.* USING t1, t2, t3 AS a; DROP TABLE t1, t2, t3; --echo End of 5.1 tests + + +--echo # +--echo # Bug#51099 Assertion in mysql_multi_delete_prepare() +--echo # + +--disable_warnings +DROP TABLE IF EXISTS t1, t2; +DROP VIEW IF EXISTS v1, v2; +--enable_warnings + +CREATE TABLE t1(a INT); +CREATE TABLE t2(b INT); +CREATE VIEW v1 AS SELECT a, b FROM t1, t2; +CREATE VIEW v2 AS SELECT a FROM v1; + +# This is a normal delete +--error ER_VIEW_DELETE_MERGE_VIEW +DELETE FROM v2; +# This is a multi table delete, check that we get the same error +# This caused the assertion. +--error ER_VIEW_DELETE_MERGE_VIEW +DELETE v2 FROM v2; + +DROP VIEW v2, v1; +DROP TABLE t1, t2; diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 2f69bac917e..685ce1c7b42 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -525,9 +525,7 @@ int mysql_multi_delete_prepare(THD *thd) if (!(target_tbl->table= target_tbl->correspondent_table->table)) { DBUG_ASSERT(target_tbl->correspondent_table->view && - target_tbl->correspondent_table->merge_underlying_list && - target_tbl->correspondent_table->merge_underlying_list-> - next_local); + target_tbl->correspondent_table->multitable_view); my_error(ER_VIEW_DELETE_MERGE_VIEW, MYF(0), target_tbl->correspondent_table->view_db.str, target_tbl->correspondent_table->view_name.str); From ae0029041136a7bc4f6493954aa005c530344100 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 5 Oct 2010 14:18:16 +0200 Subject: [PATCH 04/47] Bug#55629 5.5.x goes into infinite loop and high cpu after error flushing io cache The reason for the error was incorrect return code from my_win_write() in case of error on 64 bit Windows. Error should be indicated by return code (size_t)-1 == 2^64 -1, but due to cast it was (DWORD)-1 = 2^32 -1 The caller of this function would fail to recognize the error and continue looping. Fix is to return correct error code (size_t)-1 in case of error as expected by caller. Also minimal cleanup is done : my_win_write() now uses the same parameter checks as related functions (0 and overflow handling for count parameter). --- mysys/my_winfile.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/mysys/my_winfile.c b/mysys/my_winfile.c index 6c0b191ca2c..4d80d774dad 100644 --- a/mysys/my_winfile.c +++ b/mysys/my_winfile.c @@ -97,7 +97,7 @@ HANDLE my_get_osfhandle(File fd) static int my_get_open_flags(File fd) { - DBUG_ENTER("my_get_osfhandle"); + DBUG_ENTER("my_get_open_flags"); DBUG_ASSERT(fd >= MY_FILE_MIN && fd < (int)my_file_limit); DBUG_RETURN(my_file_info[fd].oflag); } @@ -321,7 +321,7 @@ size_t my_win_pread(File Filedes, uchar *Buffer, size_t Count, my_off_t offset) if(lastError == ERROR_HANDLE_EOF || lastError == ERROR_BROKEN_PIPE) DBUG_RETURN(0); /*return 0 at EOF*/ my_osmaperr(lastError); - DBUG_RETURN(-1); + DBUG_RETURN((size_t)-1); } DBUG_RETURN(nBytesRead); } @@ -352,7 +352,7 @@ size_t my_win_read(File Filedes, uchar *Buffer, size_t Count) if(lastError == ERROR_HANDLE_EOF || lastError == ERROR_BROKEN_PIPE) DBUG_RETURN(0); /*return 0 at EOF*/ my_osmaperr(lastError); - DBUG_RETURN(-1); + DBUG_RETURN((size_t)-1); } DBUG_RETURN(nBytesRead); } @@ -386,7 +386,7 @@ size_t my_win_pwrite(File Filedes, const uchar *Buffer, size_t Count, if(!WriteFile(hFile, Buffer, (DWORD)Count, &nBytesWritten, &ov)) { my_osmaperr(GetLastError()); - DBUG_RETURN(-1); + DBUG_RETURN((size_t)-1); } else DBUG_RETURN(nBytesWritten); @@ -427,6 +427,15 @@ size_t my_win_write(File fd, const uchar *Buffer, size_t Count) DBUG_ENTER("my_win_write"); DBUG_PRINT("my",("Filedes: %d, Buffer: %p, Count %llu", fd, Buffer, (ulonglong)Count)); + + if(!Count) + DBUG_RETURN(0); + +#ifdef _WIN64 + if(Count > UINT_MAX) + Count= UINT_MAX; +#endif + if(my_get_open_flags(fd) & _O_APPEND) { /* @@ -442,10 +451,10 @@ size_t my_win_write(File fd, const uchar *Buffer, size_t Count) hFile= my_get_osfhandle(fd); if(!WriteFile(hFile, Buffer, (DWORD)Count, &nWritten, pov)) { - nWritten= (size_t)-1; my_osmaperr(GetLastError()); + DBUG_RETURN((size_t)-1); } - DBUG_RETURN((size_t)nWritten); + DBUG_RETURN(nWritten); } From 5efd9b4f1dc5ffb1a77e2707492d71640d7a22e2 Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Tue, 5 Oct 2010 18:03:48 +0300 Subject: [PATCH 05/47] Enable partition_innodb_plugin after Bug#53307 has been fixed --- mysql-test/t/disabled.def | 1 - 1 file changed, 1 deletion(-) diff --git a/mysql-test/t/disabled.def b/mysql-test/t/disabled.def index cede26f555a..bb931fb7b14 100644 --- a/mysql-test/t/disabled.def +++ b/mysql-test/t/disabled.def @@ -11,6 +11,5 @@ ############################################################################## kill : Bug#37780 2008-12-03 HHunger need some changes to be robust enough for pushbuild. query_cache_28249 : Bug#43861 2009-03-25 main.query_cache_28249 fails sporadically -partition_innodb_plugin : Bug#53307 2010-04-30 VasilDimov valgrind warnings main.mysqlhotcopy_myisam : bug#54129 2010-06-04 Horst main.mysqlhotcopy_archive: bug#54129 2010-06-04 Horst From 5df8fd90beb7877cc81ccfd60e2fca38fd8e7c71 Mon Sep 17 00:00:00 2001 From: Calvin Sun Date: Tue, 5 Oct 2010 13:38:30 -0500 Subject: [PATCH 06/47] bug#56318: Replication aborts with ER_TOO_BIG_ROWSIZE if innodb parameters don't match Revert the changes of the default values of innodb_file_per_table and innobase_file_format in 5.5, until WL#5135 is implemented. --- .../sys_vars/r/innodb_file_format_basic.result | 14 +++++++------- storage/innobase/handler/ha_innodb.cc | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mysql-test/suite/sys_vars/r/innodb_file_format_basic.result b/mysql-test/suite/sys_vars/r/innodb_file_format_basic.result index 41369038cf6..58e009ea705 100644 --- a/mysql-test/suite/sys_vars/r/innodb_file_format_basic.result +++ b/mysql-test/suite/sys_vars/r/innodb_file_format_basic.result @@ -1,28 +1,28 @@ SET @start_global_value = @@global.innodb_file_format; SELECT @start_global_value; @start_global_value -Barracuda +Antelope Valid values are 'Antelope' and 'Barracuda' select @@global.innodb_file_format in ('Antelope', 'Barracuda'); @@global.innodb_file_format in ('Antelope', 'Barracuda') 1 select @@global.innodb_file_format; @@global.innodb_file_format -Barracuda +Antelope select @@session.innodb_file_format; ERROR HY000: Variable 'innodb_file_format' is a GLOBAL variable show global variables like 'innodb_file_format'; Variable_name Value -innodb_file_format Barracuda +innodb_file_format Antelope show session variables like 'innodb_file_format'; Variable_name Value -innodb_file_format Barracuda +innodb_file_format Antelope select * from information_schema.global_variables where variable_name='innodb_file_format'; VARIABLE_NAME VARIABLE_VALUE -INNODB_FILE_FORMAT Barracuda +INNODB_FILE_FORMAT Antelope select * from information_schema.session_variables where variable_name='innodb_file_format'; VARIABLE_NAME VARIABLE_VALUE -INNODB_FILE_FORMAT Barracuda +INNODB_FILE_FORMAT Antelope set global innodb_file_format='Antelope'; select @@global.innodb_file_format; @@global.innodb_file_format @@ -56,4 +56,4 @@ ERROR 42000: Variable 'innodb_file_format' can't be set to the value of 'Salmon' SET @@global.innodb_file_format = @start_global_value; SELECT @@global.innodb_file_format; @@global.innodb_file_format -Barracuda +Antelope diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index bbf3c5aa3c8..83fa1853e25 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -10835,13 +10835,13 @@ static MYSQL_SYSVAR_ULONG(fast_shutdown, innobase_fast_shutdown, static MYSQL_SYSVAR_BOOL(file_per_table, srv_file_per_table, PLUGIN_VAR_NOCMDARG, "Stores each InnoDB table to an .ibd file in the database dir.", - NULL, NULL, TRUE); + NULL, NULL, FALSE); static MYSQL_SYSVAR_STR(file_format, innobase_file_format_name, PLUGIN_VAR_RQCMDARG, "File format to use for new tables in .ibd files.", innodb_file_format_name_validate, - innodb_file_format_name_update, "Barracuda"); + innodb_file_format_name_update, "Antelope"); /* "innobase_file_format_check" decides whether we would continue booting the server if the file format stamped on the system From fd7dd37e2eb94cb87320b0f1eb355e5ba660fd6c Mon Sep 17 00:00:00 2001 From: Jon Olav Hauglid Date: Wed, 6 Oct 2010 09:56:29 +0200 Subject: [PATCH 07/47] Bug #57002 Assert in upgrade_shared_lock_to_exclusive() for ALTER TABLE + MERGE tables The patch for Bug#56292 changed how metadata locks are taken for MERGE tables. After the patch, locking the MERGE table will also lock the children tables with the same metadata lock type. This means that LOCK TABLES on a MERGE table also will implicitly do LOCK TABLES on the children tables. A consequence of this change, is that it is possible to do LOCK TABLES on a child table both explicitly and implicitly with the same statement and that these two locks can be of different strength. For example, LOCK TABLES child READ, merge WRITE. In LOCK TABLES mode, we are not allowed to take new locks and each statement must therefore try to find an existing TABLE instance with a suitable lock. The code that searched for a suitable TABLE instance, only considered table level locks. If a child table was locked twice, it was therefore possible for this code to find a TABLE instance with suitable table level locks but without suitable metadata lock. This problem caused the assert in upgrade_shared_lock_to_exclusive() to be triggered as it tried to upgrade a MDL_SHARED lock to EXCLUSIVE. The problem was a regression caused by the patch for Bug#56292. This patch fixes the problem by partially reverting the changes done by Bug#56292. Now, the children tables will only use the same metadata lock as the MERGE table for MDL_SHARED_NO_WRITE when not in locked tables mode. This means that LOCK TABLE on a MERGE table will not implicitly lock the children tables. This still fixes the original problem in Bug#56292 without causing a regression. Test case added to merge.test. --- mysql-test/r/merge.result | 15 ++++++++++++++- mysql-test/t/merge.test | 24 +++++++++++++++++++++++- storage/myisammrg/ha_myisammrg.cc | 27 +++++++++++++++++++++++++-- 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/merge.result b/mysql-test/r/merge.result index bb6af084f38..ace834a26c2 100644 --- a/mysql-test/r/merge.result +++ b/mysql-test/r/merge.result @@ -3486,12 +3486,13 @@ ALTER TABLE m1 ADD INDEX (c1); UNLOCK TABLES; DROP TABLE m1, t1; # -# Locking the merge table will implicitly lock children. +# Locking the merge table won't implicitly lock children. # CREATE TABLE t1 (c1 INT); CREATE TABLE m1 (c1 INT) ENGINE=MRG_MyISAM UNION=(t1); LOCK TABLE m1 WRITE; ALTER TABLE t1 ADD INDEX (c1); +ERROR HY000: Table 't1' was locked with a READ lock and can't be updated LOCK TABLE m1 WRITE, t1 WRITE; ALTER TABLE t1 ADD INDEX (c1); UNLOCK TABLES; @@ -3661,4 +3662,16 @@ REPAIR TABLE t2 USE_FRM; Table Op Msg_type Msg_text test.t2 repair note The storage engine for the table doesn't support repair DROP TABLE t1, t2; +# +# Bug#57002 Assert in upgrade_shared_lock_to_exclusive() +# for ALTER TABLE + MERGE tables +# +DROP TABLE IF EXISTS t1, m1; +CREATE TABLE t1(a INT) engine=myisam; +CREATE TABLE m1(a INT) engine=merge UNION(t1); +LOCK TABLES t1 READ, m1 WRITE; +ALTER TABLE t1 engine=myisam; +ERROR HY000: Table 't1' was locked with a READ lock and can't be updated +UNLOCK TABLES; +DROP TABLE m1, t1; End of 6.0 tests diff --git a/mysql-test/t/merge.test b/mysql-test/t/merge.test index 34d0b5bf237..07839257a15 100644 --- a/mysql-test/t/merge.test +++ b/mysql-test/t/merge.test @@ -2600,11 +2600,12 @@ UNLOCK TABLES; DROP TABLE m1, t1; --echo # ---echo # Locking the merge table will implicitly lock children. +--echo # Locking the merge table won't implicitly lock children. --echo # CREATE TABLE t1 (c1 INT); CREATE TABLE m1 (c1 INT) ENGINE=MRG_MyISAM UNION=(t1); LOCK TABLE m1 WRITE; +--error ER_TABLE_NOT_LOCKED_FOR_WRITE ALTER TABLE t1 ADD INDEX (c1); LOCK TABLE m1 WRITE, t1 WRITE; ALTER TABLE t1 ADD INDEX (c1); @@ -2776,6 +2777,27 @@ REPAIR TABLE t2 USE_FRM; DROP TABLE t1, t2; +--echo # +--echo # Bug#57002 Assert in upgrade_shared_lock_to_exclusive() +--echo # for ALTER TABLE + MERGE tables +--echo # + +--disable_warnings +DROP TABLE IF EXISTS t1, m1; +--enable_warnings + +CREATE TABLE t1(a INT) engine=myisam; +CREATE TABLE m1(a INT) engine=merge UNION(t1); +LOCK TABLES t1 READ, m1 WRITE; + +# This caused an assert +--error ER_TABLE_NOT_LOCKED_FOR_WRITE +ALTER TABLE t1 engine=myisam; + +UNLOCK TABLES; +DROP TABLE m1, t1; + + --echo End of 6.0 tests --disable_result_log diff --git a/storage/myisammrg/ha_myisammrg.cc b/storage/myisammrg/ha_myisammrg.cc index 466c66ec769..26e54d61101 100644 --- a/storage/myisammrg/ha_myisammrg.cc +++ b/storage/myisammrg/ha_myisammrg.cc @@ -478,8 +478,31 @@ int ha_myisammrg::add_children_list(void) /* Set the expected table version, to not cause spurious re-prepare. */ child_l->set_table_ref_id(mrg_child_def->get_child_table_ref_type(), mrg_child_def->get_child_def_version()); - /* Use the same metadata lock type for children. */ - child_l->mdl_request.set_type(parent_l->mdl_request.type); + /* + For statements which acquire a SNW metadata lock on a parent table and + then later try to upgrade it to an X lock (e.g. ALTER TABLE), SNW + locks should be also taken on the children tables. + + Otherwise we end up in a situation where the thread trying to upgrade SNW + to X lock on the parent also holds a SR metadata lock and a read + thr_lock.c lock on the child. As a result, another thread might be + blocked on the thr_lock.c lock for the child after successfully acquiring + a SR or SW metadata lock on it. If at the same time this second thread + has a shared metadata lock on the parent table or there is some other + thread which has a shared metadata lock on the parent and is waiting for + this second thread, we get a deadlock. This deadlock cannot be properly + detected by the MDL subsystem as part of the waiting happens within + thr_lock.c. By taking SNW locks on the child tables we ensure that any + thread which waits for a thread doing SNW -> X upgrade, does this within + the MDL subsystem and thus potential deadlocks are exposed to the deadlock + detector. + + We don't do the same thing for SNRW locks as this would allow + DDL on implicitly locked underlying tables of a MERGE table. + */ + if (! thd->locked_tables_mode && + parent_l->mdl_request.type == MDL_SHARED_NO_WRITE) + child_l->mdl_request.set_type(MDL_SHARED_NO_WRITE); /* Link TABLE_LIST object into the children list. */ if (this->children_last_l) child_l->prev_global= this->children_last_l; From 623ed1946215e25682847ac3b0ea066cab35ea59 Mon Sep 17 00:00:00 2001 From: Magne Mahre Date: Wed, 6 Oct 2010 11:01:24 +0200 Subject: [PATCH 08/47] Bug#56452 Assertion failed: thd->transaction.stmt.is_empty() || thd->in_sub_stmt In a precursor patch for Bug#52044 (revid:bzr/kostja@stripped), a number of reorganizations of code was made. In addition some assertions were added to ensure the correct transactional state. The reorganization had a small glitch so statements that was active in the query cache was not followed by a statement commit/rollback (this code was removed). A section in the trans_commit_stmt/trans_rollback_stmt code is to clear the thd->transaction.stmt list of affected storage engines. When a new statement is initiated, an assert introduced by the 523044 patch checks if this list is cleared. When the query cache is accessed, this list may be populated, and since it's not committed it will not be cleared. This fix adds explicit statement commit or rollback for statements that is contained in the query cache. --- mysql-test/r/cache_innodb.result | 11 +++++++++++ mysql-test/t/cache_innodb.test | 15 +++++++++++++++ sql/sql_cache.cc | 10 ++++++++++ 3 files changed, 36 insertions(+) diff --git a/mysql-test/r/cache_innodb.result b/mysql-test/r/cache_innodb.result index 600ed84c3c9..293d7a3f412 100644 --- a/mysql-test/r/cache_innodb.result +++ b/mysql-test/r/cache_innodb.result @@ -220,3 +220,14 @@ Variable_name Value Qcache_hits 1 set GLOBAL query_cache_size=1048576; drop table t2; +CREATE TABLE t1 (a INT) ENGINE=InnoDB; +BEGIN; +INSERT INTO t1 VALUES(1); +ROLLBACK WORK AND CHAIN NO RELEASE; +SELECT a FROM t1; +a +ROLLBACK WORK AND CHAIN NO RELEASE; +SELECT a FROM t1; +a +ROLLBACK; +DROP TABLE t1; diff --git a/mysql-test/t/cache_innodb.test b/mysql-test/t/cache_innodb.test index 33a328d1d6c..f7102627506 100644 --- a/mysql-test/t/cache_innodb.test +++ b/mysql-test/t/cache_innodb.test @@ -14,3 +14,18 @@ let $engine_type= InnoDB; let $test_foreign_keys= 1; --source include/query_cache.inc + +# +# Bug#56452 Assertion failed: thd->transaction.stmt.is_empty() || +# thd->in_sub_stmt +# +CREATE TABLE t1 (a INT) ENGINE=InnoDB; +BEGIN; + INSERT INTO t1 VALUES(1); +ROLLBACK WORK AND CHAIN NO RELEASE; +SELECT a FROM t1; +ROLLBACK WORK AND CHAIN NO RELEASE; +SELECT a FROM t1; +ROLLBACK; +DROP TABLE t1; + diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index b57c851edf4..a10e470afd4 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -341,6 +341,7 @@ TODO list: #include "../storage/myisammrg/ha_myisammrg.h" #include "../storage/myisammrg/myrg_def.h" #include "probes_mysql.h" +#include "transaction.h" #ifdef EMBEDDED_LIBRARY #include "emb_qcache.h" @@ -1683,6 +1684,8 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d", } else thd->lex->safe_to_cache_query= 0; // Don't try to cache this + /* End the statement transaction potentially started by engine. */ + trans_rollback_stmt(thd); goto err_unlock; // Parse query } else @@ -1724,6 +1727,13 @@ def_week_frmt: %lu, in_trans: %d, autocommit: %d", thd->limit_found_rows = query->found_rows(); thd->status_var.last_query_cost= 0.0; + /* + End the statement transaction potentially started by an + engine callback. We ignore the return value for now, + since as long as EOF packet is part of the query cache + response, we can't handle it anyway. + */ + (void) trans_commit_stmt(thd); if (!thd->stmt_da->is_set()) thd->stmt_da->disable_status(); From 361833796f3ddbcc1641a941ee0fb55a90b8e0cc Mon Sep 17 00:00:00 2001 From: Alfranio Correia Date: Wed, 6 Oct 2010 11:19:51 +0100 Subject: [PATCH 09/47] BUG#57098 RBR breaks on changing user password on 5.1 master -> 5.5 slave Backported the patch for BUG#55452. --- sql/sql_acl.cc | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index b507b70d1fb..ea002f59fe3 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -1593,6 +1593,7 @@ bool change_password(THD *thd, const char *host, const char *user, /* Buffer should be extended when password length is extended. */ char buff[512]; ulong query_length; + bool save_binlog_row_based; uint new_password_len= (uint) strlen(new_password); bool result= 1; DBUG_ENTER("change_password"); @@ -1628,6 +1629,14 @@ bool change_password(THD *thd, const char *host, const char *user, if (!(table= open_ltable(thd, &tables, TL_WRITE, 0))) DBUG_RETURN(1); + /* + This statement will be replicated as a statement, even when using + row-based replication. The flag will be reset at the end of the + statement. + */ + if ((save_binlog_row_based= thd->current_stmt_binlog_row_based)) + thd->clear_current_stmt_binlog_row_based(); + VOID(pthread_mutex_lock(&acl_cache->lock)); ACL_USER *acl_user; if (!(acl_user= find_acl_user(host, user, TRUE))) @@ -1663,6 +1672,12 @@ bool change_password(THD *thd, const char *host, const char *user, } end: close_thread_tables(thd); + + /* Restore the state of binlog format */ + DBUG_ASSERT(!thd->current_stmt_binlog_row_based); + if (save_binlog_row_based) + thd->set_current_stmt_binlog_row_based(); + DBUG_RETURN(result); } From d09c19f7063813a3812e4c3c511ede6f28105496 Mon Sep 17 00:00:00 2001 From: Luis Soares Date: Wed, 6 Oct 2010 11:48:46 +0100 Subject: [PATCH 10/47] BUG#52202: mysqlbinlog_row* fail in daily-trunk on Sol10 x86_64 debug_max Removed test cases affected by this bug from experimental list. --- mysql-test/collections/default.experimental | 3 --- 1 file changed, 3 deletions(-) diff --git a/mysql-test/collections/default.experimental b/mysql-test/collections/default.experimental index b292356f1c7..48e10511b80 100644 --- a/mysql-test/collections/default.experimental +++ b/mysql-test/collections/default.experimental @@ -15,9 +15,6 @@ main.lock_multi_bug38499 # Bug#47448 2009-09-19 alik main.lock_m main.lock_multi_bug38691 @solaris # Bug#47792 2009-10-02 alik main.lock_multi_bug38691 times out sporadically on Solaris 10 main.log_tables # Bug#47924 2009-10-08 alik main.log_tables times out sporadically main.lowercase_table2 @darwin # Bug#55509 2010-07-26 alik main.lowercase_table2 fails on Mac OSX (again) -main.mysqlbinlog_row @solaris # Bug#52202 2010-03-22 alik mysqlbinlog_row* fail in daily-trunk on Sol10 x86_64 debug_max -main.mysqlbinlog_row_innodb @solaris # Bug#52202 2010-03-22 alik mysqlbinlog_row* fail in daily-trunk on Sol10 x86_64 debug_max -main.mysqlbinlog_row_myisam @solaris # Bug#52202 2010-03-22 alik mysqlbinlog_row* fail in daily-trunk on Sol10 x86_64 debug_max main.outfile_loaddata @solaris # Bug#46895 2010-01-20 alik Test "outfile_loaddata" fails (reproducible) main.signal_demo3 @solaris # Bug#47791 2010-01-20 alik Several test cases fail on Solaris with error Thread stack overrun main.sp @solaris # Bug#47791 2010-01-20 alik Several test cases fail on Solaris with error Thread stack overrun From ab15833ac265e11710e4de1390a82678011aab59 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Wed, 6 Oct 2010 16:15:59 +0400 Subject: [PATCH 11/47] Bug#55744 GROUP_CONCAT + CASE + ucs return garbage Problem: CASE didn't work with a mixture of different character sets in THEN/ELSE in some cases. This happened because after character set aggregation newly created Item_func_conv_charset items corresponding to THEN/ELSE arguments were not put back to args[] array. Fix: put all Item_func_conv_charset back to args[]. @ mysql-test/include/ctype_numconv.inc @ mysql-test/r/ctype_ucs.result Adding tests @ sql/item_cmpfunc.cc Put "agg" back to args[] after character set aggregation. --- mysql-test/include/ctype_numconv.inc | 7 +------ mysql-test/r/ctype_ucs.result | 3 +++ sql/item_cmpfunc.cc | 8 ++++++++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/mysql-test/include/ctype_numconv.inc b/mysql-test/include/ctype_numconv.inc index 06a9107e963..c4a39879947 100644 --- a/mysql-test/include/ctype_numconv.inc +++ b/mysql-test/include/ctype_numconv.inc @@ -1635,12 +1635,7 @@ CREATE TABLE t1 (a MEDIUMINT NULL) ENGINE=MYISAM; INSERT INTO t1 VALUES (1234567); SELECT GROUP_CONCAT(IFNULL(a,'')) FROM t1; SELECT GROUP_CONCAT(IF(a,a,'')) FROM t1; -if (`SELECT @@character_set_connection != 'ucs2'`) -{ - # Temporarily disable for ucs2 - # For details, see Bug#55744 GROUP_CONCAT + CASE + ucs return garbage - SELECT GROUP_CONCAT(CASE WHEN a THEN a ELSE '' END) FROM t1; -} +SELECT GROUP_CONCAT(CASE WHEN a THEN a ELSE '' END) FROM t1; --enable_metadata SELECT COALESCE(a,'') FROM t1 GROUP BY 1; --disable_metadata diff --git a/mysql-test/r/ctype_ucs.result b/mysql-test/r/ctype_ucs.result index 1215eb1db02..c2fb90ecfa6 100644 --- a/mysql-test/r/ctype_ucs.result +++ b/mysql-test/r/ctype_ucs.result @@ -3853,6 +3853,9 @@ GROUP_CONCAT(IFNULL(a,'')) SELECT GROUP_CONCAT(IF(a,a,'')) FROM t1; GROUP_CONCAT(IF(a,a,'')) 1234567 +SELECT GROUP_CONCAT(CASE WHEN a THEN a ELSE '' END) FROM t1; +GROUP_CONCAT(CASE WHEN a THEN a ELSE '' END) +1234567 SELECT COALESCE(a,'') FROM t1 GROUP BY 1; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr def COALESCE(a,'') 253 9 7 Y 0 31 8 diff --git a/sql/item_cmpfunc.cc b/sql/item_cmpfunc.cc index b7aad733e67..b04ec105468 100644 --- a/sql/item_cmpfunc.cc +++ b/sql/item_cmpfunc.cc @@ -3029,6 +3029,14 @@ void Item_func_case::fix_length_and_dec() { if (agg_arg_charsets_for_string_result(collation, agg, nagg)) return; + /* + Copy all THEN and ELSE items back to args[] array. + Some of the items might have been changed to Item_func_conv_charset. + */ + for (nagg= 0 ; nagg < ncases / 2 ; nagg++) + args[nagg * 2 + 1]= agg[nagg]; + if (else_expr_num != -1) + args[else_expr_num]= agg[nagg++]; } else collation.set_numeric(); From 5f911fa874f2472562de5b595b5dab86a92fbdf1 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Wed, 6 Oct 2010 11:34:28 -0300 Subject: [PATCH 12/47] Bug#49938: Failing assertion: inode or deadlock in fsp/fsp0fsp.c Bug#54678: InnoDB, TRUNCATE, ALTER, I_S SELECT, crash or deadlock - Incompatible change: truncate no longer resorts to a row by row delete if the storage engine does not support the truncate method. Consequently, the count of affected rows does not, in any case, reflect the actual number of rows. - Incompatible change: it is no longer possible to truncate a table that participates as a parent in a foreign key constraint, unless it is a self-referencing constraint (both parent and child are in the same table). To work around this incompatible change and still be able to truncate such tables, disable foreign checks with SET foreign_key_checks=0 before truncate. Alternatively, if foreign key checks are necessary, please use a DELETE statement without a WHERE condition. Problem description: The problem was that for storage engines that do not support truncate table via a external drop and recreate, such as InnoDB which implements truncate via a internal drop and recreate, the delete_all_rows method could be invoked with a shared metadata lock, causing problems if the engine needed exclusive access to some internal metadata. This problem originated with the fact that there is no truncate specific handler method, which ended up leading to a abuse of the delete_all_rows method that is primarily used for delete operations without a condition. Solution: The solution is to introduce a truncate handler method that is invoked when the engine does not support truncation via a table drop and recreate. This method is invoked under a exclusive metadata lock, so that there is only a single instance of the table when the method is invoked. Also, the method is not invoked and a error is thrown if the table is a parent in a non-self-referencing foreign key relationship. This was necessary to avoid inconsistency as some integrity checks are bypassed. This is inline with the fact that truncate is primarily a DDL operation that was designed to quickly remove all data from a table. --- mysql-test/r/mdl_sync.result | 10 +- mysql-test/r/sp_trans.result | 17 + mysql-test/r/trigger-trans.result | 5 + .../suite/innodb/r/innodb-truncate.result | 68 +++ mysql-test/suite/innodb/r/innodb.result | 12 +- mysql-test/suite/innodb/r/innodb_mysql.result | 21 +- .../suite/innodb/t/innodb-truncate.test | 65 +++ mysql-test/suite/innodb/t/innodb.test | 13 +- mysql-test/suite/innodb/t/innodb_mysql.test | 19 +- .../suite/parts/inc/partition_check.inc | 10 +- .../sys_vars/r/foreign_key_checks_func.result | 2 +- .../sys_vars/t/foreign_key_checks_func.test | 2 +- mysql-test/t/mdl_sync.test | 15 +- mysql-test/t/sp_trans.test | 24 + mysql-test/t/trigger-trans.test | 5 + sql/ha_partition.cc | 192 +++---- sql/ha_partition.h | 10 + sql/handler.cc | 15 + sql/handler.h | 58 ++- sql/share/errmsg-utf8.txt | 3 + sql/sql_lex.h | 1 + sql/sql_parse.cc | 3 +- sql/sql_partition_admin.cc | 95 +++- sql/sql_partition_admin.h | 6 +- sql/sql_show.cc | 12 +- sql/sql_string.h | 8 +- sql/sql_truncate.cc | 487 +++++++++--------- sql/sql_truncate.h | 23 +- sql/sql_yacc.yy | 2 +- sql/table.h | 4 +- storage/archive/ha_archive.cc | 4 +- storage/archive/ha_archive.h | 2 +- storage/blackhole/ha_blackhole.cc | 10 + storage/blackhole/ha_blackhole.h | 1 + storage/example/ha_example.cc | 93 ++-- storage/example/ha_example.h | 1 + storage/federated/ha_federated.cc | 10 + storage/federated/ha_federated.h | 1 + storage/heap/ha_heap.cc | 7 + storage/heap/ha_heap.h | 1 + storage/ibmdb2i/db2i_constraints.cc | 4 +- storage/ibmdb2i/ha_ibmdb2i.cc | 7 + storage/innobase/handler/ha_innodb.cc | 311 ++++++----- storage/innobase/handler/ha_innodb.h | 4 +- storage/innobase/row/row0mysql.c | 3 +- storage/myisam/ha_myisam.cc | 12 + storage/myisam/ha_myisam.h | 1 + storage/myisammrg/ha_myisammrg.cc | 16 + storage/myisammrg/ha_myisammrg.h | 1 + storage/perfschema/ha_perfschema.cc | 5 + storage/perfschema/ha_perfschema.h | 2 + 51 files changed, 1095 insertions(+), 608 deletions(-) create mode 100644 mysql-test/suite/innodb/r/innodb-truncate.result create mode 100644 mysql-test/suite/innodb/t/innodb-truncate.test diff --git a/mysql-test/r/mdl_sync.result b/mysql-test/r/mdl_sync.result index de57e3859b7..d2a32c25201 100644 --- a/mysql-test/r/mdl_sync.result +++ b/mysql-test/r/mdl_sync.result @@ -2632,7 +2632,8 @@ DROP TABLE IF EXISTS t1; CREATE TABLE t1 (a INT) ENGINE=InnoDB; INSERT INTO t1 VALUES (1),(2),(3); # Connection: con1 -SET debug_sync='lock_table_for_truncate SIGNAL parked_truncate WAIT_FOR go_truncate'; +LOCK TABLES t1 WRITE; +SET debug_sync='upgrade_lock_for_truncate SIGNAL parked_truncate WAIT_FOR go_truncate'; TRUNCATE TABLE t1; # Connection: default SET debug_sync='now WAIT_FOR parked_truncate'; @@ -2647,10 +2648,11 @@ FLUSH TABLES t1; # Connection: default SET debug_sync='now WAIT_FOR parked_flush'; SET debug_sync='now SIGNAL go_truncate'; -# Connection: con1 -# Reaping... -# Connection: default +# Ensure that truncate waits for a exclusive lock SET debug_sync= 'now SIGNAL go_show'; +# Connection: con1 (TRUNCATE) +# Reaping... +UNLOCK TABLES; # Connection: con2 (SHOW FIELDS FROM t1) # Reaping... Field Type Null Key Default Extra diff --git a/mysql-test/r/sp_trans.result b/mysql-test/r/sp_trans.result index 4fa91121f50..4163725a196 100644 --- a/mysql-test/r/sp_trans.result +++ b/mysql-test/r/sp_trans.result @@ -585,3 +585,20 @@ UPDATE t1_aux SET f2 = 2 WHERE f1 = f1_two_inserts()| ERROR 23000: Column 'f2' cannot be null DROP TABLE t1_aux, t1_not_null| DROP FUNCTION f1_two_inserts| +# +# Bug#49938: Failing assertion: inode or deadlock in fsp/fsp0fsp.c +# +DROP PROCEDURE IF EXISTS p1| +DROP TABLE IF EXISTS t1| +CREATE TABLE t1 (a INT) ENGINE=INNODB| +CREATE PROCEDURE p1() +BEGIN +TRUNCATE TABLE t1; +END| +LOCK TABLES t1 WRITE| +CALL p1()| +FLUSH TABLES; +UNLOCK TABLES| +CALL p1()| +DROP PROCEDURE p1| +DROP TABLE t1| diff --git a/mysql-test/r/trigger-trans.result b/mysql-test/r/trigger-trans.result index 2c4e355af9d..722ac79854d 100644 --- a/mysql-test/r/trigger-trans.result +++ b/mysql-test/r/trigger-trans.result @@ -151,9 +151,14 @@ CREATE TRIGGER t1_ad AFTER DELETE ON t1 FOR EACH ROW SET @b = 1; SET @a = 0; SET @b = 0; TRUNCATE t1; +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`b`) REFERENCES `test`.`t1` (`a`)) SELECT @a, @b; @a @b 0 0 +DELETE FROM t1; +SELECT @a, @b; +@a @b +1 1 INSERT INTO t1 VALUES (1); DELETE FROM t1; SELECT @a, @b; diff --git a/mysql-test/suite/innodb/r/innodb-truncate.result b/mysql-test/suite/innodb/r/innodb-truncate.result new file mode 100644 index 00000000000..f63e9272850 --- /dev/null +++ b/mysql-test/suite/innodb/r/innodb-truncate.result @@ -0,0 +1,68 @@ +# +# TRUNCATE TABLE +# +# Truncating is disallowed for parent tables unless such table +# participates in self-referencing foreign keys only. +# +CREATE TABLE t1 (pk INT PRIMARY KEY) ENGINE=INNODB; +CREATE TABLE t2 (fk INT NOT NULL, FOREIGN KEY (fk) REFERENCES t1 (pk)) ENGINE=INNODB; +TRUNCATE TABLE t1; +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fk`) REFERENCES `test`.`t1` (`pk`)) +# Truncation of child should succeed. +TRUNCATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 (pk INT PRIMARY KEY, fk INT, +FOREIGN KEY (fk) REFERENCES t1 (pk)) ENGINE=INNODB; +# Truncation of self-referencing table should succeed. +TRUNCATE TABLE t1; +DROP TABLE t1; +# +# Also, truncating such tables is allowed if foreign key +# checks are disabled. +# +SET @old_foreign_key_checks = @@SESSION.foreign_key_checks; +CREATE TABLE t1 (pk INT PRIMARY KEY) ENGINE=INNODB; +CREATE TABLE t2 (fk INT NOT NULL, FOREIGN KEY (fk) REFERENCES t1 (pk)) ENGINE=INNODB; +CREATE TABLE t3 (pk INT PRIMARY KEY, fk INT, +FOREIGN KEY (fk) REFERENCES t1 (pk)) ENGINE=INNODB; +SET @@SESSION.foreign_key_checks = 0; +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +TRUNCATE TABLE t3; +SET @@SESSION.foreign_key_checks = 1; +TRUNCATE TABLE t1; +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fk`) REFERENCES `test`.`t1` (`pk`)) +TRUNCATE TABLE t2; +TRUNCATE TABLE t3; +LOCK TABLES t1 WRITE; +SET @@SESSION.foreign_key_checks = 0; +TRUNCATE TABLE t1; +SET @@SESSION.foreign_key_checks = 1; +TRUNCATE TABLE t1; +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`fk`) REFERENCES `test`.`t1` (`pk`)) +UNLOCK TABLES; +DROP TABLE t3,t2,t1; +SET @@SESSION.foreign_key_checks = @old_foreign_key_checks; +# +# Test that TRUNCATE resets auto-increment. +# +CREATE TABLE t1 (a INT PRIMARY KEY NOT NULL AUTO_INCREMENT); +INSERT INTO t1 VALUES (NULL), (NULL); +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't1'; +AUTO_INCREMENT +3 +SELECT * FROM t1 ORDER BY a; +a +1 +2 +TRUNCATE TABLE t1; +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't1'; +AUTO_INCREMENT +1 +INSERT INTO t1 VALUES (NULL), (NULL); +SELECT * FROM t1 ORDER BY a; +a +1 +2 +DROP TABLE t1; diff --git a/mysql-test/suite/innodb/r/innodb.result b/mysql-test/suite/innodb/r/innodb.result index 2e5585ee7af..09a2c5b9ef4 100644 --- a/mysql-test/suite/innodb/r/innodb.result +++ b/mysql-test/suite/innodb/r/innodb.result @@ -2424,10 +2424,6 @@ drop table t1,t2; CREATE TABLE t1 ( id INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY (id) ) ENGINE=InnoDB; -CREATE TABLE t2 ( -id INTEGER NOT NULL, -FOREIGN KEY (id) REFERENCES t1 (id) -) ENGINE=InnoDB; INSERT INTO t1 (id) VALUES (NULL); SELECT * FROM t1; id @@ -2443,7 +2439,7 @@ INSERT INTO t1 (id) VALUES (NULL); SELECT * FROM t1; id 1 -DROP TABLE t2, t1; +DROP TABLE t1; CREATE TABLE t1 ( id INT PRIMARY KEY @@ -2621,13 +2617,15 @@ ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fail update t4 set a=2; ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) truncate t1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `test`.`t1` (`a`)) truncate t3; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t3` (`a`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `test`.`t3` (`a`)) truncate t2; truncate t4; truncate t1; +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `test`.`t1` (`a`)) truncate t3; +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t4`, CONSTRAINT `t4_ibfk_1` FOREIGN KEY (`a`) REFERENCES `test`.`t3` (`a`)) drop table t4,t3,t2,t1; create table t1 (a varchar(255) character set utf8, b varchar(255) character set utf8, diff --git a/mysql-test/suite/innodb/r/innodb_mysql.result b/mysql-test/suite/innodb/r/innodb_mysql.result index 14eb3f0a6a8..5a52ba0ee54 100644 --- a/mysql-test/suite/innodb/r/innodb_mysql.result +++ b/mysql-test/suite/innodb/r/innodb_mysql.result @@ -1941,7 +1941,7 @@ INSERT INTO t2 VALUES (3,2); SET AUTOCOMMIT = 0; START TRANSACTION; TRUNCATE TABLE t1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `test`.`t1` (`id`)) SELECT * FROM t1; id 1 @@ -1953,7 +1953,7 @@ id 2 START TRANSACTION; TRUNCATE TABLE t1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `test`.`t1` (`id`)) SELECT * FROM t1; id 1 @@ -1971,7 +1971,7 @@ id 2 COMMIT; TRUNCATE TABLE t1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `t1` (`id`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `test`.`t1` (`id`)) SELECT * FROM t1; id 1 @@ -1983,9 +1983,12 @@ id 1 2 TRUNCATE TABLE t1; +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`t1_id`) REFERENCES `test`.`t1` (`id`)) ROLLBACK; SELECT * FROM t1; id +1 +2 TRUNCATE TABLE t2; DROP TABLE t2; DROP TABLE t1; @@ -2077,9 +2080,9 @@ i i ** error handling inside a row iteration. ** DROP TRIGGER trg; -TRUNCATE TABLE t1; -TRUNCATE TABLE t2; -TRUNCATE TABLE t3; +DELETE FROM t1; +DELETE FROM t2; +DELETE FROM t3; INSERT INTO t1 VALUES (1),(2),(3),(4); INSERT INTO t3 VALUES (1),(2),(3),(4); INSERT INTO t4 VALUES (3,3),(4,4); @@ -2105,9 +2108,9 @@ DROP TRIGGER trg; ** ** Induce an error midway through an AFTER-trigger ** -TRUNCATE TABLE t4; -TRUNCATE TABLE t1; -TRUNCATE TABLE t3; +DELETE FROM t4; +DELETE FROM t1; +DELETE FROM t3; INSERT INTO t1 VALUES (1),(2),(3),(4); INSERT INTO t3 VALUES (1),(2),(3),(4); CREATE TRIGGER trg AFTER DELETE ON t1 FOR EACH ROW diff --git a/mysql-test/suite/innodb/t/innodb-truncate.test b/mysql-test/suite/innodb/t/innodb-truncate.test new file mode 100644 index 00000000000..7629eb1a980 --- /dev/null +++ b/mysql-test/suite/innodb/t/innodb-truncate.test @@ -0,0 +1,65 @@ +--source include/have_innodb.inc + +--echo # +--echo # TRUNCATE TABLE +--echo # +--echo # Truncating is disallowed for parent tables unless such table +--echo # participates in self-referencing foreign keys only. +--echo # +CREATE TABLE t1 (pk INT PRIMARY KEY) ENGINE=INNODB; +CREATE TABLE t2 (fk INT NOT NULL, FOREIGN KEY (fk) REFERENCES t1 (pk)) ENGINE=INNODB; +--error ER_TRUNCATE_ILLEGAL_FK +TRUNCATE TABLE t1; +--echo # Truncation of child should succeed. +TRUNCATE TABLE t2; +DROP TABLE t2; +DROP TABLE t1; +CREATE TABLE t1 (pk INT PRIMARY KEY, fk INT, + FOREIGN KEY (fk) REFERENCES t1 (pk)) ENGINE=INNODB; +--echo # Truncation of self-referencing table should succeed. +TRUNCATE TABLE t1; +DROP TABLE t1; + +--echo # +--echo # Also, truncating such tables is allowed if foreign key +--echo # checks are disabled. +--echo # + +SET @old_foreign_key_checks = @@SESSION.foreign_key_checks; +CREATE TABLE t1 (pk INT PRIMARY KEY) ENGINE=INNODB; +CREATE TABLE t2 (fk INT NOT NULL, FOREIGN KEY (fk) REFERENCES t1 (pk)) ENGINE=INNODB; +CREATE TABLE t3 (pk INT PRIMARY KEY, fk INT, + FOREIGN KEY (fk) REFERENCES t1 (pk)) ENGINE=INNODB; +SET @@SESSION.foreign_key_checks = 0; +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +TRUNCATE TABLE t3; +SET @@SESSION.foreign_key_checks = 1; +--error ER_TRUNCATE_ILLEGAL_FK +TRUNCATE TABLE t1; +TRUNCATE TABLE t2; +TRUNCATE TABLE t3; +LOCK TABLES t1 WRITE; +SET @@SESSION.foreign_key_checks = 0; +TRUNCATE TABLE t1; +SET @@SESSION.foreign_key_checks = 1; +--error ER_TRUNCATE_ILLEGAL_FK +TRUNCATE TABLE t1; +UNLOCK TABLES; +DROP TABLE t3,t2,t1; +SET @@SESSION.foreign_key_checks = @old_foreign_key_checks; + +--echo # +--echo # Test that TRUNCATE resets auto-increment. +--echo # + +CREATE TABLE t1 (a INT PRIMARY KEY NOT NULL AUTO_INCREMENT); +INSERT INTO t1 VALUES (NULL), (NULL); +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't1'; +SELECT * FROM t1 ORDER BY a; +TRUNCATE TABLE t1; +SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE table_name = 't1'; +INSERT INTO t1 VALUES (NULL), (NULL); +SELECT * FROM t1 ORDER BY a; +DROP TABLE t1; + diff --git a/mysql-test/suite/innodb/t/innodb.test b/mysql-test/suite/innodb/t/innodb.test index a283cd26ccb..8c24457e07c 100644 --- a/mysql-test/suite/innodb/t/innodb.test +++ b/mysql-test/suite/innodb/t/innodb.test @@ -1471,11 +1471,6 @@ CREATE TABLE t1 ( id INTEGER NOT NULL AUTO_INCREMENT, PRIMARY KEY (id) ) ENGINE=InnoDB; -CREATE TABLE t2 ( -id INTEGER NOT NULL, -FOREIGN KEY (id) REFERENCES t1 (id) -) ENGINE=InnoDB; - INSERT INTO t1 (id) VALUES (NULL); SELECT * FROM t1; TRUNCATE t1; @@ -1488,7 +1483,7 @@ DELETE FROM t1; TRUNCATE t1; INSERT INTO t1 (id) VALUES (NULL); SELECT * FROM t1; -DROP TABLE t2, t1; +DROP TABLE t1; # Test that foreign keys in temporary tables are not accepted (bug #12084) CREATE TABLE t1 @@ -1723,13 +1718,15 @@ update t2 set a=2; update t3 set a=2; -- error 1452 update t4 set a=2; --- error 1451 +-- error ER_TRUNCATE_ILLEGAL_FK truncate t1; --- error 1451 +-- error ER_TRUNCATE_ILLEGAL_FK truncate t3; truncate t2; truncate t4; +-- error ER_TRUNCATE_ILLEGAL_FK truncate t1; +-- error ER_TRUNCATE_ILLEGAL_FK truncate t3; drop table t4,t3,t2,t1; diff --git a/mysql-test/suite/innodb/t/innodb_mysql.test b/mysql-test/suite/innodb/t/innodb_mysql.test index 8925f538c38..052db7d789a 100644 --- a/mysql-test/suite/innodb/t/innodb_mysql.test +++ b/mysql-test/suite/innodb/t/innodb_mysql.test @@ -151,14 +151,14 @@ INSERT INTO t2 VALUES (3,2); SET AUTOCOMMIT = 0; START TRANSACTION; ---error ER_ROW_IS_REFERENCED_2 +--error ER_TRUNCATE_ILLEGAL_FK TRUNCATE TABLE t1; SELECT * FROM t1; COMMIT; SELECT * FROM t1; START TRANSACTION; ---error ER_ROW_IS_REFERENCED_2 +--error ER_TRUNCATE_ILLEGAL_FK TRUNCATE TABLE t1; SELECT * FROM t1; ROLLBACK; @@ -170,13 +170,14 @@ START TRANSACTION; SELECT * FROM t1; COMMIT; ---error ER_ROW_IS_REFERENCED_2 +--error ER_TRUNCATE_ILLEGAL_FK TRUNCATE TABLE t1; SELECT * FROM t1; DELETE FROM t2 WHERE id = 3; START TRANSACTION; SELECT * FROM t1; +--error ER_TRUNCATE_ILLEGAL_FK TRUNCATE TABLE t1; ROLLBACK; SELECT * FROM t1; @@ -275,9 +276,9 @@ SELECT * FROM t1 LEFT JOIN t3 ON t1.i=t3.i; --echo ** error handling inside a row iteration. --echo ** DROP TRIGGER trg; -TRUNCATE TABLE t1; -TRUNCATE TABLE t2; -TRUNCATE TABLE t3; +DELETE FROM t1; +DELETE FROM t2; +DELETE FROM t3; INSERT INTO t1 VALUES (1),(2),(3),(4); INSERT INTO t3 VALUES (1),(2),(3),(4); @@ -304,9 +305,9 @@ DROP TRIGGER trg; --echo ** --echo ** Induce an error midway through an AFTER-trigger --echo ** -TRUNCATE TABLE t4; -TRUNCATE TABLE t1; -TRUNCATE TABLE t3; +DELETE FROM t4; +DELETE FROM t1; +DELETE FROM t3; INSERT INTO t1 VALUES (1),(2),(3),(4); INSERT INTO t3 VALUES (1),(2),(3),(4); delimiter ||; diff --git a/mysql-test/suite/parts/inc/partition_check.inc b/mysql-test/suite/parts/inc/partition_check.inc index 19d548cc8ef..235764a034f 100644 --- a/mysql-test/suite/parts/inc/partition_check.inc +++ b/mysql-test/suite/parts/inc/partition_check.inc @@ -177,7 +177,7 @@ let $any_unique= `SELECT @my_errno IN ($ER_DUP_KEY,$ER_DUP_ENTRY)`; # @my_errno AS sql_errno; if (`SELECT @my_errno NOT IN (0,$ER_DUP_KEY,$ER_DUP_ENTRY)`) { - --echo # The last command got an unexepected error response. + --echo # The last command got an unexpected error response. --echo # Expected/handled SQL codes are 0,$ER_DUP_KEY,$ER_DUP_ENTRY SELECT '# SQL code we got was: ' AS "", @my_errno AS ""; --echo # Sorry, have to abort. @@ -219,7 +219,7 @@ if ($any_unique) # @my_errno AS sql_errno; if (`SELECT @my_errno NOT IN (0,$ER_DUP_KEY,$ER_DUP_ENTRY)`) { - --echo # The last command got an unexepected error response. + --echo # The last command got an unexpected error response. --echo # Expected/handled SQL codes are 0,$ER_DUP_KEY,$ER_DUP_ENTRY SELECT '# SQL code we got was: ' AS "", @my_errno AS ""; --echo # Sorry, have to abort. @@ -255,7 +255,7 @@ if ($any_unique) # @my_errno AS sql_errno; if (`SELECT @my_errno NOT IN (0,$ER_DUP_KEY,$ER_DUP_ENTRY)`) { - --echo # The last command got an unexepected error response. + --echo # The last command got an unexpected error response. --echo # Expected/handled SQL codes are 0,$ER_DUP_KEY,$ER_DUP_ENTRY SELECT '# SQL code we got was: ' AS "", @my_errno AS ""; --echo # Sorry, have to abort. @@ -503,7 +503,7 @@ if ($no_debug) eval SET @my_errno = $mysql_errno; if (`SELECT @my_errno NOT IN (0,$ER_SAME_NAME_PARTITION,$ER_NO_PARTITION_FOR_GIVEN_VALUE)`) { - --echo # The last command got an unexepected error response. + --echo # The last command got an unexpected error response. --echo # Expected/handled SQL codes are 0,$ER_SAME_NAME_PARTITION,$ER_NO_PARTITION_FOR_GIVEN_VALUE SELECT '# SQL code we got was: ' AS "", @my_errno AS ""; --echo # Sorry, have to abort. @@ -566,7 +566,7 @@ eval SET @my_errno = $mysql_errno; let $run= `SELECT @my_errno = 0`; if (`SELECT @my_errno NOT IN (0,$ER_BAD_NULL_ERROR)`) { - --echo # The last command got an unexepected error response. + --echo # The last command got an unexpected error response. --echo # Expected/handled SQL codes are 0,$ER_BAD_NULL_ERROR SELECT '# SQL code we got was: ' AS "", @my_errno AS ""; --echo # Sorry, have to abort. diff --git a/mysql-test/suite/sys_vars/r/foreign_key_checks_func.result b/mysql-test/suite/sys_vars/r/foreign_key_checks_func.result index 9b1736541c1..398a2a76eb8 100644 --- a/mysql-test/suite/sys_vars/r/foreign_key_checks_func.result +++ b/mysql-test/suite/sys_vars/r/foreign_key_checks_func.result @@ -26,7 +26,7 @@ INSERT INTO t2 values (20,22); ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `fk` FOREIGN KEY (`b`) REFERENCES `t1` (`a`)) '---Check when foreign_key_checks is disabled---' TRUNCATE t1; -ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`t2`, CONSTRAINT `fk` FOREIGN KEY (`b`) REFERENCES `t1` (`a`)) +ERROR 42000: Cannot truncate a table referenced in a foreign key constraint (`test`.`t2`, CONSTRAINT `fk` FOREIGN KEY (`b`) REFERENCES `test`.`t1` (`a`)) SET @@session.foreign_key_checks = 0; TRUNCATE t1; TRUNCATE t2; diff --git a/mysql-test/suite/sys_vars/t/foreign_key_checks_func.test b/mysql-test/suite/sys_vars/t/foreign_key_checks_func.test index 5786b9283be..14134a5fb95 100644 --- a/mysql-test/suite/sys_vars/t/foreign_key_checks_func.test +++ b/mysql-test/suite/sys_vars/t/foreign_key_checks_func.test @@ -76,7 +76,7 @@ INSERT INTO t2 values (20,22); --echo '---Check when foreign_key_checks is disabled---' #=========================================================== ---Error ER_ROW_IS_REFERENCED_2 +--Error ER_TRUNCATE_ILLEGAL_FK TRUNCATE t1; SET @@session.foreign_key_checks = 0; diff --git a/mysql-test/t/mdl_sync.test b/mysql-test/t/mdl_sync.test index f7780d2003a..5c4fc20b428 100644 --- a/mysql-test/t/mdl_sync.test +++ b/mysql-test/t/mdl_sync.test @@ -3969,7 +3969,8 @@ INSERT INTO t1 VALUES (1),(2),(3); --echo # Connection: con1 connection con1; -SET debug_sync='lock_table_for_truncate SIGNAL parked_truncate WAIT_FOR go_truncate'; +LOCK TABLES t1 WRITE; +SET debug_sync='upgrade_lock_for_truncate SIGNAL parked_truncate WAIT_FOR go_truncate'; send TRUNCATE TABLE t1; connection default; @@ -3994,15 +3995,17 @@ connection default; --echo # Connection: default SET debug_sync='now WAIT_FOR parked_flush'; SET debug_sync='now SIGNAL go_truncate'; +--echo # Ensure that truncate waits for a exclusive lock +let $wait_condition=SELECT COUNT(*)=1 FROM information_schema.processlist + WHERE state='Waiting for table metadata lock' AND info='TRUNCATE TABLE t1'; +--source include/wait_condition.inc +SET debug_sync= 'now SIGNAL go_show'; connection con1; ---echo # Connection: con1 +--echo # Connection: con1 (TRUNCATE) --echo # Reaping... reap; - -connection default; ---echo # Connection: default -SET debug_sync= 'now SIGNAL go_show'; +UNLOCK TABLES; connection con2; --echo # Connection: con2 (SHOW FIELDS FROM t1) diff --git a/mysql-test/t/sp_trans.test b/mysql-test/t/sp_trans.test index c4915bdb87a..c114d397e43 100644 --- a/mysql-test/t/sp_trans.test +++ b/mysql-test/t/sp_trans.test @@ -636,6 +636,30 @@ UPDATE t1_aux SET f2 = 2 WHERE f1 = f1_two_inserts()| DROP TABLE t1_aux, t1_not_null| DROP FUNCTION f1_two_inserts| +--echo # +--echo # Bug#49938: Failing assertion: inode or deadlock in fsp/fsp0fsp.c +--echo # + +--disable_warnings +DROP PROCEDURE IF EXISTS p1| +DROP TABLE IF EXISTS t1| +--enable_warnings + +CREATE TABLE t1 (a INT) ENGINE=INNODB| + +CREATE PROCEDURE p1() +BEGIN + TRUNCATE TABLE t1; +END| + +LOCK TABLES t1 WRITE| +CALL p1()| +FLUSH TABLES; +UNLOCK TABLES| +CALL p1()| + +DROP PROCEDURE p1| +DROP TABLE t1| # # BUG#NNNN: New bug synopsis diff --git a/mysql-test/t/trigger-trans.test b/mysql-test/t/trigger-trans.test index 4d6e82dedcb..82bee7aa224 100644 --- a/mysql-test/t/trigger-trans.test +++ b/mysql-test/t/trigger-trans.test @@ -148,10 +148,15 @@ CREATE TRIGGER t1_ad AFTER DELETE ON t1 FOR EACH ROW SET @b = 1; SET @a = 0; SET @b = 0; +--error ER_TRUNCATE_ILLEGAL_FK TRUNCATE t1; SELECT @a, @b; +DELETE FROM t1; + +SELECT @a, @b; + INSERT INTO t1 VALUES (1); DELETE FROM t1; diff --git a/sql/ha_partition.cc b/sql/ha_partition.cc index 8bf35f79ba9..3d8d5ae9eb8 100644 --- a/sql/ha_partition.cc +++ b/sql/ha_partition.cc @@ -3337,113 +3337,123 @@ int ha_partition::delete_row(const uchar *buf) Called from sql_delete.cc by mysql_delete(). Called from sql_select.cc by JOIN::reinit(). Called from sql_union.cc by st_select_lex_unit::exec(). - - Also used for handle ALTER TABLE t TRUNCATE PARTITION ... - NOTE: auto increment value will be truncated in that partition as well! */ int ha_partition::delete_all_rows() { int error; - bool truncate= FALSE; handler **file; - THD *thd= ha_thd(); DBUG_ENTER("ha_partition::delete_all_rows"); - if (thd->lex->sql_command == SQLCOM_TRUNCATE) - { - Alter_info *alter_info= &thd->lex->alter_info; - /* TRUNCATE also means resetting auto_increment */ - lock_auto_increment(); - table_share->ha_part_data->next_auto_inc_val= 0; - table_share->ha_part_data->auto_inc_initialized= FALSE; - unlock_auto_increment(); - if (alter_info->flags & ALTER_ADMIN_PARTITION) - { - /* ALTER TABLE t TRUNCATE PARTITION ... */ - List_iterator part_it(m_part_info->partitions); - int saved_error= 0; - uint num_parts= m_part_info->num_parts; - uint num_subparts= m_part_info->num_subparts; - uint i= 0; - uint num_parts_set= alter_info->partition_names.elements; - uint num_parts_found= set_part_state(alter_info, m_part_info, - PART_ADMIN); - if (num_parts_set != num_parts_found && - (!(alter_info->flags & ALTER_ALL_PARTITION))) - DBUG_RETURN(HA_ERR_NO_PARTITION_FOUND); - - /* - Cannot return HA_ERR_WRONG_COMMAND here without correct pruning - since that whould delete the whole table row by row in sql_delete.cc - */ - bitmap_clear_all(&m_part_info->used_partitions); - do - { - partition_element *part_elem= part_it++; - if (part_elem->part_state == PART_ADMIN) - { - if (m_is_sub_partitioned) - { - List_iterator - subpart_it(part_elem->subpartitions); - partition_element *sub_elem; - uint j= 0, part; - do - { - sub_elem= subpart_it++; - part= i * num_subparts + j; - bitmap_set_bit(&m_part_info->used_partitions, part); - if (!saved_error) - { - DBUG_PRINT("info", ("truncate subpartition %u (%s)", - part, sub_elem->partition_name)); - if ((error= m_file[part]->ha_delete_all_rows())) - saved_error= error; - /* If not reset_auto_increment is supported, just accept it */ - if (!saved_error && - (error= m_file[part]->ha_reset_auto_increment(0)) && - error != HA_ERR_WRONG_COMMAND) - saved_error= error; - } - } while (++j < num_subparts); - } - else - { - DBUG_PRINT("info", ("truncate partition %u (%s)", i, - part_elem->partition_name)); - bitmap_set_bit(&m_part_info->used_partitions, i); - if (!saved_error) - { - if ((error= m_file[i]->ha_delete_all_rows()) && !saved_error) - saved_error= error; - /* If not reset_auto_increment is supported, just accept it */ - if (!saved_error && - (error= m_file[i]->ha_reset_auto_increment(0)) && - error != HA_ERR_WRONG_COMMAND) - saved_error= error; - } - } - part_elem->part_state= PART_NORMAL; - } - } while (++i < num_parts); - DBUG_RETURN(saved_error); - } - truncate= TRUE; - } file= m_file; do { if ((error= (*file)->ha_delete_all_rows())) DBUG_RETURN(error); - /* Ignore the error */ - if (truncate) - (void) (*file)->ha_reset_auto_increment(0); } while (*(++file)); DBUG_RETURN(0); } +/** + Manually truncate the table. + + @retval 0 Success. + @retval > 0 Error code. +*/ + +int ha_partition::truncate() +{ + int error; + handler **file; + DBUG_ENTER("ha_partition::truncate"); + + /* + TRUNCATE also means resetting auto_increment. Hence, reset + it so that it will be initialized again at the next use. + */ + lock_auto_increment(); + table_share->ha_part_data->next_auto_inc_val= 0; + table_share->ha_part_data->auto_inc_initialized= FALSE; + unlock_auto_increment(); + + file= m_file; + do + { + if ((error= (*file)->ha_truncate())) + DBUG_RETURN(error); + } while (*(++file)); + DBUG_RETURN(0); +} + + +/** + Truncate a set of specific partitions. + + @remark Auto increment value will be truncated in that partition as well! + + ALTER TABLE t TRUNCATE PARTITION ... +*/ + +int ha_partition::truncate_partition(Alter_info *alter_info) +{ + int error= 0; + List_iterator part_it(m_part_info->partitions); + uint num_parts= m_part_info->num_parts; + uint num_subparts= m_part_info->num_subparts; + uint i= 0; + uint num_parts_set= alter_info->partition_names.elements; + uint num_parts_found= set_part_state(alter_info, m_part_info, + PART_ADMIN); + DBUG_ENTER("ha_partition::truncate_partition"); + + /* + TRUNCATE also means resetting auto_increment. Hence, reset + it so that it will be initialized again at the next use. + */ + lock_auto_increment(); + table_share->ha_part_data->next_auto_inc_val= 0; + table_share->ha_part_data->auto_inc_initialized= FALSE; + unlock_auto_increment(); + + if (num_parts_set != num_parts_found && + (!(alter_info->flags & ALTER_ALL_PARTITION))) + DBUG_RETURN(HA_ERR_NO_PARTITION_FOUND); + + do + { + partition_element *part_elem= part_it++; + if (part_elem->part_state == PART_ADMIN) + { + if (m_is_sub_partitioned) + { + List_iterator + subpart_it(part_elem->subpartitions); + partition_element *sub_elem; + uint j= 0, part; + do + { + sub_elem= subpart_it++; + part= i * num_subparts + j; + DBUG_PRINT("info", ("truncate subpartition %u (%s)", + part, sub_elem->partition_name)); + if ((error= m_file[part]->ha_truncate())) + break; + } while (++j < num_subparts); + } + else + { + DBUG_PRINT("info", ("truncate partition %u (%s)", i, + part_elem->partition_name)); + error= m_file[i]->ha_truncate(); + } + part_elem->part_state= PART_NORMAL; + } + } while (!error && (++i < num_parts)); + DBUG_RETURN(error); +} + + /* Start a large batch of insert rows @@ -6327,8 +6337,8 @@ void ha_partition::print_error(int error, myf errflag) /* Should probably look for my own errors first */ DBUG_PRINT("enter", ("error: %d", error)); - if (error == HA_ERR_NO_PARTITION_FOUND && - thd->lex->sql_command != SQLCOM_TRUNCATE) + if ((error == HA_ERR_NO_PARTITION_FOUND) && + ! (thd->lex->alter_info.flags & ALTER_TRUNCATE_PARTITION)) m_part_info->print_no_partition_found(table); else { diff --git a/sql/ha_partition.h b/sql/ha_partition.h index 353e0d17159..f1abc0cefe2 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -346,6 +346,7 @@ public: virtual int update_row(const uchar * old_data, uchar * new_data); virtual int delete_row(const uchar * buf); virtual int delete_all_rows(void); + virtual int truncate(); virtual void start_bulk_insert(ha_rows rows); virtual int end_bulk_insert(); private: @@ -354,6 +355,15 @@ private: long estimate_read_buffer_size(long original_size); public: + /* + Method for truncating a specific partition. + (i.e. ALTER TABLE t1 TRUNCATE PARTITION p). + + @remark This method is a partitioning-specific hook + and thus not a member of the general SE API. + */ + int truncate_partition(Alter_info *); + virtual bool is_fatal_error(int error, uint flags) { if (!handler::is_fatal_error(error, flags) || diff --git a/sql/handler.cc b/sql/handler.cc index 567dbe6ea49..1542dd99ec6 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -3208,6 +3208,21 @@ handler::ha_delete_all_rows() } +/** + Truncate table: public interface. + + @sa handler::truncate() +*/ + +int +handler::ha_truncate() +{ + mark_trx_read_write(); + + return truncate(); +} + + /** Reset auto increment: public interface. diff --git a/sql/handler.h b/sql/handler.h index b1d64a1114b..325df003215 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -1331,6 +1331,7 @@ public: int ha_bulk_update_row(const uchar *old_data, uchar *new_data, uint *dup_key_found); int ha_delete_all_rows(); + int ha_truncate(); int ha_reset_auto_increment(ulonglong value); int ha_optimize(THD* thd, HA_CHECK_OPT* check_opt); int ha_analyze(THD* thd, HA_CHECK_OPT* check_opt); @@ -1644,8 +1645,33 @@ public: { return(NULL);} /* gets tablespace name from handler */ /** used in ALTER TABLE; 1 if changing storage engine is allowed */ virtual bool can_switch_engines() { return 1; } - /** used in REPLACE; is > 0 if table is referred by a FOREIGN KEY */ - virtual int get_foreign_key_list(THD *thd, List *f_key_list) + /** + Get the list of foreign keys in this table. + + @remark Returns the set of foreign keys where this table is the + dependent or child table. + + @param thd The thread handle. + @param f_key_list[out] The list of foreign keys. + + @return The handler error code or zero for success. + */ + virtual int + get_foreign_key_list(THD *thd, List *f_key_list) + { return 0; } + /** + Get the list of foreign keys referencing this table. + + @remark Returns the set of foreign keys where this table is the + referenced or parent table. + + @param thd The thread handle. + @param f_key_list[out] The list of foreign keys. + + @return The handler error code or zero for success. + */ + virtual int + get_parent_foreign_key_list(THD *thd, List *f_key_list) { return 0; } virtual uint referenced_by_foreign_key() { return 0;} virtual void init_table_handle_for_HANDLER() @@ -2010,16 +2036,34 @@ private: This is called to delete all rows in a table If the handler don't support this, then this function will return HA_ERR_WRONG_COMMAND and MySQL will delete the rows one - by one. It should reset auto_increment if - thd->lex->sql_command == SQLCOM_TRUNCATE. + by one. */ virtual int delete_all_rows() { return (my_errno=HA_ERR_WRONG_COMMAND); } + /** + Quickly remove all rows from a table. + + @remark This method is responsible for implementing MySQL's TRUNCATE + TABLE statement, which is a DDL operation. As such, a engine + can bypass certain integrity checks and in some cases avoid + fine-grained locking (e.g. row locks) which would normally be + required for a DELETE statement. + + @remark Typically, truncate is not used if it can result in integrity + violation. For example, truncate is not used when a foreign + key references the table, but it might be used if foreign key + checks are disabled. + + @remark Engine is responsible for resetting the auto-increment counter. + + @remark The table is locked in exclusive mode. + */ + virtual int truncate() + { return HA_ERR_WRONG_COMMAND; } /** Reset the auto-increment counter to the given value, i.e. the next row - inserted will get the given value. This is called e.g. after TRUNCATE - is emulated by doing a 'DELETE FROM t'. HA_ERR_WRONG_COMMAND is - returned by storage engines that don't support this operation. + inserted will get the given value. HA_ERR_WRONG_COMMAND is returned by + storage engines that don't support this operation. */ virtual int reset_auto_increment(ulonglong value) { return HA_ERR_WRONG_COMMAND; } diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index 07f5589135d..c7d016b19ca 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -6379,3 +6379,6 @@ ER_SET_PASSWORD_AUTH_PLUGIN ER_GRANT_PLUGIN_USER_EXISTS eng "GRANT with IDENTIFIED WITH is illegal because the user %-.*s already exists" + +ER_TRUNCATE_ILLEGAL_FK 42000 + eng "Cannot truncate a table referenced in a foreign key constraint (%.192s)" diff --git a/sql/sql_lex.h b/sql/sql_lex.h index 3a559433e2d..0f93275434d 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -958,6 +958,7 @@ inline bool st_select_lex_unit::is_union () #define ALTER_ALL_PARTITION (1L << 21) #define ALTER_REMOVE_PARTITIONING (1L << 22) #define ALTER_FOREIGN_KEY (1L << 23) +#define ALTER_TRUNCATE_PARTITION (1L << 24) enum enum_alter_table_change_level { diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index e44d2563483..2f8a72ee25c 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -34,7 +34,7 @@ #include "sql_locale.h" // my_locale_en_US #include "log.h" // flush_error_log #include "sql_view.h" // mysql_create_view, mysql_drop_view -#include "sql_delete.h" // mysql_truncate, mysql_delete +#include "sql_delete.h" // mysql_delete #include "sql_insert.h" // mysql_insert #include "sql_update.h" // mysql_update, mysql_multi_update #include "sql_partition.h" // struct partition_info @@ -49,7 +49,6 @@ // mysql_recreate_table, // mysql_backup_table, // mysql_restore_table -#include "sql_truncate.h" // mysql_truncate_table #include "sql_reload.h" // reload_acl_and_cache #include "sql_admin.h" // mysql_assign_to_keycache #include "sql_connect.h" // check_user, diff --git a/sql/sql_partition_admin.cc b/sql/sql_partition_admin.cc index fee33303a04..98750314a4a 100644 --- a/sql/sql_partition_admin.cc +++ b/sql/sql_partition_admin.cc @@ -16,10 +16,10 @@ #include "sql_parse.h" // check_one_table_access #include "sql_table.h" // mysql_alter_table, etc. #include "sql_lex.h" // Sql_statement -#include "sql_truncate.h" // mysql_truncate_table, - // Truncate_statement #include "sql_admin.h" // Analyze/Check/.._table_statement #include "sql_partition_admin.h" // Alter_table_*_partition +#include "ha_partition.h" // ha_partition +#include "sql_base.h" // open_and_lock_tables #ifndef WITH_PARTITION_STORAGE_ENGINE @@ -46,7 +46,7 @@ bool Alter_table_analyze_partition_statement::execute(THD *thd) m_lex->alter_info.flags|= ALTER_ADMIN_PARTITION; res= Analyze_table_statement::execute(thd); - + DBUG_RETURN(res); } @@ -104,36 +104,85 @@ bool Alter_table_repair_partition_statement::execute(THD *thd) bool Alter_table_truncate_partition_statement::execute(THD *thd) { + int error; + ha_partition *partition; + ulong timeout= thd->variables.lock_wait_timeout; TABLE_LIST *first_table= thd->lex->select_lex.table_list.first; - bool res; - enum_sql_command original_sql_command; DBUG_ENTER("Alter_table_truncate_partition_statement::execute"); - /* - Execute TRUNCATE PARTITION just like TRUNCATE TABLE. - Some storage engines (InnoDB, partition) checks thd_sql_command, - so we set it to SQLCOM_TRUNCATE during the execution. - */ - original_sql_command= m_lex->sql_command; - m_lex->sql_command= SQLCOM_TRUNCATE; - /* Flag that it is an ALTER command which administrates partitions, used by ha_partition. */ - m_lex->alter_info.flags|= ALTER_ADMIN_PARTITION; - - /* - Fix the lock types (not the same as ordinary ALTER TABLE). - */ + m_lex->alter_info.flags|= ALTER_ADMIN_PARTITION | + ALTER_TRUNCATE_PARTITION; + + /* Fix the lock types (not the same as ordinary ALTER TABLE). */ first_table->lock_type= TL_WRITE; - first_table->mdl_request.set_type(MDL_SHARED_NO_READ_WRITE); + first_table->mdl_request.set_type(MDL_EXCLUSIVE); - /* execute as a TRUNCATE TABLE */ - res= Truncate_statement::execute(thd); + /* + Check table permissions and open it with a exclusive lock. + Ensure it is a partitioned table and finally, upcast the + handler and invoke the partition truncate method. Lastly, + write the statement to the binary log if necessary. + */ - m_lex->sql_command= original_sql_command; - DBUG_RETURN(res); + if (check_one_table_access(thd, DROP_ACL, first_table)) + DBUG_RETURN(TRUE); + + if (open_and_lock_tables(thd, first_table, FALSE, 0)) + DBUG_RETURN(TRUE); + + /* + TODO: Add support for TRUNCATE PARTITION for NDB and other + engines supporting native partitioning. + */ + if (first_table->table->s->db_type() != partition_hton) + { + my_error(ER_PARTITION_MGMT_ON_NONPARTITIONED, MYF(0)); + DBUG_RETURN(TRUE); + } + + /* + Under locked table modes this might still not be an exclusive + lock. Hence, upgrade the lock since the handler truncate method + mandates an exclusive metadata lock. + */ + MDL_ticket *ticket= first_table->table->mdl_ticket; + if (thd->mdl_context.upgrade_shared_lock_to_exclusive(ticket, timeout)) + DBUG_RETURN(TRUE); + + tdc_remove_table(thd, TDC_RT_REMOVE_NOT_OWN, first_table->db, + first_table->table_name, FALSE); + + partition= (ha_partition *) first_table->table->file; + + /* Invoke the handler method responsible for truncating the partition. */ + if ((error= partition->truncate_partition(&thd->lex->alter_info))) + first_table->table->file->print_error(error, MYF(0)); + + /* + All effects of a truncate operation are committed even if the + operation fails. Thus, the query must be written to the binary + log. The only exception is a unimplemented truncate method. Also, + it is logged in statement format, regardless of the binlog format. + */ + if (error != HA_ERR_WRONG_COMMAND) + error|= write_bin_log(thd, !error, thd->query(), thd->query_length()); + + /* + A locked table ticket was upgraded to a exclusive lock. After the + the query has been written to the binary log, downgrade the lock + to a shared one. + */ + if (thd->locked_tables_mode) + ticket->downgrade_exclusive_lock(MDL_SHARED_NO_READ_WRITE); + + if (! error) + my_ok(thd); + + DBUG_RETURN(error); } #endif /* WITH_PARTITION_STORAGE_ENGINE */ diff --git a/sql/sql_partition_admin.h b/sql/sql_partition_admin.h index 36bafec4202..564b8676be8 100644 --- a/sql/sql_partition_admin.h +++ b/sql/sql_partition_admin.h @@ -210,7 +210,7 @@ public: /** Class that represents the ALTER TABLE t1 TRUNCATE PARTITION p statement. */ -class Alter_table_truncate_partition_statement : public Truncate_statement +class Alter_table_truncate_partition_statement : public Sql_statement { public: /** @@ -218,10 +218,10 @@ public: @param lex the LEX structure for this statement. */ Alter_table_truncate_partition_statement(LEX *lex) - : Truncate_statement(lex) + : Sql_statement(lex) {} - ~Alter_table_truncate_partition_statement() + virtual ~Alter_table_truncate_partition_statement() {} /** diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 6b24e3db7bc..ba4b0ae7a0a 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -5063,8 +5063,8 @@ static int get_schema_constraints_record(THD *thd, TABLE_LIST *tables, while ((f_key_info=it++)) { if (store_constraints(thd, table, db_name, table_name, - f_key_info->forein_id->str, - strlen(f_key_info->forein_id->str), + f_key_info->foreign_id->str, + strlen(f_key_info->foreign_id->str), "FOREIGN KEY", 11)) DBUG_RETURN(1); } @@ -5263,8 +5263,8 @@ static int get_schema_key_column_usage_record(THD *thd, f_idx++; restore_record(table, s->default_values); store_key_column_usage(table, db_name, table_name, - f_key_info->forein_id->str, - f_key_info->forein_id->length, + f_key_info->foreign_id->str, + f_key_info->foreign_id->length, f_info->str, f_info->length, (longlong) f_idx); table->field[8]->store((longlong) f_idx, TRUE); @@ -6053,8 +6053,8 @@ get_referential_constraints_record(THD *thd, TABLE_LIST *tables, table->field[0]->store(STRING_WITH_LEN("def"), cs); table->field[1]->store(db_name->str, db_name->length, cs); table->field[9]->store(table_name->str, table_name->length, cs); - table->field[2]->store(f_key_info->forein_id->str, - f_key_info->forein_id->length, cs); + table->field[2]->store(f_key_info->foreign_id->str, + f_key_info->foreign_id->length, cs); table->field[3]->store(STRING_WITH_LEN("def"), cs); table->field[4]->store(f_key_info->referenced_db->str, f_key_info->referenced_db->length, cs); diff --git a/sql/sql_string.h b/sql/sql_string.h index d21b5353b76..845b7c280b1 100644 --- a/sql/sql_string.h +++ b/sql/sql_string.h @@ -265,8 +265,12 @@ public: CHARSET_INFO *csto, uint *errors); bool append(const String &s); bool append(const char *s); - bool append(const char *s,uint32 arg_length); - bool append(const char *s,uint32 arg_length, CHARSET_INFO *cs); + bool append(LEX_STRING *ls) + { + return append(ls->str, ls->length); + } + bool append(const char *s, uint32 arg_length); + bool append(const char *s, uint32 arg_length, CHARSET_INFO *cs); bool append_ulonglong(ulonglong val); bool append(IO_CACHE* file, uint32 arg_length); bool append_with_prefill(const char *s, uint32 arg_length, diff --git a/sql/sql_truncate.cc b/sql/sql_truncate.cc index c0bc726a188..0cff2875ac8 100644 --- a/sql/sql_truncate.cc +++ b/sql/sql_truncate.cc @@ -13,11 +13,8 @@ along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "sql_priv.h" -#include "transaction.h" -#include "debug_sync.h" -#include "records.h" // READ_RECORD -#include "table.h" // TABLE +#include "debug_sync.h" // DEBUG_SYNC +#include "table.h" // TABLE, FOREIGN_KEY_INFO #include "sql_class.h" // THD #include "sql_base.h" // open_and_lock_tables #include "sql_table.h" // write_bin_log @@ -29,145 +26,212 @@ #include "sql_truncate.h" -/* - Delete all rows of a locked table. +/** + Append a list of field names to a string. - @param thd Thread context. - @param table_list Table list element for the table. - @param rows_deleted Whether rows might have been deleted. + @param str The string. + @param fields The list of field names. - @retval FALSE Success. - @retval TRUE Error. + @return TRUE on failure, FALSE otherwise. +*/ + +static bool fk_info_append_fields(String *str, List *fields) +{ + bool res= FALSE; + LEX_STRING *field; + List_iterator_fast it(*fields); + + while ((field= it++)) + { + res|= str->append("`"); + res|= str->append(field); + res|= str->append("`, "); + } + + str->chop(); + str->chop(); + + return res; +} + + +/** + Generate a foreign key description suitable for a error message. + + @param thd Thread context. + @param fk_info The foreign key information. + + @return A human-readable string describing the foreign key. +*/ + +static const char *fk_info_str(THD *thd, FOREIGN_KEY_INFO *fk_info) +{ + bool res= FALSE; + char buffer[STRING_BUFFER_USUAL_SIZE*2]; + String str(buffer, sizeof(buffer), system_charset_info); + + str.length(0); + + /* + `db`.`tbl`, CONSTRAINT `id` FOREIGN KEY (`fk`) REFERENCES `db`.`tbl` (`fk`) + */ + + res|= str.append('`'); + res|= str.append(fk_info->foreign_db); + res|= str.append("`.`"); + res|= str.append(fk_info->foreign_table); + res|= str.append("`, CONSTRAINT `"); + res|= str.append(fk_info->foreign_id); + res|= str.append("` FOREIGN KEY ("); + res|= fk_info_append_fields(&str, &fk_info->foreign_fields); + res|= str.append(") REFERENCES `"); + res|= str.append(fk_info->referenced_db); + res|= str.append("`.`"); + res|= str.append(fk_info->referenced_table); + res|= str.append("` ("); + res|= fk_info_append_fields(&str, &fk_info->referenced_fields); + res|= str.append(')'); + + return res ? NULL : thd->strmake(str.ptr(), str.length()); +} + + +/** + Check and emit a fatal error if the table which is going to be + affected by TRUNCATE TABLE is a parent table in some non-self- + referencing foreign key. + + @remark The intention is to allow truncate only for tables that + are not dependent on other tables. + + @param thd Thread context. + @param table Table handle. + + @retval FALSE This table is not parent in a non-self-referencing foreign + key. Statement can proceed. + @retval TRUE This table is parent in a non-self-referencing foreign key, + error was emitted. */ static bool -delete_all_rows(THD *thd, TABLE *table) +fk_truncate_illegal_if_parent(THD *thd, TABLE *table) { - int error; - READ_RECORD info; - bool is_bulk_delete; - bool some_rows_deleted= FALSE; - bool save_binlog_row_based= thd->is_current_stmt_binlog_format_row(); - DBUG_ENTER("delete_all_rows"); - - /* Replication of truncate table must be statement based. */ - thd->clear_current_stmt_binlog_format_row(); + FOREIGN_KEY_INFO *fk_info; + List fk_list; + List_iterator_fast it; /* - Update handler statistics (e.g. table->file->stats.records). - Might be used by the storage engine to aggregate information - necessary to allow deletion. Currently, this seems to be - meaningful only to the archive storage engine, which uses - the info method to set the number of records. Although - archive does not support deletion, it becomes necessary in - order to return a error if the table is not empty. + Bail out early if the table is not referenced by a foreign key. + In this case, the table could only be, if at all, a child table. */ - error= table->file->info(HA_STATUS_VARIABLE | HA_STATUS_NO_LOCK); - if (error && error != HA_ERR_WRONG_COMMAND) - { - table->file->print_error(error, MYF(0)); - goto end; - } + if (! table->file->referenced_by_foreign_key()) + return FALSE; /* - Attempt to delete all rows in the table. - If it is unsupported, switch to row by row deletion. + This table _is_ referenced by a foreign key. At this point, only + self-referencing keys are acceptable. For this reason, get the list + of foreign keys referencing this table in order to check the name + of the child (dependent) tables. */ - if (! (error= table->file->ha_delete_all_rows())) - goto end; + table->file->get_parent_foreign_key_list(thd, &fk_list); - if (error != HA_ERR_WRONG_COMMAND) - { - /* - If a transactional engine fails in the middle of deletion, - we expect it to be able to roll it back. Some reasons - for the engine to fail would be media failure or corrupted - data dictionary (i.e. in case of a partitioned table). We - have sufficiently strong metadata locks to rule out any - potential deadlocks. - - If a non-transactional engine fails here (that would - not be MyISAM, since MyISAM does TRUNCATE by recreate), - and binlog is on, replication breaks, since nothing gets - written to the binary log. (XXX: is this a bug?) - */ - table->file->print_error(error, MYF(0)); - goto end; - } - - /* - A workaround for Bug#53696 "Performance schema engine violates the - PSEA API by calling my_error()". - */ + /* Out of memory when building list. */ if (thd->is_error()) - goto end; + return TRUE; - /* Handler didn't support fast delete. Delete rows one by one. */ + it.init(fk_list); - init_read_record(&info, thd, table, NULL, TRUE, TRUE, FALSE); - - /* - Start bulk delete. If the engine does not support it, go on, - it's not an error. - */ - is_bulk_delete= ! table->file->start_bulk_delete(); - - table->mark_columns_needed_for_delete(); - - while (!(error= info.read_record(&info)) && !thd->killed) + /* Loop over the set of foreign keys for which this table is a parent. */ + while ((fk_info= it++)) { - if ((error= table->file->ha_delete_row(table->record[0]))) - { - table->file->print_error(error, MYF(0)); + DBUG_ASSERT(!my_strcasecmp(system_charset_info, + fk_info->referenced_db->str, + table->s->db.str)); + + DBUG_ASSERT(!my_strcasecmp(system_charset_info, + fk_info->referenced_table->str, + table->s->table_name.str)); + + if (my_strcasecmp(system_charset_info, fk_info->foreign_db->str, + table->s->db.str) || + my_strcasecmp(system_charset_info, fk_info->foreign_table->str, + table->s->table_name.str)) break; - } - - some_rows_deleted= TRUE; } - /* HA_ERR_END_OF_FILE */ - if (error == -1) - error= 0; - - /* Close down the bulk delete. */ - if (is_bulk_delete) + /* Table is parent in a non-self-referencing foreign key. */ + if (fk_info) { - int bulk_delete_error= table->file->end_bulk_delete(); - if (bulk_delete_error && !error) - { - table->file->print_error(bulk_delete_error, MYF(0)); - error= bulk_delete_error; - } + my_error(ER_TRUNCATE_ILLEGAL_FK, MYF(0), fk_info_str(thd, fk_info)); + return TRUE; } - end_read_record(&info); + return FALSE; +} + + +/* + Open and truncate a locked table. + + @param thd Thread context. + @param table_ref Table list element for the table to be truncated. + @param is_tmp_table True if element refers to a temp table. + + @retval 0 Success. + @retval > 0 Error code. +*/ + +int Truncate_statement::handler_truncate(THD *thd, TABLE_LIST *table_ref, + bool is_tmp_table) +{ + int error= 0; + uint flags; + DBUG_ENTER("Truncate_statement::handler_truncate"); /* - Regardless of the error status, the query must be written to the - binary log if rows of the table is non-transactional. + Can't recreate, the engine must mechanically delete all rows + in the table. Use open_and_lock_tables() to open a write cursor. */ - if (some_rows_deleted && !table->file->has_transactions()) + + /* If it is a temporary table, no need to take locks. */ + if (is_tmp_table) + flags= MYSQL_OPEN_TEMPORARY_ONLY; + else { - thd->transaction.stmt.modified_non_trans_table= TRUE; - thd->transaction.all.modified_non_trans_table= TRUE; + /* We don't need to load triggers. */ + DBUG_ASSERT(table_ref->trg_event_map == 0); + /* + Our metadata lock guarantees that no transaction is reading + or writing into the table. Yet, to open a write cursor we need + a thr_lock lock. Allow to open base tables only. + */ + table_ref->required_type= FRMTYPE_TABLE; + /* + Ignore pending FLUSH TABLES since we don't want to release + the MDL lock taken above and otherwise there is no way to + wait for FLUSH TABLES in deadlock-free fashion. + */ + flags= MYSQL_OPEN_IGNORE_FLUSH | MYSQL_OPEN_SKIP_TEMPORARY; + /* + Even though we have an MDL lock on the table here, we don't + pass MYSQL_OPEN_HAS_MDL_LOCK to open_and_lock_tables + since to truncate a MERGE table, we must open and lock + merge children, and on those we don't have an MDL lock. + Thus clear the ticket to satisfy MDL asserts. + */ + table_ref->mdl_request.ticket= NULL; } - if (error || thd->killed) - goto end; + /* Open the table as it will handle some required preparations. */ + if (open_and_lock_tables(thd, table_ref, FALSE, flags)) + DBUG_RETURN(1); - /* Truncate resets the auto-increment counter. */ - error= table->file->ha_reset_auto_increment(0); - if (error) - { - if (error != HA_ERR_WRONG_COMMAND) - table->file->print_error(error, MYF(0)); - else - error= 0; - } + /* Whether to truncate regardless of foreign keys. */ + if (! (thd->variables.option_bits & OPTION_NO_FOREIGN_KEY_CHECKS)) + error= fk_truncate_illegal_if_parent(thd, table_ref->table); -end: - if (save_binlog_row_based) - thd->set_current_stmt_binlog_format_row(); + if (!error && (error= table_ref->table->file->ha_truncate())) + table_ref->table->file->print_error(error, MYF(0)); DBUG_RETURN(error); } @@ -225,30 +289,29 @@ static bool recreate_temporary_table(THD *thd, TABLE *table) /* - Handle opening and locking if a base table for truncate. + Handle locking a base table for truncate. @param[in] thd Thread context. @param[in] table_ref Table list element for the table to be truncated. @param[out] hton_can_recreate Set to TRUE if table can be dropped and recreated. - @param[out] ticket_downgrade Set if a lock must be downgraded after - truncate is done. @retval FALSE Success. @retval TRUE Error. */ -static bool open_and_lock_table_for_truncate(THD *thd, TABLE_LIST *table_ref, - bool *hton_can_recreate, - MDL_ticket **ticket_downgrade) +bool Truncate_statement::lock_table(THD *thd, TABLE_LIST *table_ref, + bool *hton_can_recreate) { TABLE *table= NULL; - handlerton *table_type; - DBUG_ENTER("open_and_lock_table_for_truncate"); + DBUG_ENTER("Truncate_statement::lock_table"); + /* Lock types are set in the parser. */ DBUG_ASSERT(table_ref->lock_type == TL_WRITE); - DBUG_ASSERT(table_ref->mdl_request.type == MDL_SHARED_NO_READ_WRITE); + /* The handler truncate protocol dictates a exclusive lock. */ + DBUG_ASSERT(table_ref->mdl_request.type == MDL_EXCLUSIVE); + /* Before doing anything else, acquire a metadata lock on the table, or ensure we have one. We don't use open_and_lock_tables() @@ -268,103 +331,45 @@ static bool open_and_lock_table_for_truncate(THD *thd, TABLE_LIST *table_ref, table_ref->table_name, FALSE))) DBUG_RETURN(TRUE); - table_type= table->s->db_type(); - *hton_can_recreate= ha_check_storage_engine_flag(table_type, + *hton_can_recreate= ha_check_storage_engine_flag(table->s->db_type(), HTON_CAN_RECREATE); table_ref->mdl_request.ticket= table->mdl_ticket; } else { - /* - Even though we could use the previous execution branch here just as - well, we must not try to open the table: - */ + /* Acquire an exclusive lock. */ DBUG_ASSERT(table_ref->next_global == NULL); if (lock_table_names(thd, table_ref, NULL, thd->variables.lock_wait_timeout, MYSQL_OPEN_SKIP_TEMPORARY)) DBUG_RETURN(TRUE); - if (dd_frm_storage_engine(thd, table_ref->db, table_ref->table_name, - &table_type)) + if (dd_check_storage_engine_flag(thd, table_ref->db, table_ref->table_name, + HTON_CAN_RECREATE, hton_can_recreate)) DBUG_RETURN(TRUE); - *hton_can_recreate= ha_check_storage_engine_flag(table_type, - HTON_CAN_RECREATE); } -#ifdef WITH_PARTITION_STORAGE_ENGINE /* - TODO: Add support for TRUNCATE PARTITION for NDB and other engines - supporting native partitioning. + A storage engine can recreate or truncate the table only if there + are no references to it from anywhere, i.e. no cached TABLE in the + table cache. */ - if (thd->lex->alter_info.flags & ALTER_ADMIN_PARTITION && - table_type != partition_hton) + if (thd->locked_tables_mode) { - my_error(ER_PARTITION_MGMT_ON_NONPARTITIONED, MYF(0)); - DBUG_RETURN(TRUE); - } -#endif - DEBUG_SYNC(thd, "lock_table_for_truncate"); - - if (*hton_can_recreate) - { - /* - Acquire an exclusive lock. The storage engine can recreate the - table only if there are no references to it from anywhere, i.e. - no cached TABLE in the table cache. To remove the table from the - cache we need an exclusive lock. - */ - if (thd->locked_tables_mode) - { - if (wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN)) - DBUG_RETURN(TRUE); - *ticket_downgrade= table->mdl_ticket; + DEBUG_SYNC(thd, "upgrade_lock_for_truncate"); + /* To remove the table from the cache we need an exclusive lock. */ + if (wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN)) + DBUG_RETURN(TRUE); + m_ticket_downgrade= table->mdl_ticket; + /* Close if table is going to be recreated. */ + if (*hton_can_recreate) close_all_tables_for_name(thd, table->s, FALSE); - } - else - { - ulong timeout= thd->variables.lock_wait_timeout; - if (thd->mdl_context. - upgrade_shared_lock_to_exclusive(table_ref->mdl_request.ticket, - timeout)) - DBUG_RETURN(TRUE); - tdc_remove_table(thd, TDC_RT_REMOVE_ALL, table_ref->db, - table_ref->table_name, FALSE); - } } else { - /* - Can't recreate, we must mechanically delete all rows in - the table. Our metadata lock guarantees that no transaction - is reading or writing into the table. Yet, to open a write - cursor we need a thr_lock lock. Use open_and_lock_tables() - to do the necessary job. - */ - - /* Allow to open base tables only. */ - table_ref->required_type= FRMTYPE_TABLE; - /* We don't need to load triggers. */ - DBUG_ASSERT(table_ref->trg_event_map == 0); - /* - Even though we have an MDL lock on the table here, we don't - pass MYSQL_OPEN_HAS_MDL_LOCK to open_and_lock_tables - since to truncate a MERGE table, we must open and lock - merge children, and on those we don't have an MDL lock. - Thus clear the ticket to satisfy MDL asserts. - */ - table_ref->mdl_request.ticket= NULL; - - /* - Open the table as it will handle some required preparations. - Ignore pending FLUSH TABLES since we don't want to release - the MDL lock taken above and otherwise there is no way to - wait for FLUSH TABLES in deadlock-free fashion. - */ - if (open_and_lock_tables(thd, table_ref, FALSE, - MYSQL_OPEN_IGNORE_FLUSH | - MYSQL_OPEN_SKIP_TEMPORARY)) - DBUG_RETURN(TRUE); + /* Table is already locked exclusively. Remove cached instances. */ + tdc_remove_table(thd, TDC_RT_REMOVE_ALL, table_ref->db, + table_ref->table_name, FALSE); } DBUG_RETURN(FALSE); @@ -385,14 +390,17 @@ static bool open_and_lock_table_for_truncate(THD *thd, TABLE_LIST *table_ref, @retval TRUE Error. */ -bool mysql_truncate_table(THD *thd, TABLE_LIST *table_ref) +bool Truncate_statement::truncate_table(THD *thd, TABLE_LIST *table_ref) { + int error; TABLE *table; - bool error= TRUE, binlog_stmt; - MDL_ticket *mdl_ticket= NULL; - DBUG_ENTER("mysql_truncate_table"); + bool binlog_stmt; + DBUG_ENTER("Truncate_statement::truncate_table"); - /* Remove tables from the HANDLER's hash. */ + /* Initialize, or reinitialize in case of reexecution (SP). */ + m_ticket_downgrade= NULL; + + /* Remove table from the HANDLER's hash. */ mysql_ha_rm_tables(thd, table_ref); /* If it is a temporary table, no need to take locks. */ @@ -413,14 +421,11 @@ bool mysql_truncate_table(THD *thd, TABLE_LIST *table_ref) { /* The engine does not support truncate-by-recreate. Open the - table and delete all rows. In such a manner this can in fact - open several tables if it's a temporary MyISAMMRG table. + table and invoke the handler truncate. In such a manner this + can in fact open several tables if it's a temporary MyISAMMRG + table. */ - if (open_and_lock_tables(thd, table_ref, FALSE, - MYSQL_OPEN_TEMPORARY_ONLY)) - DBUG_RETURN(TRUE); - - error= delete_all_rows(thd, table_ref->table); + error= handler_truncate(thd, table_ref, TRUE); } /* @@ -434,8 +439,7 @@ bool mysql_truncate_table(THD *thd, TABLE_LIST *table_ref) { bool hton_can_recreate; - if (open_and_lock_table_for_truncate(thd, table_ref, - &hton_can_recreate, &mdl_ticket)) + if (lock_table(thd, table_ref, &hton_can_recreate)) DBUG_RETURN(TRUE); if (hton_can_recreate) @@ -454,13 +458,18 @@ bool mysql_truncate_table(THD *thd, TABLE_LIST *table_ref) } else { - error= delete_all_rows(thd, table_ref->table); + /* + The engine does not support truncate-by-recreate. + Attempt to use the handler truncate method. + */ + error= handler_truncate(thd, table_ref, FALSE); /* - Regardless of the error status, the query must be written to the - binary log if rows of a non-transactional table were deleted. + All effects of a TRUNCATE TABLE operation are committed even if + truncation fails. Thus, the query must be written to the binary + log. The only exception is a unimplemented truncate method. */ - binlog_stmt= !error || thd->transaction.stmt.modified_non_trans_table; + binlog_stmt= !error || error != HA_ERR_WRONG_COMMAND; } query_cache_invalidate3(thd, table_ref, FALSE); @@ -470,50 +479,38 @@ bool mysql_truncate_table(THD *thd, TABLE_LIST *table_ref) if (binlog_stmt) error|= write_bin_log(thd, !error, thd->query(), thd->query_length()); - /* - All effects of a TRUNCATE TABLE operation are rolled back if a row - by row deletion fails. Otherwise, it is automatically committed at - the end. - */ - if (error) - { - trans_rollback_stmt(thd); - trans_rollback(thd); - } - /* A locked table ticket was upgraded to a exclusive lock. After the the query has been written to the binary log, downgrade the lock to a shared one. */ - if (mdl_ticket) - mdl_ticket->downgrade_exclusive_lock(MDL_SHARED_NO_READ_WRITE); + if (m_ticket_downgrade) + m_ticket_downgrade->downgrade_exclusive_lock(MDL_SHARED_NO_READ_WRITE); - DBUG_PRINT("exit", ("error: %d", error)); - DBUG_RETURN(test(error)); + DBUG_RETURN(error); } +/** + Execute a TRUNCATE statement at runtime. + + @param thd The current thread. + + @return FALSE on success. +*/ + bool Truncate_statement::execute(THD *thd) { - TABLE_LIST *first_table= thd->lex->select_lex.table_list.first; bool res= TRUE; + TABLE_LIST *first_table= thd->lex->select_lex.table_list.first; DBUG_ENTER("Truncate_statement::execute"); if (check_one_table_access(thd, DROP_ACL, first_table)) - goto error; - /* - Don't allow this within a transaction because we want to use - re-generate table - */ - if (thd->in_active_multi_stmt_transaction()) - { - my_message(ER_LOCK_OR_ACTIVE_TRANSACTION, - ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0)); - goto error; - } - if (! (res= mysql_truncate_table(thd, first_table))) + DBUG_RETURN(res); + + if (! (res= truncate_table(thd, first_table))) my_ok(thd); -error: + DBUG_RETURN(res); } + diff --git a/sql/sql_truncate.h b/sql/sql_truncate.h index b8b1d3da53d..95a2f35df4f 100644 --- a/sql/sql_truncate.h +++ b/sql/sql_truncate.h @@ -18,13 +18,15 @@ class THD; struct TABLE_LIST; -bool mysql_truncate_table(THD *thd, TABLE_LIST *table_ref); - /** Truncate_statement represents the TRUNCATE statement. */ class Truncate_statement : public Sql_statement { +private: + /* Set if a lock must be downgraded after truncate is done. */ + MDL_ticket *m_ticket_downgrade; + public: /** Constructor, used to represent a ALTER TABLE statement. @@ -34,7 +36,7 @@ public: : Sql_statement(lex) {} - ~Truncate_statement() + virtual ~Truncate_statement() {} /** @@ -43,7 +45,20 @@ public: @return false on success. */ bool execute(THD *thd); + +protected: + /** Handle locking a base table for truncate. */ + bool lock_table(THD *, TABLE_LIST *, bool *); + + /** Truncate table via the handler method. */ + int handler_truncate(THD *, TABLE_LIST *, bool); + + /** + Optimized delete of all rows by doing a full regenerate of the table. + Depending on the storage engine, it can be accomplished through a + drop and recreate or via the handler truncate method. + */ + bool truncate_table(THD *, TABLE_LIST *); }; - #endif diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 7c24f18aa6a..2fc39757511 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -10770,7 +10770,7 @@ truncate: lex->select_lex.sql_cache= SELECT_LEX::SQL_CACHE_UNSPECIFIED; lex->select_lex.init_order(); YYPS->m_lock_type= TL_WRITE; - YYPS->m_mdl_type= MDL_SHARED_NO_READ_WRITE; + YYPS->m_mdl_type= MDL_EXCLUSIVE; } table_name { diff --git a/sql/table.h b/sql/table.h index 6723293c1ec..c8e1ad8e658 100644 --- a/sql/table.h +++ b/sql/table.h @@ -1170,7 +1170,9 @@ enum enum_schema_table_state typedef struct st_foreign_key_info { - LEX_STRING *forein_id; + LEX_STRING *foreign_id; + LEX_STRING *foreign_db; + LEX_STRING *foreign_table; LEX_STRING *referenced_db; LEX_STRING *referenced_table; LEX_STRING *update_method; diff --git a/storage/archive/ha_archive.cc b/storage/archive/ha_archive.cc index ef907b035b5..c24fbc21f94 100644 --- a/storage/archive/ha_archive.cc +++ b/storage/archive/ha_archive.cc @@ -1650,9 +1650,9 @@ int ha_archive::end_bulk_insert() This is done for security reasons. In a later version we will enable this by allowing the user to select a different row format. */ -int ha_archive::delete_all_rows() +int ha_archive::truncate() { - DBUG_ENTER("ha_archive::delete_all_rows"); + DBUG_ENTER("ha_archive::truncate"); DBUG_RETURN(HA_ERR_WRONG_COMMAND); } diff --git a/storage/archive/ha_archive.h b/storage/archive/ha_archive.h index b258b403c3c..fec41c12b81 100644 --- a/storage/archive/ha_archive.h +++ b/storage/archive/ha_archive.h @@ -115,7 +115,7 @@ public: int close(void); int write_row(uchar * buf); int real_write_row(uchar *buf, azio_stream *writer); - int delete_all_rows(); + int truncate(); int rnd_init(bool scan=1); int rnd_next(uchar *buf); int rnd_pos(uchar * buf, uchar *pos); diff --git a/storage/blackhole/ha_blackhole.cc b/storage/blackhole/ha_blackhole.cc index 6591c3a2c78..04560d89be3 100644 --- a/storage/blackhole/ha_blackhole.cc +++ b/storage/blackhole/ha_blackhole.cc @@ -87,6 +87,16 @@ int ha_blackhole::create(const char *name, TABLE *table_arg, DBUG_RETURN(0); } +/* + Intended to support partitioning. + Allows a particular partition to be truncated. +*/ +int ha_blackhole::truncate() +{ + DBUG_ENTER("ha_blackhole::truncate"); + DBUG_RETURN(0); +} + const char *ha_blackhole::index_type(uint key_number) { DBUG_ENTER("ha_blackhole::index_type"); diff --git a/storage/blackhole/ha_blackhole.h b/storage/blackhole/ha_blackhole.h index 9de3c22c614..17066b6edce 100644 --- a/storage/blackhole/ha_blackhole.h +++ b/storage/blackhole/ha_blackhole.h @@ -76,6 +76,7 @@ public: uint max_supported_key_part_length() const { return BLACKHOLE_MAX_KEY_LENGTH; } int open(const char *name, int mode, uint test_if_locked); int close(void); + int truncate(); int rnd_init(bool scan); int rnd_next(uchar *buf); int rnd_pos(uchar * buf, uchar *pos); diff --git a/storage/example/ha_example.cc b/storage/example/ha_example.cc index 306f8eaeccd..6af471494af 100644 --- a/storage/example/ha_example.cc +++ b/storage/example/ha_example.cc @@ -356,14 +356,14 @@ int ha_example::close(void) is happening. buf() is a byte array of data. You can use the field information to extract the data from the native byte array type. - @details + @details Example of this would be: - @code + @code for (Field **field=table->field ; *field ; field++) { ... } - @endcode + @endcode See ha_tina.cc for an example of extracting all of the data as strings. ha_berekly.cc has an example of how to store it intact by "packing" it @@ -375,7 +375,7 @@ int ha_example::close(void) Called from item_sum.cc, item_sum.cc, sql_acl.cc, sql_insert.cc, sql_insert.cc, sql_select.cc, sql_table.cc, sql_udf.cc, and sql_update.cc. - @see + @see item_sum.cc, item_sum.cc, sql_acl.cc, sql_insert.cc, sql_insert.cc, sql_select.cc, sql_table.cc, sql_udf.cc and sql_update.cc */ @@ -400,19 +400,19 @@ int ha_example::write_row(uchar *buf) Keep in mind that the server can do updates based on ordering if an ORDER BY clause was used. Consecutive ordering is not guaranteed. - @details + @details Currently new_data will not have an updated auto_increament record, or and updated timestamp field. You can do these for example by doing: - @code + @code if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_UPDATE) table->timestamp_field->set_time(); if (table->next_number_field && record == table->record[0]) update_auto_increment(); - @endcode + @endcode Called from sql_select.cc, sql_acl.cc, sql_update.cc, and sql_insert.cc. - @see + @see sql_select.cc, sql_acl.cc, sql_update.cc and sql_insert.cc */ int ha_example::update_row(const uchar *old_data, uchar *new_data) @@ -507,10 +507,10 @@ int ha_example::index_prev(uchar *buf) @brief index_first() asks for the first key in the index. - @details + @details Called from opt_range.cc, opt_sum.cc, sql_handler.cc, and sql_select.cc. - @see + @see opt_range.cc, opt_sum.cc, sql_handler.cc and sql_select.cc */ int ha_example::index_first(uchar *buf) @@ -528,10 +528,10 @@ int ha_example::index_first(uchar *buf) @brief index_last() asks for the last key in the index. - @details + @details Called from opt_range.cc, opt_sum.cc, sql_handler.cc, and sql_select.cc. - @see + @see opt_range.cc, opt_sum.cc, sql_handler.cc and sql_select.cc */ int ha_example::index_last(uchar *buf) @@ -551,11 +551,11 @@ int ha_example::index_last(uchar *buf) scan. See the example in the introduction at the top of this file to see when rnd_init() is called. - @details + @details Called from filesort.cc, records.cc, sql_handler.cc, sql_select.cc, sql_table.cc, and sql_update.cc. - @see + @see filesort.cc, records.cc, sql_handler.cc, sql_select.cc, sql_table.cc and sql_update.cc */ int ha_example::rnd_init(bool scan) @@ -578,11 +578,11 @@ int ha_example::rnd_end() The Field structure for the table is the key to getting data into buf in a manner that will allow the server to understand it. - @details + @details Called from filesort.cc, records.cc, sql_handler.cc, sql_select.cc, sql_table.cc, and sql_update.cc. - @see + @see filesort.cc, records.cc, sql_handler.cc, sql_select.cc, sql_table.cc and sql_update.cc */ int ha_example::rnd_next(uchar *buf) @@ -602,11 +602,11 @@ int ha_example::rnd_next(uchar *buf) position() is called after each call to rnd_next() if the data needs to be ordered. You can do something like the following to store the position: - @code + @code my_store_ptr(ref, ref_length, current_position); - @endcode + @endcode - @details + @details The server uses ref to store data. ref_length in the above case is the size needed to store current_position. ref is just a byte array that the server will maintain. If you are using offsets to mark rows, then @@ -615,7 +615,7 @@ int ha_example::rnd_next(uchar *buf) Called from filesort.cc, sql_select.cc, sql_delete.cc, and sql_update.cc. - @see + @see filesort.cc, sql_select.cc, sql_delete.cc and sql_update.cc */ void ha_example::position(const uchar *record) @@ -632,10 +632,10 @@ void ha_example::position(const uchar *record) ref. You can use ha_get_ptr(pos,ref_length) to retrieve whatever key or position you saved when position() was called. - @details + @details Called from filesort.cc, records.cc, sql_insert.cc, sql_select.cc, and sql_update.cc. - @see + @see filesort.cc, records.cc, sql_insert.cc, sql_select.cc and sql_update.cc */ int ha_example::rnd_pos(uchar *buf, uchar *pos) @@ -655,15 +655,15 @@ int ha_example::rnd_pos(uchar *buf, uchar *pos) ::info() is used to return information to the optimizer. See my_base.h for the complete description. - @details + @details Currently this table handler doesn't implement most of the fields really needed. SHOW also makes use of this data. You will probably want to have the following in your code: - @code + @code if (records < 2) records = 2; - @endcode + @endcode The reason is that the server will optimize for cases of only a single record. If, in a table scan, you don't know the number of records, it will probably be better to set records to two so you can return as many @@ -682,7 +682,7 @@ int ha_example::rnd_pos(uchar *buf, uchar *pos) sql_select.cc, sql_select.cc, sql_show.cc, sql_show.cc, sql_show.cc, sql_show.cc, sql_table.cc, sql_union.cc, and sql_update.cc. - @see + @see filesort.cc, ha_heap.cc, item_sum.cc, opt_sum.cc, sql_delete.cc, sql_delete.cc, sql_derived.cc, sql_select.cc, sql_select.cc, sql_select.cc, sql_select.cc, sql_select.cc, sql_show.cc, sql_show.cc, sql_show.cc, sql_show.cc, sql_table.cc, @@ -716,14 +716,14 @@ int ha_example::extra(enum ha_extra_function operation) Used to delete all rows in a table, including cases of truncate and cases where the optimizer realizes that all rows will be removed as a result of an SQL statement. - @details + @details Called from item_sum.cc by Item_func_group_concat::clear(), Item_sum_count_distinct::clear(), and Item_func_group_concat::clear(). Called from sql_delete.cc by mysql_delete(). Called from sql_select.cc by JOIN::reinit(). Called from sql_union.cc by st_select_lex_unit::exec(). - @see + @see Item_func_group_concat::clear(), Item_sum_count_distinct::clear() and Item_func_group_concat::clear() in item_sum.cc; mysql_delete() in sql_delete.cc; @@ -737,6 +737,29 @@ int ha_example::delete_all_rows() } +/** + @brief + Used for handler specific truncate table. The table is locked in + exclusive mode and handler is responsible for reseting the auto- + increment counter. + + @details + Called from Truncate_statement::handler_truncate. + Not used if the handlerton supports HTON_CAN_RECREATE, unless this + engine can be used as a partition. In this case, it is invoked when + a particular partition is to be truncated. + + @see + Truncate_statement in sql_truncate.cc + Remarks in handler::truncate. +*/ +int ha_example::truncate() +{ + DBUG_ENTER("ha_example::truncate"); + DBUG_RETURN(HA_ERR_WRONG_COMMAND); +} + + /** @brief This create a lock on the table. If you are implementing a storage engine @@ -745,11 +768,11 @@ int ha_example::delete_all_rows() here. Hint: Read the section "locking functions for mysql" in lock.cc to understand this. - @details + @details Called from lock.cc by lock_external() and unlock_external(). Also called from sql_table.cc by copy_data_between_tables(). - @see + @see lock.cc by lock_external() and unlock_external() in lock.cc; the section "locking functions for mysql" in lock.cc; copy_data_between_tables() in sql_table.cc. @@ -767,7 +790,7 @@ int ha_example::external_lock(THD *thd, int lock_type) should be needed for the table. For updates/deletes/inserts we get WRITE locks, for SELECT... we get read locks. - @details + @details Before adding the lock into the table lock handler (see thr_lock.c), mysqld calls store lock with the requested locks. Store lock can now modify a write lock to a read lock (or some other lock), ignore the @@ -790,12 +813,12 @@ int ha_example::external_lock(THD *thd, int lock_type) Called from lock.cc by get_lock_data(). - @note + @note In this method one should NEVER rely on table->in_use, it may, in fact, refer to a different thread! (this happens if get_lock_data() is called from mysql_lock_abort_for_thread() function) - @see + @see get_lock_data() in lock.cc */ THR_LOCK_DATA **ha_example::store_lock(THD *thd, @@ -816,7 +839,7 @@ THR_LOCK_DATA **ha_example::store_lock(THD *thd, shared references released). The variable name will just be the name of the table. You will need to remove any files you have created at this point. - @details + @details If you do not implement this, the default delete_table() is called from handler.cc and it will delete all files with the file extensions returned by bas_ext(). @@ -825,7 +848,7 @@ THR_LOCK_DATA **ha_example::store_lock(THD *thd, during create if the table_flag HA_DROP_BEFORE_CREATE was specified for the storage engine. - @see + @see delete_table and ha_create_table() in handler.cc */ int ha_example::delete_table(const char *name) diff --git a/storage/example/ha_example.h b/storage/example/ha_example.h index 12e088f5f05..5555a10930b 100644 --- a/storage/example/ha_example.h +++ b/storage/example/ha_example.h @@ -245,6 +245,7 @@ public: int extra(enum ha_extra_function operation); int external_lock(THD *thd, int lock_type); ///< required int delete_all_rows(void); + int truncate(); ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key); int delete_table(const char *from); diff --git a/storage/federated/ha_federated.cc b/storage/federated/ha_federated.cc index b1ae276dce8..fb10ce82334 100644 --- a/storage/federated/ha_federated.cc +++ b/storage/federated/ha_federated.cc @@ -3041,6 +3041,16 @@ int ha_federated::delete_all_rows() } +/* + Used to manually truncate the table via a delete of all rows in a table. +*/ + +int ha_federated::truncate() +{ + return delete_all_rows(); +} + + /* The idea with handler::store_lock() is the following: diff --git a/storage/federated/ha_federated.h b/storage/federated/ha_federated.h index 0f4c0201bd7..e39bac525b5 100644 --- a/storage/federated/ha_federated.h +++ b/storage/federated/ha_federated.h @@ -248,6 +248,7 @@ public: int optimize(THD* thd, HA_CHECK_OPT* check_opt); int delete_all_rows(void); + int truncate(); int create(const char *name, TABLE *form, HA_CREATE_INFO *create_info); //required ha_rows records_in_range(uint inx, key_range *start_key, diff --git a/storage/heap/ha_heap.cc b/storage/heap/ha_heap.cc index 481257def1d..fc870d33fb2 100644 --- a/storage/heap/ha_heap.cc +++ b/storage/heap/ha_heap.cc @@ -455,6 +455,13 @@ int ha_heap::delete_all_rows() } +int ha_heap::truncate() +{ + int error= delete_all_rows(); + return error ? error : reset_auto_increment(0); +} + + int ha_heap::reset_auto_increment(ulonglong value) { file->s->auto_increment= value; diff --git a/storage/heap/ha_heap.h b/storage/heap/ha_heap.h index 7185fbc7720..5f3d66cd53c 100644 --- a/storage/heap/ha_heap.h +++ b/storage/heap/ha_heap.h @@ -99,6 +99,7 @@ public: int reset(); int external_lock(THD *thd, int lock_type); int delete_all_rows(void); + int truncate(); int reset_auto_increment(ulonglong value); int disable_indexes(uint mode); int enable_indexes(uint mode); diff --git a/storage/ibmdb2i/db2i_constraints.cc b/storage/ibmdb2i/db2i_constraints.cc index 3afa12032d0..5b9d3600393 100644 --- a/storage/ibmdb2i/db2i_constraints.cc +++ b/storage/ibmdb2i/db2i_constraints.cc @@ -494,10 +494,10 @@ int ha_ibmdb2i::get_foreign_key_list(THD *thd, List *f_key_lis convFromEbcdic(FKCstDef->CstName.Name, convName,FKCstDef->CstName.Len); if (convName[0] == '"') // If quoted, exclude quotes. - f_key_info.forein_id = thd_make_lex_string(thd, 0, + f_key_info.foreign_id = thd_make_lex_string(thd, 0, convName + 1, (uint) (FKCstDef->CstName.Len - 2), 1); else // Not quoted - f_key_info.forein_id = thd_make_lex_string(thd, 0, + f_key_info.foreign_id = thd_make_lex_string(thd, 0, convName, (uint) FKCstDef->CstName.Len, 1); /* Process the names of the foreign keys. */ diff --git a/storage/ibmdb2i/ha_ibmdb2i.cc b/storage/ibmdb2i/ha_ibmdb2i.cc index 947df8ad2fe..e5eccad1573 100644 --- a/storage/ibmdb2i/ha_ibmdb2i.cc +++ b/storage/ibmdb2i/ha_ibmdb2i.cc @@ -1806,6 +1806,13 @@ int ha_ibmdb2i::delete_all_rows() } +int ha_ibmdb2i::truncate() +{ + int error = delete_all_rows(); + return error ? error : reset_auto_increment(0); +} + + int ha_ibmdb2i::external_lock(THD *thd, int lock_type) { int rc = 0; diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index eafc73b4f87..d68fcadffad 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -7081,33 +7081,21 @@ Deletes all rows of an InnoDB table. @return error number */ UNIV_INTERN int -ha_innobase::delete_all_rows(void) +ha_innobase::truncate(void) /*==============================*/ { int error; - DBUG_ENTER("ha_innobase::delete_all_rows"); + DBUG_ENTER("ha_innobase::truncate"); /* Get the transaction associated with the current thd, or create one if not yet created, and update prebuilt->trx */ update_thd(ha_thd()); - if (thd_sql_command(user_thd) != SQLCOM_TRUNCATE) { - fallback: - /* We only handle TRUNCATE TABLE t as a special case. - DELETE FROM t will have to use ha_innobase::delete_row(), - because DELETE is transactional while TRUNCATE is not. */ - DBUG_RETURN(my_errno=HA_ERR_WRONG_COMMAND); - } - /* Truncate the table in InnoDB */ error = row_truncate_table_for_mysql(prebuilt->table, prebuilt->trx); - if (error == DB_ERROR) { - /* Cannot truncate; resort to ha_innobase::delete_row() */ - goto fallback; - } error = convert_error_code_to_mysql(error, prebuilt->table->flags, NULL); @@ -8315,136 +8303,199 @@ ha_innobase::get_foreign_key_create_info(void) } +/***********************************************************************//** +Maps a InnoDB foreign key constraint to a equivalent MySQL foreign key info. +@return pointer to foreign key info */ +static +FOREIGN_KEY_INFO* +get_foreign_key_info( +/*=================*/ + THD* thd, /*!< in: user thread handle */ + dict_foreign_t* foreign) /*!< in: foreign key constraint */ +{ + FOREIGN_KEY_INFO f_key_info; + FOREIGN_KEY_INFO* pf_key_info; + uint i = 0; + ulint len; + char tmp_buff[NAME_LEN+1]; + char name_buff[NAME_LEN+1]; + const char* ptr; + LEX_STRING* referenced_key_name; + LEX_STRING* name = NULL; + + ptr = dict_remove_db_name(foreign->id); + f_key_info.foreign_id = thd_make_lex_string(thd, 0, ptr, + (uint) strlen(ptr), 1); + + /* Name format: database name, '/', table name, '\0' */ + + /* Referenced (parent) database name */ + len = dict_get_db_name_len(foreign->referenced_table_name); + ut_a(len < sizeof(tmp_buff)); + ut_memcpy(tmp_buff, foreign->referenced_table_name, len); + tmp_buff[len] = 0; + + len = filename_to_tablename(tmp_buff, name_buff, sizeof(name_buff)); + f_key_info.referenced_db = thd_make_lex_string(thd, 0, name_buff, len, 1); + + /* Referenced (parent) table name */ + ptr = dict_remove_db_name(foreign->referenced_table_name); + len = filename_to_tablename(ptr, name_buff, sizeof(name)); + f_key_info.referenced_table = thd_make_lex_string(thd, 0, name_buff, len, 1); + + /* Dependent (child) database name */ + len = dict_get_db_name_len(foreign->foreign_table_name); + ut_a(len < sizeof(tmp_buff)); + ut_memcpy(tmp_buff, foreign->foreign_table_name, len); + tmp_buff[len] = 0; + + len = filename_to_tablename(tmp_buff, name_buff, sizeof(name_buff)); + f_key_info.foreign_db = thd_make_lex_string(thd, 0, name_buff, len, 1); + + /* Dependent (child) table name */ + ptr = dict_remove_db_name(foreign->foreign_table_name); + len = filename_to_tablename(ptr, name_buff, sizeof(name_buff)); + f_key_info.foreign_table = thd_make_lex_string(thd, 0, name_buff, len, 1); + + do { + ptr = foreign->foreign_col_names[i]; + name = thd_make_lex_string(thd, name, ptr, + (uint) strlen(ptr), 1); + f_key_info.foreign_fields.push_back(name); + ptr = foreign->referenced_col_names[i]; + name = thd_make_lex_string(thd, name, ptr, + (uint) strlen(ptr), 1); + f_key_info.referenced_fields.push_back(name); + } while (++i < foreign->n_fields); + + if (foreign->type & DICT_FOREIGN_ON_DELETE_CASCADE) { + len = 7; + ptr = "CASCADE"; + } else if (foreign->type & DICT_FOREIGN_ON_DELETE_SET_NULL) { + len = 8; + ptr = "SET NULL"; + } else if (foreign->type & DICT_FOREIGN_ON_DELETE_NO_ACTION) { + len = 9; + ptr = "NO ACTION"; + } else { + len = 8; + ptr = "RESTRICT"; + } + + f_key_info.delete_method = thd_make_lex_string(thd, + f_key_info.delete_method, + ptr, len, 1); + + if (foreign->type & DICT_FOREIGN_ON_UPDATE_CASCADE) { + len = 7; + ptr = "CASCADE"; + } else if (foreign->type & DICT_FOREIGN_ON_UPDATE_SET_NULL) { + len = 8; + ptr = "SET NULL"; + } else if (foreign->type & DICT_FOREIGN_ON_UPDATE_NO_ACTION) { + len = 9; + ptr = "NO ACTION"; + } else { + len = 8; + ptr = "RESTRICT"; + } + + f_key_info.update_method = thd_make_lex_string(thd, + f_key_info.update_method, + ptr, len, 1); + + if (foreign->referenced_index && foreign->referenced_index->name) { + referenced_key_name = thd_make_lex_string(thd, + f_key_info.referenced_key_name, + foreign->referenced_index->name, + (uint) strlen(foreign->referenced_index->name), + 1); + } else { + referenced_key_name = NULL; + } + + f_key_info.referenced_key_name = referenced_key_name; + + pf_key_info = (FOREIGN_KEY_INFO *) thd_memdup(thd, &f_key_info, + sizeof(FOREIGN_KEY_INFO)); + + return(pf_key_info); +} + +/*******************************************************************//** +Gets the list of foreign keys in this table. +@return always 0, that is, always succeeds */ UNIV_INTERN int -ha_innobase::get_foreign_key_list(THD *thd, List *f_key_list) +ha_innobase::get_foreign_key_list( +/*==============================*/ + THD* thd, /*!< in: user thread handle */ + List* f_key_list) /*!< out: foreign key list */ { - dict_foreign_t* foreign; + FOREIGN_KEY_INFO* pf_key_info; + dict_foreign_t* foreign; - DBUG_ENTER("get_foreign_key_list"); - ut_a(prebuilt != NULL); - update_thd(ha_thd()); - prebuilt->trx->op_info = (char*)"getting list of foreign keys"; - trx_search_latch_release_if_reserved(prebuilt->trx); - mutex_enter(&(dict_sys->mutex)); - foreign = UT_LIST_GET_FIRST(prebuilt->table->foreign_list); + ut_a(prebuilt != NULL); + update_thd(ha_thd()); - while (foreign != NULL) { - uint i; - FOREIGN_KEY_INFO f_key_info; - LEX_STRING *name= 0; - uint ulen; - char uname[NAME_LEN+1]; /* Unencoded name */ - char db_name[NAME_LEN+1]; - const char *tmp_buff; + prebuilt->trx->op_info = "getting list of foreign keys"; - tmp_buff= foreign->id; - i= 0; - while (tmp_buff[i] != '/') - i++; - tmp_buff+= i + 1; - f_key_info.forein_id = thd_make_lex_string(thd, 0, - tmp_buff, (uint) strlen(tmp_buff), 1); - tmp_buff= foreign->referenced_table_name; + trx_search_latch_release_if_reserved(prebuilt->trx); - /* Database name */ - i= 0; - while (tmp_buff[i] != '/') - { - db_name[i]= tmp_buff[i]; - i++; - } - db_name[i]= 0; - ulen= filename_to_tablename(db_name, uname, sizeof(uname)); - f_key_info.referenced_db = thd_make_lex_string(thd, 0, - uname, ulen, 1); + mutex_enter(&(dict_sys->mutex)); - /* Table name */ - tmp_buff+= i + 1; - ulen= filename_to_tablename(tmp_buff, uname, sizeof(uname)); - f_key_info.referenced_table = thd_make_lex_string(thd, 0, - uname, ulen, 1); + for (foreign = UT_LIST_GET_FIRST(prebuilt->table->foreign_list); + foreign != NULL; + foreign = UT_LIST_GET_NEXT(referenced_list, foreign)) { + pf_key_info = get_foreign_key_info(thd, foreign); + if (pf_key_info) { + f_key_list->push_back(pf_key_info); + } + } - for (i= 0;;) { - tmp_buff= foreign->foreign_col_names[i]; - name = thd_make_lex_string(thd, name, - tmp_buff, (uint) strlen(tmp_buff), 1); - f_key_info.foreign_fields.push_back(name); - tmp_buff= foreign->referenced_col_names[i]; - name = thd_make_lex_string(thd, name, - tmp_buff, (uint) strlen(tmp_buff), 1); - f_key_info.referenced_fields.push_back(name); - if (++i >= foreign->n_fields) - break; - } + mutex_exit(&(dict_sys->mutex)); - ulong length; - if (foreign->type & DICT_FOREIGN_ON_DELETE_CASCADE) - { - length=7; - tmp_buff= "CASCADE"; - } - else if (foreign->type & DICT_FOREIGN_ON_DELETE_SET_NULL) - { - length=8; - tmp_buff= "SET NULL"; - } - else if (foreign->type & DICT_FOREIGN_ON_DELETE_NO_ACTION) - { - length=9; - tmp_buff= "NO ACTION"; - } - else - { - length=8; - tmp_buff= "RESTRICT"; - } - f_key_info.delete_method = thd_make_lex_string( - thd, f_key_info.delete_method, tmp_buff, length, 1); + prebuilt->trx->op_info = ""; + return(0); +} - if (foreign->type & DICT_FOREIGN_ON_UPDATE_CASCADE) - { - length=7; - tmp_buff= "CASCADE"; - } - else if (foreign->type & DICT_FOREIGN_ON_UPDATE_SET_NULL) - { - length=8; - tmp_buff= "SET NULL"; - } - else if (foreign->type & DICT_FOREIGN_ON_UPDATE_NO_ACTION) - { - length=9; - tmp_buff= "NO ACTION"; - } - else - { - length=8; - tmp_buff= "RESTRICT"; - } - f_key_info.update_method = thd_make_lex_string( - thd, f_key_info.update_method, tmp_buff, length, 1); - if (foreign->referenced_index && - foreign->referenced_index->name) - { - f_key_info.referenced_key_name = thd_make_lex_string( - thd, f_key_info.referenced_key_name, - foreign->referenced_index->name, - (uint) strlen(foreign->referenced_index->name), 1); - } - else - f_key_info.referenced_key_name= 0; +/*******************************************************************//** +Gets the set of foreign keys where this table is the referenced table. +@return always 0, that is, always succeeds */ +UNIV_INTERN +int +ha_innobase::get_parent_foreign_key_list( +/*=====================================*/ + THD* thd, /*!< in: user thread handle */ + List* f_key_list) /*!< out: foreign key list */ +{ + FOREIGN_KEY_INFO* pf_key_info; + dict_foreign_t* foreign; - FOREIGN_KEY_INFO *pf_key_info = (FOREIGN_KEY_INFO *) - thd_memdup(thd, &f_key_info, sizeof(FOREIGN_KEY_INFO)); - f_key_list->push_back(pf_key_info); - foreign = UT_LIST_GET_NEXT(foreign_list, foreign); - } - mutex_exit(&(dict_sys->mutex)); - prebuilt->trx->op_info = (char*)""; + ut_a(prebuilt != NULL); + update_thd(ha_thd()); - DBUG_RETURN(0); + prebuilt->trx->op_info = "getting list of referencing foreign keys"; + + trx_search_latch_release_if_reserved(prebuilt->trx); + + mutex_enter(&(dict_sys->mutex)); + + for (foreign = UT_LIST_GET_FIRST(prebuilt->table->referenced_list); + foreign != NULL; + foreign = UT_LIST_GET_NEXT(referenced_list, foreign)) { + pf_key_info = get_foreign_key_info(thd, foreign); + if (pf_key_info) { + f_key_list->push_back(pf_key_info); + } + } + + mutex_exit(&(dict_sys->mutex)); + + prebuilt->trx->op_info = ""; + + return(0); } /*****************************************************************//** diff --git a/storage/innobase/handler/ha_innodb.h b/storage/innobase/handler/ha_innodb.h index 8f118199ad8..4e128178f2b 100644 --- a/storage/innobase/handler/ha_innodb.h +++ b/storage/innobase/handler/ha_innodb.h @@ -178,13 +178,15 @@ class ha_innobase: public handler void update_create_info(HA_CREATE_INFO* create_info); int create(const char *name, register TABLE *form, HA_CREATE_INFO *create_info); - int delete_all_rows(); + int truncate(); int delete_table(const char *name); int rename_table(const char* from, const char* to); int check(THD* thd, HA_CHECK_OPT* check_opt); char* update_table_comment(const char* comment); char* get_foreign_key_create_info(); int get_foreign_key_list(THD *thd, List *f_key_list); + int get_parent_foreign_key_list(THD *thd, + List *f_key_list); bool can_switch_engines(); uint referenced_by_foreign_key(); void free_foreign_key_create_info(char* str); diff --git a/storage/innobase/row/row0mysql.c b/storage/innobase/row/row0mysql.c index c12970b40ed..62f9ab07af9 100644 --- a/storage/innobase/row/row0mysql.c +++ b/storage/innobase/row/row0mysql.c @@ -2985,8 +2985,7 @@ next_rec: dict_table_change_id_in_cache(table, new_id); } - /* MySQL calls ha_innobase::reset_auto_increment() which does - the same thing. */ + /* Reset auto-increment. */ dict_table_autoinc_lock(table); dict_table_autoinc_initialize(table, 1); dict_table_autoinc_unlock(table); diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index 87de58076cd..2ba62d03c6b 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -1788,6 +1788,18 @@ int ha_myisam::delete_all_rows() return mi_delete_all_rows(file); } + +/* + Intended to support partitioning. + Allows a particular partition to be truncated. +*/ + +int ha_myisam::truncate() +{ + int error= delete_all_rows(); + return error ? error : reset_auto_increment(0); +} + int ha_myisam::reset_auto_increment(ulonglong value) { file->s->state.auto_increment= value; diff --git a/storage/myisam/ha_myisam.h b/storage/myisam/ha_myisam.h index 1a8246ae882..46b732512ac 100644 --- a/storage/myisam/ha_myisam.h +++ b/storage/myisam/ha_myisam.h @@ -107,6 +107,7 @@ class ha_myisam: public handler int reset(void); int external_lock(THD *thd, int lock_type); int delete_all_rows(void); + int truncate(); int reset_auto_increment(ulonglong value); int disable_indexes(uint mode); int enable_indexes(uint mode); diff --git a/storage/myisammrg/ha_myisammrg.cc b/storage/myisammrg/ha_myisammrg.cc index 26e54d61101..79696cad721 100644 --- a/storage/myisammrg/ha_myisammrg.cc +++ b/storage/myisammrg/ha_myisammrg.cc @@ -1226,6 +1226,22 @@ ha_rows ha_myisammrg::records_in_range(uint inx, key_range *min_key, } +int ha_myisammrg::truncate() +{ + int err= 0; + MYRG_TABLE *table; + DBUG_ENTER("ha_myisammrg::truncate"); + + for (table= file->open_tables; table != file->end_table; table++) + { + if ((err= mi_delete_all_rows(table->table))) + break; + } + + DBUG_RETURN(err); +} + + int ha_myisammrg::info(uint flag) { MYMERGE_INFO mrg_info; diff --git a/storage/myisammrg/ha_myisammrg.h b/storage/myisammrg/ha_myisammrg.h index 4ff24c69071..cae4bd17f50 100644 --- a/storage/myisammrg/ha_myisammrg.h +++ b/storage/myisammrg/ha_myisammrg.h @@ -131,6 +131,7 @@ public: int rnd_pos(uchar * buf, uchar *pos); void position(const uchar *record); ha_rows records_in_range(uint inx, key_range *min_key, key_range *max_key); + int truncate(); int info(uint); int reset(void); int extra(enum ha_extra_function operation); diff --git a/storage/perfschema/ha_perfschema.cc b/storage/perfschema/ha_perfschema.cc index e5e324d6c6b..896117397a2 100644 --- a/storage/perfschema/ha_perfschema.cc +++ b/storage/perfschema/ha_perfschema.cc @@ -345,6 +345,11 @@ int ha_perfschema::delete_all_rows(void) DBUG_RETURN(result); } +int ha_perfschema::truncate() +{ + return delete_all_rows(); +} + THR_LOCK_DATA **ha_perfschema::store_lock(THD *thd, THR_LOCK_DATA **to, enum thr_lock_type lock_type) diff --git a/storage/perfschema/ha_perfschema.h b/storage/perfschema/ha_perfschema.h index 2c7b45fbbf7..1a0c16541be 100644 --- a/storage/perfschema/ha_perfschema.h +++ b/storage/perfschema/ha_perfschema.h @@ -127,6 +127,8 @@ public: int delete_all_rows(void); + int truncate(); + int delete_table(const char *from); int rename_table(const char * from, const char * to); From f79f6e0c3429329c3a6be968827d91237a7df899 Mon Sep 17 00:00:00 2001 From: Alexander Nozdrin Date: Wed, 6 Oct 2010 19:06:13 +0400 Subject: [PATCH 13/47] Fix for Bug#57094 (Copyright notice incorrect?). The fix is to: - introduce ORACLE_WELCOME_COPYRIGHT_NOTICE define to have a single place to specify copyright notice; - replace custom copyright notices with ORACLE_WELCOME_COPYRIGHT_NOTICE in programs. --- client/mysql.cc | 10 +++------- client/mysql_upgrade.c | 5 ++++- client/mysqladmin.cc | 9 ++++----- client/mysqlbinlog.cc | 8 +++----- client/mysqlcheck.c | 9 +++------ client/mysqldump.c | 7 ++++--- client/mysqlimport.c | 7 ++++--- client/mysqlshow.c | 6 +++--- client/mysqlslap.c | 13 ++++--------- client/mysqltest.cc | 7 ++++--- include/welcome_copyright_notice.h | 31 ++++++++++++++++++++++++++++++ sql/mysqld.cc | 11 ++++------- 12 files changed, 71 insertions(+), 52 deletions(-) create mode 100644 include/welcome_copyright_notice.h diff --git a/client/mysql.cc b/client/mysql.cc index 14473ba4b51..4a8579bbd4d 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -13,11 +13,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#define COPYRIGHT_NOTICE "\ -Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.\n\ -This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n\ -and you are welcome to modify and redistribute it under the GPL v2 license\n" - /* mysql command tool * Commands compatible with mSQL by David J. Hughes * @@ -110,6 +105,7 @@ extern "C" { #endif #include "completion_hash.h" +#include // ORACLE_WELCOME_COPYRIGHT_NOTICE #define PROMPT_CHAR '\\' #define DEFAULT_DELIMITER ";" @@ -1177,7 +1173,7 @@ int main(int argc,char *argv[]) mysql_thread_id(&mysql), server_version_string(&mysql)); put_info((char*) glob_buffer.ptr(),INFO_INFO); - put_info(COPYRIGHT_NOTICE, INFO_INFO); + put_info(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000, 2010"), INFO_INFO); #ifdef HAVE_READLINE initialize_readline((char*) my_progname); @@ -1595,7 +1591,7 @@ static void usage(int version) if (version) return; - printf("%s", COPYRIGHT_NOTICE); + puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000, 2010")); printf("Usage: %s [OPTIONS] [database]\n", my_progname); my_print_help(my_long_options); print_defaults("my", load_default_groups); diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c index 882350f813b..4fbf08102bd 100644 --- a/client/mysql_upgrade.c +++ b/client/mysql_upgrade.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 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 @@ -17,6 +17,8 @@ #include #include "../scripts/mysql_fix_privilege_tables_sql.c" +#include /* ORACLE_WELCOME_COPYRIGHT_NOTICE */ + #define VER "1.1" #ifdef HAVE_SYS_WAIT_H @@ -232,6 +234,7 @@ get_one_option(int optid, const struct my_option *opt, case '?': printf("%s Ver %s Distrib %s, for %s (%s)\n", my_progname, VER, MYSQL_SERVER_VERSION, SYSTEM_TYPE, MACHINE_TYPE); + puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000, 2010")); puts("MySQL utility for upgrading databases to new MySQL versions.\n"); my_print_help(my_long_options); exit(0); diff --git a/client/mysqladmin.cc b/client/mysqladmin.cc index 69381b749a1..342a67fbc29 100644 --- a/client/mysqladmin.cc +++ b/client/mysqladmin.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 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 @@ -23,6 +23,7 @@ #include #include #include +#include /* ORACLE_WELCOME_COPYRIGHT_NOTICE */ #define ADMIN_VERSION "8.42" #define MAX_MYSQL_VAR 512 @@ -671,8 +672,7 @@ static int execute_commands(MYSQL *mysql,int argc, char **argv) case ADMIN_VER: new_line=1; print_version(); - puts("Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc."); - puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n"); + puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000, 2010")); printf("Server version\t\t%s\n", mysql_get_server_info(mysql)); printf("Protocol version\t%d\n", mysql_get_proto_info(mysql)); printf("Connection\t\t%s\n",mysql_get_host_info(mysql)); @@ -1070,8 +1070,7 @@ static void print_version(void) static void usage(void) { print_version(); - puts("Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc."); - puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n"); + puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000, 2010")); puts("Administration program for the mysqld daemon."); printf("Usage: %s [OPTIONS] command command....\n", my_progname); my_print_help(my_long_options); diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 277c2d62544..226776e4404 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2001-2004 MySQL AB +/* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. 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 @@ -34,6 +34,7 @@ #include "sql_priv.h" #include "log_event.h" #include "sql_common.h" +#include // ORACLE_WELCOME_COPYRIGHT_NOTICE #define BIN_LOG_HEADER_SIZE 4 #define PROBE_HEADER_LEN (EVENT_LEN_OFFSET+4) @@ -1239,10 +1240,7 @@ static void print_version() static void usage() { print_version(); - puts("By Monty and Sasha, for your professional use\n\ -This software comes with NO WARRANTY: This is free software,\n\ -and you are welcome to modify and redistribute it under the GPL license.\n"); - + puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2001, 2010")); printf("\ Dumps a MySQL binary log in a format usable for viewing or for piping to\n\ the mysql command line client.\n\n"); diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c index ce733e57db6..aebe80b9ba6 100644 --- a/client/mysqlcheck.c +++ b/client/mysqlcheck.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 MySQL AB, 2009 Sun Microsystems, Inc +/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 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 @@ -13,8 +13,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* By Jani Tolonen, 2001-04-20, MySQL Development Team */ - #define CHECK_VERSION "2.5.0" #include "client_priv.h" @@ -22,6 +20,7 @@ #include #include #include +#include /* ORACLE_WELCOME_COPYRIGHT_NOTICE */ /* Exit codes */ @@ -215,9 +214,7 @@ static void print_version(void) static void usage(void) { print_version(); - puts("By Jani Tolonen, 2001-04-20, MySQL Development Team.\n"); - puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n"); - puts("and you are welcome to modify and redistribute it under the GPL license.\n"); + puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000, 2010")); puts("This program can be used to CHECK (-c, -m, -C), REPAIR (-r), ANALYZE (-a),"); puts("or OPTIMIZE (-o) tables. Some of the options (like -e or -q) can be"); puts("used at the same time. Not all options are supported by all storage engines."); diff --git a/client/mysqldump.c b/client/mysqldump.c index ac704f152de..b47d88290a5 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -1,4 +1,4 @@ -/* Copyright 2000-2008 MySQL AB, 2008, 2009 Sun Microsystems, Inc. +/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 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 @@ -51,6 +51,8 @@ #include "mysql_version.h" #include "mysqld_error.h" +#include /* ORACLE_WELCOME_COPYRIGHT_NOTICE */ + /* Exit codes */ #define EX_USAGE 1 @@ -584,8 +586,7 @@ static void short_usage_sub(void) static void usage(void) { print_version(); - puts("By Igor Romanenko, Monty, Jani & Sinisa."); - puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license.\n"); + puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000, 2010")); puts("Dumping structure and contents of MySQL databases and tables."); short_usage_sub(); print_defaults("my",load_default_groups); diff --git a/client/mysqlimport.c b/client/mysqlimport.c index 3d71e437e40..aea1cb79e74 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB, 2009 Sun Microsystems, Inc. +/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 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 @@ -32,6 +32,8 @@ #include #endif +#include /* ORACLE_WELCOME_COPYRIGHT_NOTICE */ + /* Global Thread counter */ uint counter; @@ -191,8 +193,7 @@ static void print_version(void) static void usage(void) { print_version(); - puts("Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc."); - puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license.\n"); + puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000, 2010")); printf("\ Loads tables from text files in various formats. The base name of the\n\ text file must be the name of the table that should be used.\n\ diff --git a/client/mysqlshow.c b/client/mysqlshow.c index bb05400e0d8..8cd70db1424 100644 --- a/client/mysqlshow.c +++ b/client/mysqlshow.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000-2006 MySQL AB +/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 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 @@ -25,6 +25,7 @@ #include #include #include +#include /* ORACLE_WELCOME_COPYRIGHT_NOTICE */ static char * host=0, *opt_password=0, *user=0; static my_bool opt_show_keys= 0, opt_compress= 0, opt_count=0, opt_status= 0; @@ -247,8 +248,7 @@ static void print_version(void) static void usage(void) { print_version(); - puts("Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc."); - puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license.\n"); + puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000, 2010)")); puts("Shows the structure of a MySQL database (databases, tables, and columns).\n"); printf("Usage: %s [OPTIONS] [database [table [column]]]\n",my_progname); puts("\n\ diff --git a/client/mysqlslap.c b/client/mysqlslap.c index e605e2d522c..4e8e4f1aa67 100644 --- a/client/mysqlslap.c +++ b/client/mysqlslap.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2005 MySQL AB, 2009 Sun Microsystems, Inc. +/* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 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 @@ -11,12 +11,7 @@ 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 - - original idea: Brian Aker via playing with ab for too many years - coded by: Patrick Galbraith -*/ - + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* MySQL Slap @@ -94,6 +89,7 @@ TODO: #include #endif #include +#include /* ORACLE_WELCOME_COPYRIGHT_NOTICE */ #ifdef __WIN__ #define srandom srand @@ -686,8 +682,7 @@ static void print_version(void) static void usage(void) { print_version(); - puts("Copyright (C) 2005 MySQL AB"); - puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license.\n"); + puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2005, 2010")); puts("Run a query multiple times against the server.\n"); printf("Usage: %s [OPTIONS]\n",my_progname); print_defaults("my",load_default_groups); diff --git a/client/mysqltest.cc b/client/mysqltest.cc index b75fae7b685..376ce0fa59d 100644 --- a/client/mysqltest.cc +++ b/client/mysqltest.cc @@ -1,4 +1,4 @@ -/* Copyright (C) 2000 MySQL AB +/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. 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 @@ -52,6 +52,8 @@ #include #include +#include // ORACLE_WELCOME_COPYRIGHT_NOTICE + #ifdef __WIN__ #include #define SIGNAL_FMT "exception 0x%x" @@ -6260,8 +6262,7 @@ void print_version(void) void usage() { print_version(); - printf("MySQL AB, by Sasha, Matt, Monty & Jani\n"); - printf("This software comes with ABSOLUTELY NO WARRANTY\n\n"); + puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000, 2010")); printf("Runs a test against the mysql server and compares output with a results file.\n\n"); printf("Usage: %s [OPTIONS] [database] < test_file\n", my_progname); my_print_help(my_long_options); diff --git a/include/welcome_copyright_notice.h b/include/welcome_copyright_notice.h new file mode 100644 index 00000000000..c3ffad1527d --- /dev/null +++ b/include/welcome_copyright_notice.h @@ -0,0 +1,31 @@ +/* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + + 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 _welcome_copyright_notice_h_ +#define _welcome_copyright_notice_h_ + +/* + This define specifies copyright notice which is displayed by every MySQL + program on start, or on help screen. +*/ + +#define ORACLE_WELCOME_COPYRIGHT_NOTICE(years) \ + "Copyright (c) " years ", Oracle and/or its affiliates. All rights reserved.\n" \ + "\n" \ + "Oracle is a registered trademark of Oracle Corporation and/or its\n" \ + "affiliates. Other names may be trademarks of their respective\n" \ + "owners.\n" + +#endif /* _welcome_copyright_notice_h_ */ diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 1ab335eb106..e43320f12a5 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -265,6 +265,8 @@ extern "C" sig_handler handle_segfault(int sig); /* Constants */ +#include // ORACLE_WELCOME_COPYRIGHT_NOTICE + const char *show_comp_option_name[]= {"YES", "NO", "DISABLED"}; static const char *tc_heuristic_recover_names[]= @@ -6593,13 +6595,8 @@ static void usage(void) if (!default_collation_name) default_collation_name= (char*) default_charset_info->name; print_version(); - puts("\ -Copyright (C) 2000-2008 MySQL AB, by Monty and others.\n\ -Copyright (C) 2008,2009 Sun Microsystems, Inc.\n\ -This software comes with ABSOLUTELY NO WARRANTY. This is free software,\n\ -and you are welcome to modify and redistribute it under the GPL license\n\n\ -Starts the MySQL database server.\n"); - + puts(ORACLE_WELCOME_COPYRIGHT_NOTICE("2000, 2010")); + puts("Starts the MySQL database server.\n"); printf("Usage: %s [OPTIONS]\n", my_progname); if (!opt_verbose) puts("\nFor more help options (several pages), use mysqld --verbose --help."); From 4bfec5733d8a6c5096a65032a6036e17ddbdbd3e Mon Sep 17 00:00:00 2001 From: Evgeny Potemkin Date: Thu, 7 Oct 2010 11:07:56 +0400 Subject: [PATCH 14/47] Bug#57039: constant subtime expression returns incorrect result. The subtime function wasn't able to produce correct int representation of its result. For constant expressions the Item_datetime_cache is used to speedup evaluation and Item_datetime_cache expects underlying item to return correct int representation of DATETIME value. These two factors combined led to a wrong query result. Now the Item_func_add_time has function val_datetime which performs the calculation and saves result into given MYSQL_TIME struct, it also sets null_value to appropriate value. val_int and val_str member functions convert the result obtained from val_datetime to int or string respectively and returns it. --- mysql-test/r/func_time.result | 11 ++++++ mysql-test/t/func_time.test | 11 ++++++ sql/item_timefunc.cc | 70 +++++++++++++++++++++++++---------- sql/item_timefunc.h | 2 + 4 files changed, 74 insertions(+), 20 deletions(-) diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result index f2c26110d8a..f1b2196ebfa 100644 --- a/mysql-test/r/func_time.result +++ b/mysql-test/r/func_time.result @@ -1316,3 +1316,14 @@ SELECT 1 FROM t1 ORDER BY @x:=makedate(a,a); 1 DROP TABLE t1; End of 5.1 tests +# +# Bug#57039: constant subtime expression returns incorrect result. +# +CREATE TABLE t1 (`date_date` datetime NOT NULL); +INSERT INTO t1 VALUES ('2008-01-03 00:00:00'), ('2008-01-03 00:00:00'); +SELECT * FROM t1 WHERE date_date >= subtime(now(), "00:30:00"); +date_date +SELECT * FROM t1 WHERE date_date <= addtime(date_add("2000-1-1", INTERVAL "1:1:1" HOUR_SECOND), "00:20:00"); +date_date +DROP TABLE t1; +# diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test index 1f6001219a3..08c09adb093 100644 --- a/mysql-test/t/func_time.test +++ b/mysql-test/t/func_time.test @@ -833,3 +833,14 @@ SELECT 1 FROM t1 ORDER BY @x:=makedate(a,a); DROP TABLE t1; --echo End of 5.1 tests + +--echo # +--echo # Bug#57039: constant subtime expression returns incorrect result. +--echo # +CREATE TABLE t1 (`date_date` datetime NOT NULL); +INSERT INTO t1 VALUES ('2008-01-03 00:00:00'), ('2008-01-03 00:00:00'); +SELECT * FROM t1 WHERE date_date >= subtime(now(), "00:30:00"); +SELECT * FROM t1 WHERE date_date <= addtime(date_add("2000-1-1", INTERVAL "1:1:1" HOUR_SECOND), "00:20:00"); +DROP TABLE t1; +--echo # + diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index cc363398fdd..e53558a3385 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -2857,10 +2857,11 @@ void Item_func_add_time::fix_length_and_dec() Result: Time value or datetime value */ -String *Item_func_add_time::val_str(String *str) +MYSQL_TIME *Item_func_add_time::val_datetime(MYSQL_TIME *time, + date_time_format_types *format) { DBUG_ASSERT(fixed == 1); - MYSQL_TIME l_time1, l_time2, l_time3; + MYSQL_TIME l_time1, l_time2; bool is_time= 0; long days, microseconds; longlong seconds; @@ -2886,41 +2887,38 @@ String *Item_func_add_time::val_str(String *str) if (l_time1.neg != l_time2.neg) l_sign= -l_sign; - bzero((char *)&l_time3, sizeof(l_time3)); + bzero((char *)time, sizeof(MYSQL_TIME)); - l_time3.neg= calc_time_diff(&l_time1, &l_time2, -l_sign, - &seconds, µseconds); + time->neg= calc_time_diff(&l_time1, &l_time2, -l_sign, + &seconds, µseconds); /* If first argument was negative and diff between arguments is non-zero we need to swap sign to get proper result. */ if (l_time1.neg && (seconds || microseconds)) - l_time3.neg= 1-l_time3.neg; // Swap sign of result + time->neg= 1 - time->neg; // Swap sign of result - if (!is_time && l_time3.neg) + if (!is_time && time->neg) goto null_date; days= (long)(seconds/86400L); - calc_time_from_sec(&l_time3, (long)(seconds%86400L), microseconds); + calc_time_from_sec(time, (long)(seconds%86400L), microseconds); if (!is_time) { - get_date_from_daynr(days,&l_time3.year,&l_time3.month,&l_time3.day); - if (l_time3.day && - !make_datetime(l_time1.second_part || l_time2.second_part ? - DATE_TIME_MICROSECOND : DATE_TIME, - &l_time3, str)) - return str; + get_date_from_daynr(days, &time->year, &time->month, &time->day); + *format= l_time1.second_part || l_time2.second_part ? + DATE_TIME_MICROSECOND : DATE_TIME; + if (time->day) + return time; goto null_date; } - - l_time3.hour+= days*24; - if (!make_datetime_with_warn(l_time1.second_part || l_time2.second_part ? - TIME_MICROSECOND : TIME_ONLY, - &l_time3, str)) - return str; + *format= l_time1.second_part || l_time2.second_part ? + TIME_MICROSECOND : TIME_ONLY; + time->hour+= days*24; + return time; null_date: null_value=1; @@ -2928,6 +2926,38 @@ null_date: } +String *Item_func_add_time::val_str(String *str) +{ + MYSQL_TIME ltime; + date_time_format_types format; + + val_datetime(<ime, &format); + + if (null_value) + return 0; + + if (!make_datetime_with_warn(format, <ime, str)) + return str; + + null_value= 1; + return 0; +} + + +longlong Item_func_add_time::val_int() +{ + MYSQL_TIME ltime; + date_time_format_types format; + + val_datetime(<ime, &format); + + if (null_value) + return 0; + + return TIME_to_ulonglong_datetime(<ime); +} + + void Item_func_add_time::print(String *str, enum_query_type query_type) { if (is_date) diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index 6e31b5c6705..d82a8f9e969 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -949,6 +949,8 @@ public: return save_date_in_field(field); return Item_str_func::save_in_field(field, no_conversions); } + longlong val_int(); + MYSQL_TIME *val_datetime(MYSQL_TIME *time, date_time_format_types *format); }; class Item_func_timediff :public Item_str_timefunc From 9c82ecec3790614af7a5b4575758c0a003ef6bbd Mon Sep 17 00:00:00 2001 From: Martin Hansson Date: Thu, 7 Oct 2010 10:13:11 +0200 Subject: [PATCH 15/47] Bug#56423: Different count with SELECT and CREATE SELECT queries This is a regression from the fix for bug no 38999. A storage engine capable of reading only a subset of a table's columns updates corresponding bits in the read buffer to signal that it has read NULL values for the corresponding columns. It cannot, and should not, update any other bits. Bug no 38999 occurred because the implementation of UPDATE statements compare the NULL bits using memcmp, inadvertently comparing bits that were never requested from the storage engine. The regression was caused by the storage engine trying to alleviate the situation by writing to all NULL bits, even those that it had no knowledge of. This has devastating effects for the index merge algorithm, which relies on all NULL bits, except those explicitly requested, being left unchanged. The fix reverts the fix for bug no 38999 in both InnoDB and InnoDB plugin and changes the server's method of comparing records. For engines that always read entire rows, we proceed as usual. For engines capable of reading only select columns, the record buffers are now compared on a column by column basis. An assertion was also added so that non comparable buffers are never read. Some relevant copy-pasted code was also consolidated in a new function. --- mysql-test/include/index_merge2.inc | 52 ++++++++++++++ mysql-test/r/index_merge_innodb.result | 55 +++++++++++++++ mysql-test/r/index_merge_myisam.result | 55 +++++++++++++++ sql/mysql_priv.h | 3 +- sql/sql_insert.cc | 4 +- sql/sql_update.cc | 93 +++++++++++++++++--------- storage/innobase/row/row0sel.c | 6 -- storage/innodb_plugin/row/row0sel.c | 6 -- 8 files changed, 227 insertions(+), 47 deletions(-) diff --git a/mysql-test/include/index_merge2.inc b/mysql-test/include/index_merge2.inc index d65115eac0f..d21562d000c 100644 --- a/mysql-test/include/index_merge2.inc +++ b/mysql-test/include/index_merge2.inc @@ -343,3 +343,55 @@ explain select * from t1 where (key3 > 30 and key3<35) or (key2 >32 and key2 < 4 select * from t1 where (key3 > 30 and key3<35) or (key2 >32 and key2 < 40); drop table t1; +--echo # +--echo # Bug#56423: Different count with SELECT and CREATE SELECT queries +--echo # + +CREATE TABLE t1 ( + a INT, + b INT, + c INT, + d INT, + PRIMARY KEY (a), + KEY (c), + KEY bd (b,d) +); + +INSERT INTO t1 VALUES +(1, 0, 1, 0), +(2, 1, 1, 1), +(3, 1, 1, 1), +(4, 0, 1, 1); + +EXPLAIN +SELECT a +FROM t1 +WHERE c = 1 AND b = 1 AND d = 1; + +CREATE TABLE t2 ( a INT ) +SELECT a +FROM t1 +WHERE c = 1 AND b = 1 AND d = 1; + +SELECT * FROM t2; + +DROP TABLE t1, t2; + +CREATE TABLE t1( a INT, b INT, KEY(a), KEY(b) ); +INSERT INTO t1 VALUES (1, 2), (1, 2), (1, 2), (1, 2); +SELECT * FROM t1 FORCE INDEX(a, b) WHERE a = 1 AND b = 2; + +DROP TABLE t1; + +--echo # Code coverage of fix. +CREATE TABLE t1 ( a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b INT); +INSERT INTO t1 (b) VALUES (1); +UPDATE t1 SET b = 2 WHERE a = 1; +SELECT * FROM t1; + +CREATE TABLE t2 ( a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b VARCHAR(1) ); +INSERT INTO t2 (b) VALUES ('a'); +UPDATE t2 SET b = 'b' WHERE a = 1; +SELECT * FROM t2; + +DROP TABLE t1, t2; diff --git a/mysql-test/r/index_merge_innodb.result b/mysql-test/r/index_merge_innodb.result index 58ed99b1e67..eaff7df280d 100644 --- a/mysql-test/r/index_merge_innodb.result +++ b/mysql-test/r/index_merge_innodb.result @@ -324,6 +324,61 @@ key1 key2 key3 38 38 38 39 39 39 drop table t1; +# +# Bug#56423: Different count with SELECT and CREATE SELECT queries +# +CREATE TABLE t1 ( +a INT, +b INT, +c INT, +d INT, +PRIMARY KEY (a), +KEY (c), +KEY bd (b,d) +); +INSERT INTO t1 VALUES +(1, 0, 1, 0), +(2, 1, 1, 1), +(3, 1, 1, 1), +(4, 0, 1, 1); +EXPLAIN +SELECT a +FROM t1 +WHERE c = 1 AND b = 1 AND d = 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 index_merge c,bd c,bd 5,10 NULL 1 Using intersect(c,bd); Using where; Using index +CREATE TABLE t2 ( a INT ) +SELECT a +FROM t1 +WHERE c = 1 AND b = 1 AND d = 1; +SELECT * FROM t2; +a +2 +3 +DROP TABLE t1, t2; +CREATE TABLE t1( a INT, b INT, KEY(a), KEY(b) ); +INSERT INTO t1 VALUES (1, 2), (1, 2), (1, 2), (1, 2); +SELECT * FROM t1 FORCE INDEX(a, b) WHERE a = 1 AND b = 2; +a b +1 2 +1 2 +1 2 +1 2 +DROP TABLE t1; +# Code coverage of fix. +CREATE TABLE t1 ( a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b INT); +INSERT INTO t1 (b) VALUES (1); +UPDATE t1 SET b = 2 WHERE a = 1; +SELECT * FROM t1; +a b +1 2 +CREATE TABLE t2 ( a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b VARCHAR(1) ); +INSERT INTO t2 (b) VALUES ('a'); +UPDATE t2 SET b = 'b' WHERE a = 1; +SELECT * FROM t2; +a b +1 b +DROP TABLE t1, t2; #---------------- 2-sweeps read Index merge test 2 ------------------------------- SET SESSION STORAGE_ENGINE = InnoDB; drop table if exists t1; diff --git a/mysql-test/r/index_merge_myisam.result b/mysql-test/r/index_merge_myisam.result index 6bfec69fad9..1ebc94dff5d 100644 --- a/mysql-test/r/index_merge_myisam.result +++ b/mysql-test/r/index_merge_myisam.result @@ -1158,6 +1158,61 @@ key1 key2 key3 38 38 38 39 39 39 drop table t1; +# +# Bug#56423: Different count with SELECT and CREATE SELECT queries +# +CREATE TABLE t1 ( +a INT, +b INT, +c INT, +d INT, +PRIMARY KEY (a), +KEY (c), +KEY bd (b,d) +); +INSERT INTO t1 VALUES +(1, 0, 1, 0), +(2, 1, 1, 1), +(3, 1, 1, 1), +(4, 0, 1, 1); +EXPLAIN +SELECT a +FROM t1 +WHERE c = 1 AND b = 1 AND d = 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref c,bd bd 10 const,const 2 Using where +CREATE TABLE t2 ( a INT ) +SELECT a +FROM t1 +WHERE c = 1 AND b = 1 AND d = 1; +SELECT * FROM t2; +a +2 +3 +DROP TABLE t1, t2; +CREATE TABLE t1( a INT, b INT, KEY(a), KEY(b) ); +INSERT INTO t1 VALUES (1, 2), (1, 2), (1, 2), (1, 2); +SELECT * FROM t1 FORCE INDEX(a, b) WHERE a = 1 AND b = 2; +a b +1 2 +1 2 +1 2 +1 2 +DROP TABLE t1; +# Code coverage of fix. +CREATE TABLE t1 ( a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b INT); +INSERT INTO t1 (b) VALUES (1); +UPDATE t1 SET b = 2 WHERE a = 1; +SELECT * FROM t1; +a b +1 2 +CREATE TABLE t2 ( a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b VARCHAR(1) ); +INSERT INTO t2 (b) VALUES ('a'); +UPDATE t2 SET b = 'b' WHERE a = 1; +SELECT * FROM t2; +a b +1 b +DROP TABLE t1, t2; #---------------- 2-sweeps read Index merge test 2 ------------------------------- SET SESSION STORAGE_ENGINE = MyISAM; drop table if exists t1; diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 9f2c0b04f2c..709a49b2036 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -1047,7 +1047,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd, char* packet, uint packet_length); void log_slow_statement(THD *thd); bool check_dup(const char *db, const char *name, TABLE_LIST *tables); -bool compare_record(TABLE *table); +bool records_are_comparable(const TABLE *table); +bool compare_records(const TABLE *table); bool append_file_to_dir(THD *thd, const char **filename_ptr, const char *table_name); void wait_while_table_is_used(THD *thd, TABLE *table, diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 567c7ff2b30..f0735a9e093 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1483,9 +1483,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) table->file->adjust_next_insert_id_after_explicit_value( table->next_number_field->val_int()); info->touched++; - if ((table->file->ha_table_flags() & HA_PARTIAL_COLUMN_READ && - !bitmap_is_subset(table->write_set, table->read_set)) || - compare_record(table)) + if (!records_are_comparable(table) || compare_records(table)) { if ((error=table->file->ha_update_row(table->record[1], table->record[0])) && diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 7da8a68546f..01c70a7a268 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -25,11 +25,68 @@ #include "sql_trigger.h" #include "debug_sync.h" -/* Return 0 if row hasn't changed */ -bool compare_record(TABLE *table) +/** + True if the table's input and output record buffers are comparable using + compare_records(TABLE*). + */ +bool records_are_comparable(const TABLE *table) { + return ((table->file->ha_table_flags() & HA_PARTIAL_COLUMN_READ) == 0) || + bitmap_is_subset(table->write_set, table->read_set); +} + + +/** + Compares the input and outbut record buffers of the table to see if a row + has changed. The algorithm iterates over updated columns and if they are + nullable compares NULL bits in the buffer before comparing actual + data. Special care must be taken to compare only the relevant NULL bits and + mask out all others as they may be undefined. The storage engine will not + and should not touch them. + + @param table The table to evaluate. + + @return true if row has changed. + @return false otherwise. +*/ +bool compare_records(const TABLE *table) { + DBUG_ASSERT(records_are_comparable(table)); + + if ((table->file->ha_table_flags() & HA_PARTIAL_COLUMN_READ) != 0) + { + /* + Storage engine may not have read all columns of the record. Fields + (including NULL bits) not in the write_set may not have been read and + can therefore not be compared. + */ + for (Field **ptr= table->field ; *ptr != NULL; ptr++) + { + Field *field= *ptr; + if (bitmap_is_set(table->write_set, field->field_index)) + { + if (field->real_maybe_null()) + { + uchar null_byte_index= field->null_ptr - table->record[0]; + + if (((table->record[0][null_byte_index]) & field->null_bit) != + ((table->record[1][null_byte_index]) & field->null_bit)) + return TRUE; + } + if (field->cmp_binary_offset(table->s->rec_buff_length)) + return TRUE; + } + } + return FALSE; + } + + /* + The storage engine has read all columns, so it's safe to compare all bits + including those not in the write_set. This is cheaper than the field-by-field + comparison done above. + */ if (table->s->blob_fields + table->s->varchar_fields == 0) + // Fixed-size record: do bitwise comparison of the records return cmp_record(table,record[1]); /* Compare null bits */ if (memcmp(table->null_flags, @@ -186,7 +243,6 @@ int mysql_update(THD *thd, bool using_limit= limit != HA_POS_ERROR; bool safe_update= test(thd->options & OPTION_SAFE_UPDATES); bool used_key_is_modified, transactional_table, will_batch; - bool can_compare_record; int res; int error, loc_error; uint used_index= MAX_KEY, dup_key_found; @@ -575,15 +631,6 @@ int mysql_update(THD *thd, if (table->file->ha_table_flags() & HA_PARTIAL_COLUMN_READ) table->prepare_for_position(); - /* - We can use compare_record() to optimize away updates if - the table handler is returning all columns OR if - if all updated columns are read - */ - can_compare_record= (!(table->file->ha_table_flags() & - HA_PARTIAL_COLUMN_READ) || - bitmap_is_subset(table->write_set, table->read_set)); - while (!(error=info.read_record(&info)) && !thd->killed) { thd->examined_row_count++; @@ -601,7 +648,7 @@ int mysql_update(THD *thd, found++; - if (!can_compare_record || compare_record(table)) + if (!records_are_comparable(table) || compare_records(table)) { if ((res= table_list->view_check_option(thd, ignore)) != VIEW_CHECK_OK) @@ -1695,18 +1742,8 @@ bool multi_update::send_data(List ¬_used_values) if (table->status & (STATUS_NULL_ROW | STATUS_UPDATED)) continue; - /* - We can use compare_record() to optimize away updates if - the table handler is returning all columns OR if - if all updated columns are read - */ if (table == table_to_update) { - bool can_compare_record; - can_compare_record= (!(table->file->ha_table_flags() & - HA_PARTIAL_COLUMN_READ) || - bitmap_is_subset(table->write_set, - table->read_set)); table->status|= STATUS_UPDATED; store_record(table,record[1]); if (fill_record_n_invoke_before_triggers(thd, *fields_for_table[offset], @@ -1721,7 +1758,7 @@ bool multi_update::send_data(List ¬_used_values) */ table->auto_increment_field_not_null= FALSE; found++; - if (!can_compare_record || compare_record(table)) + if (!records_are_comparable(table) || compare_records(table)) { int error; if ((error= cur_table->view_check_option(thd, ignore)) != @@ -1908,7 +1945,6 @@ int multi_update::do_updates() DBUG_RETURN(0); for (cur_table= update_tables; cur_table; cur_table= cur_table->next_local) { - bool can_compare_record; uint offset= cur_table->shared; table = cur_table->table; @@ -1945,11 +1981,6 @@ int multi_update::do_updates() if ((local_error = tmp_table->file->ha_rnd_init(1))) goto err; - can_compare_record= (!(table->file->ha_table_flags() & - HA_PARTIAL_COLUMN_READ) || - bitmap_is_subset(table->write_set, - table->read_set)); - for (;;) { if (thd->killed && trans_safe) @@ -1990,7 +2021,7 @@ int multi_update::do_updates() TRG_ACTION_BEFORE, TRUE)) goto err2; - if (!can_compare_record || compare_record(table)) + if (!records_are_comparable(table) || compare_records(table)) { int error; if ((error= cur_table->view_check_option(thd, ignore)) != diff --git a/storage/innobase/row/row0sel.c b/storage/innobase/row/row0sel.c index a64dd3151ee..ecc5b47d377 100644 --- a/storage/innobase/row/row0sel.c +++ b/storage/innobase/row/row0sel.c @@ -2621,12 +2621,6 @@ row_sel_store_mysql_rec( prebuilt->blob_heap = NULL; } - /* init null bytes with default values as they might be - left uninitialized in some cases and this uninited bytes - might be copied into mysql record buffer that leads to - valgrind warnings */ - memcpy(mysql_rec, prebuilt->default_rec, prebuilt->null_bitmap_len); - for (i = 0; i < prebuilt->n_template; i++) { templ = prebuilt->mysql_template + i; diff --git a/storage/innodb_plugin/row/row0sel.c b/storage/innodb_plugin/row/row0sel.c index 8b17bdc6ad3..b19651735d8 100644 --- a/storage/innodb_plugin/row/row0sel.c +++ b/storage/innodb_plugin/row/row0sel.c @@ -2696,12 +2696,6 @@ row_sel_store_mysql_rec( prebuilt->blob_heap = NULL; } - /* init null bytes with default values as they might be - left uninitialized in some cases and these uninited bytes - might be copied into mysql record buffer that leads to - valgrind warnings */ - memcpy(mysql_rec, prebuilt->default_rec, prebuilt->null_bitmap_len); - for (i = 0; i < prebuilt->n_template; i++) { templ = prebuilt->mysql_template + i; From 455d1f6ade5070f7ffa81e355bc3715bed1d92ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Bl=C3=A5udd?= Date: Thu, 7 Oct 2010 11:02:16 +0200 Subject: [PATCH 16/47] WL#5503 SEAGULL: Move config/ac-macros/ha_ndbcluster.m4 to storage/ndb/ - Move file ha_ndbcluster.m4 - Move "sinclude" directive from configure.in to storag/ndb/plug.in --- configure.in | 1 - .../ac-macros/ha_ndbcluster.m4 => storage/ndb/ndb_configure.m4 | 0 storage/ndb/plug.in | 2 ++ 3 files changed, 2 insertions(+), 1 deletion(-) rename config/ac-macros/ha_ndbcluster.m4 => storage/ndb/ndb_configure.m4 (100%) diff --git a/configure.in b/configure.in index a5fe8d292da..c272efe9214 100644 --- a/configure.in +++ b/configure.in @@ -87,7 +87,6 @@ sinclude(config/ac-macros/character_sets.m4) sinclude(config/ac-macros/compiler_flag.m4) sinclude(config/ac-macros/plugins.m4) sinclude(config/ac-macros/dtrace.m4) -sinclude(config/ac-macros/ha_ndbcluster.m4) sinclude(config/ac-macros/large_file.m4) sinclude(config/ac-macros/misc.m4) sinclude(config/ac-macros/readline.m4) diff --git a/config/ac-macros/ha_ndbcluster.m4 b/storage/ndb/ndb_configure.m4 similarity index 100% rename from config/ac-macros/ha_ndbcluster.m4 rename to storage/ndb/ndb_configure.m4 diff --git a/storage/ndb/plug.in b/storage/ndb/plug.in index a7e351417b1..d3395b66771 100644 --- a/storage/ndb/plug.in +++ b/storage/ndb/plug.in @@ -1,3 +1,5 @@ +sinclude(storage/ndb/ndb_configure.m4) + MYSQL_STORAGE_ENGINE(ndbcluster, ndbcluster, [Cluster Storage Engine], [High Availability Clustered tables], [max]) MYSQL_PLUGIN_DIRECTORY(ndbcluster,[storage/ndb]) From ef7300b838c0a9637912d3cc581873b21951094d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Bl=C3=A5udd?= Date: Thu, 7 Oct 2010 11:13:30 +0200 Subject: [PATCH 17/47] Bug#56397 The version of NDB in MySQL Server should be constant - Fix the version of NDB in MySQL Server to 5.5.7(although it's actually 6.2.18) --- storage/ndb/ndb_configure.m4 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/storage/ndb/ndb_configure.m4 b/storage/ndb/ndb_configure.m4 index 533dba09feb..21e4627515f 100644 --- a/storage/ndb/ndb_configure.m4 +++ b/storage/ndb/ndb_configure.m4 @@ -2,10 +2,16 @@ dnl --------------------------------------------------------------------------- dnl Macro: MYSQL_CHECK_NDBCLUSTER dnl --------------------------------------------------------------------------- -NDB_VERSION_MAJOR=`echo $MYSQL_NUMERIC_VERSION | cut -d. -f1` -NDB_VERSION_MINOR=`echo $MYSQL_NUMERIC_VERSION | cut -d. -f2` -NDB_VERSION_BUILD=`echo $MYSQL_NUMERIC_VERSION | cut -d. -f3` -NDB_VERSION_STATUS=`echo $VERSION | sed 's/^[[-.0-9]]*//'` +# The version of NDB in this version of MySQL is currently fixed +# and not supposed to be changed unless major changes happen in +# storage/ndb directory. +# NOTE! To avoid mixup with MySQL Cluster's version numbers +# this version of NDB is set to 5.5.7 although it's basically +# a copy of MySQL Cluster 6.2.18 +NDB_VERSION_MAJOR=5 +NDB_VERSION_MINOR=5 +NDB_VERSION_BUILD=7 +NDB_VERSION_STATUS="" TEST_NDBCLUSTER="" dnl for build ndb docs From d6ee2ecf90b8ad7110bef3aae9d447b8908f8cfb Mon Sep 17 00:00:00 2001 From: Martin Hansson Date: Thu, 7 Oct 2010 12:01:51 +0200 Subject: [PATCH 18/47] Bug#56423: Different count with SELECT and CREATE SELECT queries This is the 5.5 version of the fix. The 5.1 version was too complicated to merge and was null merged. This is a regression from the fix for bug no 38999. A storage engine capable of reading only a subset of a table's columns updates corresponding bits in the read buffer to signal that it has read NULL values for the corresponding columns. It cannot, and should not, update any other bits. Bug no 38999 occurred because the implementation of UPDATE statements compare the NULL bits using memcmp, inadvertently comparing bits that were never requested from the storage engine. The regression was caused by the storage engine trying to alleviate the situation by writing to all NULL bits, even those that it had no knowledge of. This has devastating effects for the index merge algorithm, which relies on all NULL bits, except those explicitly requested, being left unchanged. The fix reverts the fix for bug no 38999 in both InnoDB and InnoDB plugin and changes the server's method of comparing records. For engines that always read entire rows, we proceed as usual. For engines capable of reading only select columns, the record buffers are now compared on a column by column basis. An assertion was also added so that non comparable buffers are never read. Some relevant copy-pasted code was also consolidated in a new function. --- mysql-test/include/index_merge2.inc | 112 +++++++++++++++++++++++++ mysql-test/r/index_merge_myisam.result | 55 ++++++++++++ sql/sql_insert.cc | 4 +- sql/sql_update.cc | 93 +++++++++++++------- sql/sql_update.h | 3 +- storage/innobase/row/row0sel.c | 6 -- 6 files changed, 232 insertions(+), 41 deletions(-) diff --git a/mysql-test/include/index_merge2.inc b/mysql-test/include/index_merge2.inc index 9b98eb3ebf2..23c8c6466c7 100644 --- a/mysql-test/include/index_merge2.inc +++ b/mysql-test/include/index_merge2.inc @@ -351,3 +351,115 @@ explain select * from t1 where (key3 > 30 and key3<35) or (key2 >32 and key2 < 4 select * from t1 where (key3 > 30 and key3<35) or (key2 >32 and key2 < 40); drop table t1; +--echo # +--echo # Bug#56423: Different count with SELECT and CREATE SELECT queries +--echo # + +CREATE TABLE t1 ( + a INT, + b INT, + c INT, + d INT, + PRIMARY KEY (a), + KEY (c), + KEY bd (b,d) +); + +INSERT INTO t1 VALUES +(1, 0, 1, 0), +(2, 1, 1, 1), +(3, 1, 1, 1), +(4, 0, 1, 1); + +EXPLAIN +SELECT a +FROM t1 +WHERE c = 1 AND b = 1 AND d = 1; + +CREATE TABLE t2 ( a INT ) +SELECT a +FROM t1 +WHERE c = 1 AND b = 1 AND d = 1; + +SELECT * FROM t2; + +DROP TABLE t1, t2; + +CREATE TABLE t1( a INT, b INT, KEY(a), KEY(b) ); +INSERT INTO t1 VALUES (1, 2), (1, 2), (1, 2), (1, 2); +SELECT * FROM t1 FORCE INDEX(a, b) WHERE a = 1 AND b = 2; + +DROP TABLE t1; + +--echo # Code coverage of fix. +CREATE TABLE t1 ( a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b INT); +INSERT INTO t1 (b) VALUES (1); +UPDATE t1 SET b = 2 WHERE a = 1; +SELECT * FROM t1; + +CREATE TABLE t2 ( a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b VARCHAR(1) ); +INSERT INTO t2 (b) VALUES ('a'); +UPDATE t2 SET b = 'b' WHERE a = 1; +SELECT * FROM t2; + +DROP TABLE t1, t2; + +# The test was inactive for InnoDB at the time of pushing. The following is +# expected result for the Bug#56423 test. It can be uncommented and pasted +# into result file when reactivating the test. + +## +## Bug#56423: Different count with SELECT and CREATE SELECT queries +## +#CREATE TABLE t1 ( +#a INT, +#b INT, +#c INT, +#d INT, +#PRIMARY KEY (a), +#KEY (c), +#KEY bd (b,d) +#); +#INSERT INTO t1 VALUES +#(1, 0, 1, 0), +#(2, 1, 1, 1), +#(3, 1, 1, 1), +#(4, 0, 1, 1); +#EXPLAIN +#SELECT a +#FROM t1 +#WHERE c = 1 AND b = 1 AND d = 1; +#id select_type table type possible_keys key key_len ref rows Extra +#1 SIMPLE t1 ref c,bd bd 10 const,const 2 Using where +#CREATE TABLE t2 ( a INT ) +#SELECT a +#FROM t1 +#WHERE c = 1 AND b = 1 AND d = 1; +#SELECT * FROM t2; +#a +#2 +#3 +#DROP TABLE t1, t2; +#CREATE TABLE t1( a INT, b INT, KEY(a), KEY(b) ); +#INSERT INTO t1 VALUES (1, 2), (1, 2), (1, 2), (1, 2); +#SELECT * FROM t1 FORCE INDEX(a, b) WHERE a = 1 AND b = 2; +#a b +#1 2 +#1 2 +#1 2 +#1 2 +#DROP TABLE t1; +## Code coverage of fix. +#CREATE TABLE t1 ( a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b INT); +#INSERT INTO t1 (b) VALUES (1); +#UPDATE t1 SET b = 2 WHERE a = 1; +#SELECT * FROM t1; +#a b +#1 2 +#CREATE TABLE t2 ( a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b VARCHAR(1) ); +#INSERT INTO t2 (b) VALUES ('a'); +#UPDATE t2 SET b = 'b' WHERE a = 1; +#SELECT * FROM t2; +#a b +#1 b +#DROP TABLE t1, t2; diff --git a/mysql-test/r/index_merge_myisam.result b/mysql-test/r/index_merge_myisam.result index 7377b450872..cfe0c841c0c 100644 --- a/mysql-test/r/index_merge_myisam.result +++ b/mysql-test/r/index_merge_myisam.result @@ -1156,6 +1156,61 @@ key1 key2 key3 38 38 38 39 39 39 drop table t1; +# +# Bug#56423: Different count with SELECT and CREATE SELECT queries +# +CREATE TABLE t1 ( +a INT, +b INT, +c INT, +d INT, +PRIMARY KEY (a), +KEY (c), +KEY bd (b,d) +); +INSERT INTO t1 VALUES +(1, 0, 1, 0), +(2, 1, 1, 1), +(3, 1, 1, 1), +(4, 0, 1, 1); +EXPLAIN +SELECT a +FROM t1 +WHERE c = 1 AND b = 1 AND d = 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t1 ref c,bd bd 10 const,const 2 Using where +CREATE TABLE t2 ( a INT ) +SELECT a +FROM t1 +WHERE c = 1 AND b = 1 AND d = 1; +SELECT * FROM t2; +a +2 +3 +DROP TABLE t1, t2; +CREATE TABLE t1( a INT, b INT, KEY(a), KEY(b) ); +INSERT INTO t1 VALUES (1, 2), (1, 2), (1, 2), (1, 2); +SELECT * FROM t1 FORCE INDEX(a, b) WHERE a = 1 AND b = 2; +a b +1 2 +1 2 +1 2 +1 2 +DROP TABLE t1; +# Code coverage of fix. +CREATE TABLE t1 ( a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b INT); +INSERT INTO t1 (b) VALUES (1); +UPDATE t1 SET b = 2 WHERE a = 1; +SELECT * FROM t1; +a b +1 2 +CREATE TABLE t2 ( a INT NOT NULL AUTO_INCREMENT PRIMARY KEY, b VARCHAR(1) ); +INSERT INTO t2 (b) VALUES ('a'); +UPDATE t2 SET b = 'b' WHERE a = 1; +SELECT * FROM t2; +a b +1 b +DROP TABLE t1, t2; #---------------- 2-sweeps read Index merge test 2 ------------------------------- SET SESSION STORAGE_ENGINE = MyISAM; drop table if exists t1; diff --git a/sql/sql_insert.cc b/sql/sql_insert.cc index 3ac6cf28c90..1f8da3fab5c 100644 --- a/sql/sql_insert.cc +++ b/sql/sql_insert.cc @@ -1620,9 +1620,7 @@ int write_record(THD *thd, TABLE *table,COPY_INFO *info) table->file->adjust_next_insert_id_after_explicit_value( table->next_number_field->val_int()); info->touched++; - if ((table->file->ha_table_flags() & HA_PARTIAL_COLUMN_READ && - !bitmap_is_subset(table->write_set, table->read_set)) || - compare_record(table)) + if (!records_are_comparable(table) || compare_records(table)) { if ((error=table->file->ha_update_row(table->record[1], table->record[0])) && diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 68440f6623a..96b1ac67b49 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -42,11 +42,68 @@ // mysql_handle_derived, // mysql_derived_filling -/* Return 0 if row hasn't changed */ -bool compare_record(TABLE *table) +/** + True if the table's input and output record buffers are comparable using + compare_records(TABLE*). + */ +bool records_are_comparable(const TABLE *table) { + return ((table->file->ha_table_flags() & HA_PARTIAL_COLUMN_READ) == 0) || + bitmap_is_subset(table->write_set, table->read_set); +} + + +/** + Compares the input and outbut record buffers of the table to see if a row + has changed. The algorithm iterates over updated columns and if they are + nullable compares NULL bits in the buffer before comparing actual + data. Special care must be taken to compare only the relevant NULL bits and + mask out all others as they may be undefined. The storage engine will not + and should not touch them. + + @param table The table to evaluate. + + @return true if row has changed. + @return false otherwise. +*/ +bool compare_records(const TABLE *table) { + DBUG_ASSERT(records_are_comparable(table)); + + if ((table->file->ha_table_flags() & HA_PARTIAL_COLUMN_READ) != 0) + { + /* + Storage engine may not have read all columns of the record. Fields + (including NULL bits) not in the write_set may not have been read and + can therefore not be compared. + */ + for (Field **ptr= table->field ; *ptr != NULL; ptr++) + { + Field *field= *ptr; + if (bitmap_is_set(table->write_set, field->field_index)) + { + if (field->real_maybe_null()) + { + uchar null_byte_index= field->null_ptr - table->record[0]; + + if (((table->record[0][null_byte_index]) & field->null_bit) != + ((table->record[1][null_byte_index]) & field->null_bit)) + return TRUE; + } + if (field->cmp_binary_offset(table->s->rec_buff_length)) + return TRUE; + } + } + return FALSE; + } + + /* + The storage engine has read all columns, so it's safe to compare all bits + including those not in the write_set. This is cheaper than the field-by-field + comparison done above. + */ if (table->s->blob_fields + table->s->varchar_fields == 0) + // Fixed-size record: do bitwise comparison of the records return cmp_record(table,record[1]); /* Compare null bits */ if (memcmp(table->null_flags, @@ -204,7 +261,6 @@ int mysql_update(THD *thd, bool using_limit= limit != HA_POS_ERROR; bool safe_update= test(thd->variables.option_bits & OPTION_SAFE_UPDATES); bool used_key_is_modified= FALSE, transactional_table, will_batch; - bool can_compare_record; int res; int error, loc_error; uint used_index, dup_key_found; @@ -579,15 +635,6 @@ int mysql_update(THD *thd, if (table->file->ha_table_flags() & HA_PARTIAL_COLUMN_READ) table->prepare_for_position(); - /* - We can use compare_record() to optimize away updates if - the table handler is returning all columns OR if - if all updated columns are read - */ - can_compare_record= (!(table->file->ha_table_flags() & - HA_PARTIAL_COLUMN_READ) || - bitmap_is_subset(table->write_set, table->read_set)); - while (!(error=info.read_record(&info)) && !thd->killed) { thd->examined_row_count++; @@ -605,7 +652,7 @@ int mysql_update(THD *thd, found++; - if (!can_compare_record || compare_record(table)) + if (!records_are_comparable(table) || compare_records(table)) { if ((res= table_list->view_check_option(thd, ignore)) != VIEW_CHECK_OK) @@ -1645,18 +1692,8 @@ bool multi_update::send_data(List ¬_used_values) if (table->status & (STATUS_NULL_ROW | STATUS_UPDATED)) continue; - /* - We can use compare_record() to optimize away updates if - the table handler is returning all columns OR if - if all updated columns are read - */ if (table == table_to_update) { - bool can_compare_record; - can_compare_record= (!(table->file->ha_table_flags() & - HA_PARTIAL_COLUMN_READ) || - bitmap_is_subset(table->write_set, - table->read_set)); table->status|= STATUS_UPDATED; store_record(table,record[1]); if (fill_record_n_invoke_before_triggers(thd, *fields_for_table[offset], @@ -1671,7 +1708,7 @@ bool multi_update::send_data(List ¬_used_values) */ table->auto_increment_field_not_null= FALSE; found++; - if (!can_compare_record || compare_record(table)) + if (!records_are_comparable(table) || compare_records(table)) { int error; if ((error= cur_table->view_check_option(thd, ignore)) != @@ -1860,7 +1897,6 @@ int multi_update::do_updates() DBUG_RETURN(0); for (cur_table= update_tables; cur_table; cur_table= cur_table->next_local) { - bool can_compare_record; uint offset= cur_table->shared; table = cur_table->table; @@ -1897,11 +1933,6 @@ int multi_update::do_updates() if ((local_error = tmp_table->file->ha_rnd_init(1))) goto err; - can_compare_record= (!(table->file->ha_table_flags() & - HA_PARTIAL_COLUMN_READ) || - bitmap_is_subset(table->write_set, - table->read_set)); - for (;;) { if (thd->killed && trans_safe) @@ -1942,7 +1973,7 @@ int multi_update::do_updates() TRG_ACTION_BEFORE, TRUE)) goto err2; - if (!can_compare_record || compare_record(table)) + if (!records_are_comparable(table) || compare_records(table)) { int error; if ((error= cur_table->view_check_option(thd, ignore)) != diff --git a/sql/sql_update.h b/sql/sql_update.h index 6bf022a171c..50ff50f025d 100644 --- a/sql/sql_update.h +++ b/sql/sql_update.h @@ -38,6 +38,7 @@ bool mysql_multi_update(THD *thd, TABLE_LIST *table_list, enum enum_duplicates handle_duplicates, bool ignore, SELECT_LEX_UNIT *unit, SELECT_LEX *select_lex, multi_update **result); -bool compare_record(TABLE *table); +bool records_are_comparable(const TABLE *table); +bool compare_records(const TABLE *table); #endif /* SQL_UPDATE_INCLUDED */ diff --git a/storage/innobase/row/row0sel.c b/storage/innobase/row/row0sel.c index 61ef4edb7a6..0bbca7c2147 100644 --- a/storage/innobase/row/row0sel.c +++ b/storage/innobase/row/row0sel.c @@ -2688,12 +2688,6 @@ row_sel_store_mysql_rec( prebuilt->blob_heap = NULL; } - /* init null bytes with default values as they might be - left uninitialized in some cases and these uninited bytes - might be copied into mysql record buffer that leads to - valgrind warnings */ - memcpy(mysql_rec, prebuilt->default_rec, prebuilt->null_bitmap_len); - for (i = 0; i < prebuilt->n_template; i++) { templ = prebuilt->mysql_template + i; From 2913b025daaa62f376529d70acd4328d171c64f6 Mon Sep 17 00:00:00 2001 From: Calvin Sun Date: Thu, 7 Oct 2010 06:00:22 -0500 Subject: [PATCH 19/47] bug#56318: adjust the result files. --- mysql-test/suite/innodb/r/innodb-index.result | 6 +++--- mysql-test/suite/innodb/r/innodb-zip.result | 4 ++-- mysql-test/suite/innodb/r/innodb_bug52745.result | 4 ++-- mysql-test/suite/innodb/r/innodb_bug53591.result | 4 ++-- mysql-test/suite/innodb/r/innodb_file_format.result | 8 ++++---- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/mysql-test/suite/innodb/r/innodb-index.result b/mysql-test/suite/innodb/r/innodb-index.result index 1aeca2c226a..e43f70a2365 100644 --- a/mysql-test/suite/innodb/r/innodb-index.result +++ b/mysql-test/suite/innodb/r/innodb-index.result @@ -918,9 +918,9 @@ ERROR HY000: Too big row alter table t1 row_format=compact; create index t1u on t1 (u(1)); drop table t1; -set global innodb_file_per_table=1; -set global innodb_file_format=Barracuda; -set global innodb_file_format_max=Barracuda; +set global innodb_file_per_table=0; +set global innodb_file_format=Antelope; +set global innodb_file_format_max=Antelope; SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; CREATE TABLE t1( diff --git a/mysql-test/suite/innodb/r/innodb-zip.result b/mysql-test/suite/innodb/r/innodb-zip.result index da2be2bb07d..18fdb63d889 100644 --- a/mysql-test/suite/innodb/r/innodb-zip.result +++ b/mysql-test/suite/innodb/r/innodb-zip.result @@ -394,8 +394,8 @@ table_schema table_name row_format test t8 Compact test t9 Redundant drop table t8, t9; -set global innodb_file_per_table=1; -set global innodb_file_format=Barracuda; +set global innodb_file_per_table=0; +set global innodb_file_format=Antelope; set global innodb_file_per_table=on; set global innodb_file_format=`Barracuda`; set global innodb_file_format_max=`Antelope`; diff --git a/mysql-test/suite/innodb/r/innodb_bug52745.result b/mysql-test/suite/innodb/r/innodb_bug52745.result index 16dd356997e..d746fb427b5 100644 --- a/mysql-test/suite/innodb/r/innodb_bug52745.result +++ b/mysql-test/suite/innodb/r/innodb_bug52745.result @@ -125,6 +125,6 @@ Warning 1264 Out of range value for column 'col78' at row 1 Warning 1265 Data truncated for column 'col79' at row 1 Warning 1264 Out of range value for column 'col84' at row 1 DROP TABLE bug52745; -SET GLOBAL innodb_file_format=Barracuda; +SET GLOBAL innodb_file_format=Antelope; SET GLOBAL innodb_file_format_max=Antelope; -SET GLOBAL innodb_file_per_table=1; +SET GLOBAL innodb_file_per_table=0; diff --git a/mysql-test/suite/innodb/r/innodb_bug53591.result b/mysql-test/suite/innodb/r/innodb_bug53591.result index 8573fb60718..d3f8dfeafc2 100644 --- a/mysql-test/suite/innodb/r/innodb_bug53591.result +++ b/mysql-test/suite/innodb/r/innodb_bug53591.result @@ -11,6 +11,6 @@ Error 139 Too big row Error 1118 Row size too large. The maximum row size for the used table type, not counting BLOBs, is 8126. You have to change some columns to TEXT or BLOBs Error 1030 Got error 139 from storage engine DROP TABLE bug53591; -SET GLOBAL innodb_file_format=Barracuda; +SET GLOBAL innodb_file_format=Antelope; SET GLOBAL innodb_file_format_max=Antelope; -SET GLOBAL innodb_file_per_table=1; +SET GLOBAL innodb_file_per_table=0; diff --git a/mysql-test/suite/innodb/r/innodb_file_format.result b/mysql-test/suite/innodb/r/innodb_file_format.result index 447e13f0d60..70cfc9e4f47 100644 --- a/mysql-test/suite/innodb/r/innodb_file_format.result +++ b/mysql-test/suite/innodb/r/innodb_file_format.result @@ -1,6 +1,6 @@ select @@innodb_file_format; @@innodb_file_format -Barracuda +Antelope select @@innodb_file_format_check; @@innodb_file_format_check 1 @@ -17,14 +17,14 @@ Barracuda set global innodb_file_format=default; select @@innodb_file_format; @@innodb_file_format -Barracuda +Antelope set global innodb_file_format=on; ERROR 42000: Variable 'innodb_file_format' can't be set to the value of 'ON' set global innodb_file_format=off; ERROR 42000: Variable 'innodb_file_format' can't be set to the value of 'off' select @@innodb_file_format; @@innodb_file_format -Barracuda +Antelope set global innodb_file_format_max=antelope; set global innodb_file_format_max=barracuda; set global innodb_file_format_max=cheetah; @@ -46,5 +46,5 @@ Antelope set global innodb_file_format_max=antelope; set global innodb_file_format_check=off; ERROR HY000: Variable 'innodb_file_format_check' is a read only variable -SET GLOBAL innodb_file_format=Barracuda; +SET GLOBAL innodb_file_format=Antelope; SET GLOBAL innodb_file_format_max=Antelope; From eec581e07f80c34dd0a91b231f15e6c1a59b7f62 Mon Sep 17 00:00:00 2001 From: Dmitry Shulga Date: Thu, 7 Oct 2010 18:57:12 +0700 Subject: [PATCH 20/47] Fixed bug#45445 - cannot execute procedures with thread_stack set to 128k. --- mysql-test/collections/default.experimental | 1 - sql/sp_head.cc | 23 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/mysql-test/collections/default.experimental b/mysql-test/collections/default.experimental index b292356f1c7..47b2c215ac1 100644 --- a/mysql-test/collections/default.experimental +++ b/mysql-test/collections/default.experimental @@ -29,7 +29,6 @@ rpl.rpl_heartbeat_2slaves # BUG#43828 2009-10-22 luis fails spora rpl.rpl_innodb_bug28430* # Bug#46029 rpl.rpl_innodb_bug30888* @solaris # Bug#47646 2009-09-25 alik rpl.rpl_innodb_bug30888 fails sporadically on Solaris rpl.rpl_killed_ddl @windows # Bug#47638 2010-01-20 alik The rpl_killed_ddl test fails on Windows -rpl.rpl_row_sp011* @solaris # Bug#47791 2010-01-20 alik Several test cases fail on Solaris with error Thread stack overrun sys_vars.max_sp_recursion_depth_func @solaris # Bug#47791 2010-01-20 alik Several test cases fail on Solaris with error Thread stack overrun sys_vars.slow_query_log_func @solaris # Bug#54819 2010-06-26 alik sys_vars.slow_query_log_func fails sporadically on Solaris 10 diff --git a/sql/sp_head.cc b/sql/sp_head.cc index a95bbe094c0..e25b10957ac 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -1213,8 +1213,27 @@ sp_head::execute(THD *thd) Object_creation_ctx *saved_creation_ctx; Warning_info *saved_warning_info, warning_info(thd->warning_info->warn_id()); - /* Use some extra margin for possible SP recursion and functions */ - if (check_stack_overrun(thd, 8 * STACK_MIN_SIZE, (uchar*)&old_packet)) + /* + Just reporting a stack overrun error + (@sa check_stack_overrun()) requires stack memory for error + message buffer. Thus, we have to put the below check + relatively close to the beginning of the execution stack, + where available stack margin is still big. As long as the check + has to be fairly high up the call stack, the amount of memory + we "book" for has to stay fairly high as well, and hence + not very accurate. The number below has been calculated + by trial and error, and reflects the amount of memory necessary + to execute a single stored procedure instruction, be it either + an SQL statement, or, heaviest of all, a CALL, which involves + parsing and loading of another stored procedure into the cache + (@sa db_load_routine() and Bug#10100). + At the time of measuring, a recursive SP invocation required + 3232 bytes of stack on 32 bit Linux and 6016 bytes on 64 bit Mac. + The same with db_load_routine() required circa 7k bytes and + 14k bytes accordingly. Hence, here we book the stack with some + reasonable margin. + */ + if (check_stack_overrun(thd, 2 * STACK_MIN_SIZE, (uchar*)&old_packet)) DBUG_RETURN(TRUE); /* init per-instruction memroot */ From bf48832462f89ba84a29e6aefe5ed8b81d8f157f Mon Sep 17 00:00:00 2001 From: Georgi Kodinov Date: Thu, 7 Oct 2010 17:28:17 +0300 Subject: [PATCH 21/47] bumped the version to 5.1.53 --- configure.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.in b/configure.in index c1672557bd1..7680a60226a 100644 --- a/configure.in +++ b/configure.in @@ -12,7 +12,7 @@ dnl dnl When changing the major version number please also check the switch dnl statement in mysqlbinlog::check_master_version(). You may also need dnl to update version.c in ndb. -AC_INIT([MySQL Server], [5.1.52], [], [mysql]) +AC_INIT([MySQL Server], [5.1.53], [], [mysql]) AC_CONFIG_SRCDIR([sql/mysqld.cc]) AC_CANONICAL_SYSTEM From cc15d2462cf0b32576010d1810960969cba48182 Mon Sep 17 00:00:00 2001 From: Luis Soares Date: Thu, 7 Oct 2010 16:38:23 +0100 Subject: [PATCH 22/47] BUG#54144: ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE is hard coded The error message for ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE was hard coded. Additionally, the same error was used in three separate error symptoms: 1. when heartbeat period exceeds the value of slave_net_timeout, 2. when it is smaller than 1 milisecond and 3. when it was not in range, ie, either negative or greater than the maximum allowed. We fix this by splitting into three distinct errors and by removing the message from the source code and moving it to the errmsg-utf8.txt file. --- mysql-test/suite/rpl/r/rpl_heartbeat.result | 10 +++--- .../suite/rpl/r/rpl_heartbeat_basic.result | 14 ++++----- sql/share/errmsg-utf8.txt | 9 +++++- sql/sql_yacc.yy | 31 +++++++------------ sql/sys_vars.cc | 7 ++--- 5 files changed, 34 insertions(+), 37 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_heartbeat.result b/mysql-test/suite/rpl/r/rpl_heartbeat.result index 05d37dc7d04..99e873be90c 100644 --- a/mysql-test/suite/rpl/r/rpl_heartbeat.result +++ b/mysql-test/suite/rpl/r/rpl_heartbeat.result @@ -6,19 +6,19 @@ show status like 'Slave_heartbeat_period';; Variable_name Slave_heartbeat_period Value 5.000 change master to master_host='127.0.0.1',master_port=MASTER_PORT, master_user='root', master_heartbeat_period= 4294968; -ERROR HY000: The requested value for the heartbeat period is negative or exceeds the maximum 4294967 seconds +ERROR HY000: The requested value for the heartbeat period is either negative or exceeds the maximum allowed (4294967 seconds). show status like 'Slave_heartbeat_period';; Variable_name Slave_heartbeat_period Value 5.000 change master to master_host='127.0.0.1',master_port=MASTER_PORT, master_user='root', master_heartbeat_period= 0.0009999; Warnings: -Warning 1624 The requested value for the heartbeat period is less than 1 msec. The period is reset to zero which means no heartbeats will be sending +Warning 1701 The requested value for the heartbeat period is less than 1 millisecond. The value is reset to 0, meaning that heartbeating will effectively be disabled. show status like 'Slave_heartbeat_period';; Variable_name Slave_heartbeat_period Value 0.000 change master to master_host='127.0.0.1',master_port=MASTER_PORT, master_user='root', master_heartbeat_period= 4294967; Warnings: -Warning 1624 The requested value for the heartbeat period exceeds the value of `slave_net_timeout' sec. A sensible value for the period should be less than the timeout. +Warning 1702 The requested value for the heartbeat period exceeds the value of `slave_net_timeout' seconds. A sensible value for the period should be less than the timeout. show status like 'Slave_heartbeat_period';; Variable_name Slave_heartbeat_period Value 4294967.000 @@ -30,7 +30,7 @@ reset slave; set @@global.slave_net_timeout= 5; change master to master_host='127.0.0.1',master_port=MASTER_PORT, master_user='root', master_heartbeat_period= 5.001; Warnings: -Warning 1624 The requested value for the heartbeat period exceeds the value of `slave_net_timeout' sec. A sensible value for the period should be less than the timeout. +Warning 1702 The requested value for the heartbeat period exceeds the value of `slave_net_timeout' seconds. A sensible value for the period should be less than the timeout. show status like 'Slave_heartbeat_period';; Variable_name Slave_heartbeat_period Value 5.001 @@ -42,7 +42,7 @@ Variable_name Slave_heartbeat_period Value 4.000 set @@global.slave_net_timeout= 3 /* must be a warning */; Warnings: -Warning 1624 The current value for master_heartbeat_period exceeds the new value of `slave_net_timeout' sec. A sensible value for the period should be less than the timeout. +Warning 1702 The requested value for the heartbeat period exceeds the value of `slave_net_timeout' seconds. A sensible value for the period should be less than the timeout. reset slave; drop table if exists t1; set @@global.slave_net_timeout= 10; diff --git a/mysql-test/suite/rpl/r/rpl_heartbeat_basic.result b/mysql-test/suite/rpl/r/rpl_heartbeat_basic.result index b54602663d8..a78b84e209d 100644 --- a/mysql-test/suite/rpl/r/rpl_heartbeat_basic.result +++ b/mysql-test/suite/rpl/r/rpl_heartbeat_basic.result @@ -38,14 +38,14 @@ RESET SLAVE; *** Warning if updated slave_net_timeout < slave_heartbeat_timeout *** SET @@global.slave_net_timeout=FLOOR(SLAVE_HEARTBEAT_TIMEOUT)-1; Warnings: -Warning 1624 The current value for master_heartbeat_period exceeds the new value of `slave_net_timeout' sec. A sensible value for the period should be less than the timeout. +Warning 1702 The requested value for the heartbeat period exceeds the value of `slave_net_timeout' seconds. A sensible value for the period should be less than the timeout. SET @@global.slave_net_timeout=@restore_slave_net_timeout; RESET SLAVE; *** Warning if updated slave_heartbeat_timeout > slave_net_timeout *** CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=SLAVE_NET_TIMEOUT; Warnings: -Warning 1624 The requested value for the heartbeat period exceeds the value of `slave_net_timeout' sec. A sensible value for the period should be less than the timeout. +Warning 1702 The requested value for the heartbeat period exceeds the value of `slave_net_timeout' seconds. A sensible value for the period should be less than the timeout. RESET SLAVE; *** CHANGE MASTER statement only updates slave_heartbeat_period *** @@ -140,7 +140,7 @@ Slave_heartbeat_period 0.001 RESET SLAVE; CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=0.0009; Warnings: -Warning 1624 The requested value for the heartbeat period is less than 1 msec. The period is reset to zero which means no heartbeats will be sending +Warning 1701 The requested value for the heartbeat period is less than 1 millisecond. The period is reset to 0, meaning that heartbeating will effectively be disabled. SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period'; Variable_name Value Slave_heartbeat_period 0.000 @@ -149,19 +149,19 @@ RESET SLAVE; *** Max slave_heartbeat_timeout *** CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=4294967; Warnings: -Warning 1624 The requested value for the heartbeat period exceeds the value of `slave_net_timeout' sec. A sensible value for the period should be less than the timeout. +Warning 1702 The requested value for the heartbeat period exceeds the value of `slave_net_timeout' seconds. A sensible value for the period should be less than the timeout. SHOW GLOBAL STATUS LIKE 'slave_heartbeat_period'; Variable_name Value Slave_heartbeat_period 4294967.000 RESET SLAVE; CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=4294968; -ERROR HY000: The requested value for the heartbeat period is negative or exceeds the maximum 4294967 seconds +ERROR HY000: The requested value for the heartbeat period is either negative or exceeds the maximum allowed (4294967 seconds). RESET SLAVE; CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=8589935; -ERROR HY000: The requested value for the heartbeat period is negative or exceeds the maximum 4294967 seconds +ERROR HY000: The requested value for the heartbeat period is either negative or exceeds the maximum allowed (4294967 seconds). RESET SLAVE; CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=MASTER_PORT, MASTER_USER='root', MASTER_HEARTBEAT_PERIOD=4294967296; -ERROR HY000: The requested value for the heartbeat period is negative or exceeds the maximum 4294967 seconds +ERROR HY000: The requested value for the heartbeat period is either negative or exceeds the maximum allowed (4294967 seconds). RESET SLAVE; *** Misc incorrect values *** diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt index 07f5589135d..c0ce32e68d8 100644 --- a/sql/share/errmsg-utf8.txt +++ b/sql/share/errmsg-utf8.txt @@ -6152,7 +6152,7 @@ ER_WARN_ENGINE_TRANSACTION_ROLLBACK ER_SLAVE_HEARTBEAT_FAILURE eng "Unexpected master's heartbeat data: %s" ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE - eng "The requested value for the heartbeat period %s %s" + eng "The requested value for the heartbeat period is either negative or exceeds the maximum allowed (%s seconds)." ER_NDB_REPLICATION_SCHEMA_ERROR eng "Bad schema for mysql.ndb_replication table. Message: %-.64s" @@ -6379,3 +6379,10 @@ ER_SET_PASSWORD_AUTH_PLUGIN ER_GRANT_PLUGIN_USER_EXISTS eng "GRANT with IDENTIFIED WITH is illegal because the user %-.*s already exists" + +ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MIN + eng "The requested value for the heartbeat period is less than 1 millisecond. The value is reset to 0, meaning that heartbeating will effectively be disabled." + +ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX + eng "The requested value for the heartbeat period exceeds the value of `slave_net_timeout' seconds. A sensible value for the period should be less than the timeout." + diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 7c24f18aa6a..dc482caa29c 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1933,35 +1933,28 @@ master_def: | MASTER_HEARTBEAT_PERIOD_SYM EQ NUM_literal { Lex->mi.heartbeat_period= (float) $3->val_real(); - if (Lex->mi.heartbeat_period > SLAVE_MAX_HEARTBEAT_PERIOD || - Lex->mi.heartbeat_period < 0.0) - { - const char format[]= "%d seconds"; - char buf[4*sizeof(SLAVE_MAX_HEARTBEAT_PERIOD) + sizeof(format)]; - sprintf(buf, format, SLAVE_MAX_HEARTBEAT_PERIOD); - my_error(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE, - MYF(0), " is negative or exceeds the maximum ", buf); - MYSQL_YYABORT; + if (Lex->mi.heartbeat_period > SLAVE_MAX_HEARTBEAT_PERIOD || + Lex->mi.heartbeat_period < 0.0) + { + const char format[]= "%d"; + char buf[4*sizeof(SLAVE_MAX_HEARTBEAT_PERIOD) + sizeof(format)]; + sprintf(buf, format, SLAVE_MAX_HEARTBEAT_PERIOD); + my_error(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE, MYF(0), buf); + MYSQL_YYABORT; } if (Lex->mi.heartbeat_period > slave_net_timeout) { push_warning_printf(YYTHD, MYSQL_ERROR::WARN_LEVEL_WARN, - ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE, - ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE), - " exceeds the value of `slave_net_timeout' sec.", - " A sensible value for the period should be" - " less than the timeout."); + ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX, + ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX)); } if (Lex->mi.heartbeat_period < 0.001) { if (Lex->mi.heartbeat_period != 0.0) { push_warning_printf(YYTHD, MYSQL_ERROR::WARN_LEVEL_WARN, - ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE, - ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE), - " is less than 1 msec.", - " The period is reset to zero which means" - " no heartbeats will be sending"); + ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MIN, + ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MIN)); Lex->mi.heartbeat_period= 0.0; } Lex->mi.heartbeat_opt= LEX_MASTER_INFO::LEX_MI_DISABLE; diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index 69a01259fc0..b8b73bc0387 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -2943,11 +2943,8 @@ static bool fix_slave_net_timeout(sys_var *self, THD *thd, enum_var_type type) (active_mi? active_mi->heartbeat_period : 0.0))); if (active_mi && slave_net_timeout < active_mi->heartbeat_period) push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN, - ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE, - "The current value for master_heartbeat_period" - " exceeds the new value of `slave_net_timeout' sec." - " A sensible value for the period should be" - " less than the timeout."); + ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX, + ER(ER_SLAVE_HEARTBEAT_VALUE_OUT_OF_RANGE_MAX)); mysql_mutex_unlock(&LOCK_active_mi); return false; } From 2fd0bc63bb19b1a691d73ff3d40d613f383238e5 Mon Sep 17 00:00:00 2001 From: Evgeny Potemkin Date: Thu, 7 Oct 2010 20:16:30 +0400 Subject: [PATCH 23/47] Bug#57095: Wrongly chosen expression cache type led to a wrong result. The coalesce function returned DATETIME type due to a DATETIME argument, but since it's not a date/time function it can't return correct int value for it. Nevertheless Item_datetime_cache was chosen to cache coalesce's result and that led to a wrong result. Now Item_datetime_cache is used only for those function that could return correct int representation of DATETIME values. --- mysql-test/r/type_datetime.result | 12 ++++++++++++ mysql-test/t/type_datetime.test | 10 ++++++++++ sql/item.cc | 8 +++++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/type_datetime.result b/mysql-test/r/type_datetime.result index f7bfba0accd..958285d6a23 100644 --- a/mysql-test/r/type_datetime.result +++ b/mysql-test/r/type_datetime.result @@ -680,5 +680,17 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 const PRIMARY PRIMARY 8 const 1 Using index DROP TABLE t1,t2; # +# Bug#57095: Wrongly chosen expression cache type led to a wrong +# result. +# +CREATE TABLE t1 (`b` datetime ); +INSERT INTO t1 VALUES ('2010-01-01 00:00:00'), ('2010-01-01 00:00:00'); +SELECT * FROM t1 WHERE b <= coalesce(NULL, now()); +b +2010-01-01 00:00:00 +2010-01-01 00:00:00 +DROP TABLE t1; +# +# # End of 5.5 tests # diff --git a/mysql-test/t/type_datetime.test b/mysql-test/t/type_datetime.test index 6e40c9ccfa0..ca2a7804907 100644 --- a/mysql-test/t/type_datetime.test +++ b/mysql-test/t/type_datetime.test @@ -484,6 +484,16 @@ explain select * from t2 where f1=STR_TO_DATE('4/1/2010', '%m/%d/%Y'); DROP TABLE t1,t2; +--echo # +--echo # Bug#57095: Wrongly chosen expression cache type led to a wrong +--echo # result. +--echo # +CREATE TABLE t1 (`b` datetime ); +INSERT INTO t1 VALUES ('2010-01-01 00:00:00'), ('2010-01-01 00:00:00'); +SELECT * FROM t1 WHERE b <= coalesce(NULL, now()); +DROP TABLE t1; +--echo # + --echo # --echo # End of 5.5 tests --echo # diff --git a/sql/item.cc b/sql/item.cc index e782e90b874..fff7511015f 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -7356,9 +7356,11 @@ Item_cache* Item_cache::get_cache(const Item *item, const Item_result type) case DECIMAL_RESULT: return new Item_cache_decimal(); case STRING_RESULT: - if (item->field_type() == MYSQL_TYPE_DATE || - item->field_type() == MYSQL_TYPE_DATETIME || - item->field_type() == MYSQL_TYPE_TIME) + /* Not all functions that return DATE/TIME are actually DATE/TIME funcs. */ + if ((item->field_type() == MYSQL_TYPE_DATE || + item->field_type() == MYSQL_TYPE_DATETIME || + item->field_type() == MYSQL_TYPE_TIME) && + (const_cast(item))->result_as_longlong()) return new Item_cache_datetime(item->field_type()); return new Item_cache_str(item); case ROW_RESULT: From 76643a469a58beee1ffff9636c87eb8c36f2177d Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Thu, 7 Oct 2010 19:51:37 -0300 Subject: [PATCH 24/47] Bug#56822: Add a thread state for sessions waiting on the query cache lock The problem was that threads waiting on the query cache lock are not easily seen due to the lack of a state indicating that the thread is waiting on the said lock. This made it difficult for users to quickly spot (for example, via SHOW PROCESSLIST) a query cache contention problem. The solution is to update the thread state when the query cache lock needs to be acquired. Whenever the lock is to be acquired, the thread state is updated to "Waiting for query cache lock" and is reset once the lock is granted or the wait is interrupted. The intention is to make query cache related hangs more evident. To further investigate query cache related locking problems, one may use PERFORMANCE_SCHEMA to track the overhead associated with the locking bits and determine which particular lock is being a contention point. --- mysql-test/r/query_cache_debug.result | 75 +++++++++++---- mysql-test/t/query_cache_debug.test | 126 ++++++++++++++++++-------- sql/sql_cache.cc | 74 +++++++-------- 3 files changed, 180 insertions(+), 95 deletions(-) diff --git a/mysql-test/r/query_cache_debug.result b/mysql-test/r/query_cache_debug.result index eb59e62c8ba..30996e5e86b 100644 --- a/mysql-test/r/query_cache_debug.result +++ b/mysql-test/r/query_cache_debug.result @@ -5,20 +5,24 @@ drop table if exists t1; create table t1 (a varchar(100)); insert into t1 values ('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'),('bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb'); Activate debug hook and attempt to retrieve the statement from the cache. -set session debug='+d,wait_in_query_cache_insert'; +set debug_sync="wait_in_query_cache_insert SIGNAL parked WAIT_FOR go"; select SQL_CACHE * from t1;; +set debug_sync="now WAIT_FOR parked"; On a second connection; clear the query cache. show status like 'Qcache_queries_in_cache'; Variable_name Value Qcache_queries_in_cache 1 set global query_cache_size= 0; Signal the debug hook to release the lock. -select id from information_schema.processlist where state='wait_in_query_cache_insert' into @thread_id; -kill query @thread_id; +set debug_sync="now SIGNAL go"; Show query cache status. show status like 'Qcache_queries_in_cache'; Variable_name Value Qcache_queries_in_cache 0 +a +aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb +set debug_sync= 'RESET'; set global query_cache_size= 0; use test; drop table t1; @@ -32,11 +36,12 @@ SET GLOBAL concurrent_insert= 1; SET GLOBAL query_cache_size= 1024*512; SET GLOBAL query_cache_type= ON; # Switch to connection con1 -SET SESSION debug='+d,wait_after_query_cache_invalidate'; +SET DEBUG_SYNC = "wait_after_query_cache_invalidate SIGNAL parked WAIT_FOR go"; # Send concurrent insert, will wait in the query cache table invalidate INSERT INTO t1 VALUES (4); # Switch to connection default # Wait for concurrent insert to reach the debug point +SET DEBUG_SYNC = "now WAIT_FOR parked"; # Switch to connection con2 # Send SELECT that shouldn't be cached SELECT * FROM t1; @@ -46,9 +51,7 @@ a 3 # Switch to connection default # Notify the concurrent insert to proceed -SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST -WHERE STATE = 'wait_after_query_cache_invalidate' INTO @thread_id; -KILL QUERY @thread_id; +SET DEBUG_SYNC = "now SIGNAL go"; # Switch to connection con1 # Gather insert result SHOW STATUS LIKE "Qcache_queries_in_cache"; @@ -66,6 +69,7 @@ Variable_name Value Qcache_queries_in_cache 1 # Disconnect # Restore defaults +SET DEBUG_SYNC= 'RESET'; RESET QUERY CACHE; DROP TABLE t1,t2; SET GLOBAL concurrent_insert= DEFAULT; @@ -108,43 +112,44 @@ bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb ** before the mutex lock in invalidate_table_internal. ** This will allow new result sets to be written into the QC. ** -SET SESSION debug='+d,wait_in_query_cache_invalidate1'; -SET SESSION debug='+d,wait_in_query_cache_invalidate2'; +SET DEBUG_SYNC="wait_in_query_cache_invalidate1 SIGNAL parked1_1 WAIT_FOR go1_1"; +SET DEBUG_SYNC="wait_in_query_cache_invalidate2 SIGNAL parked1_2 WAIT_FOR go1_2"; DELETE FROM t1 WHERE a like '%a%';; =================================== Connection default ** Assert that the expect process status is obtained. +SET DEBUG_SYNC="now WAIT_FOR parked1_1"; ** =================================== Connection thd2 ** On THD2: Insert a result into the cache. This attempt will be blocked ** because of a debug hook placed just before the mutex lock after which ** the first part of the result set is written. -SET SESSION debug='+d,wait_in_query_cache_insert'; +SET DEBUG_SYNC="wait_in_query_cache_insert SIGNAL parked2 WAIT_FOR go2"; SELECT SQL_CACHE * FROM t2 UNION SELECT * FROM t3; =================================== Connection thd3 ** On THD3: Insert another result into the cache and block on the same ** debug hook. -SET SESSION debug='+d,wait_in_query_cache_insert'; +SET DEBUG_SYNC="wait_in_query_cache_insert SIGNAL parked3 WAIT_FOR go3"; SELECT SQL_CACHE * FROM t4 UNION SELECT * FROM t5;; =================================== Connection default ** Assert that the two SELECT-stmt threads to reach the hook. +SET DEBUG_SYNC="now WAIT_FOR parked2"; +SET DEBUG_SYNC="now WAIT_FOR parked3"; ** ** ** Signal the DELETE thread, THD1, to continue. It will enter the mutex ** lock and set query cache status to TABLE_FLUSH_IN_PROGRESS and then ** unlock the mutex before stopping on the next debug hook. -SELECT SQL_NO_CACHE id FROM information_schema.processlist WHERE state='wait_in_query_cache_invalidate1' LIMIT 1 INTO @flush_thread_id; -KILL QUERY @flush_thread_id; +SET DEBUG_SYNC="now SIGNAL go1_1"; ** Assert that we reach the next debug hook. +SET DEBUG_SYNC="now WAIT_FOR parked1_2"; ** ** Signal the remaining debug hooks blocking THD2 and THD3. ** The threads will grab the guard mutex enter the wait condition and ** and finally release the mutex. The threads will continue to wait ** until a broadcast signal reaches them causing both threads to ** come alive and check the condition. -SELECT SQL_NO_CACHE id FROM information_schema.processlist WHERE state='wait_in_query_cache_insert' ORDER BY id ASC LIMIT 1 INTO @thread_id; -KILL QUERY @thread_id; -SELECT SQL_NO_CACHE id FROM information_schema.processlist WHERE state='wait_in_query_cache_insert' ORDER BY id DESC LIMIT 1 INTO @thread_id; -KILL QUERY @thread_id; +SET DEBUG_SYNC="now SIGNAL go2"; +SET DEBUG_SYNC="now SIGNAL go3"; ** ** Finally signal the DELETE statement on THD1 one last time. ** The stmt will complete the query cache invalidation and return @@ -152,8 +157,7 @@ KILL QUERY @thread_id; ** One signal will be sent to the thread group waiting for executing ** invalidations and a broadcast signal will be sent to the thread ** group holding result set writers. -SELECT SQL_NO_CACHE id FROM information_schema.processlist WHERE state='wait_in_query_cache_invalidate2' LIMIT 1 INTO @flush_thread_id; -KILL QUERY @flush_thread_id; +SET DEBUG_SYNC="now SIGNAL go1_2"; ** ************************************************************************* ** No tables should be locked @@ -172,6 +176,7 @@ DELETE FROM t4; DELETE FROM t5; =================================== Connection thd1 ** Done. +SET DEBUG_SYNC= 'RESET'; SET GLOBAL query_cache_size= 0; # Restore defaults RESET QUERY CACHE; @@ -179,3 +184,35 @@ FLUSH STATUS; DROP TABLE t1,t2,t3,t4,t5; SET GLOBAL query_cache_size= DEFAULT; SET GLOBAL query_cache_type= DEFAULT; +# +# Bug#56822: Add a thread state for sessions waiting on the query cache lock +# +SET @old_query_cache_size= @@GLOBAL.query_cache_size; +DROP TABLE IF EXISTS t1; +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2),(3); +SET GLOBAL concurrent_insert= 1; +SET GLOBAL query_cache_size= 1024*512; +SET GLOBAL query_cache_type= ON; +# Switch to connection con1 +SET DEBUG_SYNC = "wait_in_query_cache_invalidate2 SIGNAL parked WAIT_FOR go"; +# Send INSERT, will wait in the query cache table invalidation +INSERT INTO t1 VALUES (4);; +# Switch to connection default +# Wait for insert to reach the debug point +SET DEBUG_SYNC = "now WAIT_FOR parked"; +# Switch to connection con2 +# Send a query that should wait on the query cache lock +RESET QUERY CACHE; +# Switch to connection default +# Wait for the state to be reflected in the processlist +# Signal that the query cache can be unlocked +SET DEBUG_SYNC="now SIGNAL go"; +# Reap con1 and disconnect +# Reap con2 and disconnect +# Restore defaults +SET DEBUG_SYNC= 'RESET'; +RESET QUERY CACHE; +DROP TABLE t1; +SET GLOBAL query_cache_size= DEFAULT; +SET GLOBAL query_cache_type= DEFAULT; diff --git a/mysql-test/t/query_cache_debug.test b/mysql-test/t/query_cache_debug.test index ce62b931a93..77e714aa6f5 100644 --- a/mysql-test/t/query_cache_debug.test +++ b/mysql-test/t/query_cache_debug.test @@ -1,6 +1,6 @@ --source include/not_embedded.inc --source include/have_query_cache.inc ---source include/have_debug.inc +--source include/have_debug_sync.inc # # Bug #30887 Server crashes on SET GLOBAL query_cache_size=0 @@ -18,12 +18,11 @@ connect (bug30887con2, localhost, root, ,test); connection bug30887con1; --echo Activate debug hook and attempt to retrieve the statement from the cache. -set session debug='+d,wait_in_query_cache_insert'; +set debug_sync="wait_in_query_cache_insert SIGNAL parked WAIT_FOR go"; --send select SQL_CACHE * from t1; connection default; -let $wait_condition= select count(*)= 1 from information_schema.processlist where state= 'wait_in_query_cache_insert'; ---source include/wait_condition.inc +set debug_sync="now WAIT_FOR parked"; connection bug30887con2; --echo On a second connection; clear the query cache. @@ -32,14 +31,18 @@ set global query_cache_size= 0; connection default; --echo Signal the debug hook to release the lock. -select id from information_schema.processlist where state='wait_in_query_cache_insert' into @thread_id; -kill query @thread_id; +set debug_sync="now SIGNAL go"; --echo Show query cache status. show status like 'Qcache_queries_in_cache'; +connection bug30887con1; +--reap + disconnect bug30887con1; disconnect bug30887con2; +connection default; +set debug_sync= 'RESET'; set global query_cache_size= 0; use test; drop table t1; @@ -67,18 +70,14 @@ connect(con2,localhost,root,,test,,); connection con1; --echo # Switch to connection con1 -SET SESSION debug='+d,wait_after_query_cache_invalidate'; +SET DEBUG_SYNC = "wait_after_query_cache_invalidate SIGNAL parked WAIT_FOR go"; --echo # Send concurrent insert, will wait in the query cache table invalidate --send INSERT INTO t1 VALUES (4) connection default; --echo # Switch to connection default --echo # Wait for concurrent insert to reach the debug point -let $wait_condition= - SELECT COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST - WHERE STATE = "wait_after_query_cache_invalidate" AND - INFO = "INSERT INTO t1 VALUES (4)"; ---source include/wait_condition.inc +SET DEBUG_SYNC = "now WAIT_FOR parked"; connection con2; --echo # Switch to connection con2 @@ -88,9 +87,7 @@ SELECT * FROM t1; connection default; --echo # Switch to connection default --echo # Notify the concurrent insert to proceed -SELECT ID FROM INFORMATION_SCHEMA.PROCESSLIST - WHERE STATE = 'wait_after_query_cache_invalidate' INTO @thread_id; -KILL QUERY @thread_id; +SET DEBUG_SYNC = "now SIGNAL go"; connection con1; --echo # Switch to connection con1 @@ -107,6 +104,7 @@ disconnect con2; connection default; --echo # Restore defaults +SET DEBUG_SYNC= 'RESET'; RESET QUERY CACHE; DROP TABLE t1,t2; SET GLOBAL concurrent_insert= DEFAULT; @@ -157,15 +155,14 @@ SELECT SQL_CACHE * FROM t1; --echo ** before the mutex lock in invalidate_table_internal. --echo ** This will allow new result sets to be written into the QC. --echo ** -SET SESSION debug='+d,wait_in_query_cache_invalidate1'; -SET SESSION debug='+d,wait_in_query_cache_invalidate2'; +SET DEBUG_SYNC="wait_in_query_cache_invalidate1 SIGNAL parked1_1 WAIT_FOR go1_1"; +SET DEBUG_SYNC="wait_in_query_cache_invalidate2 SIGNAL parked1_2 WAIT_FOR go1_2"; --send DELETE FROM t1 WHERE a like '%a%'; connection default; --echo =================================== Connection default --echo ** Assert that the expect process status is obtained. -LET $wait_condition= SELECT SQL_NO_CACHE COUNT(*)= 1 FROM information_schema.processlist WHERE state= 'wait_in_query_cache_invalidate1'; ---source include/wait_condition.inc +SET DEBUG_SYNC="now WAIT_FOR parked1_1"; -- echo ** connection thd2; @@ -173,32 +170,30 @@ connection thd2; --echo ** On THD2: Insert a result into the cache. This attempt will be blocked --echo ** because of a debug hook placed just before the mutex lock after which --echo ** the first part of the result set is written. -SET SESSION debug='+d,wait_in_query_cache_insert'; +SET DEBUG_SYNC="wait_in_query_cache_insert SIGNAL parked2 WAIT_FOR go2"; --send SELECT SQL_CACHE * FROM t2 UNION SELECT * FROM t3 connection thd3; --echo =================================== Connection thd3 --echo ** On THD3: Insert another result into the cache and block on the same --echo ** debug hook. -SET SESSION debug='+d,wait_in_query_cache_insert'; +SET DEBUG_SYNC="wait_in_query_cache_insert SIGNAL parked3 WAIT_FOR go3"; --send SELECT SQL_CACHE * FROM t4 UNION SELECT * FROM t5; connection default; --echo =================================== Connection default --echo ** Assert that the two SELECT-stmt threads to reach the hook. -LET $wait_condition= SELECT SQL_NO_CACHE COUNT(*)= 2 FROM information_schema.processlist WHERE state='wait_in_query_cache_insert'; ---source include/wait_condition.inc +SET DEBUG_SYNC="now WAIT_FOR parked2"; +SET DEBUG_SYNC="now WAIT_FOR parked3"; --echo ** --echo ** --echo ** Signal the DELETE thread, THD1, to continue. It will enter the mutex --echo ** lock and set query cache status to TABLE_FLUSH_IN_PROGRESS and then --echo ** unlock the mutex before stopping on the next debug hook. -SELECT SQL_NO_CACHE id FROM information_schema.processlist WHERE state='wait_in_query_cache_invalidate1' LIMIT 1 INTO @flush_thread_id; -KILL QUERY @flush_thread_id; +SET DEBUG_SYNC="now SIGNAL go1_1"; --echo ** Assert that we reach the next debug hook. -LET $wait_condition= SELECT SQL_NO_CACHE COUNT(*)= 1 FROM information_schema.processlist WHERE state='wait_in_query_cache_invalidate2'; ---source include/wait_condition.inc +SET DEBUG_SYNC="now WAIT_FOR parked1_2"; --echo ** --echo ** Signal the remaining debug hooks blocking THD2 and THD3. @@ -206,10 +201,8 @@ LET $wait_condition= SELECT SQL_NO_CACHE COUNT(*)= 1 FROM information_schema.pro --echo ** and finally release the mutex. The threads will continue to wait --echo ** until a broadcast signal reaches them causing both threads to --echo ** come alive and check the condition. -SELECT SQL_NO_CACHE id FROM information_schema.processlist WHERE state='wait_in_query_cache_insert' ORDER BY id ASC LIMIT 1 INTO @thread_id; -KILL QUERY @thread_id; -SELECT SQL_NO_CACHE id FROM information_schema.processlist WHERE state='wait_in_query_cache_insert' ORDER BY id DESC LIMIT 1 INTO @thread_id; -KILL QUERY @thread_id; +SET DEBUG_SYNC="now SIGNAL go2"; +SET DEBUG_SYNC="now SIGNAL go3"; --echo ** --echo ** Finally signal the DELETE statement on THD1 one last time. @@ -218,11 +211,7 @@ KILL QUERY @thread_id; --echo ** One signal will be sent to the thread group waiting for executing --echo ** invalidations and a broadcast signal will be sent to the thread --echo ** group holding result set writers. -SELECT SQL_NO_CACHE id FROM information_schema.processlist WHERE state='wait_in_query_cache_invalidate2' LIMIT 1 INTO @flush_thread_id; -KILL QUERY @flush_thread_id; - -LET $wait_condition= SELECT SQL_NO_CACHE COUNT(*) = 1 FROM INFORMATION_SCHEMA.PROCESSLIST WHERE Id = @flush_thread_id AND Command = 'Sleep'; ---source include/wait_condition.inc +SET DEBUG_SYNC="now SIGNAL go1_2"; --echo ** --echo ************************************************************************* @@ -250,6 +239,7 @@ connection default; disconnect thd1; disconnect thd2; disconnect thd3; +SET DEBUG_SYNC= 'RESET'; SET GLOBAL query_cache_size= 0; connection default; @@ -259,4 +249,66 @@ FLUSH STATUS; DROP TABLE t1,t2,t3,t4,t5; SET GLOBAL query_cache_size= DEFAULT; SET GLOBAL query_cache_type= DEFAULT; -exit; + +--echo # +--echo # Bug#56822: Add a thread state for sessions waiting on the query cache lock +--echo # + +SET @old_query_cache_size= @@GLOBAL.query_cache_size; + +--disable_warnings +DROP TABLE IF EXISTS t1; +--enable_warnings +CREATE TABLE t1 (a INT); +INSERT INTO t1 VALUES (1),(2),(3); + +SET GLOBAL concurrent_insert= 1; +SET GLOBAL query_cache_size= 1024*512; +SET GLOBAL query_cache_type= ON; + +connect(con1,localhost,root,,test,,); +connect(con2,localhost,root,,test,,); + +connection con1; +--echo # Switch to connection con1 +SET DEBUG_SYNC = "wait_in_query_cache_invalidate2 SIGNAL parked WAIT_FOR go"; +--echo # Send INSERT, will wait in the query cache table invalidation +--send INSERT INTO t1 VALUES (4); + +connection default; +--echo # Switch to connection default +--echo # Wait for insert to reach the debug point +SET DEBUG_SYNC = "now WAIT_FOR parked"; + +connection con2; +--echo # Switch to connection con2 +--echo # Send a query that should wait on the query cache lock +--send RESET QUERY CACHE + +connection default; +--echo # Switch to connection default +--echo # Wait for the state to be reflected in the processlist +let $wait_condition= + SELECT COUNT(*) = 1 FROM information_schema.processlist + WHERE state = "Waiting for query cache lock" AND info = "RESET QUERY CACHE"; +--source include/wait_condition.inc +--echo # Signal that the query cache can be unlocked +SET DEBUG_SYNC="now SIGNAL go"; + +connection con1; +--echo # Reap con1 and disconnect +--reap +disconnect con1; + +connection con2; +--echo # Reap con2 and disconnect +--reap +disconnect con2; + +connection default; +--echo # Restore defaults +SET DEBUG_SYNC= 'RESET'; +RESET QUERY CACHE; +DROP TABLE t1; +SET GLOBAL query_cache_size= DEFAULT; +SET GLOBAL query_cache_type= DEFAULT; diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index a10e470afd4..b68355206b5 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -334,6 +334,7 @@ TODO list: #include "tztime.h" // struct Time_zone #include "sql_acl.h" // SELECT_ACL #include "sql_base.h" // TMP_TABLE_KEY_EXTRA +#include "debug_sync.h" // DEBUG_SYNC #ifdef HAVE_QUERY_CACHE #include #include @@ -372,30 +373,32 @@ TODO list: #define DUMP(C) DBUG_EXECUTE("qcache", {\ (C)->cache_dump(); (C)->queries_dump();(C)->tables_dump();}) - /** - Causes the thread to wait in a spin lock for a query kill signal. - This function is used by the test frame work to identify race conditions. - - The signal is caught and ignored and the thread is not killed. + Thread state to be used when the query cache lock needs to be acquired. + Sets the thread state name in the constructor, resets on destructor. */ -static void debug_wait_for_kill(const char *info) +struct Query_cache_wait_state { - DBUG_ENTER("debug_wait_for_kill"); - const char *prev_info; - THD *thd; - thd= current_thd; - prev_info= thd->proc_info; - thd->proc_info= info; - sql_print_information("%s", info); - while(!thd->killed) - my_sleep(1000); - thd->killed= THD::NOT_KILLED; - sql_print_information("Exit debug_wait_for_kill"); - thd->proc_info= prev_info; - DBUG_VOID_RETURN; -} + THD *m_thd; + const char *m_proc_info; + + Query_cache_wait_state(THD *thd, const char *func, + const char *file, unsigned int line) + : m_thd(thd) + { + if (m_thd) + m_proc_info= set_thd_proc_info(m_thd, + "Waiting for query cache lock", + func, file, line); + } + + ~Query_cache_wait_state() + { + if (m_thd) + set_thd_proc_info(m_thd, m_proc_info, NULL, NULL, 0); + } +}; #else #define RW_WLOCK(M) mysql_rwlock_wrlock(M) @@ -429,6 +432,8 @@ static void debug_wait_for_kill(const char *info) bool Query_cache::try_lock(bool use_timeout) { bool interrupt= FALSE; + THD *thd= current_thd; + Query_cache_wait_state wait_state(thd, __func__, __FILE__, __LINE__); DBUG_ENTER("Query_cache::try_lock"); mysql_mutex_lock(&structure_guard_mutex); @@ -438,7 +443,6 @@ bool Query_cache::try_lock(bool use_timeout) { m_cache_lock_status= Query_cache::LOCKED; #ifndef DBUG_OFF - THD *thd= current_thd; if (thd) m_cache_lock_thread_id= thd->thread_id; #endif @@ -497,6 +501,8 @@ bool Query_cache::try_lock(bool use_timeout) void Query_cache::lock_and_suspend(void) { + THD *thd= current_thd; + Query_cache_wait_state wait_state(thd, __func__, __FILE__, __LINE__); DBUG_ENTER("Query_cache::lock_and_suspend"); mysql_mutex_lock(&structure_guard_mutex); @@ -504,7 +510,6 @@ void Query_cache::lock_and_suspend(void) mysql_cond_wait(&COND_cache_status_changed, &structure_guard_mutex); m_cache_lock_status= Query_cache::LOCKED_NO_WAIT; #ifndef DBUG_OFF - THD *thd= current_thd; if (thd) m_cache_lock_thread_id= thd->thread_id; #endif @@ -525,6 +530,8 @@ void Query_cache::lock_and_suspend(void) void Query_cache::lock(void) { + THD *thd= current_thd; + Query_cache_wait_state wait_state(thd, __func__, __FILE__, __LINE__); DBUG_ENTER("Query_cache::lock"); mysql_mutex_lock(&structure_guard_mutex); @@ -532,7 +539,6 @@ void Query_cache::lock(void) mysql_cond_wait(&COND_cache_status_changed, &structure_guard_mutex); m_cache_lock_status= Query_cache::LOCKED; #ifndef DBUG_OFF - THD *thd= current_thd; if (thd) m_cache_lock_thread_id= thd->thread_id; #endif @@ -872,9 +878,7 @@ Query_cache::insert(Query_cache_tls *query_cache_tls, if (is_disabled() || query_cache_tls->first_query_block == NULL) DBUG_VOID_RETURN; - DBUG_EXECUTE_IF("wait_in_query_cache_insert", - debug_wait_for_kill("wait_in_query_cache_insert"); ); - + DEBUG_SYNC(current_thd, "wait_in_query_cache_insert"); if (try_lock()) DBUG_VOID_RETURN; @@ -1779,8 +1783,7 @@ void Query_cache::invalidate(THD *thd, TABLE_LIST *tables_used, invalidate_table(thd, tables_used); } - DBUG_EXECUTE_IF("wait_after_query_cache_invalidate", - debug_wait_for_kill("wait_after_query_cache_invalidate");); + DEBUG_SYNC(thd, "wait_after_query_cache_invalidate"); DBUG_VOID_RETURN; } @@ -1971,8 +1974,7 @@ void Query_cache::flush() if (is_disabled()) DBUG_VOID_RETURN; - DBUG_EXECUTE_IF("wait_in_query_cache_flush1", - debug_wait_for_kill("wait_in_query_cache_flush1");); + DEBUG_SYNC(current_thd, "wait_in_query_cache_flush1"); lock_and_suspend(); if (query_cache_size > 0) @@ -2312,9 +2314,7 @@ void Query_cache::free_cache() void Query_cache::flush_cache() { - - DBUG_EXECUTE_IF("wait_in_query_cache_flush2", - debug_wait_for_kill("wait_in_query_cache_flush2");); + DEBUG_SYNC(current_thd, "wait_in_query_cache_flush2"); my_hash_reset(&queries); while (queries_blocks != 0) @@ -2760,8 +2760,7 @@ void Query_cache::invalidate_table(THD *thd, TABLE *table) void Query_cache::invalidate_table(THD *thd, uchar * key, uint32 key_length) { - DBUG_EXECUTE_IF("wait_in_query_cache_invalidate1", - debug_wait_for_kill("wait_in_query_cache_invalidate1"); ); + DEBUG_SYNC(thd, "wait_in_query_cache_invalidate1"); /* Lock the query cache and queue all invalidation attempts to avoid @@ -2769,9 +2768,7 @@ void Query_cache::invalidate_table(THD *thd, uchar * key, uint32 key_length) */ lock(); - DBUG_EXECUTE_IF("wait_in_query_cache_invalidate2", - debug_wait_for_kill("wait_in_query_cache_invalidate2"); ); - + DEBUG_SYNC(thd, "wait_in_query_cache_invalidate2"); if (query_cache_size > 0) invalidate_table_internal(thd, key, key_length); @@ -2821,7 +2818,6 @@ Query_cache::invalidate_query_block_list(THD *thd, Query_cache_block *query_block= list_root->next->block(); BLOCK_LOCK_WR(query_block); free_query(query_block); - DBUG_EXECUTE_IF("debug_cache_locks", sleep(10);); } } From ea4c11f923b570624e541dfece9767d4551fdc81 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Thu, 7 Oct 2010 21:05:23 -0300 Subject: [PATCH 25/47] Bug#56822: Add a thread state for sessions waiting on the query cache lock Move Query_cache_wait_state declaration out of a debug block. --- sql/sql_cache.cc | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index b68355206b5..8c3abdbf1b0 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -372,6 +372,17 @@ TODO list: __LINE__,(ulong)(B)));B->query()->unlock_reading();} #define DUMP(C) DBUG_EXECUTE("qcache", {\ (C)->cache_dump(); (C)->queries_dump();(C)->tables_dump();}) +#else +#define RW_WLOCK(M) mysql_rwlock_wrlock(M) +#define RW_RLOCK(M) mysql_rwlock_rdlock(M) +#define RW_UNLOCK(M) mysql_rwlock_unlock(M) +#define BLOCK_LOCK_WR(B) B->query()->lock_writing() +#define BLOCK_LOCK_RD(B) B->query()->lock_reading() +#define BLOCK_UNLOCK_WR(B) B->query()->unlock_writing() +#define BLOCK_UNLOCK_RD(B) B->query()->unlock_reading() +#define DUMP(C) +#endif + /** Thread state to be used when the query cache lock needs to be acquired. @@ -400,16 +411,6 @@ struct Query_cache_wait_state } }; -#else -#define RW_WLOCK(M) mysql_rwlock_wrlock(M) -#define RW_RLOCK(M) mysql_rwlock_rdlock(M) -#define RW_UNLOCK(M) mysql_rwlock_unlock(M) -#define BLOCK_LOCK_WR(B) B->query()->lock_writing() -#define BLOCK_LOCK_RD(B) B->query()->lock_reading() -#define BLOCK_UNLOCK_WR(B) B->query()->unlock_writing() -#define BLOCK_UNLOCK_RD(B) B->query()->unlock_reading() -#define DUMP(C) -#endif /** Serialize access to the query cache. From 96c99602d4ef2b67b15ec5fb5676ad1a45e9a805 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Thu, 7 Oct 2010 21:53:00 -0300 Subject: [PATCH 26/47] Bug#45288: pb2 returns a lot of compilation warnings on linux Fix warnings related to the use of the deprecated gets() function and passing NULL to non-pointer argument of the sys_var constructor. --- plugin/auth/dialog.c | 17 ++++++++++------- sql/sys_vars.h | 8 +++----- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/plugin/auth/dialog.c b/plugin/auth/dialog.c index b7c65b3d601..54f88dd9b4e 100644 --- a/plugin/auth/dialog.c +++ b/plugin/auth/dialog.c @@ -1,15 +1,15 @@ /* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. - + 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 */ @@ -181,7 +181,7 @@ mysql_declare_plugin_end; To support all this variety, the dialog plugin has a callback function "authentication_dialog_ask". If the client has a function of this name dialog plugin will use it for communication with the user. Otherwise - a default gets() based implementation will be used. + a default fgets() based implementation will be used. */ /** @@ -208,12 +208,15 @@ static mysql_authentication_dialog_ask_t ask; static char *builtin_ask(MYSQL *mysql __attribute__((unused)), int type __attribute__((unused)), const char *prompt, - char *buf, int buf_len __attribute__((unused))) + char *buf, int buf_len) { + char *ptr; fputs(prompt, stdout); fputc(' ', stdout); - if (gets(buf) == 0) - return 0; + if (fgets(buf, buf_len, stdin) == NULL) + return NULL; + if ((ptr= strchr(buf, '\n'))) + *ptr= 0; return buf; } diff --git a/sql/sys_vars.h b/sql/sys_vars.h index 89e2bdfdf60..e16bd3c5330 100644 --- a/sql/sys_vars.h +++ b/sql/sys_vars.h @@ -458,12 +458,10 @@ class Sys_var_proxy_user: public sys_var public: Sys_var_proxy_user(const char *name_arg, const char *comment, enum charset_enum is_os_charset_arg) - : sys_var(&all_sys_vars, name_arg, comment, + : sys_var(&all_sys_vars, name_arg, comment, sys_var::READONLY+sys_var::ONLY_SESSION, 0, -1, - NO_ARG, SHOW_CHAR, (intptr)NULL, - 0, VARIABLE_NOT_IN_BINLOG, - 0, 0, - 0, 0, PARSE_NORMAL) + NO_ARG, SHOW_CHAR, 0, NULL, VARIABLE_NOT_IN_BINLOG, + NULL, NULL, 0, NULL, PARSE_NORMAL) { is_os_charset= is_os_charset_arg == IN_FS_CHARSET; option.var_type= GET_STR; From 6adb077efc36ef068826aea8050d615e71fa450f Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Fri, 8 Oct 2010 12:09:47 +0500 Subject: [PATCH 27/47] Bug#35269 mysqlcheck behaves different depending on order of parameters Issue an error if user specifies multiple commands to run. Also there was an unnoticed bug that DO_CHECK was actually 0 which lead to wrong actions in some cases. The mysqlcheck.test contained commands with the suspicious meaning for the above reason. Extra commands removed from there. per-file commands: client/mysqlcheck.c Bug#35269 mysqlcheck behaves different depending on order of parameters Drop with an error if multiple commands. mysql-test/r/mysqlcheck.result Bug#35269 mysqlcheck behaves different depending on order of parameters result completed. mysql-test/t/mysqlcheck.test Bug#35269 mysqlcheck behaves different depending on order of parameters testcase added. not-working commands removed from some mysqlcheck calls. --- client/mysqlcheck.c | 11 +++++- mysql-test/r/mysqlcheck.result | 64 ++++++++++++++++++++++++++++++++-- mysql-test/t/mysqlcheck.test | 29 +++++++++++---- 3 files changed, 95 insertions(+), 9 deletions(-) diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c index aebe80b9ba6..7b188d7ce18 100644 --- a/client/mysqlcheck.c +++ b/client/mysqlcheck.c @@ -47,7 +47,7 @@ static char *shared_memory_base_name=0; #endif static uint opt_protocol=0; -enum operations { DO_CHECK, DO_REPAIR, DO_ANALYZE, DO_OPTIMIZE, DO_UPGRADE }; +enum operations { DO_CHECK=1, DO_REPAIR, DO_ANALYZE, DO_OPTIMIZE, DO_UPGRADE }; static struct my_option my_long_options[] = { @@ -241,6 +241,8 @@ static my_bool get_one_option(int optid, const struct my_option *opt __attribute__((unused)), char *argument) { + int orig_what_to_do= what_to_do; + switch(optid) { case 'a': what_to_do = DO_ANALYZE; @@ -315,6 +317,13 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), opt->name); break; } + + if (orig_what_to_do && (what_to_do != orig_what_to_do)) + { + fprintf(stderr, "Error: %s doesn't support multiple contradicting commands.\n", + my_progname); + return 1; + } return 0; } diff --git a/mysql-test/r/mysqlcheck.result b/mysql-test/r/mysqlcheck.result index c51d71510f4..241c92f0aa6 100644 --- a/mysql-test/r/mysqlcheck.result +++ b/mysql-test/r/mysqlcheck.result @@ -8,7 +8,7 @@ mysql.db OK mysql.event OK mysql.func OK mysql.general_log -note : The storage engine for the table doesn't support optimize +note : The storage engine for the table doesn't support analyze mysql.help_category OK mysql.help_keyword OK mysql.help_relation OK @@ -21,7 +21,7 @@ mysql.procs_priv OK mysql.proxy_priv OK mysql.servers OK mysql.slow_log -note : The storage engine for the table doesn't support optimize +note : The storage engine for the table doesn't support analyze mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK @@ -29,6 +29,8 @@ mysql.time_zone_name OK mysql.time_zone_transition OK mysql.time_zone_transition_type OK mysql.user OK +mtr.global_suppressions Table is already up to date +mtr.test_suppressions Table is already up to date mysql.columns_priv OK mysql.db OK mysql.event OK @@ -55,10 +57,64 @@ mysql.time_zone_name OK mysql.time_zone_transition OK mysql.time_zone_transition_type OK mysql.user OK +mysql.columns_priv OK +mysql.db OK +mysql.event OK +mysql.func OK +mysql.general_log +note : The storage engine for the table doesn't support analyze +mysql.help_category OK +mysql.help_keyword OK +mysql.help_relation OK +mysql.help_topic OK +mysql.host OK +mysql.ndb_binlog_index OK +mysql.plugin OK +mysql.proc OK +mysql.procs_priv OK +mysql.proxy_priv OK +mysql.servers OK +mysql.slow_log +note : The storage engine for the table doesn't support analyze +mysql.tables_priv OK +mysql.time_zone OK +mysql.time_zone_leap_second OK +mysql.time_zone_name OK +mysql.time_zone_transition OK +mysql.time_zone_transition_type OK +mysql.user OK +mysql.columns_priv Table is already up to date +mysql.db Table is already up to date +mysql.event Table is already up to date +mysql.func Table is already up to date +mysql.general_log +note : The storage engine for the table doesn't support optimize +mysql.help_category Table is already up to date +mysql.help_keyword Table is already up to date +mysql.help_relation Table is already up to date +mysql.help_topic Table is already up to date +mysql.host Table is already up to date +mysql.ndb_binlog_index Table is already up to date +mysql.plugin Table is already up to date +mysql.proc Table is already up to date +mysql.procs_priv Table is already up to date +mysql.proxy_priv Table is already up to date +mysql.servers Table is already up to date +mysql.slow_log +note : The storage engine for the table doesn't support optimize +mysql.tables_priv Table is already up to date +mysql.time_zone Table is already up to date +mysql.time_zone_leap_second Table is already up to date +mysql.time_zone_name Table is already up to date +mysql.time_zone_transition Table is already up to date +mysql.time_zone_transition_type Table is already up to date +mysql.user Table is already up to date create table t1 (a int); create view v1 as select * from t1; test.t1 OK +test.t1 Table is already up to date test.t1 OK +test.t1 Table is already up to date drop view v1; drop table t1; create table `t``1`(a int); @@ -127,6 +183,7 @@ Tables_in_test t1 #mysql50#v-1 v1 +test.t1 OK show tables; Tables_in_test t1 @@ -200,3 +257,6 @@ Tables_in_test (t1-1) t1-1 drop table `t1-1`; End of 5.1 tests +# +# Bug #35269: mysqlcheck behaves different depending on order of parameters +# diff --git a/mysql-test/t/mysqlcheck.test b/mysql-test/t/mysqlcheck.test index 831aba72fb5..dd113cb4e74 100644 --- a/mysql-test/t/mysqlcheck.test +++ b/mysql-test/t/mysqlcheck.test @@ -23,10 +23,13 @@ drop database if exists client_test_db; # Bug #13783 mysqlcheck tries to optimize and analyze information_schema # --replace_result 'Table is already up to date' OK ---exec $MYSQL_CHECK --all-databases --analyze --optimize +--exec $MYSQL_CHECK --all-databases --analyze +--exec $MYSQL_CHECK --all-databases --optimize --replace_result 'Table is already up to date' OK ---exec $MYSQL_CHECK --analyze --optimize --databases test information_schema mysql ---exec $MYSQL_CHECK --analyze --optimize information_schema schemata +--exec $MYSQL_CHECK --analyze --databases test information_schema mysql +--exec $MYSQL_CHECK --optimize --databases test information_schema mysql +--exec $MYSQL_CHECK --analyze information_schema schemata +--exec $MYSQL_CHECK --optimize information_schema schemata # # Bug #16502: mysqlcheck tries to check views @@ -34,9 +37,11 @@ drop database if exists client_test_db; create table t1 (a int); create view v1 as select * from t1; --replace_result 'Table is already up to date' OK ---exec $MYSQL_CHECK --analyze --optimize --databases test +--exec $MYSQL_CHECK --analyze --databases test +--exec $MYSQL_CHECK --optimize --databases test --replace_result 'Table is already up to date' OK ---exec $MYSQL_CHECK --all-in-1 --analyze --optimize --databases test +--exec $MYSQL_CHECK --all-in-1 --analyze --databases test +--exec $MYSQL_CHECK --all-in-1 --optimize --databases test drop view v1; drop table t1; @@ -113,7 +118,8 @@ show tables; let $MYSQLD_DATADIR= `select @@datadir`; --copy_file $MYSQLD_DATADIR/test/v1.frm $MYSQLD_DATADIR/test/v-1.frm show tables; ---exec $MYSQL_CHECK --check-upgrade --fix-table-names --databases test +--exec $MYSQL_CHECK --check-upgrade --databases test +--exec $MYSQL_CHECK --fix-table-names --databases test show tables; drop view v1, `v-1`; drop table t1; @@ -212,3 +218,14 @@ show tables like 't1-1'; drop table `t1-1`; --echo End of 5.1 tests + + +--echo # +--echo # Bug #35269: mysqlcheck behaves different depending on order of parameters +--echo # + +--error 13 +--exec $MYSQL_CHECK -a --fix-table-names test "#mysql50#t1-1" +--error 1 +--exec $MYSQL_CHECK -aoc test "#mysql50#t1-1" + From a3983787764d82e312e28f6f65fa86750e491fec Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Fri, 8 Oct 2010 12:12:18 +0500 Subject: [PATCH 28/47] Bug#30025 Mysqld prints out warnings/errors being run with --no-defaults --help now do no initializations for the --help. Do it for --verbose --help though. per-file comments: sql/mysqld.cc Bug#30025 Mysqld prints out warnings/errors being run with --no-defaults --help quit with the help message at once as --help was given --- sql/mysqld.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index e43320f12a5..e489d466d5f 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -3202,6 +3202,11 @@ static int init_common_variables() return 1; set_server_version(); +#ifndef EMBEDDED_LIBRARY + if (opt_help && !opt_verbose) + unireg_abort(0); +#endif /*!EMBEDDED_LIBRARY*/ + DBUG_PRINT("info",("%s Ver %s for %s on %s\n",my_progname, server_version, SYSTEM_TYPE,MACHINE_TYPE)); From b2ccb7d0fe31798779f58fcd77436b9cc293d063 Mon Sep 17 00:00:00 2001 From: Sergey Vojtovich Date: Fri, 8 Oct 2010 13:20:42 +0400 Subject: [PATCH 29/47] Fixed plugin_load_option failure, when example storage engine is not available. We need to add loose prefix to example load option. --- mysql-test/t/plugin_load_option-master.opt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/t/plugin_load_option-master.opt b/mysql-test/t/plugin_load_option-master.opt index 3be53c3b713..e22ecb4ff3a 100644 --- a/mysql-test/t/plugin_load_option-master.opt +++ b/mysql-test/t/plugin_load_option-master.opt @@ -1,3 +1,3 @@ $EXAMPLE_PLUGIN_OPT $EXAMPLE_PLUGIN_LOAD ---plugin-example=FORCE_PLUS_PERMANENT +--loose-plugin-example=FORCE_PLUS_PERMANENT From 2e1c48e0697c140f5c2265d1a3d065c5ad057b5b Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Fri, 8 Oct 2010 12:34:08 +0300 Subject: [PATCH 30/47] Adjust results files after innodb_file_per_table became 0. In calvin.sun@oracle.com-20101005183830-p81bemgffq8l2en9 the default value of innodb_file_per_table was changed from 1 to 0. --- .../parts/r/partition_alter3_innodb.result | 94 ---- .../parts/r/partition_basic_innodb.result | 432 ------------------ 2 files changed, 526 deletions(-) diff --git a/mysql-test/suite/parts/r/partition_alter3_innodb.result b/mysql-test/suite/parts/r/partition_alter3_innodb.result index c5750e007e6..7825a2350b0 100644 --- a/mysql-test/suite/parts/r/partition_alter3_innodb.result +++ b/mysql-test/suite/parts/r/partition_alter3_innodb.result @@ -57,7 +57,6 @@ t1 CREATE TABLE `t1` ( `f_varchar` varchar(30) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 t1.frm -t1.ibd EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 20 Using where @@ -79,7 +78,6 @@ t1 CREATE TABLE `t1` ( `f_varchar` varchar(30) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 /*!50100 PARTITION BY HASH (YEAR(f_date)) */ -t1#P#p0.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; @@ -98,7 +96,6 @@ t1 CREATE TABLE `t1` ( `f_varchar` varchar(30) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 /*!50100 PARTITION BY HASH (DAYOFYEAR(f_date)) */ -t1#P#p0.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; @@ -115,7 +112,6 @@ t1 CREATE TABLE `t1` ( `f_varchar` varchar(30) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 /*!50100 PARTITION BY HASH (YEAR(f_date)) */ -t1#P#p0.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; @@ -141,9 +137,6 @@ t1 CREATE TABLE `t1` ( (PARTITION p0 ENGINE = InnoDB, PARTITION part1 ENGINE = InnoDB, PARTITION part7 ENGINE = InnoDB) */ -t1#P#p0.ibd -t1#P#part1.ibd -t1#P#part7.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; @@ -168,10 +161,6 @@ t1 CREATE TABLE `t1` ( PARTITION part1 ENGINE = InnoDB, PARTITION part7 ENGINE = InnoDB, PARTITION part2 ENGINE = InnoDB) */ -t1#P#p0.ibd -t1#P#part1.ibd -t1#P#part2.ibd -t1#P#part7.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; @@ -197,14 +186,6 @@ t1 CREATE TABLE `t1` ( PARTITION p5 ENGINE = InnoDB, PARTITION p6 ENGINE = InnoDB, PARTITION p7 ENGINE = InnoDB) */ -t1#P#p0.ibd -t1#P#p4.ibd -t1#P#p5.ibd -t1#P#p6.ibd -t1#P#p7.ibd -t1#P#part1.ibd -t1#P#part2.ibd -t1#P#part7.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; @@ -241,13 +222,6 @@ t1 CREATE TABLE `t1` ( PARTITION p4 ENGINE = InnoDB, PARTITION p5 ENGINE = InnoDB, PARTITION p6 ENGINE = InnoDB) */ -t1#P#p0.ibd -t1#P#p4.ibd -t1#P#p5.ibd -t1#P#p6.ibd -t1#P#part1.ibd -t1#P#part2.ibd -t1#P#part7.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; @@ -270,12 +244,6 @@ t1 CREATE TABLE `t1` ( PARTITION part2 ENGINE = InnoDB, PARTITION p4 ENGINE = InnoDB, PARTITION p5 ENGINE = InnoDB) */ -t1#P#p0.ibd -t1#P#p4.ibd -t1#P#p5.ibd -t1#P#part1.ibd -t1#P#part2.ibd -t1#P#part7.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; @@ -297,11 +265,6 @@ t1 CREATE TABLE `t1` ( PARTITION part7 ENGINE = InnoDB, PARTITION part2 ENGINE = InnoDB, PARTITION p4 ENGINE = InnoDB) */ -t1#P#p0.ibd -t1#P#p4.ibd -t1#P#part1.ibd -t1#P#part2.ibd -t1#P#part7.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; @@ -322,10 +285,6 @@ t1 CREATE TABLE `t1` ( PARTITION part1 ENGINE = InnoDB, PARTITION part7 ENGINE = InnoDB, PARTITION part2 ENGINE = InnoDB) */ -t1#P#p0.ibd -t1#P#part1.ibd -t1#P#part2.ibd -t1#P#part7.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; @@ -345,9 +304,6 @@ t1 CREATE TABLE `t1` ( (PARTITION p0 ENGINE = InnoDB, PARTITION part1 ENGINE = InnoDB, PARTITION part7 ENGINE = InnoDB) */ -t1#P#p0.ibd -t1#P#part1.ibd -t1#P#part7.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; @@ -366,8 +322,6 @@ t1 CREATE TABLE `t1` ( /*!50100 PARTITION BY HASH (YEAR(f_date)) (PARTITION p0 ENGINE = InnoDB, PARTITION part1 ENGINE = InnoDB) */ -t1#P#p0.ibd -t1#P#part1.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; @@ -385,7 +339,6 @@ t1 CREATE TABLE `t1` ( ) ENGINE=InnoDB DEFAULT CHARSET=latin1 /*!50100 PARTITION BY HASH (YEAR(f_date)) (PARTITION p0 ENGINE = InnoDB) */ -t1#P#p0.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; @@ -406,7 +359,6 @@ t1 CREATE TABLE `t1` ( `f_varchar` varchar(30) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 t1.frm -t1.ibd EXPLAIN PARTITIONS SELECT COUNT(*) FROM t1 WHERE f_date = '1000-02-10'; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 20 Using where @@ -446,7 +398,6 @@ t1 CREATE TABLE `t1` ( `f_charbig` varchar(1000) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 t1.frm -t1.ibd EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 20 Using where @@ -469,7 +420,6 @@ t1 CREATE TABLE `t1` ( `f_charbig` varchar(1000) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 /*!50100 PARTITION BY KEY (f_int1) */ -t1#P#p0.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; @@ -498,9 +448,6 @@ t1 CREATE TABLE `t1` ( (PARTITION p0 ENGINE = InnoDB, PARTITION part1 ENGINE = InnoDB, PARTITION part7 ENGINE = InnoDB) */ -t1#P#p0.ibd -t1#P#part1.ibd -t1#P#part7.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; @@ -525,10 +472,6 @@ t1 CREATE TABLE `t1` ( PARTITION part1 ENGINE = InnoDB, PARTITION part7 ENGINE = InnoDB, PARTITION part2 ENGINE = InnoDB) */ -t1#P#p0.ibd -t1#P#part1.ibd -t1#P#part2.ibd -t1#P#part7.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; @@ -557,14 +500,6 @@ t1 CREATE TABLE `t1` ( PARTITION p5 ENGINE = InnoDB, PARTITION p6 ENGINE = InnoDB, PARTITION p7 ENGINE = InnoDB) */ -t1#P#p0.ibd -t1#P#p4.ibd -t1#P#p5.ibd -t1#P#p6.ibd -t1#P#p7.ibd -t1#P#part1.ibd -t1#P#part2.ibd -t1#P#part7.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; @@ -599,13 +534,6 @@ t1 CREATE TABLE `t1` ( PARTITION p4 ENGINE = InnoDB, PARTITION p5 ENGINE = InnoDB, PARTITION p6 ENGINE = InnoDB) */ -t1#P#p0.ibd -t1#P#p4.ibd -t1#P#p5.ibd -t1#P#p6.ibd -t1#P#part1.ibd -t1#P#part2.ibd -t1#P#part7.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; @@ -631,12 +559,6 @@ t1 CREATE TABLE `t1` ( PARTITION part2 ENGINE = InnoDB, PARTITION p4 ENGINE = InnoDB, PARTITION p5 ENGINE = InnoDB) */ -t1#P#p0.ibd -t1#P#p4.ibd -t1#P#p5.ibd -t1#P#part1.ibd -t1#P#part2.ibd -t1#P#part7.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; @@ -661,11 +583,6 @@ t1 CREATE TABLE `t1` ( PARTITION part7 ENGINE = InnoDB, PARTITION part2 ENGINE = InnoDB, PARTITION p4 ENGINE = InnoDB) */ -t1#P#p0.ibd -t1#P#p4.ibd -t1#P#part1.ibd -t1#P#part2.ibd -t1#P#part7.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; @@ -689,10 +606,6 @@ t1 CREATE TABLE `t1` ( PARTITION part1 ENGINE = InnoDB, PARTITION part7 ENGINE = InnoDB, PARTITION part2 ENGINE = InnoDB) */ -t1#P#p0.ibd -t1#P#part1.ibd -t1#P#part2.ibd -t1#P#part7.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; @@ -715,9 +628,6 @@ t1 CREATE TABLE `t1` ( (PARTITION p0 ENGINE = InnoDB, PARTITION part1 ENGINE = InnoDB, PARTITION part7 ENGINE = InnoDB) */ -t1#P#p0.ibd -t1#P#part1.ibd -t1#P#part7.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; @@ -739,8 +649,6 @@ t1 CREATE TABLE `t1` ( /*!50100 PARTITION BY KEY (f_int1) (PARTITION p0 ENGINE = InnoDB, PARTITION part1 ENGINE = InnoDB) */ -t1#P#p0.ibd -t1#P#part1.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; @@ -761,7 +669,6 @@ t1 CREATE TABLE `t1` ( ) ENGINE=InnoDB DEFAULT CHARSET=latin1 /*!50100 PARTITION BY KEY (f_int1) (PARTITION p0 ENGINE = InnoDB) */ -t1#P#p0.ibd t1.frm t1.par EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; @@ -785,7 +692,6 @@ t1 CREATE TABLE `t1` ( `f_charbig` varchar(1000) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1 t1.frm -t1.ibd EXPLAIN PARTITIONS SELECT COUNT(*) <> 1 FROM t1 WHERE f_int1 = 3; id select_type table partitions type possible_keys key key_len ref rows Extra 1 SIMPLE t1 NULL ALL NULL NULL NULL NULL 20 Using where diff --git a/mysql-test/suite/parts/r/partition_basic_innodb.result b/mysql-test/suite/parts/r/partition_basic_innodb.result index c6a89e970b3..21c5d70e6e3 100644 --- a/mysql-test/suite/parts/r/partition_basic_innodb.result +++ b/mysql-test/suite/parts/r/partition_basic_innodb.result @@ -77,8 +77,6 @@ t1 CREATE TABLE `t1` ( PARTITIONS 2 */ unified filelist -t1#P#p0.ibd -t1#P#p1.ibd t1.frm t1.par @@ -534,11 +532,6 @@ t1 CREATE TABLE `t1` ( PARTITIONS 5 */ unified filelist -t1#P#p0.ibd -t1#P#p1.ibd -t1#P#p2.ibd -t1#P#p3.ibd -t1#P#p4.ibd t1.frm t1.par @@ -1009,14 +1002,6 @@ t1 CREATE TABLE `t1` ( PARTITION part3 VALUES IN (3) ENGINE = InnoDB) */ unified filelist -t1#P#part0.ibd -t1#P#part1.ibd -t1#P#part2.ibd -t1#P#part3.ibd -t1#P#part_1.ibd -t1#P#part_2.ibd -t1#P#part_3.ibd -t1#P#part_N.ibd t1.frm t1.par @@ -1483,12 +1468,6 @@ t1 CREATE TABLE `t1` ( PARTITION partf VALUES LESS THAN (2147483646) ENGINE = InnoDB) */ unified filelist -t1#P#parta.ibd -t1#P#partb.ibd -t1#P#partc.ibd -t1#P#partd.ibd -t1#P#parte.ibd -t1#P#partf.ibd t1.frm t1.par @@ -1951,14 +1930,6 @@ SUBPARTITIONS 2 PARTITION partd VALUES LESS THAN (2147483646) ENGINE = InnoDB) */ unified filelist -t1#P#parta#SP#partasp0.ibd -t1#P#parta#SP#partasp1.ibd -t1#P#partb#SP#partbsp0.ibd -t1#P#partb#SP#partbsp1.ibd -t1#P#partc#SP#partcsp0.ibd -t1#P#partc#SP#partcsp1.ibd -t1#P#partd#SP#partdsp0.ibd -t1#P#partd#SP#partdsp1.ibd t1.frm t1.par @@ -2434,14 +2405,6 @@ SUBPARTITION BY KEY (f_int1) SUBPARTITION subpart42 ENGINE = InnoDB)) */ unified filelist -t1#P#part1#SP#subpart11.ibd -t1#P#part1#SP#subpart12.ibd -t1#P#part2#SP#subpart21.ibd -t1#P#part2#SP#subpart22.ibd -t1#P#part3#SP#subpart31.ibd -t1#P#part3#SP#subpart32.ibd -t1#P#part4#SP#subpart41.ibd -t1#P#part4#SP#subpart42.ibd t1.frm t1.par @@ -2919,14 +2882,6 @@ SUBPARTITION BY HASH (f_int1 + 1) SUBPARTITION sp42 ENGINE = InnoDB)) */ unified filelist -t1#P#part1#SP#sp11.ibd -t1#P#part1#SP#sp12.ibd -t1#P#part2#SP#sp21.ibd -t1#P#part2#SP#sp22.ibd -t1#P#part3#SP#sp31.ibd -t1#P#part3#SP#sp32.ibd -t1#P#part4#SP#sp41.ibd -t1#P#part4#SP#sp42.ibd t1.frm t1.par @@ -3390,15 +3345,6 @@ SUBPARTITIONS 3 PARTITION part3 VALUES IN (NULL) ENGINE = InnoDB) */ unified filelist -t1#P#part1#SP#part1sp0.ibd -t1#P#part1#SP#part1sp1.ibd -t1#P#part1#SP#part1sp2.ibd -t1#P#part2#SP#part2sp0.ibd -t1#P#part2#SP#part2sp1.ibd -t1#P#part2#SP#part2sp2.ibd -t1#P#part3#SP#part3sp0.ibd -t1#P#part3#SP#part3sp1.ibd -t1#P#part3#SP#part3sp2.ibd t1.frm t1.par @@ -3856,8 +3802,6 @@ t1 CREATE TABLE `t1` ( PARTITIONS 2 */ unified filelist -t1#P#p0.ibd -t1#P#p1.ibd t1.frm t1.par @@ -4313,11 +4257,6 @@ t1 CREATE TABLE `t1` ( PARTITIONS 5 */ unified filelist -t1#P#p0.ibd -t1#P#p1.ibd -t1#P#p2.ibd -t1#P#p3.ibd -t1#P#p4.ibd t1.frm t1.par @@ -4788,14 +4727,6 @@ t1 CREATE TABLE `t1` ( PARTITION part3 VALUES IN (3) ENGINE = InnoDB) */ unified filelist -t1#P#part0.ibd -t1#P#part1.ibd -t1#P#part2.ibd -t1#P#part3.ibd -t1#P#part_1.ibd -t1#P#part_2.ibd -t1#P#part_3.ibd -t1#P#part_N.ibd t1.frm t1.par @@ -5262,12 +5193,6 @@ t1 CREATE TABLE `t1` ( PARTITION partf VALUES LESS THAN (2147483646) ENGINE = InnoDB) */ unified filelist -t1#P#parta.ibd -t1#P#partb.ibd -t1#P#partc.ibd -t1#P#partd.ibd -t1#P#parte.ibd -t1#P#partf.ibd t1.frm t1.par @@ -5730,14 +5655,6 @@ SUBPARTITIONS 2 PARTITION partd VALUES LESS THAN (2147483646) ENGINE = InnoDB) */ unified filelist -t1#P#parta#SP#partasp0.ibd -t1#P#parta#SP#partasp1.ibd -t1#P#partb#SP#partbsp0.ibd -t1#P#partb#SP#partbsp1.ibd -t1#P#partc#SP#partcsp0.ibd -t1#P#partc#SP#partcsp1.ibd -t1#P#partd#SP#partdsp0.ibd -t1#P#partd#SP#partdsp1.ibd t1.frm t1.par @@ -6211,14 +6128,6 @@ SUBPARTITION BY KEY (f_int2) SUBPARTITION subpart42 ENGINE = InnoDB)) */ unified filelist -t1#P#part1#SP#subpart11.ibd -t1#P#part1#SP#subpart12.ibd -t1#P#part2#SP#subpart21.ibd -t1#P#part2#SP#subpart22.ibd -t1#P#part3#SP#subpart31.ibd -t1#P#part3#SP#subpart32.ibd -t1#P#part4#SP#subpart41.ibd -t1#P#part4#SP#subpart42.ibd t1.frm t1.par @@ -6692,14 +6601,6 @@ SUBPARTITION BY HASH (f_int2 + 1) SUBPARTITION sp42 ENGINE = InnoDB)) */ unified filelist -t1#P#part1#SP#sp11.ibd -t1#P#part1#SP#sp12.ibd -t1#P#part2#SP#sp21.ibd -t1#P#part2#SP#sp22.ibd -t1#P#part3#SP#sp31.ibd -t1#P#part3#SP#sp32.ibd -t1#P#part4#SP#sp41.ibd -t1#P#part4#SP#sp42.ibd t1.frm t1.par @@ -7163,15 +7064,6 @@ SUBPARTITIONS 3 PARTITION part3 VALUES IN (NULL) ENGINE = InnoDB) */ unified filelist -t1#P#part1#SP#part1sp0.ibd -t1#P#part1#SP#part1sp1.ibd -t1#P#part1#SP#part1sp2.ibd -t1#P#part2#SP#part2sp0.ibd -t1#P#part2#SP#part2sp1.ibd -t1#P#part2#SP#part2sp2.ibd -t1#P#part3#SP#part3sp0.ibd -t1#P#part3#SP#part3sp1.ibd -t1#P#part3#SP#part3sp2.ibd t1.frm t1.par @@ -7635,8 +7527,6 @@ t1 CREATE TABLE `t1` ( PARTITIONS 2 */ unified filelist -t1#P#p0.ibd -t1#P#p1.ibd t1.frm t1.par @@ -8129,11 +8019,6 @@ t1 CREATE TABLE `t1` ( PARTITIONS 5 */ unified filelist -t1#P#p0.ibd -t1#P#p1.ibd -t1#P#p2.ibd -t1#P#p3.ibd -t1#P#p4.ibd t1.frm t1.par @@ -8641,14 +8526,6 @@ t1 CREATE TABLE `t1` ( PARTITION part3 VALUES IN (3) ENGINE = InnoDB) */ unified filelist -t1#P#part0.ibd -t1#P#part1.ibd -t1#P#part2.ibd -t1#P#part3.ibd -t1#P#part_1.ibd -t1#P#part_2.ibd -t1#P#part_3.ibd -t1#P#part_N.ibd t1.frm t1.par @@ -9152,12 +9029,6 @@ t1 CREATE TABLE `t1` ( PARTITION partf VALUES LESS THAN (2147483646) ENGINE = InnoDB) */ unified filelist -t1#P#parta.ibd -t1#P#partb.ibd -t1#P#partc.ibd -t1#P#partd.ibd -t1#P#parte.ibd -t1#P#partf.ibd t1.frm t1.par @@ -9657,14 +9528,6 @@ SUBPARTITIONS 2 PARTITION partd VALUES LESS THAN (2147483646) ENGINE = InnoDB) */ unified filelist -t1#P#parta#SP#partasp0.ibd -t1#P#parta#SP#partasp1.ibd -t1#P#partb#SP#partbsp0.ibd -t1#P#partb#SP#partbsp1.ibd -t1#P#partc#SP#partcsp0.ibd -t1#P#partc#SP#partcsp1.ibd -t1#P#partd#SP#partdsp0.ibd -t1#P#partd#SP#partdsp1.ibd t1.frm t1.par @@ -10177,14 +10040,6 @@ SUBPARTITION BY KEY (f_int1) SUBPARTITION subpart42 ENGINE = InnoDB)) */ unified filelist -t1#P#part1#SP#subpart11.ibd -t1#P#part1#SP#subpart12.ibd -t1#P#part2#SP#subpart21.ibd -t1#P#part2#SP#subpart22.ibd -t1#P#part3#SP#subpart31.ibd -t1#P#part3#SP#subpart32.ibd -t1#P#part4#SP#subpart41.ibd -t1#P#part4#SP#subpart42.ibd t1.frm t1.par @@ -10699,14 +10554,6 @@ SUBPARTITION BY HASH (f_int1 + 1) SUBPARTITION sp42 ENGINE = InnoDB)) */ unified filelist -t1#P#part1#SP#sp11.ibd -t1#P#part1#SP#sp12.ibd -t1#P#part2#SP#sp21.ibd -t1#P#part2#SP#sp22.ibd -t1#P#part3#SP#sp31.ibd -t1#P#part3#SP#sp32.ibd -t1#P#part4#SP#sp41.ibd -t1#P#part4#SP#sp42.ibd t1.frm t1.par @@ -11207,15 +11054,6 @@ SUBPARTITIONS 3 PARTITION part3 VALUES IN (NULL) ENGINE = InnoDB) */ unified filelist -t1#P#part1#SP#part1sp0.ibd -t1#P#part1#SP#part1sp1.ibd -t1#P#part1#SP#part1sp2.ibd -t1#P#part2#SP#part2sp0.ibd -t1#P#part2#SP#part2sp1.ibd -t1#P#part2#SP#part2sp2.ibd -t1#P#part3#SP#part3sp0.ibd -t1#P#part3#SP#part3sp1.ibd -t1#P#part3#SP#part3sp2.ibd t1.frm t1.par @@ -11709,8 +11547,6 @@ t1 CREATE TABLE `t1` ( PARTITIONS 2 */ unified filelist -t1#P#p0.ibd -t1#P#p1.ibd t1.frm t1.par @@ -12203,11 +12039,6 @@ t1 CREATE TABLE `t1` ( PARTITIONS 5 */ unified filelist -t1#P#p0.ibd -t1#P#p1.ibd -t1#P#p2.ibd -t1#P#p3.ibd -t1#P#p4.ibd t1.frm t1.par @@ -12715,14 +12546,6 @@ t1 CREATE TABLE `t1` ( PARTITION part3 VALUES IN (3) ENGINE = InnoDB) */ unified filelist -t1#P#part0.ibd -t1#P#part1.ibd -t1#P#part2.ibd -t1#P#part3.ibd -t1#P#part_1.ibd -t1#P#part_2.ibd -t1#P#part_3.ibd -t1#P#part_N.ibd t1.frm t1.par @@ -13226,12 +13049,6 @@ t1 CREATE TABLE `t1` ( PARTITION partf VALUES LESS THAN (2147483646) ENGINE = InnoDB) */ unified filelist -t1#P#parta.ibd -t1#P#partb.ibd -t1#P#partc.ibd -t1#P#partd.ibd -t1#P#parte.ibd -t1#P#partf.ibd t1.frm t1.par @@ -13731,14 +13548,6 @@ SUBPARTITIONS 2 PARTITION partd VALUES LESS THAN (2147483646) ENGINE = InnoDB) */ unified filelist -t1#P#parta#SP#partasp0.ibd -t1#P#parta#SP#partasp1.ibd -t1#P#partb#SP#partbsp0.ibd -t1#P#partb#SP#partbsp1.ibd -t1#P#partc#SP#partcsp0.ibd -t1#P#partc#SP#partcsp1.ibd -t1#P#partd#SP#partdsp0.ibd -t1#P#partd#SP#partdsp1.ibd t1.frm t1.par @@ -14251,14 +14060,6 @@ SUBPARTITION BY KEY (f_int1) SUBPARTITION subpart42 ENGINE = InnoDB)) */ unified filelist -t1#P#part1#SP#subpart11.ibd -t1#P#part1#SP#subpart12.ibd -t1#P#part2#SP#subpart21.ibd -t1#P#part2#SP#subpart22.ibd -t1#P#part3#SP#subpart31.ibd -t1#P#part3#SP#subpart32.ibd -t1#P#part4#SP#subpart41.ibd -t1#P#part4#SP#subpart42.ibd t1.frm t1.par @@ -14773,14 +14574,6 @@ SUBPARTITION BY HASH (f_int1 + 1) SUBPARTITION sp42 ENGINE = InnoDB)) */ unified filelist -t1#P#part1#SP#sp11.ibd -t1#P#part1#SP#sp12.ibd -t1#P#part2#SP#sp21.ibd -t1#P#part2#SP#sp22.ibd -t1#P#part3#SP#sp31.ibd -t1#P#part3#SP#sp32.ibd -t1#P#part4#SP#sp41.ibd -t1#P#part4#SP#sp42.ibd t1.frm t1.par @@ -15281,15 +15074,6 @@ SUBPARTITIONS 3 PARTITION part3 VALUES IN (NULL) ENGINE = InnoDB) */ unified filelist -t1#P#part1#SP#part1sp0.ibd -t1#P#part1#SP#part1sp1.ibd -t1#P#part1#SP#part1sp2.ibd -t1#P#part2#SP#part2sp0.ibd -t1#P#part2#SP#part2sp1.ibd -t1#P#part2#SP#part2sp2.ibd -t1#P#part3#SP#part3sp0.ibd -t1#P#part3#SP#part3sp1.ibd -t1#P#part3#SP#part3sp2.ibd t1.frm t1.par @@ -15783,8 +15567,6 @@ t1 CREATE TABLE `t1` ( PARTITIONS 2 */ unified filelist -t1#P#p0.ibd -t1#P#p1.ibd t1.frm t1.par @@ -16293,11 +16075,6 @@ t1 CREATE TABLE `t1` ( PARTITIONS 5 */ unified filelist -t1#P#p0.ibd -t1#P#p1.ibd -t1#P#p2.ibd -t1#P#p3.ibd -t1#P#p4.ibd t1.frm t1.par @@ -16821,14 +16598,6 @@ t1 CREATE TABLE `t1` ( PARTITION part3 VALUES IN (3) ENGINE = InnoDB) */ unified filelist -t1#P#part0.ibd -t1#P#part1.ibd -t1#P#part2.ibd -t1#P#part3.ibd -t1#P#part_1.ibd -t1#P#part_2.ibd -t1#P#part_3.ibd -t1#P#part_N.ibd t1.frm t1.par @@ -17348,12 +17117,6 @@ t1 CREATE TABLE `t1` ( PARTITION partf VALUES LESS THAN (2147483646) ENGINE = InnoDB) */ unified filelist -t1#P#parta.ibd -t1#P#partb.ibd -t1#P#partc.ibd -t1#P#partd.ibd -t1#P#parte.ibd -t1#P#partf.ibd t1.frm t1.par @@ -17869,14 +17632,6 @@ SUBPARTITIONS 2 PARTITION partd VALUES LESS THAN (2147483646) ENGINE = InnoDB) */ unified filelist -t1#P#parta#SP#partasp0.ibd -t1#P#parta#SP#partasp1.ibd -t1#P#partb#SP#partbsp0.ibd -t1#P#partb#SP#partbsp1.ibd -t1#P#partc#SP#partcsp0.ibd -t1#P#partc#SP#partcsp1.ibd -t1#P#partd#SP#partdsp0.ibd -t1#P#partd#SP#partdsp1.ibd t1.frm t1.par @@ -18405,14 +18160,6 @@ SUBPARTITION BY KEY (f_int1) SUBPARTITION subpart42 ENGINE = InnoDB)) */ unified filelist -t1#P#part1#SP#subpart11.ibd -t1#P#part1#SP#subpart12.ibd -t1#P#part2#SP#subpart21.ibd -t1#P#part2#SP#subpart22.ibd -t1#P#part3#SP#subpart31.ibd -t1#P#part3#SP#subpart32.ibd -t1#P#part4#SP#subpart41.ibd -t1#P#part4#SP#subpart42.ibd t1.frm t1.par @@ -18943,14 +18690,6 @@ SUBPARTITION BY HASH (f_int1 + 1) SUBPARTITION sp42 ENGINE = InnoDB)) */ unified filelist -t1#P#part1#SP#sp11.ibd -t1#P#part1#SP#sp12.ibd -t1#P#part2#SP#sp21.ibd -t1#P#part2#SP#sp22.ibd -t1#P#part3#SP#sp31.ibd -t1#P#part3#SP#sp32.ibd -t1#P#part4#SP#sp41.ibd -t1#P#part4#SP#sp42.ibd t1.frm t1.par @@ -19467,15 +19206,6 @@ SUBPARTITIONS 3 PARTITION part3 VALUES IN (NULL) ENGINE = InnoDB) */ unified filelist -t1#P#part1#SP#part1sp0.ibd -t1#P#part1#SP#part1sp1.ibd -t1#P#part1#SP#part1sp2.ibd -t1#P#part2#SP#part2sp0.ibd -t1#P#part2#SP#part2sp1.ibd -t1#P#part2#SP#part2sp2.ibd -t1#P#part3#SP#part3sp0.ibd -t1#P#part3#SP#part3sp1.ibd -t1#P#part3#SP#part3sp2.ibd t1.frm t1.par @@ -19990,8 +19720,6 @@ t1 CREATE TABLE `t1` ( PARTITIONS 2 */ unified filelist -t1#P#p0.ibd -t1#P#p1.ibd t1.frm t1.par @@ -20484,11 +20212,6 @@ t1 CREATE TABLE `t1` ( PARTITIONS 5 */ unified filelist -t1#P#p0.ibd -t1#P#p1.ibd -t1#P#p2.ibd -t1#P#p3.ibd -t1#P#p4.ibd t1.frm t1.par @@ -20996,14 +20719,6 @@ t1 CREATE TABLE `t1` ( PARTITION part3 VALUES IN (3) ENGINE = InnoDB) */ unified filelist -t1#P#part0.ibd -t1#P#part1.ibd -t1#P#part2.ibd -t1#P#part3.ibd -t1#P#part_1.ibd -t1#P#part_2.ibd -t1#P#part_3.ibd -t1#P#part_N.ibd t1.frm t1.par @@ -21507,12 +21222,6 @@ t1 CREATE TABLE `t1` ( PARTITION partf VALUES LESS THAN (2147483646) ENGINE = InnoDB) */ unified filelist -t1#P#parta.ibd -t1#P#partb.ibd -t1#P#partc.ibd -t1#P#partd.ibd -t1#P#parte.ibd -t1#P#partf.ibd t1.frm t1.par @@ -22012,14 +21721,6 @@ SUBPARTITIONS 2 PARTITION partd VALUES LESS THAN (2147483646) ENGINE = InnoDB) */ unified filelist -t1#P#parta#SP#partasp0.ibd -t1#P#parta#SP#partasp1.ibd -t1#P#partb#SP#partbsp0.ibd -t1#P#partb#SP#partbsp1.ibd -t1#P#partc#SP#partcsp0.ibd -t1#P#partc#SP#partcsp1.ibd -t1#P#partd#SP#partdsp0.ibd -t1#P#partd#SP#partdsp1.ibd t1.frm t1.par @@ -22530,14 +22231,6 @@ SUBPARTITION BY KEY (f_int2) SUBPARTITION subpart42 ENGINE = InnoDB)) */ unified filelist -t1#P#part1#SP#subpart11.ibd -t1#P#part1#SP#subpart12.ibd -t1#P#part2#SP#subpart21.ibd -t1#P#part2#SP#subpart22.ibd -t1#P#part3#SP#subpart31.ibd -t1#P#part3#SP#subpart32.ibd -t1#P#part4#SP#subpart41.ibd -t1#P#part4#SP#subpart42.ibd t1.frm t1.par @@ -23048,14 +22741,6 @@ SUBPARTITION BY HASH (f_int2 + 1) SUBPARTITION sp42 ENGINE = InnoDB)) */ unified filelist -t1#P#part1#SP#sp11.ibd -t1#P#part1#SP#sp12.ibd -t1#P#part2#SP#sp21.ibd -t1#P#part2#SP#sp22.ibd -t1#P#part3#SP#sp31.ibd -t1#P#part3#SP#sp32.ibd -t1#P#part4#SP#sp41.ibd -t1#P#part4#SP#sp42.ibd t1.frm t1.par @@ -23556,15 +23241,6 @@ SUBPARTITIONS 3 PARTITION part3 VALUES IN (NULL) ENGINE = InnoDB) */ unified filelist -t1#P#part1#SP#part1sp0.ibd -t1#P#part1#SP#part1sp1.ibd -t1#P#part1#SP#part1sp2.ibd -t1#P#part2#SP#part2sp0.ibd -t1#P#part2#SP#part2sp1.ibd -t1#P#part2#SP#part2sp2.ibd -t1#P#part3#SP#part3sp0.ibd -t1#P#part3#SP#part3sp1.ibd -t1#P#part3#SP#part3sp2.ibd t1.frm t1.par @@ -24058,8 +23734,6 @@ t1 CREATE TABLE `t1` ( PARTITIONS 2 */ unified filelist -t1#P#p0.ibd -t1#P#p1.ibd t1.frm t1.par @@ -24552,11 +24226,6 @@ t1 CREATE TABLE `t1` ( PARTITIONS 5 */ unified filelist -t1#P#p0.ibd -t1#P#p1.ibd -t1#P#p2.ibd -t1#P#p3.ibd -t1#P#p4.ibd t1.frm t1.par @@ -25064,14 +24733,6 @@ t1 CREATE TABLE `t1` ( PARTITION part3 VALUES IN (3) ENGINE = InnoDB) */ unified filelist -t1#P#part0.ibd -t1#P#part1.ibd -t1#P#part2.ibd -t1#P#part3.ibd -t1#P#part_1.ibd -t1#P#part_2.ibd -t1#P#part_3.ibd -t1#P#part_N.ibd t1.frm t1.par @@ -25575,12 +25236,6 @@ t1 CREATE TABLE `t1` ( PARTITION partf VALUES LESS THAN (2147483646) ENGINE = InnoDB) */ unified filelist -t1#P#parta.ibd -t1#P#partb.ibd -t1#P#partc.ibd -t1#P#partd.ibd -t1#P#parte.ibd -t1#P#partf.ibd t1.frm t1.par @@ -26080,14 +25735,6 @@ SUBPARTITIONS 2 PARTITION partd VALUES LESS THAN (2147483646) ENGINE = InnoDB) */ unified filelist -t1#P#parta#SP#partasp0.ibd -t1#P#parta#SP#partasp1.ibd -t1#P#partb#SP#partbsp0.ibd -t1#P#partb#SP#partbsp1.ibd -t1#P#partc#SP#partcsp0.ibd -t1#P#partc#SP#partcsp1.ibd -t1#P#partd#SP#partdsp0.ibd -t1#P#partd#SP#partdsp1.ibd t1.frm t1.par @@ -26598,14 +26245,6 @@ SUBPARTITION BY KEY (f_int2) SUBPARTITION subpart42 ENGINE = InnoDB)) */ unified filelist -t1#P#part1#SP#subpart11.ibd -t1#P#part1#SP#subpart12.ibd -t1#P#part2#SP#subpart21.ibd -t1#P#part2#SP#subpart22.ibd -t1#P#part3#SP#subpart31.ibd -t1#P#part3#SP#subpart32.ibd -t1#P#part4#SP#subpart41.ibd -t1#P#part4#SP#subpart42.ibd t1.frm t1.par @@ -27116,14 +26755,6 @@ SUBPARTITION BY HASH (f_int2 + 1) SUBPARTITION sp42 ENGINE = InnoDB)) */ unified filelist -t1#P#part1#SP#sp11.ibd -t1#P#part1#SP#sp12.ibd -t1#P#part2#SP#sp21.ibd -t1#P#part2#SP#sp22.ibd -t1#P#part3#SP#sp31.ibd -t1#P#part3#SP#sp32.ibd -t1#P#part4#SP#sp41.ibd -t1#P#part4#SP#sp42.ibd t1.frm t1.par @@ -27624,15 +27255,6 @@ SUBPARTITIONS 3 PARTITION part3 VALUES IN (NULL) ENGINE = InnoDB) */ unified filelist -t1#P#part1#SP#part1sp0.ibd -t1#P#part1#SP#part1sp1.ibd -t1#P#part1#SP#part1sp2.ibd -t1#P#part2#SP#part2sp0.ibd -t1#P#part2#SP#part2sp1.ibd -t1#P#part2#SP#part2sp2.ibd -t1#P#part3#SP#part3sp0.ibd -t1#P#part3#SP#part3sp1.ibd -t1#P#part3#SP#part3sp2.ibd t1.frm t1.par @@ -28126,8 +27748,6 @@ t1 CREATE TABLE `t1` ( PARTITIONS 2 */ unified filelist -t1#P#p0.ibd -t1#P#p1.ibd t1.frm t1.par @@ -28636,11 +28256,6 @@ t1 CREATE TABLE `t1` ( PARTITIONS 5 */ unified filelist -t1#P#p0.ibd -t1#P#p1.ibd -t1#P#p2.ibd -t1#P#p3.ibd -t1#P#p4.ibd t1.frm t1.par @@ -29164,14 +28779,6 @@ t1 CREATE TABLE `t1` ( PARTITION part3 VALUES IN (3) ENGINE = InnoDB) */ unified filelist -t1#P#part0.ibd -t1#P#part1.ibd -t1#P#part2.ibd -t1#P#part3.ibd -t1#P#part_1.ibd -t1#P#part_2.ibd -t1#P#part_3.ibd -t1#P#part_N.ibd t1.frm t1.par @@ -29691,12 +29298,6 @@ t1 CREATE TABLE `t1` ( PARTITION partf VALUES LESS THAN (2147483646) ENGINE = InnoDB) */ unified filelist -t1#P#parta.ibd -t1#P#partb.ibd -t1#P#partc.ibd -t1#P#partd.ibd -t1#P#parte.ibd -t1#P#partf.ibd t1.frm t1.par @@ -30212,14 +29813,6 @@ SUBPARTITIONS 2 PARTITION partd VALUES LESS THAN (2147483646) ENGINE = InnoDB) */ unified filelist -t1#P#parta#SP#partasp0.ibd -t1#P#parta#SP#partasp1.ibd -t1#P#partb#SP#partbsp0.ibd -t1#P#partb#SP#partbsp1.ibd -t1#P#partc#SP#partcsp0.ibd -t1#P#partc#SP#partcsp1.ibd -t1#P#partd#SP#partdsp0.ibd -t1#P#partd#SP#partdsp1.ibd t1.frm t1.par @@ -30746,14 +30339,6 @@ SUBPARTITION BY KEY (f_int2) SUBPARTITION subpart42 ENGINE = InnoDB)) */ unified filelist -t1#P#part1#SP#subpart11.ibd -t1#P#part1#SP#subpart12.ibd -t1#P#part2#SP#subpart21.ibd -t1#P#part2#SP#subpart22.ibd -t1#P#part3#SP#subpart31.ibd -t1#P#part3#SP#subpart32.ibd -t1#P#part4#SP#subpart41.ibd -t1#P#part4#SP#subpart42.ibd t1.frm t1.par @@ -31280,14 +30865,6 @@ SUBPARTITION BY HASH (f_int2 + 1) SUBPARTITION sp42 ENGINE = InnoDB)) */ unified filelist -t1#P#part1#SP#sp11.ibd -t1#P#part1#SP#sp12.ibd -t1#P#part2#SP#sp21.ibd -t1#P#part2#SP#sp22.ibd -t1#P#part3#SP#sp31.ibd -t1#P#part3#SP#sp32.ibd -t1#P#part4#SP#sp41.ibd -t1#P#part4#SP#sp42.ibd t1.frm t1.par @@ -31804,15 +31381,6 @@ SUBPARTITIONS 3 PARTITION part3 VALUES IN (NULL) ENGINE = InnoDB) */ unified filelist -t1#P#part1#SP#part1sp0.ibd -t1#P#part1#SP#part1sp1.ibd -t1#P#part1#SP#part1sp2.ibd -t1#P#part2#SP#part2sp0.ibd -t1#P#part2#SP#part2sp1.ibd -t1#P#part2#SP#part2sp2.ibd -t1#P#part3#SP#part3sp0.ibd -t1#P#part3#SP#part3sp1.ibd -t1#P#part3#SP#part3sp2.ibd t1.frm t1.par From 921fd5297510a063e90aa813f6a0273b90e72b2d Mon Sep 17 00:00:00 2001 From: Tor Didriksen Date: Fri, 8 Oct 2010 11:52:09 +0200 Subject: [PATCH 31/47] Bug#57209 valgrind + Assertion failed: dst > buf Buffer overrun when trying to format DBL_MAX --- mysql-test/r/func_math.result | 7 +++++++ mysql-test/t/func_math.test | 6 ++++++ sql/item_strfunc.cc | 5 +++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/func_math.result b/mysql-test/r/func_math.result index 307f1714132..bfb3af0afff 100644 --- a/mysql-test/r/func_math.result +++ b/mysql-test/r/func_math.result @@ -600,3 +600,10 @@ NULL SELECT -9223372036854775808 MOD -1; -9223372036854775808 MOD -1 0 +# +# Bug #57209 valgrind + Assertion failed: dst > buf +# +SELECT floor(log10(format(concat_ws(5445796E25, 5306463, 30837), -358821))) +as foo; +foo +2 diff --git a/mysql-test/t/func_math.test b/mysql-test/t/func_math.test index 44af2f5ad3f..efdf7201a40 100644 --- a/mysql-test/t/func_math.test +++ b/mysql-test/t/func_math.test @@ -458,3 +458,9 @@ SELECT 2 DIV -2; SELECT -(1 DIV 0); # Crashed the server with SIGFPE before the bugfix SELECT -9223372036854775808 MOD -1; + +--echo # +--echo # Bug #57209 valgrind + Assertion failed: dst > buf +--echo # +SELECT floor(log10(format(concat_ws(5445796E25, 5306463, 30837), -358821))) +as foo; diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 6d3514bf356..89c1e785c71 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2299,7 +2299,8 @@ String *Item_func_format::val_str_ascii(String *str) if (lc->grouping[0] > 0 && str_length >= dec_length + 1 + lc->grouping[0]) { - char buf[DECIMAL_MAX_STR_LENGTH * 2]; /* 2 - in the worst case when grouping=1 */ + /* We need space for ',' between each group of digits as well. */ + char buf[2 * FLOATING_POINT_BUFFER]; int count; const char *grouping= lc->grouping; char sign_length= *str->ptr() == '-' ? 1 : 0; @@ -2323,7 +2324,7 @@ String *Item_func_format::val_str_ascii(String *str) count will be initialized to -1 and we'll never get into this "if" anymore. */ - if (!count) + if (count == 0) { *--dst= lc->thousand_sep; if (grouping[1]) From 657b157511d70d77da79920a29befbd9edb96898 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Fri, 8 Oct 2010 09:16:20 -0300 Subject: [PATCH 32/47] Bug#56822: Add a thread state for sessions waiting on the query cache lock Only wait for a single debug signal at a time as the signal state is global. Also, do not activate the query cache debug sync points if the thread has no associated THD session. --- mysql-test/r/query_cache_debug.result | 14 +++++++++----- mysql-test/t/query_cache_debug.test | 16 +++++++++++----- sql/sql_cache.cc | 22 +++++++++++++++++++--- 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/mysql-test/r/query_cache_debug.result b/mysql-test/r/query_cache_debug.result index 30996e5e86b..50a3a02fe4d 100644 --- a/mysql-test/r/query_cache_debug.result +++ b/mysql-test/r/query_cache_debug.result @@ -123,16 +123,20 @@ SET DEBUG_SYNC="now WAIT_FOR parked1_1"; ** On THD2: Insert a result into the cache. This attempt will be blocked ** because of a debug hook placed just before the mutex lock after which ** the first part of the result set is written. -SET DEBUG_SYNC="wait_in_query_cache_insert SIGNAL parked2 WAIT_FOR go2"; +SET DEBUG_SYNC="wait_in_query_cache_insert SIGNAL parked2 WAIT_FOR go2 EXECUTE 1"; SELECT SQL_CACHE * FROM t2 UNION SELECT * FROM t3; +=================================== Connection default +** Assert that the SELECT-stmt thread reaches the sync point. +SET DEBUG_SYNC="now WAIT_FOR parked2"; +** +** =================================== Connection thd3 ** On THD3: Insert another result into the cache and block on the same ** debug hook. -SET DEBUG_SYNC="wait_in_query_cache_insert SIGNAL parked3 WAIT_FOR go3"; -SELECT SQL_CACHE * FROM t4 UNION SELECT * FROM t5;; +SET DEBUG_SYNC="wait_in_query_cache_insert SIGNAL parked3 WAIT_FOR go3 EXECUTE 1"; +SELECT SQL_CACHE * FROM t4 UNION SELECT * FROM t5; =================================== Connection default -** Assert that the two SELECT-stmt threads to reach the hook. -SET DEBUG_SYNC="now WAIT_FOR parked2"; +** Assert that the SELECT-stmt thread reaches the sync point. SET DEBUG_SYNC="now WAIT_FOR parked3"; ** ** diff --git a/mysql-test/t/query_cache_debug.test b/mysql-test/t/query_cache_debug.test index 77e714aa6f5..2f85813d1ef 100644 --- a/mysql-test/t/query_cache_debug.test +++ b/mysql-test/t/query_cache_debug.test @@ -170,20 +170,26 @@ connection thd2; --echo ** On THD2: Insert a result into the cache. This attempt will be blocked --echo ** because of a debug hook placed just before the mutex lock after which --echo ** the first part of the result set is written. -SET DEBUG_SYNC="wait_in_query_cache_insert SIGNAL parked2 WAIT_FOR go2"; +SET DEBUG_SYNC="wait_in_query_cache_insert SIGNAL parked2 WAIT_FOR go2 EXECUTE 1"; --send SELECT SQL_CACHE * FROM t2 UNION SELECT * FROM t3 +connection default; +--echo =================================== Connection default +--echo ** Assert that the SELECT-stmt thread reaches the sync point. +SET DEBUG_SYNC="now WAIT_FOR parked2"; +--echo ** +--echo ** + connection thd3; --echo =================================== Connection thd3 --echo ** On THD3: Insert another result into the cache and block on the same --echo ** debug hook. -SET DEBUG_SYNC="wait_in_query_cache_insert SIGNAL parked3 WAIT_FOR go3"; ---send SELECT SQL_CACHE * FROM t4 UNION SELECT * FROM t5; +SET DEBUG_SYNC="wait_in_query_cache_insert SIGNAL parked3 WAIT_FOR go3 EXECUTE 1"; +--send SELECT SQL_CACHE * FROM t4 UNION SELECT * FROM t5 connection default; --echo =================================== Connection default ---echo ** Assert that the two SELECT-stmt threads to reach the hook. -SET DEBUG_SYNC="now WAIT_FOR parked2"; +--echo ** Assert that the SELECT-stmt thread reaches the sync point. SET DEBUG_SYNC="now WAIT_FOR parked3"; --echo ** --echo ** diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index 8c3abdbf1b0..9876c46bbb3 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -384,6 +384,22 @@ TODO list: #endif +/** + Macro that executes the requested action at a synchronization point + only if the thread has a associated THD session. +*/ +#if defined(ENABLED_DEBUG_SYNC) +#define QC_DEBUG_SYNC(name) \ + do { \ + THD *thd= current_thd; \ + if (thd) \ + DEBUG_SYNC(thd, name); \ + } while (0) +#else +#define QC_DEBUG_SYNC(name) +#endif + + /** Thread state to be used when the query cache lock needs to be acquired. Sets the thread state name in the constructor, resets on destructor. @@ -879,7 +895,7 @@ Query_cache::insert(Query_cache_tls *query_cache_tls, if (is_disabled() || query_cache_tls->first_query_block == NULL) DBUG_VOID_RETURN; - DEBUG_SYNC(current_thd, "wait_in_query_cache_insert"); + QC_DEBUG_SYNC("wait_in_query_cache_insert"); if (try_lock()) DBUG_VOID_RETURN; @@ -1975,7 +1991,7 @@ void Query_cache::flush() if (is_disabled()) DBUG_VOID_RETURN; - DEBUG_SYNC(current_thd, "wait_in_query_cache_flush1"); + QC_DEBUG_SYNC("wait_in_query_cache_flush1"); lock_and_suspend(); if (query_cache_size > 0) @@ -2315,7 +2331,7 @@ void Query_cache::free_cache() void Query_cache::flush_cache() { - DEBUG_SYNC(current_thd, "wait_in_query_cache_flush2"); + QC_DEBUG_SYNC("wait_in_query_cache_flush2"); my_hash_reset(&queries); while (queries_blocks != 0) From 5d014b83198caa59344433b9b9188042e8427b8f Mon Sep 17 00:00:00 2001 From: Mats Kindahl Date: Fri, 8 Oct 2010 14:22:22 +0200 Subject: [PATCH 33/47] Bug #57338: Extreneous server variable thread_pool_size The server contained code for the server variable and option thread_pool_size, but this server variable where not used anywhere. The variable is probably remains from backporting too much from 6.0 (specifically, the thread pool implementation was not backported from 6.0, which this variable is associated with). This patch eliminates the variable from the server. --- sql/sys_vars.cc | 9 --------- 1 file changed, 9 deletions(-) diff --git a/sql/sys_vars.cc b/sql/sys_vars.cc index b8b73bc0387..5c9df82ddac 100644 --- a/sql/sys_vars.cc +++ b/sql/sys_vars.cc @@ -2014,15 +2014,6 @@ static Sys_var_ulong Sys_thread_cache_size( GLOBAL_VAR(thread_cache_size), CMD_LINE(REQUIRED_ARG), VALID_RANGE(0, 16384), DEFAULT(0), BLOCK_SIZE(1)); -#if HAVE_POOL_OF_THREADS == 1 -static Sys_var_ulong Sys_thread_pool_size( - "thread_pool_size", - "How many threads we should create to handle query requests in " - "case of 'thread_handling=pool-of-threads'", - GLOBAL_VAR(thread_pool_size), CMD_LINE(REQUIRED_ARG), - VALID_RANGE(1, 16384), DEFAULT(20), BLOCK_SIZE(0)); -#endif - /** Can't change the 'next' tx_isolation if we are already in a transaction. From fa4a4b7a64a36f8b8fde36169843ef9bb13f8134 Mon Sep 17 00:00:00 2001 From: Mats Kindahl Date: Fri, 8 Oct 2010 14:44:57 +0200 Subject: [PATCH 34/47] WL#5363: Thread Pool Service Interface Adding a comment to scheduler_types on the default values used. --- sql/scheduler.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sql/scheduler.h b/sql/scheduler.h index 40f0e28bc2c..b5a175434b6 100644 --- a/sql/scheduler.h +++ b/sql/scheduler.h @@ -57,6 +57,13 @@ struct scheduler_functions */ enum scheduler_types { + /* + The default of --thread-handling is the first one in the + thread_handling_names array, this array has to be consistent with + the order in this array, so to change default one has to change + the first entry in this enum and the first entry in the + thread_handling_names array. + */ SCHEDULER_ONE_THREAD_PER_CONNECTION=0, SCHEDULER_NO_THREADS, SCHEDULER_TYPES_COUNT From 243003f12df45ddf013f096ac298396a37df0a81 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Fri, 8 Oct 2010 10:30:58 -0300 Subject: [PATCH 35/47] Bug#42733: Type-punning warnings when compiling MySQL -- strict aliasing violations. Due to the extent of aliasing violations in the MySQL source code, at this time it is safer to disable strict aliasing related optimizations in release builds. As of this patch, only GCC enables strict aliasing by default. Hence, use the -fno-strict-aliasing option to disable the aliasing rules. --- cmake/build_configurations/mysql_release.cmake | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cmake/build_configurations/mysql_release.cmake b/cmake/build_configurations/mysql_release.cmake index 9d010ef7f2a..48d3765ea67 100644 --- a/cmake/build_configurations/mysql_release.cmake +++ b/cmake/build_configurations/mysql_release.cmake @@ -131,16 +131,16 @@ IF(UNIX) # Default GCC flags IF(CMAKE_COMPILER_IS_GNUCC) - SET(COMMON_C_FLAGS "-g -static-libgcc -fno-omit-frame-pointer") + SET(COMMON_C_FLAGS "-g -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing") SET(CMAKE_C_FLAGS_DEBUG "-O ${COMMON_C_FLAGS}") SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 ${COMMON_C_FLAGS}") ENDIF() IF(CMAKE_COMPILER_IS_GNUCXX) - SET(COMMON_CXX_FLAGS "-g -static-libgcc -fno-omit-frame-pointer") + SET(COMMON_CXX_FLAGS "-g -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing") SET(CMAKE_CXX_FLAGS_DEBUG "-O ${COMMON_CXX_FLAGS}") SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 ${COMMON_CXX_FLAGS}") ENDIF() - + # HPUX flags IF(CMAKE_SYSTEM_NAME MATCHES "HP-UX") IF(CMAKE_C_COMPILER_ID MATCHES "HP") @@ -156,7 +156,7 @@ IF(UNIX) ENDIF() SET(WITH_SSL no) ENDIF() - + # Linux flags IF(CMAKE_SYSTEM_NAME MATCHES "Linux") IF(CMAKE_C_COMPILER_ID MATCHES "Intel") @@ -173,18 +173,18 @@ IF(UNIX) SET(WITH_SSL no) ENDIF() ENDIF() - + # OSX flags IF(APPLE) - SET(COMMON_C_FLAGS "-g -fno-common") + SET(COMMON_C_FLAGS "-g -fno-common -fno-strict-aliasing") # XXX: why are we using -felide-constructors on OSX? - SET(COMMON_CXX_FLAGS "-g -fno-common -felide-constructors") + SET(COMMON_CXX_FLAGS "-g -fno-common -felide-constructors -fno-strict-aliasing") SET(CMAKE_C_FLAGS_DEBUG "-O ${COMMON_C_FLAGS}") SET(CMAKE_CXX_FLAGS_DEBUG "-O ${COMMON_CXX_FLAGS}") SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-Os ${COMMON_C_FLAGS}") SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-Os ${COMMON_CXX_FLAGS}") ENDIF() - + # Solaris flags IF(CMAKE_SYSTEM_NAME MATCHES "SunOS") IF(CMAKE_SYSTEM_VERSION VERSION_GREATER "5.9") @@ -219,7 +219,7 @@ IF(UNIX) ENDIF() ENDIF() ENDIF() - + IF(CMAKE_C_FLAGS_DEBUG) SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}" CACHE STRING "Debug C compile flags") From c57244fb174e68be30c67cb807045f9512b5aa68 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Fri, 8 Oct 2010 18:06:31 +0400 Subject: [PATCH 36/47] The fix for Bug#55744 GROUP_CONCAT + CASE + ucs return garbage revealed problems in how character set aggregation code works with prepared statements. This patch fixes (hopefully) the problems. --- sql/item.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sql/item.cc b/sql/item.cc index fff7511015f..b166f3e645f 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1783,8 +1783,7 @@ bool agg_item_set_converter(DTCollation &coll, const char *fname, In case we're in statement prepare, create conversion item in its memory: it will be reused on each execute. */ - arena= thd->is_stmt_prepare() ? thd->activate_stmt_arena_if_needed(&backup) - : NULL; + arena= thd->activate_stmt_arena_if_needed(&backup); for (i= 0, arg= args; i < nargs; i++, arg+= item_sep) { From 31e1b12eb0fb67d3d65973fb1cd574be64373e04 Mon Sep 17 00:00:00 2001 From: Davi Arnaut Date: Fri, 8 Oct 2010 11:52:39 -0300 Subject: [PATCH 37/47] Bug#45288: pb2 returns a lot of compilation warnings on linux Fix assorted compiler warnings. --- sql/mysqld.cc | 7 +++---- storage/innobase/include/ibuf0ibuf.h | 2 +- storage/innobase/include/row0row.h | 2 +- strings/my_vsnprintf.c | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index e489d466d5f..99754e8b7f6 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -3244,12 +3244,11 @@ static int init_common_variables() desired page sizes. */ int nelem; - int max_desired_page_size; - int max_page_size; + size_t max_desired_page_size; if (opt_super_large_pages) - max_page_size= SUPER_LARGE_PAGESIZE; + max_desired_page_size= SUPER_LARGE_PAGESIZE; else - max_page_size= LARGE_PAGESIZE; + max_desired_page_size= LARGE_PAGESIZE; nelem = getpagesizes(NULL, 0); if (nelem > 0) { diff --git a/storage/innobase/include/ibuf0ibuf.h b/storage/innobase/include/ibuf0ibuf.h index 0f1631fde77..4bb59be6a3e 100644 --- a/storage/innobase/include/ibuf0ibuf.h +++ b/storage/innobase/include/ibuf0ibuf.h @@ -43,7 +43,7 @@ typedef enum { IBUF_OP_DELETE = 2, /* Number of different operation types. */ - IBUF_OP_COUNT = 3, + IBUF_OP_COUNT = 3 } ibuf_op_t; /** Combinations of operations that can be buffered. Because the enum diff --git a/storage/innobase/include/row0row.h b/storage/innobase/include/row0row.h index 195691a420b..110525ecfed 100644 --- a/storage/innobase/include/row0row.h +++ b/storage/innobase/include/row0row.h @@ -267,7 +267,7 @@ enum row_search_result { secondary index leaf page was not in the buffer pool, and the operation was enqueued in the insert/delete buffer */ - ROW_NOT_DELETED_REF, /*!< BTR_DELETE was specified, and + ROW_NOT_DELETED_REF /*!< BTR_DELETE was specified, and row_purge_poss_sec() failed */ }; diff --git a/strings/my_vsnprintf.c b/strings/my_vsnprintf.c index 1284203f739..e9786dacfdc 100644 --- a/strings/my_vsnprintf.c +++ b/strings/my_vsnprintf.c @@ -513,7 +513,7 @@ start: arg_count= max(arg_count, arg_index); goto start; } - DBUG_ASSERT(0); + return 0; } From b66825912a436cb263253bf47c535f3728ccbe85 Mon Sep 17 00:00:00 2001 From: Date: Sat, 9 Oct 2010 15:05:43 +0800 Subject: [PATCH 38/47] Bug#55375 Transaction bigger than max_binlog_cache_size crashes slave When slave executes a transaction bigger than slave's max_binlog_cache_size, slave will crash. It is caused by the assert that server should only roll back the statement but not the whole transaction if the error ER_TRANS_CACHE_FULL happens. But slave sql thread always rollbacks the whole transaction when an error happens. Ather this patch, we always clear any error set in sql thread(it is different from the error in 'SHOW SLAVE STATUS') and it is cleared before rolling back the transaction. --- .../rpl/r/rpl_binlog_max_cache_size.result | 47 ++++++-- .../t/rpl_binlog_max_cache_size-master.opt | 1 - .../rpl/t/rpl_binlog_max_cache_size.test | 105 ++++++++++++++---- sql/log_event.cc | 40 +++---- sql/slave.cc | 3 +- 5 files changed, 144 insertions(+), 52 deletions(-) delete mode 100644 mysql-test/suite/rpl/t/rpl_binlog_max_cache_size-master.opt diff --git a/mysql-test/suite/rpl/r/rpl_binlog_max_cache_size.result b/mysql-test/suite/rpl/r/rpl_binlog_max_cache_size.result index 0e3f83d0aa5..f9e492db6bc 100644 --- a/mysql-test/suite/rpl/r/rpl_binlog_max_cache_size.result +++ b/mysql-test/suite/rpl/r/rpl_binlog_max_cache_size.result @@ -4,6 +4,8 @@ reset master; reset slave; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; start slave; +SET GLOBAL max_binlog_cache_size = 4096; +SET GLOBAL binlog_cache_size = 4096; CREATE TABLE t1(a INT PRIMARY KEY, data VARCHAR(30000)) ENGINE=Innodb; CREATE TABLE t2(a INT PRIMARY KEY, data VARCHAR(30000)) ENGINE=MyIsam; CREATE TABLE t3(a INT PRIMARY KEY, data VARCHAR(30000)) ENGINE=Innodb; @@ -15,11 +17,14 @@ Got one of the listed errors *** Single statement on non-transactional table *** *** After WL#2687 the difference between STATEMENT/MIXED and ROW will not exist. *** Got one of the listed errors +--source include/wait_for_slave_sql_error_and_skip.inc +include/start_slave.inc *** Single statement on both transactional and non-transactional tables. *** *** After WL#2687 we will be able to change the order of the tables. *** Got one of the listed errors -SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; -START SLAVE SQL_THREAD; +--source include/wait_for_slave_sql_error_and_skip.inc +SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; +include/start_slave.inc TRUNCATE TABLE t1; TRUNCATE TABLE t2; TRUNCATE TABLE t3; @@ -116,6 +121,37 @@ COMMIT; BEGIN; Got one of the listed errors COMMIT; +--source include/wait_for_slave_sql_error_and_skip.inc +SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; +include/start_slave.inc +######################################################################## +# 8 - Bug#55375(Regression Bug) Transaction bigger than +# max_binlog_cache_size crashes slave +######################################################################## +SET GLOBAL max_binlog_cache_size = 4096; +SET GLOBAL binlog_cache_size = 4096; +include/stop_slave.inc +include/start_slave.inc +CALL mtr.add_suppression("Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage.*"); +CALL mtr.add_suppression("Writing one row to the row-based binary log failed.*"); +TRUNCATE t1; +SET GLOBAL max_binlog_cache_size= ORIGINAL_VALUE; +SET GLOBAL binlog_cache_size= ORIGINAL_VALUE; +BEGIN; +Repeat statement 'INSERT INTO t1 VALUES($n, repeat("a", 32))' 128 times +COMMIT; +SELECT count(*) FROM t1; +count(*) +0 +show binlog events in 'slave-bin.000001' from ; +Log_name Pos Event_type Server_id End_log_pos Info +SET GLOBAL max_binlog_cache_size= ORIGINAL_VALUE; +SET GLOBAL binlog_cache_size= ORIGINAL_VALUE; +include/stop_slave.inc +include/start_slave.inc +SELECT count(*) FROM t1; +count(*) +128 ######################################################################################## # CLEAN ######################################################################################## @@ -126,10 +162,3 @@ DROP TABLE IF EXISTS t4; DROP TABLE IF EXISTS t5; DROP TABLE IF EXISTS t6; DROP PROCEDURE p1; -DROP TABLE t1; -DROP TABLE t2; -DROP TABLE t3; -DROP TABLE IF EXISTS t4; -DROP TABLE IF EXISTS t5; -DROP TABLE IF EXISTS t6; -DROP PROCEDURE p1; diff --git a/mysql-test/suite/rpl/t/rpl_binlog_max_cache_size-master.opt b/mysql-test/suite/rpl/t/rpl_binlog_max_cache_size-master.opt deleted file mode 100644 index 45631525481..00000000000 --- a/mysql-test/suite/rpl/t/rpl_binlog_max_cache_size-master.opt +++ /dev/null @@ -1 +0,0 @@ ---binlog_cache_size=4096 --max_binlog_cache_size=7680 diff --git a/mysql-test/suite/rpl/t/rpl_binlog_max_cache_size.test b/mysql-test/suite/rpl/t/rpl_binlog_max_cache_size.test index e1f1f8c54bb..9dca61d8f75 100644 --- a/mysql-test/suite/rpl/t/rpl_binlog_max_cache_size.test +++ b/mysql-test/suite/rpl/t/rpl_binlog_max_cache_size.test @@ -30,6 +30,16 @@ --source include/not_embedded.inc --source include/not_windows.inc +let $old_max_binlog_cache_size= query_get_value(SHOW VARIABLES LIKE "max_binlog_cache_size", Value, 1); +let $old_binlog_cache_size= query_get_value(SHOW VARIABLES LIKE "binlog_cache_size", Value, 1); + +SET GLOBAL max_binlog_cache_size = 4096; +# Becuase of bug#55377, we have to set binlog_cache_size until the bug is +# fixed. +SET GLOBAL binlog_cache_size = 4096; +disconnect master; +connect (master,127.0.0.1,root,,test,$MASTER_MYPORT,); + CREATE TABLE t1(a INT PRIMARY KEY, data VARCHAR(30000)) ENGINE=Innodb; CREATE TABLE t2(a INT PRIMARY KEY, data VARCHAR(30000)) ENGINE=MyIsam; CREATE TABLE t3(a INT PRIMARY KEY, data VARCHAR(30000)) ENGINE=Innodb; @@ -57,25 +67,23 @@ if (`SELECT @@binlog_format = 'STATEMENT' || @@binlog_format = 'MIXED'`) { eval INSERT INTO t2 (a, data) VALUES (2, CONCAT($data, $data, $data, $data, $data, $data)); + # Below code fakes the result of 'ROW' mode. --echo Got one of the listed errors + --echo --source include/wait_for_slave_sql_error_and_skip.inc + --echo include/start_slave.inc } if (`SELECT @@binlog_format = 'ROW'`) { --error ER_TRANS_CACHE_FULL, ER_ERROR_ON_WRITE eval INSERT INTO t2 (a, data) VALUES (2, CONCAT($data, $data, $data, $data, $data, $data)); - - connection slave; - --source include/wait_for_slave_sql_to_stop.inc - SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; - START SLAVE SQL_THREAD; - --source include/wait_for_slave_sql_to_start.inc + # Incident event + --let $slave_sql_errno=1590 + --source include/wait_for_slave_sql_error_and_skip.inc } --enable_warnings --enable_query_log -connection master; - --disable_query_log eval INSERT INTO t1 (a, data) VALUES (3, $data); eval INSERT INTO t1 (a, data) VALUES (4, $data); @@ -93,11 +101,9 @@ eval UPDATE t2, t1 SET t2.data = CONCAT($data, $data, $data, $data), t1.data = CONCAT($data, $data, $data, $data); --enable_query_log -connection slave; ---source include/wait_for_slave_sql_to_stop.inc -SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; -START SLAVE SQL_THREAD; ---source include/wait_for_slave_sql_to_start.inc +# Incident event +--let $slave_sql_errno=1590 +--source include/wait_for_slave_sql_error_and_skip.inc #--echo ######################################################################################## #--echo # 2 - BEGIN - IMPLICIT COMMIT by DDL @@ -368,8 +374,70 @@ BEGIN; --enable_query_log COMMIT; +# Incident event +--let $slave_sql_errno=1590 +--source include/wait_for_slave_sql_error_and_skip.inc + +sync_slave_with_master; + +--echo ######################################################################## +--echo # 8 - Bug#55375(Regression Bug) Transaction bigger than +--echo # max_binlog_cache_size crashes slave +--echo ######################################################################## + +SET GLOBAL max_binlog_cache_size = 4096; +SET GLOBAL binlog_cache_size = 4096; + +source include/stop_slave.inc; +source include/start_slave.inc; +CALL mtr.add_suppression("Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage.*"); +CALL mtr.add_suppression("Writing one row to the row-based binary log failed.*"); + +connection master; +TRUNCATE t1; + +sync_slave_with_master; +--let binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1) +--let binlog_file= query_get_value(SHOW MASTER STATUS, File, 1) + +connection master; +--replace_result $old_max_binlog_cache_size ORIGINAL_VALUE +--eval SET GLOBAL max_binlog_cache_size= $old_max_binlog_cache_size +--replace_result $old_binlog_cache_size ORIGINAL_VALUE +--eval SET GLOBAL binlog_cache_size= $old_binlog_cache_size +disconnect master; +connect (master,127.0.0.1,root,,test,$MASTER_MYPORT,); + +--let $n=128 +BEGIN; +--disable_query_log +--echo Repeat statement 'INSERT INTO t1 VALUES(\$n, repeat("a", 32))' $n times +while ($n) +{ + --eval INSERT INTO t1 VALUES ($n, repeat("a", 32)) + --dec $n +} +--enable_query_log +COMMIT; + connection slave; ---source include/wait_for_slave_sql_to_stop.inc +--let $slave_sql_errno= 1197 +source include/wait_for_slave_sql_error.inc; + +SELECT count(*) FROM t1; +source include/show_binlog_events.inc; + +--replace_result $old_max_binlog_cache_size ORIGINAL_VALUE +--eval SET GLOBAL max_binlog_cache_size= $old_max_binlog_cache_size +--replace_result $old_binlog_cache_size ORIGINAL_VALUE +--eval SET GLOBAL binlog_cache_size= $old_binlog_cache_size + +source include/stop_slave.inc; +source include/start_slave.inc; + +connection master; +sync_slave_with_master; +SELECT count(*) FROM t1; --echo ######################################################################################## --echo # CLEAN @@ -384,12 +452,5 @@ DROP TABLE IF EXISTS t4; DROP TABLE IF EXISTS t5; DROP TABLE IF EXISTS t6; DROP PROCEDURE p1; -connection slave; -DROP TABLE t1; -DROP TABLE t2; -DROP TABLE t3; -DROP TABLE IF EXISTS t4; -DROP TABLE IF EXISTS t5; -DROP TABLE IF EXISTS t6; -DROP PROCEDURE p1; --enable_warnings +source include/master-slave-end.inc; diff --git a/sql/log_event.cc b/sql/log_event.cc index 7becdf51747..e3ce216ab70 100644 --- a/sql/log_event.cc +++ b/sql/log_event.cc @@ -144,16 +144,21 @@ static void inline slave_rows_error_report(enum loglevel level, int ha_error, len= my_snprintf(slider, buff_end - slider, " %s, Error_code: %d;", err->msg, err->code); } - - rli->report(level, thd->is_error()? thd->main_da.sql_errno() : 0, - "Could not execute %s event on table %s.%s;" - "%s handler error %s; " - "the event's master log %s, end_log_pos %lu", - type, table->s->db.str, - table->s->table_name.str, - buff, - handler_error == NULL? "" : handler_error, - log_name, pos); + + if (ha_error != 0) + rli->report(level, thd->is_error() ? thd->main_da.sql_errno() : 0, + "Could not execute %s event on table %s.%s;" + "%s handler error %s; " + "the event's master log %s, end_log_pos %lu", + type, table->s->db.str, table->s->table_name.str, + buff, handler_error == NULL ? "" : handler_error, + log_name, pos); + else + rli->report(level, thd->is_error() ? thd->main_da.sql_errno() : 0, + "Could not execute %s event on table %s.%s;" + "%s the event's master log %s, end_log_pos %lu", + type, table->s->db.str, table->s->table_name.str, + buff, log_name, pos); } #endif @@ -7649,7 +7654,6 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli) get_type_str(), RPL_LOG_NAME, (ulong) log_pos); thd->reset_current_stmt_binlog_row_based(); - const_cast(rli)->cleanup_context(thd, error); thd->is_slave_error= 1; DBUG_RETURN(error); } @@ -7680,14 +7684,12 @@ int Rows_log_event::do_apply_event(Relay_log_info const *rli) const_cast(rli)->last_event_start_time= my_time(0); } - if (get_flags(STMT_END_F)) - if ((error= rows_event_stmt_cleanup(rli, thd))) - rli->report(ERROR_LEVEL, error, - "Error in %s event: commit of row events failed, " - "table `%s`.`%s`", - get_type_str(), m_table->s->db.str, - m_table->s->table_name.str); - + if (get_flags(STMT_END_F) && (error= rows_event_stmt_cleanup(rli, thd))) + slave_rows_error_report(ERROR_LEVEL, + thd->is_error() ? 0 : error, + rli, thd, table, + get_type_str(), + RPL_LOG_NAME, (ulong) log_pos); DBUG_RETURN(error); } diff --git a/sql/slave.cc b/sql/slave.cc index f1e0962e7e8..353d4913208 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -2343,7 +2343,7 @@ static int exec_relay_log_event(THD* thd, Relay_log_info* rli) else { exec_res= 0; - end_trans(thd, ROLLBACK); + rli->cleanup_context(thd, 1); /* chance for concurrent connection to get more locks */ safe_sleep(thd, min(rli->trans_retries, MAX_SLAVE_RETRY_PAUSE), (CHECK_KILLED_FUNC)sql_slave_killed, (void*)rli); @@ -3158,6 +3158,7 @@ the slave SQL thread with \"SLAVE START\". We stopped at log \ request is detected only by the present function, not by events), so we must "proactively" clear playgrounds: */ + thd->clear_error(); rli->cleanup_context(thd, 1); /* Some extra safety, which should not been needed (normally, event deletion From 34b889e10f8a8516a7b9ad88b962bb991434a27e Mon Sep 17 00:00:00 2001 From: Sunny Bains Date: Mon, 11 Oct 2010 11:26:49 +1100 Subject: [PATCH 39/47] Bug# 56982 Assertion Failure from ha_innobase::innobase_peek_autoinc() when auto_inc > 0 Print an error message to stderr an get rid of the assertion. Approved by: Jimmy Yang (over IM) --- storage/innodb_plugin/handler/ha_innodb.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/storage/innodb_plugin/handler/ha_innodb.cc b/storage/innodb_plugin/handler/ha_innodb.cc index a7635a402a6..95778eb0744 100644 --- a/storage/innodb_plugin/handler/ha_innodb.cc +++ b/storage/innodb_plugin/handler/ha_innodb.cc @@ -9389,7 +9389,11 @@ ha_innobase::innobase_peek_autoinc(void) auto_inc = dict_table_autoinc_read(innodb_table); - ut_a(auto_inc > 0); + if (auto_inc == 0) { + ut_print_timestamp(stderr); + fprintf(stderr, " InnoDB: AUTOINC next value generation " + "is disabled for '%s'\n", innodb_table->name); + } dict_table_autoinc_unlock(innodb_table); From 36a2727e347ea93d8438a4f8a1f8de7f3fe1a2f4 Mon Sep 17 00:00:00 2001 From: Date: Mon, 11 Oct 2010 10:49:00 +0800 Subject: [PATCH 40/47] Postfix for BUG#55375 Removed option file and changed result file. --- .../r/rpl_mixed_binlog_max_cache_size.result | 42 ++++++++++++++++--- ...rpl_mixed_binlog_max_cache_size-master.opt | 1 - 2 files changed, 37 insertions(+), 6 deletions(-) delete mode 100644 mysql-test/suite/rpl/t/rpl_mixed_binlog_max_cache_size-master.opt diff --git a/mysql-test/suite/rpl/r/rpl_mixed_binlog_max_cache_size.result b/mysql-test/suite/rpl/r/rpl_mixed_binlog_max_cache_size.result index 1ad34fbe961..479caed8e6b 100644 --- a/mysql-test/suite/rpl/r/rpl_mixed_binlog_max_cache_size.result +++ b/mysql-test/suite/rpl/r/rpl_mixed_binlog_max_cache_size.result @@ -5,6 +5,8 @@ reset slave; drop table if exists t1,t2,t3,t4,t5,t6,t7,t8,t9; start slave; call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); +SET GLOBAL max_binlog_cache_size = 4096; +SET GLOBAL binlog_cache_size = 4096; CREATE TABLE t1(a INT PRIMARY KEY, data VARCHAR(30000)) ENGINE=Innodb; CREATE TABLE t2(a INT PRIMARY KEY, data VARCHAR(30000)) ENGINE=MyIsam; CREATE TABLE t3(a INT PRIMARY KEY, data VARCHAR(30000)) ENGINE=Innodb; @@ -15,13 +17,14 @@ CREATE TABLE t3(a INT PRIMARY KEY, data VARCHAR(30000)) ENGINE=Innodb; Got one of the listed errors *** Single statement on non-transactional table *** Got one of the listed errors -SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; -START SLAVE SQL_THREAD; +--source include/wait_for_slave_sql_error_and_skip.inc +SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1; +include/start_slave.inc *** Single statement on both transactional and non-transactional tables. *** Got one of the listed errors -SET GLOBAL SQL_SLAVE_SKIP_COUNTER = 1; -START SLAVE SQL_THREAD; -source include/diff_master_slave.inc; +--source include/wait_for_slave_sql_error_and_skip.inc +SET GLOBAL SQL_SLAVE_SKIP_COUNTER= 1; +include/start_slave.inc ######################################################################################## # 2 - BEGIN - IMPLICIT COMMIT by DDL ######################################################################################## @@ -119,6 +122,35 @@ BEGIN; Got one of the listed errors COMMIT; source include/diff_master_slave.inc; +######################################################################## +# 8 - Bug#55375(Regression Bug) Transaction bigger than +# max_binlog_cache_size crashes slave +######################################################################## +# [ On Slave ] +SET GLOBAL max_binlog_cache_size = 4096; +SET GLOBAL binlog_cache_size = 4096; +include/stop_slave.inc +include/start_slave.inc +CALL mtr.add_suppression("Multi-statement transaction required more than 'max_binlog_cache_size' bytes of storage.*"); +CALL mtr.add_suppression("Writing one row to the row-based binary log failed.*"); +TRUNCATE t1; +SET GLOBAL max_binlog_cache_size= ORIGINAL_VALUE; +SET GLOBAL binlog_cache_size= ORIGINAL_VALUE; +BEGIN; +Repeat statement 'INSERT INTO t1 VALUES($n, repeat("a", 32))' 128 times +COMMIT; +SELECT count(*) FROM t1; +count(*) +0 +show binlog events in 'slave-bin.000001' from ; +Log_name Pos Event_type Server_id End_log_pos Info +SET GLOBAL max_binlog_cache_size= ORIGINAL_VALUE; +SET GLOBAL binlog_cache_size= ORIGINAL_VALUE; +include/stop_slave.inc +include/start_slave.inc +SELECT count(*) FROM t1; +count(*) +128 ######################################################################################## # CLEAN ######################################################################################## diff --git a/mysql-test/suite/rpl/t/rpl_mixed_binlog_max_cache_size-master.opt b/mysql-test/suite/rpl/t/rpl_mixed_binlog_max_cache_size-master.opt deleted file mode 100644 index 45631525481..00000000000 --- a/mysql-test/suite/rpl/t/rpl_mixed_binlog_max_cache_size-master.opt +++ /dev/null @@ -1 +0,0 @@ ---binlog_cache_size=4096 --max_binlog_cache_size=7680 From d7767d4ab66e0b9e54f09e34b90d4d1ea8274909 Mon Sep 17 00:00:00 2001 From: Date: Mon, 11 Oct 2010 11:08:49 +0800 Subject: [PATCH 41/47] Bug#56226 Table map set to 0 after altering MyISAM table After ALTER TABLE which changed only table's metadata, row-based binlog sometimes got corrupted since the tablemap was unexpectedly set to 0 for subsequent updates to the same table. ALTER TABLE which changed only table's metadata always reset table_map_id for the table share to 0. Despite the fact that 0 is a valid value for table_map_id, this step caused problems as it could have created situation in which we had more than one table share with table_map_id equal 0. If more than one table with table_map_id are 0 were updated in the same statement, updates to these different tables were written into the same rows event. This caused slave server to crash. This bug happens only on 5.1. It doesn't affect 5.5+. This patch solves this problem by ensuring that ALTER TABLE statements which change metadata only never reset table_map_id to 0. To do this it changes reopen_table() to correctly use refreshed table_map_id value instead of using the old one/ resetting it. --- mysql-test/suite/rpl/r/rpl_alter.result | 20 +++++++++ mysql-test/suite/rpl/t/rpl_alter.test | 59 ++++++++++++++++++++++--- sql/sql_base.cc | 2 - 3 files changed, 73 insertions(+), 8 deletions(-) diff --git a/mysql-test/suite/rpl/r/rpl_alter.result b/mysql-test/suite/rpl/r/rpl_alter.result index 6ef5ce3462a..cedb6854239 100644 --- a/mysql-test/suite/rpl/r/rpl_alter.result +++ b/mysql-test/suite/rpl/r/rpl_alter.result @@ -19,3 +19,23 @@ select * from mysqltest.t3; n 45 drop database mysqltest; + +# BUG#56226 Table map set to 0 after altering MyISAM table + +SET SESSION binlog_format='ROW'; +USE test; +CREATE TABLE t1 (a INT, b INT) ENGINE MyISAM; +CREATE TABLE t2 (a VARCHAR(255), b VARCHAR(255)) ENGINE MyISAM; +CREATE TRIGGER trg_t1ai +AFTER INSERT ON t1 FOR EACH ROW +BEGIN +INSERT INTO t2 (a) VALUES (NEW.a); +END;// +ALTER TABLE t1 CHANGE b c INT; +ALTER TABLE t2 CHANGE b c VARCHAR(255); + +INSERT INTO t1 (a) VALUES(2); +Comparing tables master:test.t1 and slave:test.t1 +Comparing tables master:test.t2 and slave:test.t2 + +DROP TABLE t1, t2; diff --git a/mysql-test/suite/rpl/t/rpl_alter.test b/mysql-test/suite/rpl/t/rpl_alter.test index 576376a0264..bc42476244a 100644 --- a/mysql-test/suite/rpl/t/rpl_alter.test +++ b/mysql-test/suite/rpl/t/rpl_alter.test @@ -10,15 +10,62 @@ insert into mysqltest.t1 values (1,2); create table mysqltest.t2 (n int); insert into mysqltest.t2 values (45); rename table mysqltest.t2 to mysqltest.t3, mysqltest.t1 to mysqltest.t2; -save_master_pos; -connection slave; -sync_with_master; + +sync_slave_with_master; select * from mysqltest.t2; select * from mysqltest.t3; + connection master; drop database mysqltest; -save_master_pos; -connection slave; -sync_with_master; +sync_slave_with_master; +--echo +--echo # BUG#56226 Table map set to 0 after altering MyISAM table +--echo +connection master; +SET SESSION binlog_format='ROW'; +USE test; + +CREATE TABLE t1 (a INT, b INT) ENGINE MyISAM; +CREATE TABLE t2 (a VARCHAR(255), b VARCHAR(255)) ENGINE MyISAM; + +--delimiter // +CREATE TRIGGER trg_t1ai + AFTER INSERT ON t1 FOR EACH ROW +BEGIN + INSERT INTO t2 (a) VALUES (NEW.a); +END;// +--delimiter ; + +ALTER TABLE t1 CHANGE b c INT; +ALTER TABLE t2 CHANGE b c VARCHAR(255); +let $binlog_file= query_get_value(SHOW MASTER STATUS, File, 1); +let $binlog_start= query_get_value(SHOW MASTER STATUS, Position, 1); + +--echo +INSERT INTO t1 (a) VALUES(2); +let _info= query_get_value(SHOW BINLOG EVENTS IN '$binlog_file' FROM $binlog_start, Info, 2); +# Table map id should not be 0. +if (`SELECT 'table_id: 0 (test.t1)' = '$_info'`) +{ + --echo test.t1's table map id is 0; + --die test.t1's table map id is 0; +} +let _info= query_get_value(SHOW BINLOG EVENTS IN '$binlog_file' FROM $binlog_start, Info, 3); +if (`SELECT 'table_id: 0 (test.t2)' = '$_info'`) +{ + --echo test.t2's table map id is 0; + --die test.t2's table map id is 0; +} + +let diff_table= test.t1; +source include/rpl_diff_tables.inc; +let diff_table= test.t2; +source include/rpl_diff_tables.inc; + +--echo +connection master; +DROP TABLE t1, t2; + +source include/master-slave-end.inc; # End of 4.1 tests diff --git a/sql/sql_base.cc b/sql/sql_base.cc index c38526a6d0b..3766ff18293 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -3082,8 +3082,6 @@ bool reopen_table(TABLE *table) tmp.maybe_null= table->maybe_null; tmp.status= table->status; - tmp.s->table_map_id= table->s->table_map_id; - /* Get state */ tmp.in_use= thd; tmp.reginfo.lock_type=table->reginfo.lock_type; From f3a8c2be04336006e9e65d3aaafb4cfcf66b1642 Mon Sep 17 00:00:00 2001 From: Jimmy Yang Date: Mon, 11 Oct 2010 05:36:13 -0700 Subject: [PATCH 42/47] A more complete fix for bug #57345 btr_pcur_store_position abort for load with concurrent lock/unlock tables Approved by Marko --- storage/innobase/row/row0sel.c | 14 +++++++++++++- storage/innodb_plugin/ChangeLog | 5 +++++ storage/innodb_plugin/row/row0sel.c | 14 +++++++++++++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/storage/innobase/row/row0sel.c b/storage/innobase/row/row0sel.c index a64dd3151ee..ecb2c492706 100644 --- a/storage/innobase/row/row0sel.c +++ b/storage/innobase/row/row0sel.c @@ -3259,6 +3259,7 @@ row_search_for_mysql( mem_heap_t* heap = NULL; ulint offsets_[REC_OFFS_NORMAL_SIZE]; ulint* offsets = offsets_; + ibool table_lock_waited = FALSE; *offsets_ = (sizeof offsets_) / sizeof *offsets_; @@ -3622,13 +3623,15 @@ shortcut_fails_too_big_rec: trx_assign_read_view(trx); prebuilt->sql_stat_start = FALSE; } else { +wait_table_again: err = lock_table(0, index->table, prebuilt->select_lock_type == LOCK_S ? LOCK_IS : LOCK_IX, thr); if (err != DB_SUCCESS) { - goto lock_wait_or_error; + table_lock_waited = TRUE; + goto lock_table_wait; } prebuilt->sql_stat_start = FALSE; } @@ -4408,6 +4411,7 @@ lock_wait_or_error: btr_pcur_store_position(pcur, &mtr); +lock_table_wait: mtr_commit(&mtr); mtr_has_extra_clust_latch = FALSE; @@ -4425,6 +4429,14 @@ lock_wait_or_error: thr->lock_state = QUE_THR_LOCK_NOLOCK; mtr_start(&mtr); + /* Table lock waited, go try to obtain table lock + again */ + if (table_lock_waited) { + table_lock_waited = FALSE; + + goto wait_table_again; + } + sel_restore_position_for_mysql(&same_user_rec, BTR_SEARCH_LEAF, pcur, moves_up, &mtr); diff --git a/storage/innodb_plugin/ChangeLog b/storage/innodb_plugin/ChangeLog index 986750c28bf..3b1f202c8ac 100644 --- a/storage/innodb_plugin/ChangeLog +++ b/storage/innodb_plugin/ChangeLog @@ -1,3 +1,8 @@ +2010-10-11 The InnoDB Team + * row/row0sel.c + Fix Bug #57345 btr_pcur_store_position abort for load with + concurrent lock/unlock tables + 2010-09-27 The InnoDB Team * row/row0sel.c, innodb_bug56716.result, innodb_bug56716.test: diff --git a/storage/innodb_plugin/row/row0sel.c b/storage/innodb_plugin/row/row0sel.c index 8b17bdc6ad3..cc7a7a6fe9b 100644 --- a/storage/innodb_plugin/row/row0sel.c +++ b/storage/innodb_plugin/row/row0sel.c @@ -3356,6 +3356,7 @@ row_search_for_mysql( mem_heap_t* heap = NULL; ulint offsets_[REC_OFFS_NORMAL_SIZE]; ulint* offsets = offsets_; + ibool table_lock_waited = FALSE; rec_offs_init(offsets_); @@ -3742,13 +3743,15 @@ release_search_latch_if_needed: trx_assign_read_view(trx); prebuilt->sql_stat_start = FALSE; } else { +wait_table_again: err = lock_table(0, index->table, prebuilt->select_lock_type == LOCK_S ? LOCK_IS : LOCK_IX, thr); if (err != DB_SUCCESS) { - goto lock_wait_or_error; + table_lock_waited = TRUE; + goto lock_table_wait; } prebuilt->sql_stat_start = FALSE; } @@ -4559,6 +4562,7 @@ lock_wait_or_error: btr_pcur_store_position(pcur, &mtr); +lock_table_wait: mtr_commit(&mtr); mtr_has_extra_clust_latch = FALSE; @@ -4576,6 +4580,14 @@ lock_wait_or_error: thr->lock_state = QUE_THR_LOCK_NOLOCK; mtr_start(&mtr); + /* Table lock waited, go try to obtain table lock + again */ + if (table_lock_waited) { + table_lock_waited = FALSE; + + goto wait_table_again; + } + sel_restore_position_for_mysql(&same_user_rec, BTR_SEARCH_LEAF, pcur, moves_up, &mtr); From f2dabc49e120f19088c8b90dfa2763d9ee36168e Mon Sep 17 00:00:00 2001 From: Luis Soares Date: Mon, 11 Oct 2010 15:50:14 +0100 Subject: [PATCH 43/47] Fix for crash in mysqld --verbose --help while initializing option for --init-rpl-role. Problem: There are two variables involved in this issue, rpl_status and rpl_role_type. The former is an array containing the description of the possible values for the latter. rpl_status is declared as an enumeration and is stored in a 4 bytes integer. On the other hand, my_getopt, reads enum values into a ulong: *(ulong*)value= arg; This is overwriting the memory used for rpl_role_type, corrupting the first entry in the array. Fix: We fix this by re-declaring rpl_status as a ulong, so that it has space to accommodate the value "parsed" in my_getopt . --- sql/repl_failsafe.cc | 4 ++-- sql/repl_failsafe.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sql/repl_failsafe.cc b/sql/repl_failsafe.cc index 47eb2f7031d..540b62b9d3b 100644 --- a/sql/repl_failsafe.cc +++ b/sql/repl_failsafe.cc @@ -41,7 +41,7 @@ #define SLAVE_ERRMSG_SIZE (FN_REFLEN+64) -RPL_STATUS rpl_status=RPL_NULL; +ulong rpl_status=RPL_NULL; mysql_mutex_t LOCK_rpl_status; mysql_cond_t COND_rpl_status; HASH slave_list; @@ -68,7 +68,7 @@ static Slave_log_event* find_slave_event(IO_CACHE* log, functions like register_slave()) are working. */ -void change_rpl_status(RPL_STATUS from_status, RPL_STATUS to_status) +void change_rpl_status(ulong from_status, ulong to_status) { mysql_mutex_lock(&LOCK_rpl_status); if (rpl_status == from_status || rpl_status == RPL_ANY) diff --git a/sql/repl_failsafe.h b/sql/repl_failsafe.h index c6d00de47cb..a0c41686696 100644 --- a/sql/repl_failsafe.h +++ b/sql/repl_failsafe.h @@ -26,7 +26,7 @@ typedef enum {RPL_AUTH_MASTER=0,RPL_IDLE_SLAVE,RPL_ACTIVE_SLAVE, RPL_LOST_SOLDIER,RPL_TROOP_SOLDIER, RPL_RECOVERY_CAPTAIN,RPL_NULL /* inactive */, RPL_ANY /* wild card used by change_rpl_status */ } RPL_STATUS; -extern RPL_STATUS rpl_status; +extern ulong rpl_status; extern mysql_mutex_t LOCK_rpl_status; extern mysql_cond_t COND_rpl_status; @@ -34,7 +34,7 @@ extern TYPELIB rpl_role_typelib; extern const char* rpl_role_type[], *rpl_status_type[]; pthread_handler_t handle_failsafe_rpl(void *arg); -void change_rpl_status(RPL_STATUS from_status, RPL_STATUS to_status); +void change_rpl_status(ulong from_status, ulong to_status); int find_recovery_captain(THD* thd, MYSQL* mysql); int update_slave_list(MYSQL* mysql, Master_info* mi); From c0557845a17eb1329ceae25c1fafd4385aa36a6f Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Mon, 11 Oct 2010 19:44:35 +0200 Subject: [PATCH 44/47] Do not accept invalid INSTALL_LAYOUT parameter --- cmake/install_layout.cmake | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmake/install_layout.cmake b/cmake/install_layout.cmake index ade6cdb747f..fcc1a2054b1 100644 --- a/cmake/install_layout.cmake +++ b/cmake/install_layout.cmake @@ -59,13 +59,16 @@ # - INSTALL_SUPPORTFILESDIR (various extra support files) # # - INSTALL_MYSQLDATADIR (data directory) +# +# When changing this page, _please_ do not forget to update public Wiki +# http://forge.mysql.com/wiki/CMake#Fine-tuning_installation_paths IF(NOT INSTALL_LAYOUT) SET(DEFAULT_INSTALL_LAYOUT "STANDALONE") ENDIF() SET(INSTALL_LAYOUT "${DEFAULT_INSTALL_LAYOUT}" -CACHE STRING "Installation directory layout. Options are: STANDALONE (as in zip or tar.gz installer) or UNIX") +CACHE STRING "Installation directory layout. Options are: STANDALONE (as in zip or tar.gz installer), RPM, DEB, SVR4") IF(UNIX) IF(INSTALL_LAYOUT MATCHES "RPM") @@ -83,6 +86,13 @@ IF(UNIX) SET(CMAKE_INSTALL_PREFIX ${default_prefix} CACHE PATH "install prefix" FORCE) ENDIF() + SET(VALID_INSTALL_LAYOUTS "RPM" "STANDALONE" "DEB" "SVR5") + LIST(FIND VALID_INSTALL_LAYOUTS "${INSTALL_LAYOUT}" ind) + IF(ind EQUAL -1) + MESSAGE(FATAL_ERROR "Invalid INSTALL_LAYOUT parameter:${INSTALL_LAYOUT}." + " Choose between ${VALID_INSTALL_LAYOUTS}" ) + ENDIF() + SET(SYSCONFDIR "${CMAKE_INSTALL_PREFIX}/etc" CACHE PATH "config directory (for my.cnf)") MARK_AS_ADVANCED(SYSCONFDIR) From 26e12a11bb7d8e88c07ec1e360c77834819ebc29 Mon Sep 17 00:00:00 2001 From: Alexander Nozdrin Date: Tue, 12 Oct 2010 14:07:13 +0400 Subject: [PATCH 45/47] Fix compilation warnings. --- sql-common/client.c | 2 +- sql/sql_acl.cc | 2 +- sql/sql_cache.cc | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/sql-common/client.c b/sql-common/client.c index 0a30ef150e1..e8ca74eba37 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -2923,7 +2923,7 @@ CLI_MYSQL_REAL_CONNECT(MYSQL *mysql,const char *host, const char *user, uint port, const char *unix_socket,ulong client_flag) { char buff[NAME_LEN+USERNAME_LENGTH+100]; - int scramble_data_len, pkt_scramble_len; + int scramble_data_len, pkt_scramble_len= 0; char *end,*host_info= 0, *server_version_end, *pkt_end; char *scramble_data; const char *scramble_plugin; diff --git a/sql/sql_acl.cc b/sql/sql_acl.cc index 571a7890116..5583e9a29f1 100644 --- a/sql/sql_acl.cc +++ b/sql/sql_acl.cc @@ -3936,7 +3936,7 @@ bool mysql_grant(THD *thd, const char *db, List &list, ulong rights, bool revoke_grant, bool is_proxy) { List_iterator str_list (list); - LEX_USER *Str, *tmp_Str, *proxied_user; + LEX_USER *Str, *tmp_Str, *proxied_user= NULL; char tmp_db[NAME_LEN+1]; bool create_new_users=0; TABLE_LIST tables[2]; diff --git a/sql/sql_cache.cc b/sql/sql_cache.cc index 9876c46bbb3..0dadc0f0cd4 100644 --- a/sql/sql_cache.cc +++ b/sql/sql_cache.cc @@ -412,7 +412,8 @@ struct Query_cache_wait_state Query_cache_wait_state(THD *thd, const char *func, const char *file, unsigned int line) - : m_thd(thd) + : m_thd(thd), + m_proc_info(NULL) { if (m_thd) m_proc_info= set_thd_proc_info(m_thd, From 8b4d9323861ae9a3c52fd6437467bc6fa97ead18 Mon Sep 17 00:00:00 2001 From: Alexander Nozdrin Date: Tue, 12 Oct 2010 14:07:49 +0400 Subject: [PATCH 46/47] Remove NDB test suites from default-test-suites in MTR. --- mysql-test/mysql-test-run.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index baf179a4ae6..88719ff5bb2 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -162,7 +162,7 @@ our $opt_vs_config = $ENV{'MTR_VS_CONFIG'}; # If you add a new suite, please check TEST_DIRS in Makefile.am. # -my $DEFAULT_SUITES= "main,sys_vars,binlog,federated,rpl,rpl_ndb,ndb,innodb,perfschema"; +my $DEFAULT_SUITES= "main,sys_vars,binlog,federated,rpl,innodb,perfschema"; my $opt_suites; our $opt_verbose= 0; # Verbose output, enable with --verbose From b79f67eaf4874f9111d59a85d180c4fa9597f417 Mon Sep 17 00:00:00 2001 From: Dmitry Shulga Date: Tue, 12 Oct 2010 19:19:33 +0700 Subject: [PATCH 47/47] A follow up for the patch for Bug#45445, increase stack size to fix an sp-error.test failure on Sun Sparc system. --- sql/sp_head.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sql/sp_head.cc b/sql/sp_head.cc index e25b10957ac..52f658cbe0e 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -1228,12 +1228,13 @@ sp_head::execute(THD *thd) parsing and loading of another stored procedure into the cache (@sa db_load_routine() and Bug#10100). At the time of measuring, a recursive SP invocation required - 3232 bytes of stack on 32 bit Linux and 6016 bytes on 64 bit Mac. + 3232 bytes of stack on 32 bit Linux, 6016 bytes on 64 bit Mac + and 11152 on 64 bit Solaris sparc. The same with db_load_routine() required circa 7k bytes and 14k bytes accordingly. Hence, here we book the stack with some reasonable margin. */ - if (check_stack_overrun(thd, 2 * STACK_MIN_SIZE, (uchar*)&old_packet)) + if (check_stack_overrun(thd, 4 * STACK_MIN_SIZE, (uchar*)&old_packet)) DBUG_RETURN(TRUE); /* init per-instruction memroot */