From 70e6f0d854cb7a47bd24e09f1a1723f106afd53f Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Tue, 21 Feb 2012 14:17:33 +0200 Subject: [PATCH 01/10] Fixed suppression expression. --- 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 3e1be3ab077..34b018bcc47 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -4445,7 +4445,7 @@ sub extract_warning_lines ($) { qr/Slave: Operation DROP USER failed for 'create_rout_db'/, qr|Checking table: '\..mtr.test_suppressions'|, qr|Table \./test/bug53592 has a primary key in InnoDB data dictionary, but not in MySQL|, - qr|mysqld: Table '\..mtr.test_suppressions' is marked as crashed and should be repaired|, + qr|Table '\..mtr.test_suppressions' is marked as crashed and should be repaired|, qr|InnoDB: Error: table 'test/bug39438'|, qr|table.*is full|, ); From 6fbeed067b25a07542dd989b7a816969615d7df6 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Tue, 21 Feb 2012 17:58:43 +0200 Subject: [PATCH 02/10] Fixed that 'make distcheck' works with automake 1.11.11 Fixed compiler warnings found by buildbot Makefile.am: Removed extra empty line cmd-line-utils/libedit/sys.h: Fixed that strndup() doesn't give compiler warnings mysql-test/Makefile.am: Fixes for 'make distcheck' plugin/auth_pam/auth_pam.c: Ensure that prototype for strndup() is included on linux sql/share/Makefile.am: Fixes for 'make distcheck' storage/innodb_plugin/btr/btr0sea.c: Fixed compiler warning support-files/Makefile.am: Fixes for 'make distcheck' --- Makefile.am | 1 - cmd-line-utils/libedit/sys.h | 22 +++++++++++----------- mysql-test/Makefile.am | 2 ++ plugin/auth_pam/auth_pam.c | 4 ++++ sql/share/Makefile.am | 1 + storage/innodb_plugin/btr/btr0sea.c | 4 ++-- support-files/Makefile.am | 3 +++ 7 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Makefile.am b/Makefile.am index cc1156fce5a..f0b617fcb66 100644 --- a/Makefile.am +++ b/Makefile.am @@ -277,7 +277,6 @@ API_PREPROCESSOR_HEADER = $(top_srcdir)/include/mysql.h \ TEST_PREPROCESSOR_HEADER = $(API_PREPROCESSOR_HEADER) \ $(top_srcdir)/sql/mysql_priv.h - # # Rules for checking that the abi/api has not changed. diff --git a/cmd-line-utils/libedit/sys.h b/cmd-line-utils/libedit/sys.h index 33638d1565b..af55bcd7202 100644 --- a/cmd-line-utils/libedit/sys.h +++ b/cmd-line-utils/libedit/sys.h @@ -40,6 +40,17 @@ #ifndef _h_sys #define _h_sys +#ifdef __linux__ +/* Apparently we need _GNU_SOURCE defined to get access to wcsdup on Linux */ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif +#endif + +#ifndef __USE_XOPEN +#define __USE_XOPEN +#endif + #ifdef HAVE_SYS_CDEFS_H #include #endif @@ -92,17 +103,6 @@ size_t strlcpy(char *dst, const char *src, size_t size); char *fgetln(FILE *fp, size_t *len); #endif -#ifdef __linux__ -/* Apparently we need _GNU_SOURCE defined to get access to wcsdup on Linux */ -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif -#endif - -#ifndef __USE_XOPEN -#define __USE_XOPEN -#endif - #include #include diff --git a/mysql-test/Makefile.am b/mysql-test/Makefile.am index 6a1e677fd79..e1780982b8c 100644 --- a/mysql-test/Makefile.am +++ b/mysql-test/Makefile.am @@ -144,6 +144,8 @@ install-data-local: uninstall-local: @RM@ -f -r $(DESTDIR)$(testdir) +uninstall-am: uninstall-local + # mtr - a shortcut for executing mysql-test-run.pl mtr: $(RM) -f mtr diff --git a/plugin/auth_pam/auth_pam.c b/plugin/auth_pam/auth_pam.c index ee13b37f793..de62ebf8dbd 100644 --- a/plugin/auth_pam/auth_pam.c +++ b/plugin/auth_pam/auth_pam.c @@ -1,3 +1,7 @@ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE /* For strndup() */ +#endif + #include #include #include diff --git a/sql/share/Makefile.am b/sql/share/Makefile.am index 892a720900e..8b7792481e6 100644 --- a/sql/share/Makefile.am +++ b/sql/share/Makefile.am @@ -49,6 +49,7 @@ install-data-local: $(INSTALL_DATA) $(srcdir)/charsets/*.xml $(DESTDIR)$(pkgdatadir)/charsets # FIXME maybe shouldn't remove, could be needed by other installation? +# Note that this removes the directory that support-files are using! uninstall-local: @RM@ -f -r $(DESTDIR)$(pkgdatadir) diff --git a/storage/innodb_plugin/btr/btr0sea.c b/storage/innodb_plugin/btr/btr0sea.c index 3dd30cbc0f3..04c273344f3 100644 --- a/storage/innodb_plugin/btr/btr0sea.c +++ b/storage/innodb_plugin/btr/btr0sea.c @@ -827,7 +827,7 @@ btr_search_guess_on_hash( mtr_t* mtr) /*!< in: mtr */ { buf_block_t* block; - const rec_t* rec; + rec_t* rec; ulint fold; dulint index_id; #ifdef notdefined @@ -913,7 +913,7 @@ btr_search_guess_on_hash( ut_ad(page_rec_is_user_rec(rec)); - btr_cur_position(index, (rec_t*) rec, block, cursor); + btr_cur_position(index, rec, block, cursor); /* Check the validity of the guess within the page */ diff --git a/support-files/Makefile.am b/support-files/Makefile.am index 6b5dfbd7d8d..821ba7ffac9 100644 --- a/support-files/Makefile.am +++ b/support-files/Makefile.am @@ -85,6 +85,9 @@ mysql-@VERSION@.spec: mysql.spec rm -f $@ cp mysql.spec $@ +# We don't need to uninstall as sql/share/Makefile.am is doing that for us +uninstall-am: + SUFFIXES = .sh .sh: From c9fc9f73170a8eb16ea968a2ea51b298eb5cdcfc Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 21 Feb 2012 21:18:41 +0100 Subject: [PATCH 03/10] lp:923429 Crash in decimal_cmp on using UNIX_TIMESTAMP with a wrongly formatted timestamp UNIX_TIMESTAMP() can be null, and returns null for invalid values --- mysql-test/r/type_timestamp.result | 13 +++++++++++++ mysql-test/t/type_timestamp.test | 7 +++++++ sql/item_timefunc.cc | 8 -------- sql/item_timefunc.h | 5 ----- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/mysql-test/r/type_timestamp.result b/mysql-test/r/type_timestamp.result index cfe229d2d15..5c3c3226bf8 100644 --- a/mysql-test/r/type_timestamp.result +++ b/mysql-test/r/type_timestamp.result @@ -587,3 +587,16 @@ Variable_name Value Handler_read_next 1 DROP TABLE t1, t2; End of 5.1 tests +# +# lp:923429 Crash in decimal_cmp on using UNIX_TIMESTAMP with a wrongly formatted timestamp +# +SELECT UNIX_TIMESTAMP('abc') > 0; +UNIX_TIMESTAMP('abc') > 0 +NULL +Warnings: +Warning 1292 Incorrect datetime value: 'abc' +SELECT UNIX_TIMESTAMP('abc'); +UNIX_TIMESTAMP('abc') +NULL +Warnings: +Warning 1292 Incorrect datetime value: 'abc' diff --git a/mysql-test/t/type_timestamp.test b/mysql-test/t/type_timestamp.test index 533a45ba7fe..674f22cd1c2 100644 --- a/mysql-test/t/type_timestamp.test +++ b/mysql-test/t/type_timestamp.test @@ -410,3 +410,10 @@ SHOW STATUS LIKE 'Handler_read_next'; DROP TABLE t1, t2; --echo End of 5.1 tests + +--echo # +--echo # lp:923429 Crash in decimal_cmp on using UNIX_TIMESTAMP with a wrongly formatted timestamp +--echo # +SELECT UNIX_TIMESTAMP('abc') > 0; +SELECT UNIX_TIMESTAMP('abc'); + diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc index e01a4399cbe..1002cf9fea8 100644 --- a/sql/item_timefunc.cc +++ b/sql/item_timefunc.cc @@ -1134,15 +1134,7 @@ bool Item_func_unix_timestamp::get_timestamp_value(my_time_t *seconds, MYSQL_TIME ltime; if (get_arg0_date(<ime, 0)) - { - /* - We have to set null_value again because get_arg0_date will also set it - to true if we have wrong datetime parameter (and we should return 0 in - this case). - */ - null_value= args[0]->null_value; return 1; - } uint error_code; *seconds= TIME_to_timestamp(current_thd, <ime, &error_code); diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index e1bf53a5baf..8d19e59ddfb 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -385,11 +385,6 @@ public: Item_func_unix_timestamp(Item *a) :Item_func_seconds_hybrid(a) {} const char *func_name() const { return "unix_timestamp"; } bool check_partition_func_processor(uchar *int_arg) {return FALSE;} - void fix_num_length_and_dec() - { - maybe_null= false; - Item_func_seconds_hybrid::fix_num_length_and_dec(); - } /* UNIX_TIMESTAMP() depends on the current timezone (and thus may not be used as a partitioning function) From c299e027eeddc35e0197ebc70805e0a303a4b135 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 22 Feb 2012 10:38:28 +0200 Subject: [PATCH 04/10] Changed names of statistic variables and counting matches instaed of rejected rows. --- mysql-test/include/icp_tests.inc | 6 +++--- mysql-test/r/innodb_icp.result | 18 +++++++++--------- mysql-test/r/join_cache.result | 24 ++++++++++++------------ mysql-test/r/maria_icp.result | 18 +++++++++--------- mysql-test/r/myisam_icp.result | 18 +++++++++--------- mysql-test/r/status.result | 8 ++++---- mysql-test/r/status_user.result | 4 ++-- mysql-test/t/join_cache.test | 8 ++++---- sql/handler.cc | 6 +++--- sql/mysqld.cc | 4 ++-- sql/sql_class.h | 4 ++-- sql/sql_join_cache.cc | 12 ++++++------ 12 files changed, 65 insertions(+), 65 deletions(-) diff --git a/mysql-test/include/icp_tests.inc b/mysql-test/include/icp_tests.inc index f412843ded0..e84b8622cdb 100644 --- a/mysql-test/include/icp_tests.inc +++ b/mysql-test/include/icp_tests.inc @@ -862,15 +862,15 @@ CREATE TABLE t1 ( INSERT INTO t1 VALUES ('3', '3'),('4','4'),('5','5'); flush status; -show status like "Handler_pushed%"; +show status like "Handler_icp%"; SELECT * FROM t1 FORCE INDEX(c1) WHERE (c1='3' or c1='4') and c1 % 2 = 0 ; -show status like "Handler_pushed%"; +show status like "Handler_icp%"; SELECT * FROM t1 WHERE (c2='3' or c2='4') and c2 % 2 = 0 ; -show status like "Handler_pushed%"; +show status like "Handler_icp%"; DROP TABLE t1; diff --git a/mysql-test/r/innodb_icp.result b/mysql-test/r/innodb_icp.result index d8e41113f63..2817f83bed5 100644 --- a/mysql-test/r/innodb_icp.result +++ b/mysql-test/r/innodb_icp.result @@ -816,24 +816,24 @@ KEY (c1) ); INSERT INTO t1 VALUES ('3', '3'),('4','4'),('5','5'); flush status; -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 0 -Handler_pushed_index_cond_filtered 0 +Handler_icp_attempts 0 +Handler_icp_match 0 SELECT * FROM t1 FORCE INDEX(c1) WHERE (c1='3' or c1='4') and c1 % 2 = 0 ; c1 c2 4 4 -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 2 -Handler_pushed_index_cond_filtered 1 +Handler_icp_attempts 2 +Handler_icp_match 1 SELECT * FROM t1 WHERE (c2='3' or c2='4') and c2 % 2 = 0 ; c1 c2 4 4 -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 2 -Handler_pushed_index_cond_filtered 1 +Handler_icp_attempts 2 +Handler_icp_match 1 DROP TABLE t1; set optimizer_switch=@innodb_icp_tmp; set storage_engine= @save_storage_engine; diff --git a/mysql-test/r/join_cache.result b/mysql-test/r/join_cache.result index 6908f40e854..9918ad2380d 100644 --- a/mysql-test/r/join_cache.result +++ b/mysql-test/r/join_cache.result @@ -3520,10 +3520,10 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where 1 SIMPLE t2 ref f1 f1 4 test.t1.f1 3 Using index condition(BKA); Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 20 -Handler_pushed_index_cond_filtered 16 +Handler_icp_attempts 20 +Handler_icp_match 4 set join_cache_level=6; select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; @@ -3537,10 +3537,10 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where 1 SIMPLE t2 ref f1 f1 4 test.t1.f1 3 Using index condition(BKA); Using join buffer (flat, BKA join); Key-ordered Rowid-ordered scan -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 40 -Handler_pushed_index_cond_filtered 32 +Handler_icp_attempts 40 +Handler_icp_match 8 set join_cache_level=7; select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; @@ -3554,10 +3554,10 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where 1 SIMPLE t2 ref f1 f1 4 test.t1.f1 3 Using index condition(BKA); Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 60 -Handler_pushed_index_cond_filtered 48 +Handler_icp_attempts 60 +Handler_icp_match 12 set join_cache_level=8; select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; @@ -3571,10 +3571,10 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL NULL NULL NULL NULL 3 Using where 1 SIMPLE t2 ref f1 f1 4 test.t1.f1 3 Using index condition(BKA); Using where; Using join buffer (flat, BKAH join); Key-ordered Rowid-ordered scan -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 80 -Handler_pushed_index_cond_filtered 64 +Handler_icp_attempts 80 +Handler_icp_match 16 drop table t1,t2; set join_cache_level=default; # diff --git a/mysql-test/r/maria_icp.result b/mysql-test/r/maria_icp.result index b9d3ca6c7c0..97b10fe496c 100644 --- a/mysql-test/r/maria_icp.result +++ b/mysql-test/r/maria_icp.result @@ -822,24 +822,24 @@ KEY (c1) ); INSERT INTO t1 VALUES ('3', '3'),('4','4'),('5','5'); flush status; -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 0 -Handler_pushed_index_cond_filtered 0 +Handler_icp_attempts 0 +Handler_icp_match 0 SELECT * FROM t1 FORCE INDEX(c1) WHERE (c1='3' or c1='4') and c1 % 2 = 0 ; c1 c2 4 4 -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 2 -Handler_pushed_index_cond_filtered 1 +Handler_icp_attempts 2 +Handler_icp_match 1 SELECT * FROM t1 WHERE (c2='3' or c2='4') and c2 % 2 = 0 ; c1 c2 4 4 -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 2 -Handler_pushed_index_cond_filtered 1 +Handler_icp_attempts 2 +Handler_icp_match 1 DROP TABLE t1; set storage_engine= @save_storage_engine; set optimizer_switch=@maria_icp_tmp; diff --git a/mysql-test/r/myisam_icp.result b/mysql-test/r/myisam_icp.result index d7442608b59..85a2ad921c6 100644 --- a/mysql-test/r/myisam_icp.result +++ b/mysql-test/r/myisam_icp.result @@ -820,24 +820,24 @@ KEY (c1) ); INSERT INTO t1 VALUES ('3', '3'),('4','4'),('5','5'); flush status; -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 0 -Handler_pushed_index_cond_filtered 0 +Handler_icp_attempts 0 +Handler_icp_match 0 SELECT * FROM t1 FORCE INDEX(c1) WHERE (c1='3' or c1='4') and c1 % 2 = 0 ; c1 c2 4 4 -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 2 -Handler_pushed_index_cond_filtered 1 +Handler_icp_attempts 2 +Handler_icp_match 1 SELECT * FROM t1 WHERE (c2='3' or c2='4') and c2 % 2 = 0 ; c1 c2 4 4 -show status like "Handler_pushed%"; +show status like "Handler_icp%"; Variable_name Value -Handler_pushed_index_cond_checks 2 -Handler_pushed_index_cond_filtered 1 +Handler_icp_attempts 2 +Handler_icp_match 1 DROP TABLE t1; drop table if exists t0, t1, t1i, t1m; # diff --git a/mysql-test/r/status.result b/mysql-test/r/status.result index e75cabe0e58..b5bae659eed 100644 --- a/mysql-test/r/status.result +++ b/mysql-test/r/status.result @@ -275,9 +275,9 @@ Variable_name Value Handler_commit 0 Handler_delete 0 Handler_discover 0 +Handler_icp_attempts 0 +Handler_icp_match 0 Handler_prepare 0 -Handler_pushed_index_cond_checks 0 -Handler_pushed_index_cond_filtered 0 Handler_read_first 0 Handler_read_key 4 Handler_read_next 0 @@ -312,9 +312,9 @@ Variable_name Value Handler_commit 0 Handler_delete 0 Handler_discover 0 +Handler_icp_attempts 0 +Handler_icp_match 0 Handler_prepare 0 -Handler_pushed_index_cond_checks 0 -Handler_pushed_index_cond_filtered 0 Handler_read_first 0 Handler_read_key 2 Handler_read_next 2 diff --git a/mysql-test/r/status_user.result b/mysql-test/r/status_user.result index 175839b2098..be0cfef79dc 100644 --- a/mysql-test/r/status_user.result +++ b/mysql-test/r/status_user.result @@ -100,9 +100,9 @@ Variable_name Value Handler_commit 19 Handler_delete 1 Handler_discover 0 +Handler_icp_attempts 0 +Handler_icp_match 0 Handler_prepare 18 -Handler_pushed_index_cond_checks 0 -Handler_pushed_index_cond_filtered 0 Handler_read_first 0 Handler_read_key 3 Handler_read_next 0 diff --git a/mysql-test/t/join_cache.test b/mysql-test/t/join_cache.test index 6cb8f48bd70..0962f1bf766 100644 --- a/mysql-test/t/join_cache.test +++ b/mysql-test/t/join_cache.test @@ -1533,7 +1533,7 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; explain select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; -show status like "Handler_pushed%"; +show status like "Handler_icp%"; set join_cache_level=6; select t2.f1, t2.f2, t2.f3 from t1,t2 @@ -1541,7 +1541,7 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; explain select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; -show status like "Handler_pushed%"; +show status like "Handler_icp%"; set join_cache_level=7; select t2.f1, t2.f2, t2.f3 from t1,t2 @@ -1549,7 +1549,7 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; explain select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; -show status like "Handler_pushed%"; +show status like "Handler_icp%"; set join_cache_level=8; select t2.f1, t2.f2, t2.f3 from t1,t2 @@ -1557,7 +1557,7 @@ where t1.f1=t2.f1 and t2.f2 between t1.f1 and t1.f2 and t2.f2 + 1 >= t1.f1 + 1; explain select t2.f1, t2.f2, t2.f3 from t1,t2 where t1.f1=t2.f1 and t2.f2 between t1.f1 and t2.f2; -show status like "Handler_pushed%"; +show status like "Handler_icp%"; drop table t1,t2; set join_cache_level=default; diff --git a/sql/handler.cc b/sql/handler.cc index 4a8cd77ebc3..04f10586484 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -4569,10 +4569,10 @@ extern "C" enum icp_result handler_index_cond_check(void* h_arg) if (h->end_range && h->compare_key2(h->end_range) > 0) return ICP_OUT_OF_RANGE; - h->increment_statistics(&SSV::ha_pushed_index_cond_checks); + h->increment_statistics(&SSV::ha_icp_attempts); if ((res= h->pushed_idx_cond->val_int()? ICP_MATCH : ICP_NO_MATCH) == - ICP_NO_MATCH) - h->increment_statistics(&SSV::ha_pushed_index_cond_filtered); + ICP_MATCH) + h->increment_statistics(&SSV::ha_icp_match); return res; } diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 70dba70eb15..147c2e80be3 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -8107,9 +8107,9 @@ SHOW_VAR status_vars[]= { {"Handler_mrr_extra_rowid_sorts", (char*) offsetof(STATUS_VAR, ha_mrr_extra_rowid_sorts), SHOW_LONG_STATUS}, {"Handler_mrr_init", (char*) offsetof(STATUS_VAR, ha_multi_range_read_init_count), SHOW_LONG_STATUS}, #endif + {"Handler_icp_attempts ", (char*) offsetof(STATUS_VAR, ha_icp_attempts), SHOW_LONG_STATUS}, + {"Handler_icp_match", (char*) offsetof(STATUS_VAR, ha_icp_match), SHOW_LONG_STATUS}, {"Handler_prepare", (char*) offsetof(STATUS_VAR, ha_prepare_count), SHOW_LONG_STATUS}, - {"Handler_pushed_index_cond_checks",(char*) offsetof(STATUS_VAR, ha_pushed_index_cond_checks), SHOW_LONG_STATUS}, - {"Handler_pushed_index_cond_filtered",(char*) offsetof(STATUS_VAR, ha_pushed_index_cond_filtered), SHOW_LONG_STATUS}, {"Handler_read_first", (char*) offsetof(STATUS_VAR, ha_read_first_count), SHOW_LONG_STATUS}, {"Handler_read_key", (char*) offsetof(STATUS_VAR, ha_read_key_count), SHOW_LONG_STATUS}, {"Handler_read_next", (char*) offsetof(STATUS_VAR, ha_read_next_count), SHOW_LONG_STATUS}, diff --git a/sql/sql_class.h b/sql/sql_class.h index c04af55a127..3b94270ae08 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -588,8 +588,8 @@ typedef struct system_status_var ulong ha_tmp_update_count; ulong ha_tmp_write_count; ulong ha_prepare_count; - ulong ha_pushed_index_cond_checks; - ulong ha_pushed_index_cond_filtered; + ulong ha_icp_attempts; + ulong ha_icp_match; ulong ha_discover_count; ulong ha_savepoint_count; ulong ha_savepoint_rollback_count; diff --git a/sql/sql_join_cache.cc b/sql/sql_join_cache.cc index 15b5efbfacb..a960c63e782 100644 --- a/sql/sql_join_cache.cc +++ b/sql/sql_join_cache.cc @@ -4026,9 +4026,9 @@ bool bka_skip_index_tuple(range_seq_t rseq, range_id_t range_info) JOIN_CACHE_BKA *cache= (JOIN_CACHE_BKA *) rseq; THD *thd= cache->thd(); bool res; - status_var_increment(thd->status_var.ha_pushed_index_cond_checks); - if ((res= cache->skip_index_tuple(range_info))) - status_var_increment(thd->status_var.ha_pushed_index_cond_filtered); + status_var_increment(thd->status_var.ha_icp_attempts); + if (!(res= cache->skip_index_tuple(range_info))) + status_var_increment(thd->status_var.ha_icp_match); DBUG_RETURN(res); } @@ -4505,9 +4505,9 @@ bool bkah_skip_index_tuple(range_seq_t rseq, range_id_t range_info) JOIN_CACHE_BKAH *cache= (JOIN_CACHE_BKAH *) rseq; THD *thd= cache->thd(); bool res; - status_var_increment(thd->status_var.ha_pushed_index_cond_checks); - if ((res= cache->skip_index_tuple(range_info))) - status_var_increment(thd->status_var.ha_pushed_index_cond_filtered); + status_var_increment(thd->status_var.ha_icp_attempts); + if (!(res= cache->skip_index_tuple(range_info))) + status_var_increment(thd->status_var.ha_icp_match); DBUG_RETURN(res); } From 59b2bb9aca0fb037ab4c770a8fd684a3d4a40587 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Wed, 22 Feb 2012 16:48:29 +0400 Subject: [PATCH 05/10] Added back MRR counters. The new names are: Handler_mrr_init, Handler_mrr_key_refills, Handler_mrr_rowid_refills. --- mysql-test/r/myisam_mrr.result | 15 +++++++++++++++ mysql-test/r/status.result | 8 +++++++- mysql-test/r/status_user.result | 3 +++ sql/multi_range_read.cc | 12 ++++++++---- sql/mysqld.cc | 11 +++++------ sql/sql_class.h | 6 +++--- 6 files changed, 41 insertions(+), 14 deletions(-) diff --git a/mysql-test/r/myisam_mrr.result b/mysql-test/r/myisam_mrr.result index c2f382eb9e6..0ea75c8aebb 100644 --- a/mysql-test/r/myisam_mrr.result +++ b/mysql-test/r/myisam_mrr.result @@ -563,6 +563,9 @@ drop table t1; flush status; show status like 'Handler_mrr%'; Variable_name Value +Handler_mrr_init 0 +Handler_mrr_key_refills 0 +Handler_mrr_rowid_refills 0 create table t0 (a int); insert into t0 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); create table t1 (a int, b int, filler char(200), key(a)); @@ -578,6 +581,9 @@ sum(b) 1230 show status like 'handler_mrr%'; Variable_name Value +Handler_mrr_init 1 +Handler_mrr_key_refills 0 +Handler_mrr_rowid_refills 0 set @mrr_buffer_size_save= @@mrr_buffer_size; set mrr_buffer_size=128; explain select sum(b) from t1 where a < 1600; @@ -590,6 +596,9 @@ sum(b) 196800 show status like 'handler_mrr%'; Variable_name Value +Handler_mrr_init 1 +Handler_mrr_key_refills 0 +Handler_mrr_rowid_refills 1 set @@mrr_buffer_size= @mrr_buffer_size_save; #Now, let's check BKA: set @join_cache_level_save= @@join_cache_level; @@ -605,6 +614,9 @@ sum(t1.b) 1230 show status like 'handler_mrr%'; Variable_name Value +Handler_mrr_init 1 +Handler_mrr_key_refills 0 +Handler_mrr_rowid_refills 0 set join_buffer_size=10; explain select sum(t1.b) from t0,t1 where t0.a=t1.a; id select_type table type possible_keys key key_len ref rows Extra @@ -616,6 +628,9 @@ sum(t1.b) 1230 show status like 'handler_mrr%'; Variable_name Value +Handler_mrr_init 1or2 +Handler_mrr_key_refills 1or2 +Handler_mrr_rowid_refills 1or2 set join_cache_level= @join_cache_level_save; set join_buffer_size= @join_buffer_size_save; drop table t0, t1; diff --git a/mysql-test/r/status.result b/mysql-test/r/status.result index b5bae659eed..d3e1d26cbbd 100644 --- a/mysql-test/r/status.result +++ b/mysql-test/r/status.result @@ -277,6 +277,9 @@ Handler_delete 0 Handler_discover 0 Handler_icp_attempts 0 Handler_icp_match 0 +Handler_mrr_init 0 +Handler_mrr_key_refills 0 +Handler_mrr_rowid_refills 0 Handler_prepare 0 Handler_read_first 0 Handler_read_key 4 @@ -299,7 +302,7 @@ Created_tmp_files 0 Created_tmp_tables 2 Handler_tmp_update 2 Handler_tmp_write 7 -Rows_tmp_read 37 +Rows_tmp_read 40 drop table t1; CREATE TABLE t1 (i int(11) DEFAULT NULL, KEY i (i) ) ENGINE=MyISAM; insert into t1 values (1),(2),(3),(4),(5); @@ -314,6 +317,9 @@ Handler_delete 0 Handler_discover 0 Handler_icp_attempts 0 Handler_icp_match 0 +Handler_mrr_init 0 +Handler_mrr_key_refills 0 +Handler_mrr_rowid_refills 0 Handler_prepare 0 Handler_read_first 0 Handler_read_key 2 diff --git a/mysql-test/r/status_user.result b/mysql-test/r/status_user.result index be0cfef79dc..b2d4b6f761f 100644 --- a/mysql-test/r/status_user.result +++ b/mysql-test/r/status_user.result @@ -102,6 +102,9 @@ Handler_delete 1 Handler_discover 0 Handler_icp_attempts 0 Handler_icp_match 0 +Handler_mrr_init 0 +Handler_mrr_key_refills 0 +Handler_mrr_rowid_refills 0 Handler_prepare 18 Handler_read_first 0 Handler_read_key 3 diff --git a/sql/multi_range_read.cc b/sql/multi_range_read.cc index 6ecc64207de..e86c9ca251c 100644 --- a/sql/multi_range_read.cc +++ b/sql/multi_range_read.cc @@ -510,7 +510,7 @@ int Mrr_ordered_index_reader::refill_buffer(bool initial) { /* This is a non-initial buffer fill and we've got a non-empty buffer */ THD *thd= current_thd; - status_var_increment(thd->status_var.ha_mrr_extra_key_sorts); + status_var_increment(thd->status_var.ha_mrr_key_refills_count); } key_buffer->sort((key_buffer->type() == Lifo_buffer::FORWARD)? @@ -610,7 +610,7 @@ int Mrr_ordered_rndpos_reader::refill_buffer(bool initial) { /* Ok, this was a successful buffer refill operation */ THD *thd= current_thd; - status_var_increment(thd->status_var.ha_mrr_extra_rowid_sorts); + status_var_increment(thd->status_var.ha_mrr_rowid_refills_count); } DBUG_RETURN(res); @@ -845,8 +845,6 @@ int DsMrr_impl::dsmrr_init(handler *h_arg, RANGE_SEQ_IF *seq_funcs, strategy= disk_strategy= &reader_factory.ordered_rndpos_reader; } - status_var_increment(thd->status_var.ha_multi_range_read_init_count); - full_buf= buf->buffer; full_buf_end= buf->buffer_end; @@ -936,6 +934,12 @@ int DsMrr_impl::dsmrr_init(handler *h_arg, RANGE_SEQ_IF *seq_funcs, goto error; } } + + /* + At this point, we're sure that we're running a native MRR scan (i.e. we + didnt fall back to default implementation for some reason). + */ + status_var_increment(thd->status_var.ha_mrr_init_count); res= strategy->refill_buffer(TRUE); if (res) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 147c2e80be3..484bfd168c7 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -8101,12 +8101,11 @@ SHOW_VAR status_vars[]= { {"Handler_commit", (char*) offsetof(STATUS_VAR, ha_commit_count), SHOW_LONG_STATUS}, {"Handler_delete", (char*) offsetof(STATUS_VAR, ha_delete_count), SHOW_LONG_STATUS}, {"Handler_discover", (char*) offsetof(STATUS_VAR, ha_discover_count), SHOW_LONG_STATUS}, -#if 0 - /* Made 3 counters below temporarily invisible until we agree upon their names */ - {"Handler_mrr_extra_key_sorts", (char*) offsetof(STATUS_VAR, ha_mrr_extra_key_sorts), SHOW_LONG_STATUS}, - {"Handler_mrr_extra_rowid_sorts", (char*) offsetof(STATUS_VAR, ha_mrr_extra_rowid_sorts), SHOW_LONG_STATUS}, - {"Handler_mrr_init", (char*) offsetof(STATUS_VAR, ha_multi_range_read_init_count), SHOW_LONG_STATUS}, -#endif + + {"Handler_mrr_key_refills", (char*) offsetof(STATUS_VAR, ha_mrr_key_refills_count), SHOW_LONG_STATUS}, + {"Handler_mrr_rowid_refills", (char*) offsetof(STATUS_VAR, ha_mrr_rowid_refills_count), SHOW_LONG_STATUS}, + {"Handler_mrr_init", (char*) offsetof(STATUS_VAR, ha_mrr_init_count), SHOW_LONG_STATUS}, + {"Handler_icp_attempts ", (char*) offsetof(STATUS_VAR, ha_icp_attempts), SHOW_LONG_STATUS}, {"Handler_icp_match", (char*) offsetof(STATUS_VAR, ha_icp_match), SHOW_LONG_STATUS}, {"Handler_prepare", (char*) offsetof(STATUS_VAR, ha_prepare_count), SHOW_LONG_STATUS}, diff --git a/sql/sql_class.h b/sql/sql_class.h index 3b94270ae08..c5f500a6b18 100644 --- a/sql/sql_class.h +++ b/sql/sql_class.h @@ -577,9 +577,9 @@ typedef struct system_status_var calls made by range access. The intent is to count only calls made by BatchedKeyAccess. */ - ulong ha_multi_range_read_init_count; - ulong ha_mrr_extra_key_sorts; - ulong ha_mrr_extra_rowid_sorts; + ulong ha_mrr_init_count; + ulong ha_mrr_key_refills_count; + ulong ha_mrr_rowid_refills_count; ulong ha_rollback_count; ulong ha_update_count; From 917455911f1ec995e40ac8b47f3c78ad503e7a95 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Wed, 22 Feb 2012 17:11:33 +0400 Subject: [PATCH 06/10] Sort counters by their names (otherwise, the order of SHOW STATUS output is sometimes sorted and sometimes not) --- sql/mysqld.cc | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sql/mysqld.cc b/sql/mysqld.cc index 484bfd168c7..aa3942521ed 100644 --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -8102,12 +8102,13 @@ SHOW_VAR status_vars[]= { {"Handler_delete", (char*) offsetof(STATUS_VAR, ha_delete_count), SHOW_LONG_STATUS}, {"Handler_discover", (char*) offsetof(STATUS_VAR, ha_discover_count), SHOW_LONG_STATUS}, - {"Handler_mrr_key_refills", (char*) offsetof(STATUS_VAR, ha_mrr_key_refills_count), SHOW_LONG_STATUS}, - {"Handler_mrr_rowid_refills", (char*) offsetof(STATUS_VAR, ha_mrr_rowid_refills_count), SHOW_LONG_STATUS}, - {"Handler_mrr_init", (char*) offsetof(STATUS_VAR, ha_mrr_init_count), SHOW_LONG_STATUS}, - {"Handler_icp_attempts ", (char*) offsetof(STATUS_VAR, ha_icp_attempts), SHOW_LONG_STATUS}, {"Handler_icp_match", (char*) offsetof(STATUS_VAR, ha_icp_match), SHOW_LONG_STATUS}, + + {"Handler_mrr_init", (char*) offsetof(STATUS_VAR, ha_mrr_init_count), SHOW_LONG_STATUS}, + {"Handler_mrr_key_refills", (char*) offsetof(STATUS_VAR, ha_mrr_key_refills_count), SHOW_LONG_STATUS}, + {"Handler_mrr_rowid_refills", (char*) offsetof(STATUS_VAR, ha_mrr_rowid_refills_count), SHOW_LONG_STATUS}, + {"Handler_prepare", (char*) offsetof(STATUS_VAR, ha_prepare_count), SHOW_LONG_STATUS}, {"Handler_read_first", (char*) offsetof(STATUS_VAR, ha_read_first_count), SHOW_LONG_STATUS}, {"Handler_read_key", (char*) offsetof(STATUS_VAR, ha_read_key_count), SHOW_LONG_STATUS}, From 567d871ff0c9cbdcaa4f9daa6810760edc901e14 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Wed, 22 Feb 2012 17:38:24 +0400 Subject: [PATCH 07/10] Don't run test for BUG#933412 with embedded server, as it requires concurrent query execution which mtr --embedded does not support --- mysql-test/r/myisam_icp.result | 15 --- mysql-test/r/myisam_icp_notembedded.result | 19 +++ mysql-test/t/myisam_icp.test | 128 ------------------- mysql-test/t/myisam_icp_notembedded.test | 139 +++++++++++++++++++++ 4 files changed, 158 insertions(+), 143 deletions(-) create mode 100644 mysql-test/r/myisam_icp_notembedded.result create mode 100644 mysql-test/t/myisam_icp_notembedded.test diff --git a/mysql-test/r/myisam_icp.result b/mysql-test/r/myisam_icp.result index 85a2ad921c6..188347c3324 100644 --- a/mysql-test/r/myisam_icp.result +++ b/mysql-test/r/myisam_icp.result @@ -909,19 +909,4 @@ c NULL NULL c NULL NULL SET optimizer_switch=@save_optimizer_switch; DROP TABLE t1,t2,t3,t4; -# -# BUG#933412: Server crashes in _mi_put_key_in_record on KILL QUERY with ICP, STRAIGHT_JOIN -# -CREATE TABLE t1 ( -b INT, -c VARCHAR(1) NOT NULL, -d DATETIME, -KEY (c, b) -) ENGINE=MyISAM; -# INSERT some data -CREATE TABLE t2 ( a INT ) ENGINE=MyISAM; -INSERT INTO t2 VALUES -(7),(3),(7),(3); -# Now run a number of ICP queries while trying to kill them -DROP TABLE t1,t2; set optimizer_switch=@myisam_icp_tmp; diff --git a/mysql-test/r/myisam_icp_notembedded.result b/mysql-test/r/myisam_icp_notembedded.result new file mode 100644 index 00000000000..d965cbd980d --- /dev/null +++ b/mysql-test/r/myisam_icp_notembedded.result @@ -0,0 +1,19 @@ +drop table if exists t1,t2; +set @myisam_icp_notembedded_tmp=@@optimizer_switch; +set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on'; +# +# BUG#933412: Server crashes in _mi_put_key_in_record on KILL QUERY with ICP, STRAIGHT_JOIN +# +CREATE TABLE t1 ( +b INT, +c VARCHAR(1) NOT NULL, +d DATETIME, +KEY (c, b) +) ENGINE=MyISAM; +# INSERT some data +CREATE TABLE t2 ( a INT ) ENGINE=MyISAM; +INSERT INTO t2 VALUES +(7),(3),(7),(3); +# Now run a number of ICP queries while trying to kill them +DROP TABLE t1,t2; +set optimizer_switch=@myisam_icp_notembedded_tmp; diff --git a/mysql-test/t/myisam_icp.test b/mysql-test/t/myisam_icp.test index 39a22d00a1a..5bee6e5acaa 100644 --- a/mysql-test/t/myisam_icp.test +++ b/mysql-test/t/myisam_icp.test @@ -262,133 +262,5 @@ SET optimizer_switch=@save_optimizer_switch; DROP TABLE t1,t2,t3,t4; ---echo # ---echo # BUG#933412: Server crashes in _mi_put_key_in_record on KILL QUERY with ICP, STRAIGHT_JOIN ---echo # -CREATE TABLE t1 ( - b INT, - c VARCHAR(1) NOT NULL, - d DATETIME, - KEY (c, b) -) ENGINE=MyISAM; ---echo # INSERT some data ---disable_query_log -INSERT INTO t1 ( b, d, c ) VALUES -(4,'2005-01-08 00:00:00','f'), -(1,'2004-05-20 10:45:51','c'),(2,'2006-08-11 21:33:49','e'), -(5,'2003-05-19 00:20:40','a'),(3,'2005-01-03 06:18:39','a'), -(7,'2008-11-25 18:18:14','b'),(6,'2008-11-09 15:53:46','b'), -(9,'2003-03-01 03:40:36','c'),(8,'2003-09-25 23:14:09','d'), -(0,'2007-01-17 09:18:31','f'),(9,'2008-09-08 09:52:24','c'), -(2,'2008-03-10 00:00:00','a'),(0,'2003-03-14 09:31:07','c'), -(4,'2005-04-25 00:00:00','h'),(6,'2001-08-01 05:55:55','e'), -(3,'2005-04-09 01:22:48','f'),(7,'2009-11-12 13:27:22','r'), -(0,'2009-03-28 05:05:28','h'),(15,'2005-05-16 04:35:41','f'), -(7,'2006-03-26 05:19:58','c'),(9,'2002-10-06 02:17:00','g'), -(4,'2007-01-28 03:28:20','b'),(1,'2009-04-22 10:16:40','c'), -(2,'2003-01-01 19:39:00','f'),(0,'2008-05-03 19:16:29','t'), -(2,'2005-01-28 00:00:00','j'),(8,'2004-01-10 00:00:00','w'), -(8,'2000-06-13 21:56:37','a'),(5,'2001-03-21 19:24:49','o'), -(99,'2003-12-20 21:29:06','f'),(0,'1900-01-01 00:00:00','w'), -(7,'2000-12-19 00:00:00','c'),(0,'2000-03-03 06:10:19','l'), -(3,'2000-08-11 00:00:00','q'),(0,'2007-05-25 03:46:41','e'), -(241,'2005-05-17 00:00:00','j'),(4,'2005-11-02 00:44:06','r'), -(43,'2001-07-11 00:00:00','a'),(1,'2008-12-01 18:30:27','z'), -(4,'2004-10-25 00:00:00','i'),(5,'2000-04-08 12:12:01','c'), -(0,'1900-01-01 00:00:00','f'),(9,'2002-05-13 22:47:02','p'), -(1,'2008-10-09 15:39:40','d'),(3,'2004-06-24 00:00:00','d'), -(0,'2008-03-06 00:00:00','r'),(9,'2007-04-16 18:40:03','i'), -(3,'2008-03-16 19:49:37','t'),(7,'2003-07-15 08:11:21','d'), -(8,'2005-02-11 00:04:53','r'),(0,'2002-09-21 00:00:00','y'), -(3,'2004-11-03 00:37:21','z'),(6,'2007-10-18 00:00:00','e'), -(6,'2007-01-21 10:42:56','o'),(5,'2000-03-26 21:21:04','b'), -(9,'2001-03-15 08:08:21','e'),(1,'2001-10-16 12:56:59','a'), -(6,'2004-05-01 23:45:55','o'),(4,'2000-03-04 00:00:00','f'), -(9,'2002-12-03 16:48:28','e'),(8,'2003-01-09 00:36:07','m'), -(1,'2006-06-22 04:32:41','s'),(8,'2008-09-20 05:01:48','q'), -(4,'2006-06-02 22:15:31','g'),(2,'2002-05-14 07:07:42','e'), -(7,'2005-06-05 01:30:42','r'),(127,'2004-05-11 01:56:48','a'), -(210,'2003-11-05 00:41:34','z'),(5,'1900-01-01 00:00:00','h'), -(1,'2006-04-16 00:00:00','f'),(7,'2000-12-17 00:00:00','x'), -(8,'2009-05-09 20:43:07','b'),(175,'2008-11-26 16:33:09','p'), -(0,'2002-05-09 21:18:44','v'),(8,'2002-06-01 11:32:25','k'), -(1,'2008-11-09 23:56:00','a'),(0,'2008-01-08 10:18:46','c'), -(2,'2005-04-16 00:00:00','o'),(5,'2002-08-25 00:00:00','b'), -(64,'2005-12-05 21:51:52','b'),(4,'2005-08-10 00:00:00','i'), -(6,'2006-03-23 00:00:00','d'),(9,'2007-01-27 00:00:00','i'), -(8,'2008-08-16 00:00:00','a'),(7,'2003-01-16 12:13:18','k'), -(0,'2003-06-22 00:00:00','v'),(5,'2008-06-20 05:43:56','u'), -(8,'2004-09-23 18:57:17','e'),(1,'2000-12-26 00:00:00','y'), -(4,'2009-06-01 13:00:28','e'),(1,'2009-11-18 06:28:48','m'), -(0,'2004-06-12 10:01:10','e'),(2,'2005-10-16 01:48:55','e'), -(5,'2001-12-23 09:50:21','l'),(6,'1900-01-01 00:00:00','a'), -(1,'2001-10-28 00:00:00','d'),(1,'2008-07-12 23:30:19','s'), -(0,'2002-10-11 16:51:16','r'),(4,'2007-09-18 06:27:10','x'), -(1,'2007-02-21 12:28:14','e'),(6,'2001-09-16 00:00:00','f'), -(0,'2007-09-20 02:25:45','c'),(0,'2006-08-07 03:25:56','j'), -(8,'2006-12-04 20:20:32','t'),(7,'2007-09-05 10:13:10','i'), -(9,'2006-04-12 17:59:57','t'),(2,'2009-04-28 00:06:09','b'), -(8,'2000-01-07 00:00:00','b'),(7,'2000-03-25 10:04:41','k'), -(4,'2000-07-10 00:44:55','w'),(9,'2007-09-22 14:26:26','j'), -(9,'2003-09-11 22:41:17','a'),(0,'2004-06-07 13:52:32','c'), -(8,'2008-10-09 00:00:00','p'),(1,'2007-04-01 00:00:00','c'), -(9,'2000-12-05 00:00:00','i'),(3,'1900-01-01 00:00:00','a'), -(3,'2005-12-24 21:50:54','e'),(8,'2009-07-21 19:34:55','n'), -(9,'2005-11-13 17:57:56','d'),(7,'2004-10-07 06:41:39','l'), -(1,'2004-11-20 08:05:08','u'),(3,'2005-05-25 00:00:00','r'), -(1,'2006-09-02 14:16:41','u'),(8,'2006-01-07 00:00:00','a'), -(9,'2003-04-05 00:54:20','w'),(2,'2003-12-22 00:00:00','a'), -(9,'2006-04-16 17:31:40','e'),(6,'2005-02-10 14:22:46','e'), -(7,'2004-04-27 05:54:52','p'),(1,'2005-12-07 00:00:00','t'), -(5,'2004-04-03 20:56:28','d'),(4,'2000-09-07 05:17:16','h'), -(2,'2004-08-04 16:10:42','i'),(1,'2007-03-04 00:00:00','b'), -(9,'1900-01-01 00:00:00','d'),(1,'2000-05-12 23:02:50','m'), -(2,'1900-01-01 00:00:00','l'),(1,'1900-01-01 00:00:00','k'), -(4,'2000-07-14 01:25:18','d'),(5,'2009-08-21 00:00:00','w'), -(6,'2009-05-25 13:33:54','f'),(7,'2006-06-13 00:00:00','e'), -(8,'1900-01-01 00:00:00','a'),(6,'2004-02-24 00:00:00','j'), -(0,'2003-05-21 07:03:46','k'),(9,'1900-01-01 00:00:00','e'), -(2,'1900-01-01 00:00:00','y'),(2,'2000-12-22 00:00:00','e'), -(3,'2003-09-26 00:00:00','f'),(2,'2001-01-13 08:20:19','h'), -(9,'2008-09-23 20:03:28','n'),(5,'2007-03-20 02:41:38','s'), -(1,'2009-02-14 10:27:18','a'),(0,'2001-08-10 17:44:05','s'), -(3,'2008-01-20 12:49:54','v'),(1,'2001-05-05 09:09:59','r'); ---enable_query_log -CREATE TABLE t2 ( a INT ) ENGINE=MyISAM; -INSERT INTO t2 VALUES - (7),(3),(7),(3); - -# 'con2' will be the connection that will run all the KILLable statements ---connect (con2,127.0.0.1,root,,test) - ---let $run = 300 ---let $con_id = `SELECT CONNECTION_ID()` - ---echo # Now run a number of ICP queries while trying to kill them ---disable_query_log ---disable_result_log -while ($run) -{ - --send - SELECT * FROM t1 AS alias1 STRAIGHT_JOIN t1 AS alias2 - ON alias2.c = alias1.c - WHERE alias2.b >= 9; - - --connect (con1,127.0.0.1,root,,test) - --eval KILL QUERY $con_id - --disconnect con1 - - --dec $run - - --connection con2 - --error 0,ER_QUERY_INTERRUPTED - --reap -} ---enable_result_log ---enable_query_log ---disconnect con2 ---connection default -DROP TABLE t1,t2; - set optimizer_switch=@myisam_icp_tmp; diff --git a/mysql-test/t/myisam_icp_notembedded.test b/mysql-test/t/myisam_icp_notembedded.test new file mode 100644 index 00000000000..139a9edf648 --- /dev/null +++ b/mysql-test/t/myisam_icp_notembedded.test @@ -0,0 +1,139 @@ +-- source include/not_embedded.inc + +--disable_warnings +drop table if exists t1,t2; +--enable_warnings + +set @myisam_icp_notembedded_tmp=@@optimizer_switch; +set optimizer_switch='mrr=on,mrr_sort_keys=on,index_condition_pushdown=on'; + +--echo # +--echo # BUG#933412: Server crashes in _mi_put_key_in_record on KILL QUERY with ICP, STRAIGHT_JOIN +--echo # +CREATE TABLE t1 ( + b INT, + c VARCHAR(1) NOT NULL, + d DATETIME, + KEY (c, b) +) ENGINE=MyISAM; +--echo # INSERT some data +--disable_query_log +INSERT INTO t1 ( b, d, c ) VALUES +(4,'2005-01-08 00:00:00','f'), +(1,'2004-05-20 10:45:51','c'),(2,'2006-08-11 21:33:49','e'), +(5,'2003-05-19 00:20:40','a'),(3,'2005-01-03 06:18:39','a'), +(7,'2008-11-25 18:18:14','b'),(6,'2008-11-09 15:53:46','b'), +(9,'2003-03-01 03:40:36','c'),(8,'2003-09-25 23:14:09','d'), +(0,'2007-01-17 09:18:31','f'),(9,'2008-09-08 09:52:24','c'), +(2,'2008-03-10 00:00:00','a'),(0,'2003-03-14 09:31:07','c'), +(4,'2005-04-25 00:00:00','h'),(6,'2001-08-01 05:55:55','e'), +(3,'2005-04-09 01:22:48','f'),(7,'2009-11-12 13:27:22','r'), +(0,'2009-03-28 05:05:28','h'),(15,'2005-05-16 04:35:41','f'), +(7,'2006-03-26 05:19:58','c'),(9,'2002-10-06 02:17:00','g'), +(4,'2007-01-28 03:28:20','b'),(1,'2009-04-22 10:16:40','c'), +(2,'2003-01-01 19:39:00','f'),(0,'2008-05-03 19:16:29','t'), +(2,'2005-01-28 00:00:00','j'),(8,'2004-01-10 00:00:00','w'), +(8,'2000-06-13 21:56:37','a'),(5,'2001-03-21 19:24:49','o'), +(99,'2003-12-20 21:29:06','f'),(0,'1900-01-01 00:00:00','w'), +(7,'2000-12-19 00:00:00','c'),(0,'2000-03-03 06:10:19','l'), +(3,'2000-08-11 00:00:00','q'),(0,'2007-05-25 03:46:41','e'), +(241,'2005-05-17 00:00:00','j'),(4,'2005-11-02 00:44:06','r'), +(43,'2001-07-11 00:00:00','a'),(1,'2008-12-01 18:30:27','z'), +(4,'2004-10-25 00:00:00','i'),(5,'2000-04-08 12:12:01','c'), +(0,'1900-01-01 00:00:00','f'),(9,'2002-05-13 22:47:02','p'), +(1,'2008-10-09 15:39:40','d'),(3,'2004-06-24 00:00:00','d'), +(0,'2008-03-06 00:00:00','r'),(9,'2007-04-16 18:40:03','i'), +(3,'2008-03-16 19:49:37','t'),(7,'2003-07-15 08:11:21','d'), +(8,'2005-02-11 00:04:53','r'),(0,'2002-09-21 00:00:00','y'), +(3,'2004-11-03 00:37:21','z'),(6,'2007-10-18 00:00:00','e'), +(6,'2007-01-21 10:42:56','o'),(5,'2000-03-26 21:21:04','b'), +(9,'2001-03-15 08:08:21','e'),(1,'2001-10-16 12:56:59','a'), +(6,'2004-05-01 23:45:55','o'),(4,'2000-03-04 00:00:00','f'), +(9,'2002-12-03 16:48:28','e'),(8,'2003-01-09 00:36:07','m'), +(1,'2006-06-22 04:32:41','s'),(8,'2008-09-20 05:01:48','q'), +(4,'2006-06-02 22:15:31','g'),(2,'2002-05-14 07:07:42','e'), +(7,'2005-06-05 01:30:42','r'),(127,'2004-05-11 01:56:48','a'), +(210,'2003-11-05 00:41:34','z'),(5,'1900-01-01 00:00:00','h'), +(1,'2006-04-16 00:00:00','f'),(7,'2000-12-17 00:00:00','x'), +(8,'2009-05-09 20:43:07','b'),(175,'2008-11-26 16:33:09','p'), +(0,'2002-05-09 21:18:44','v'),(8,'2002-06-01 11:32:25','k'), +(1,'2008-11-09 23:56:00','a'),(0,'2008-01-08 10:18:46','c'), +(2,'2005-04-16 00:00:00','o'),(5,'2002-08-25 00:00:00','b'), +(64,'2005-12-05 21:51:52','b'),(4,'2005-08-10 00:00:00','i'), +(6,'2006-03-23 00:00:00','d'),(9,'2007-01-27 00:00:00','i'), +(8,'2008-08-16 00:00:00','a'),(7,'2003-01-16 12:13:18','k'), +(0,'2003-06-22 00:00:00','v'),(5,'2008-06-20 05:43:56','u'), +(8,'2004-09-23 18:57:17','e'),(1,'2000-12-26 00:00:00','y'), +(4,'2009-06-01 13:00:28','e'),(1,'2009-11-18 06:28:48','m'), +(0,'2004-06-12 10:01:10','e'),(2,'2005-10-16 01:48:55','e'), +(5,'2001-12-23 09:50:21','l'),(6,'1900-01-01 00:00:00','a'), +(1,'2001-10-28 00:00:00','d'),(1,'2008-07-12 23:30:19','s'), +(0,'2002-10-11 16:51:16','r'),(4,'2007-09-18 06:27:10','x'), +(1,'2007-02-21 12:28:14','e'),(6,'2001-09-16 00:00:00','f'), +(0,'2007-09-20 02:25:45','c'),(0,'2006-08-07 03:25:56','j'), +(8,'2006-12-04 20:20:32','t'),(7,'2007-09-05 10:13:10','i'), +(9,'2006-04-12 17:59:57','t'),(2,'2009-04-28 00:06:09','b'), +(8,'2000-01-07 00:00:00','b'),(7,'2000-03-25 10:04:41','k'), +(4,'2000-07-10 00:44:55','w'),(9,'2007-09-22 14:26:26','j'), +(9,'2003-09-11 22:41:17','a'),(0,'2004-06-07 13:52:32','c'), +(8,'2008-10-09 00:00:00','p'),(1,'2007-04-01 00:00:00','c'), +(9,'2000-12-05 00:00:00','i'),(3,'1900-01-01 00:00:00','a'), +(3,'2005-12-24 21:50:54','e'),(8,'2009-07-21 19:34:55','n'), +(9,'2005-11-13 17:57:56','d'),(7,'2004-10-07 06:41:39','l'), +(1,'2004-11-20 08:05:08','u'),(3,'2005-05-25 00:00:00','r'), +(1,'2006-09-02 14:16:41','u'),(8,'2006-01-07 00:00:00','a'), +(9,'2003-04-05 00:54:20','w'),(2,'2003-12-22 00:00:00','a'), +(9,'2006-04-16 17:31:40','e'),(6,'2005-02-10 14:22:46','e'), +(7,'2004-04-27 05:54:52','p'),(1,'2005-12-07 00:00:00','t'), +(5,'2004-04-03 20:56:28','d'),(4,'2000-09-07 05:17:16','h'), +(2,'2004-08-04 16:10:42','i'),(1,'2007-03-04 00:00:00','b'), +(9,'1900-01-01 00:00:00','d'),(1,'2000-05-12 23:02:50','m'), +(2,'1900-01-01 00:00:00','l'),(1,'1900-01-01 00:00:00','k'), +(4,'2000-07-14 01:25:18','d'),(5,'2009-08-21 00:00:00','w'), +(6,'2009-05-25 13:33:54','f'),(7,'2006-06-13 00:00:00','e'), +(8,'1900-01-01 00:00:00','a'),(6,'2004-02-24 00:00:00','j'), +(0,'2003-05-21 07:03:46','k'),(9,'1900-01-01 00:00:00','e'), +(2,'1900-01-01 00:00:00','y'),(2,'2000-12-22 00:00:00','e'), +(3,'2003-09-26 00:00:00','f'),(2,'2001-01-13 08:20:19','h'), +(9,'2008-09-23 20:03:28','n'),(5,'2007-03-20 02:41:38','s'), +(1,'2009-02-14 10:27:18','a'),(0,'2001-08-10 17:44:05','s'), +(3,'2008-01-20 12:49:54','v'),(1,'2001-05-05 09:09:59','r'); +--enable_query_log +CREATE TABLE t2 ( a INT ) ENGINE=MyISAM; +INSERT INTO t2 VALUES + (7),(3),(7),(3); + +# 'con2' will be the connection that will run all the KILLable statements +--connect (con2,127.0.0.1,root,,test) + +--let $run = 300 +--let $con_id = `SELECT CONNECTION_ID()` + +--echo # Now run a number of ICP queries while trying to kill them +--disable_query_log +--disable_result_log +while ($run) +{ + --send + SELECT * FROM t1 AS alias1 STRAIGHT_JOIN t1 AS alias2 + ON alias2.c = alias1.c + WHERE alias2.b >= 9; + + --connect (con1,127.0.0.1,root,,test) + --eval KILL QUERY $con_id + --disconnect con1 + + --dec $run + + --connection con2 + --error 0,ER_QUERY_INTERRUPTED + --reap +} +--enable_result_log +--enable_query_log +--disconnect con2 +--connection default +DROP TABLE t1,t2; + +set optimizer_switch=@myisam_icp_notembedded_tmp; + From 2b625ac3e0b2173df18c69df63af00dd03e8c672 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Thu, 23 Feb 2012 16:43:35 +0200 Subject: [PATCH 08/10] Fixed lp:933719, "Assertion open_tables == 0 ... " in THD::restore_backup_open_tables_state. This also fixes a (not likely) crashing bug when forcing a thread that was doing a table lock to re-open it's files, for example by creating a trigger. mysys/thr_lock.c: Added more checking to find wrong locks. Removed one, not needed, parameter to thr_lock sql/lock.cc: Fixed mysql_lock_tables() to retry with new sql_lock if lock fails. This was needed as table may be closed and reopened between retry's and then the old sql_lock will point to stale data. sql/mysql_priv.h: Updated prototype sql/sql_base.cc: Ensure that all tables are closed if opening of system table failes; This fixes the assert in THD::restore_backup_open_tables_state sql/sql_handler.cc: Updated variable type --- mysys/thr_lock.c | 41 +++++--- sql/lock.cc | 242 +++++++++++++++++++++++++-------------------- sql/mysql_priv.h | 6 +- sql/sql_base.cc | 11 +-- sql/sql_handler.cc | 2 +- 5 files changed, 176 insertions(+), 126 deletions(-) diff --git a/mysys/thr_lock.c b/mysys/thr_lock.c index 99a498cfdd5..32b38105d1f 100644 --- a/mysys/thr_lock.c +++ b/mysys/thr_lock.c @@ -168,7 +168,8 @@ thr_lock_owner_equal(THR_LOCK_OWNER *rhs, THR_LOCK_OWNER *lhs) static uint found_errors=0; static int check_lock(struct st_lock_list *list, const char* lock_type, - const char *where, my_bool same_owner, my_bool no_cond) + const char *where, my_bool same_owner, my_bool no_cond, + my_bool read_lock) { THR_LOCK_DATA *data,**prev; uint count=0; @@ -181,6 +182,23 @@ static int check_lock(struct st_lock_list *list, const char* lock_type, for (data=list->data; data && count++ < MAX_LOCKS ; data=data->next) { + if (data->type == TL_UNLOCK) + { + fprintf(stderr, + "Warning: Found unlocked lock at %s: %s\n", + lock_type, where); + return 1; + } + if ((read_lock && data->type > TL_READ_NO_INSERT) || + (!read_lock && data->type <= TL_READ_NO_INSERT)) + { + fprintf(stderr, + "Warning: Found %s lock in %s queue at %s: %s\n", + read_lock ? "write" : "read", + read_lock ? "read" : "write", + lock_type, where); + return 1; + } if (data->type != last_lock_type) last_lock_type=TL_IGNORE; if (data->prev != prev) @@ -237,11 +255,14 @@ static void check_locks(THR_LOCK *lock, const char *where, if (found_errors < MAX_FOUND_ERRORS) { - if (check_lock(&lock->write,"write",where,1,1) | - check_lock(&lock->write_wait,"write_wait",where,0,0) | - check_lock(&lock->read,"read",where,0,1) | - check_lock(&lock->read_wait,"read_wait",where,0,0)) + if (check_lock(&lock->write,"write",where,1,1,0) | + check_lock(&lock->write_wait,"write_wait",where,0,0,0) | + check_lock(&lock->read,"read",where,0,1,1) | + check_lock(&lock->read_wait,"read_wait",where,0,0,1)) + { + DBUG_ASSERT(my_assert_on_error == 0); found_errors++; + } if (found_errors < MAX_FOUND_ERRORS) { @@ -592,18 +613,17 @@ wait_for_lock(struct st_lock_list *wait, THR_LOCK_DATA *data, static enum enum_thr_lock_result -thr_lock(THR_LOCK_DATA *data, THR_LOCK_OWNER *owner, - enum thr_lock_type lock_type) +thr_lock(THR_LOCK_DATA *data, THR_LOCK_OWNER *owner) { THR_LOCK *lock=data->lock; enum enum_thr_lock_result result= THR_LOCK_SUCCESS; struct st_lock_list *wait_queue; THR_LOCK_DATA *lock_owner; + enum thr_lock_type lock_type= data->type; DBUG_ENTER("thr_lock"); data->next=0; data->cond=0; /* safety */ - data->type=lock_type; data->owner= owner; /* Must be reset ! */ data->priority&= ~THR_LOCK_LATE_PRIV; VOID(pthread_mutex_lock(&lock->mutex)); @@ -912,9 +932,7 @@ void thr_unlock(THR_LOCK_DATA *data, uint unlock_flags) if (lock_type == TL_READ_NO_INSERT) lock->read_no_write_count--; data->type=TL_UNLOCK; /* Mark unlocked */ - check_locks(lock,"after releasing lock", lock_type, 1); wake_up_waiters(lock); - check_locks(lock,"end of thr_unlock", lock_type, 1); pthread_mutex_unlock(&lock->mutex); DBUG_VOID_RETURN; } @@ -934,6 +952,7 @@ static void wake_up_waiters(THR_LOCK *lock) enum thr_lock_type lock_type; DBUG_ENTER("wake_up_waiters"); + check_locks(lock, "before waking up waiters", TL_UNLOCK, 1); if (!lock->write.data) /* If no active write locks */ { data=lock->write_wait.data; @@ -1087,7 +1106,7 @@ thr_multi_lock(THR_LOCK_DATA **data, uint count, THR_LOCK_OWNER *owner) /* lock everything */ for (pos=data,end=data+count; pos < end ; pos++) { - enum enum_thr_lock_result result= thr_lock(*pos, owner, (*pos)->type); + enum enum_thr_lock_result result= thr_lock(*pos, owner); if (result != THR_LOCK_SUCCESS) { /* Aborted */ thr_multi_unlock(data,(uint) (pos-data), 0); diff --git a/sql/lock.cc b/sql/lock.cc index 3f9b3a9e18b..57ced99417b 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -195,31 +195,33 @@ int mysql_lock_tables_check(THD *thd, TABLE **tables, uint count, uint flags) MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count, uint flags, bool *need_reopen) { - TABLE *write_lock_used; MYSQL_LOCK *sql_lock; + TABLE *write_lock_used; + int rc; DBUG_ENTER("mysql_lock_tables(tables)"); *need_reopen= FALSE; + if (mysql_lock_tables_check(thd, tables, count, flags)) - DBUG_RETURN(NULL); + DBUG_RETURN (NULL); - if (!(sql_lock= get_lock_data(thd, tables, count, GET_LOCK_STORE_LOCKS, - &write_lock_used)) || - ! sql_lock->table_count) - DBUG_RETURN(sql_lock); - - if (mysql_lock_tables(thd, sql_lock, write_lock_used != 0, flags, - need_reopen)) + for (;;) { - /* Clear the lock type of all lock data to avoid reusage. */ - reset_lock_data(sql_lock, 1); + if (!(sql_lock= get_lock_data(thd, tables, count, GET_LOCK_STORE_LOCKS, + &write_lock_used)) || + !sql_lock->table_count) + break; + rc= mysql_lock_tables(thd, sql_lock, write_lock_used != 0, flags, + need_reopen); + if (!rc) + break; // Got lock my_free(sql_lock, MYF(0)); - sql_lock= 0; + if (rc > 0) + DBUG_RETURN(0); // Failed } DBUG_RETURN(sql_lock); } - /** Lock a table based on a MYSQL_LOCK structure. @@ -232,120 +234,150 @@ MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **tables, uint count, @param need_reopen Out parameter, TRUE if some tables were altered or deleted and should be reopened by caller. - @return 0 ok - @return 1 error + @return 0 ok + @return 1 fatal error + @return -1 retry */ -bool mysql_lock_tables(THD *thd, MYSQL_LOCK *sql_lock, - bool write_lock_used, - uint flags, bool *need_reopen) +int mysql_lock_tables(THD *thd, MYSQL_LOCK *sql_lock, + bool write_lock_used, + uint flags, bool *need_reopen) { + int res= 0; int rc; - bool error= 1; DBUG_ENTER("mysql_lock_tables(sql_lock)"); - *need_reopen= FALSE; - for (;;) + + if (write_lock_used && !(flags & MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK)) { - if (write_lock_used && !(flags & MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK)) - { - if (global_read_lock) - { - /* - Someone has issued LOCK ALL TABLES FOR READ and we want a write lock - Wait until the lock is gone - */ - if (wait_if_global_read_lock(thd, 1, 1)) - break; - if (thd->version != refresh_version) - goto retry; - } - - if (opt_readonly && - !(thd->security_ctx->master_access & SUPER_ACL) && - !thd->slave_thread) - { - /* - Someone has issued SET GLOBAL READ_ONLY=1 and we want a write lock. - We do not wait for READ_ONLY=0, and fail. - */ - my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only"); - break; - } - } - - thd_proc_info(thd, "System lock"); - if (lock_external(thd, sql_lock->table, sql_lock->table_count)) - break; - thd_proc_info(thd, "Table lock"); - /* Copy the lock data array. thr_multi_lock() reorders its contens. */ - memcpy(sql_lock->locks + sql_lock->lock_count, sql_lock->locks, - sql_lock->lock_count * sizeof(*sql_lock->locks)); - /* Lock on the copied half of the lock data array. */ - rc= thr_lock_errno_to_mysql[(int) thr_multi_lock(sql_lock->locks + - sql_lock->lock_count, - sql_lock->lock_count, - thd->lock_id)]; - if (rc) /* Locking failed */ - { - VOID(unlock_external(thd, sql_lock->table, sql_lock->table_count)); - if (rc > 1) - { - /* a timeout or a deadlock */ - my_error(rc, MYF(0)); - break; - } - /* We where aborted and should try again from upper level*/ - thd->some_tables_deleted= 1; - } - else + if (global_read_lock) { /* - Lock worked. Now check that nothing happend while we where waiting - to get the lock that would require us to free it. + Someone has issued LOCK ALL TABLES FOR READ and we want a write lock + Wait until the lock is gone */ - error= 0; - if (!thd->some_tables_deleted || (flags & MYSQL_LOCK_IGNORE_FLUSH)) + if (wait_if_global_read_lock(thd, 1, 1)) { - /* - Table was not signaled for deletion or we don't care if it was. - Return with table as locked. - */ - break; + /* Clear the lock type of all lock data to avoid reusage. */ + reset_lock_data(sql_lock, 1); + DBUG_RETURN(1); // Fatal error } - else if (!thd->open_tables && !(flags & MYSQL_LOCK_NOT_TEMPORARY)) + if (thd->version != refresh_version) { - /* - Only using temporary tables, no need to unlock. - We need the flag as open_tables is not enough to distingush if - we are only using temporary tables for tables used trough - the HANDLER interface. - - We reset some_tables_deleted as it doesn't make sense to have this - one when we are only using temporary tables. - */ - thd->some_tables_deleted=0; - break; + /* Clear the lock type of all lock data to avoid reusage. */ + reset_lock_data(sql_lock, 1); + goto retry; } - /* some table was altered or deleted. reopen tables marked deleted */ - error= 1; - mysql_unlock_tables(thd, sql_lock, 0); } -retry: - if (flags & MYSQL_LOCK_NOTIFY_IF_NEED_REOPEN) + if (opt_readonly && + !(thd->security_ctx->master_access & SUPER_ACL) && + !thd->slave_thread) { - *need_reopen= TRUE; - break; + /* + Someone has issued SET GLOBAL READ_ONLY=1 and we want a write lock. + We do not wait for READ_ONLY=0, and fail. + */ + my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only"); + reset_lock_data(sql_lock, 1); + DBUG_RETURN(1); // Fatal error } - if (wait_for_tables(thd)) - break; // Couldn't open tables - reset_lock_data(sql_lock, 0); // Set org locks and retry } + thd_proc_info(thd, "System lock"); + if (lock_external(thd, sql_lock->table, sql_lock->table_count)) + { + /* Clear the lock type of all lock data to avoid reusage. */ + res= 1; // Fatal error + goto end; + } + thd_proc_info(thd, "Table lock"); + DBUG_PRINT("info", ("thd->proc_info %s", thd->proc_info)); + /* Copy the lock data array. thr_multi_lock() reorders its contens. */ + memcpy(sql_lock->locks + sql_lock->lock_count, sql_lock->locks, + sql_lock->lock_count * sizeof(*sql_lock->locks)); + /* Lock on the copied half of the lock data array. */ + rc= thr_lock_errno_to_mysql[(int) thr_multi_lock(sql_lock->locks + + sql_lock->lock_count, + sql_lock->lock_count, + thd->lock_id)]; + if (rc) // Locking failed + { + if (sql_lock->table_count) + VOID(unlock_external(thd, sql_lock->table, sql_lock->table_count)); + + /* + reset_lock_data is required here. If thr_multi_lock fails it + resets lock type for tables, which were locked before (and + including) one that caused error. Lock type for other tables + preserved. + */ + reset_lock_data(sql_lock, 0); + + if (rc > 1) + { + my_error(rc, MYF(0)); + DBUG_RETURN(1); + } + DBUG_ASSERT(rc == 1); // Timeout + thd->some_tables_deleted= 1; // Reopen tables + sql_lock->lock_count= 0; // Locks are already freed + /* Retry */ + } + else + { + /* + Lock worked. Now check that nothing happend while we where waiting + to get the lock that would require us to free it. + */ + if (!thd->some_tables_deleted || (flags & MYSQL_LOCK_IGNORE_FLUSH)) + { + res= 0; + goto end; /* Lock was not aborted. Return to upper level */ + } + if (!thd->open_tables && !(flags & MYSQL_LOCK_NOT_TEMPORARY)) + { + /* + Only using temporary tables, no need to unlock. + We need the flag as open_tables is not enough to distingush if + we are only using temporary tables for tables used trough + the HANDLER interface. + + We reset some_tables_deleted as it doesn't make sense to have this + one when we are only using temporary tables. + */ + thd->some_tables_deleted=0; + goto end; + } + /* Free lock and retry */ + } + + /* some table was altered or deleted. reopen tables marked deleted */ + mysql_unlock_tables(thd, sql_lock, 0); + +retry: + res= -1; // Retry + if (flags & MYSQL_LOCK_NOTIFY_IF_NEED_REOPEN) + { + *need_reopen= TRUE; // Upper level will retry + DBUG_RETURN(1); // Fatal error + } + if (wait_for_tables(thd)) + res= 1; // Couldn't open tables + +end: thd_proc_info(thd, 0); + if (thd->killed) + { + thd->send_kill_message(); + if (res == 0) + mysql_unlock_tables(thd,sql_lock,0); + else + reset_lock_data(sql_lock, 1); + res= 1; // Fatal + } thd->set_time_after_lock(); - DBUG_RETURN(error); + DBUG_RETURN(res); } diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index f49b7a3c851..94b06add2bd 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -2347,9 +2347,9 @@ extern struct st_VioSSLFd * ssl_acceptor_fd; MYSQL_LOCK *mysql_lock_tables(THD *thd, TABLE **table, uint count, uint flags, bool *need_reopen); -bool mysql_lock_tables(THD *thd, MYSQL_LOCK *sql_lock, - bool write_lock_used, - uint flags, bool *need_reopen); +int mysql_lock_tables(THD *thd, MYSQL_LOCK *sql_lock, + bool write_lock_used, + uint flags, bool *need_reopen); /* mysql_lock_tables() and open_table() flags bits */ #define MYSQL_LOCK_IGNORE_GLOBAL_READ_LOCK 0x0001 diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 11fd5db2020..95a149741de 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -9606,13 +9606,12 @@ open_performance_schema_table(THD *thd, TABLE_LIST *one_table, else { /* - If error in mysql_lock_tables(), open_ltable doesn't close the - table. Thread kill during mysql_lock_tables() is such error. But - open tables cannot be accepted when restoring the open tables - state. + This can happen during a thd->kill or while we are trying to log + data for a stored procedure/trigger and someone causes the table + to be flushed (for example by creating a new trigger for the + table) */ - if (thd->killed) - close_thread_tables(thd); + close_thread_tables(thd); thd->restore_backup_open_tables_state(backup); } diff --git a/sql/sql_handler.cc b/sql/sql_handler.cc index d789957ffa4..4f1c63930d6 100644 --- a/sql/sql_handler.cc +++ b/sql/sql_handler.cc @@ -676,7 +676,7 @@ retry: /* save open_tables state */ if (handler->lock->lock_count > 0) { - bool lock_error; + int lock_error; handler->lock->locks[0]->type= handler->lock->locks[0]->org_type; lock_error= mysql_lock_tables(thd, handler->lock, 0, From d395d2514d872bc40374e900979825f81f992890 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Thu, 23 Feb 2012 16:51:58 +0200 Subject: [PATCH 09/10] Fixes for make_binary_distribution and mysql_config for OpenSuse 12.1 BUILD/SETUP.sh: By default, build also with innodb-plugin mysql-test/mysql-test-run.pl: Also search in lib64 directory for plugins (This is used at least on OpenSuse 12.1 when using default build scripts) mysql-test/r/lock_multi.result: Allow test to be re-run even if it crashed. mysql-test/t/lock_multi.test: Allow test to be re-run even if it crashed. scripts/make_binary_distribution.sh: Ensure that libexecdir is named libexec (was not on OpenSuse 12.1) scripts/mysql_config.sh: Fixed detection of lib64 was used. --- BUILD/SETUP.sh | 2 +- mysql-test/mysql-test-run.pl | 3 ++- mysql-test/r/lock_multi.result | 1 + mysql-test/t/lock_multi.test | 1 + scripts/make_binary_distribution.sh | 6 +++++- scripts/mysql_config.sh | 2 +- 6 files changed, 11 insertions(+), 4 deletions(-) diff --git a/BUILD/SETUP.sh b/BUILD/SETUP.sh index c254304a5a8..c1a05fb1007 100755 --- a/BUILD/SETUP.sh +++ b/BUILD/SETUP.sh @@ -178,7 +178,7 @@ base_configs="--prefix=$prefix --enable-assembler " base_configs="$base_configs --with-extra-charsets=complex " base_configs="$base_configs --enable-thread-safe-client " base_configs="$base_configs --with-big-tables" -base_configs="$base_configs --with-plugin-aria --with-aria-tmp-tables --without-plugin-innodb_plugin" +base_configs="$base_configs --with-plugin-aria --with-aria-tmp-tables" # Compile our client programs with static libraries to allow them to be moved base_configs="$base_configs --with-mysqld-ldflags=-static --with-client-ldflags=-static" diff --git a/mysql-test/mysql-test-run.pl b/mysql-test/mysql-test-run.pl index 4d6269044c1..e6ef03d6ad5 100755 --- a/mysql-test/mysql-test-run.pl +++ b/mysql-test/mysql-test-run.pl @@ -2518,7 +2518,8 @@ sub setup_vardir() { else { # hm, what paths work for debs and for rpms ? - for (<$bindir/lib/mysql/plugin/*.so>, + for (<$bindir/lib64/mysql/plugin/*.so>, + <$bindir/lib/mysql/plugin/*.so>, <$bindir/lib/plugin/*.dll>) { my $pname=basename($_); diff --git a/mysql-test/r/lock_multi.result b/mysql-test/r/lock_multi.result index 3fc4de3da06..72f4b22b06a 100644 --- a/mysql-test/r/lock_multi.result +++ b/mysql-test/r/lock_multi.result @@ -1,4 +1,5 @@ drop table if exists t1,t2; +drop DATABASE if exists mysqltest_1; create table t1(n int); insert into t1 values (1); lock tables t1 write; diff --git a/mysql-test/t/lock_multi.test b/mysql-test/t/lock_multi.test index f05821af5a8..044af931489 100644 --- a/mysql-test/t/lock_multi.test +++ b/mysql-test/t/lock_multi.test @@ -5,6 +5,7 @@ --disable_warnings drop table if exists t1,t2; +drop DATABASE if exists mysqltest_1; --enable_warnings # Test to see if select will get the lock ahead of low priority update diff --git a/scripts/make_binary_distribution.sh b/scripts/make_binary_distribution.sh index 789f3e3ce2e..070b396a34c 100644 --- a/scripts/make_binary_distribution.sh +++ b/scripts/make_binary_distribution.sh @@ -285,7 +285,8 @@ if [ x"$BASE_SYSTEM" != x"netware" ] ; then pkgplugindir=@pkgplugindir@ \ pkgsuppdir=@pkgsuppdir@ \ mandir=@mandir@ \ - infodir=@infodir@ + infodir=@infodir@ \ + libexecdir=@prefix@/libexec # ---------------------------------------------------------------------- # Rename top directory, and set DEST to the new directory @@ -301,7 +302,10 @@ if [ x"$BASE_SYSTEM" != x"netware" ] ; then if [ -z "$gcclib" ] ; then echo "Warning: Compiler doesn't tell libgcc.a!" elif [ -f "$gcclib" ] ; then + { + mkdir -p $DEST/lib $CP $gcclib $DEST/lib/libmygcc.a + } else echo "Warning: Compiler result '$gcclib' not found / no file!" fi diff --git a/scripts/mysql_config.sh b/scripts/mysql_config.sh index f1d46c0b2c0..ce61c09aa15 100644 --- a/scripts/mysql_config.sh +++ b/scripts/mysql_config.sh @@ -86,7 +86,7 @@ bindir='@bindir@' # If installed, search for the compiled in directory first (might be "lib64") pkglibdir='@pkglibdir@' pkglibdir_rel=`echo $pkglibdir | sed -e "s;^$basedir/;;"` -fix_path pkglibdir $pkglibdir_rel lib/mysql lib +fix_path pkglibdir $pkglibdir_rel lib64/mysql lib64 lib/mysql lib plugindir='@pkgplugindir@' From c068b831aca6334c6dea01fd9ff54b6140a52ef6 Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Fri, 24 Feb 2012 12:34:47 +0200 Subject: [PATCH 10/10] Removed const declarations to get rid of compiler warnings. The changes are similar to what is done in innobase in MySQL 5.5 --- storage/innodb_plugin/btr/btr0sea.c | 2 +- storage/innodb_plugin/ha/ha0ha.c | 6 +++--- storage/innodb_plugin/include/ha0ha.h | 10 +++++----- storage/innodb_plugin/include/ha0ha.ic | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/storage/innodb_plugin/btr/btr0sea.c b/storage/innodb_plugin/btr/btr0sea.c index 04c273344f3..f10c207b76a 100644 --- a/storage/innodb_plugin/btr/btr0sea.c +++ b/storage/innodb_plugin/btr/btr0sea.c @@ -524,7 +524,7 @@ btr_search_update_hash_ref( { dict_index_t* index; ulint fold; - const rec_t* rec; + rec_t* rec; ut_ad(cursor->flag == BTR_CUR_HASH_FAIL); #ifdef UNIV_SYNC_DEBUG diff --git a/storage/innodb_plugin/ha/ha0ha.c b/storage/innodb_plugin/ha/ha0ha.c index 65046138275..594a10dc431 100644 --- a/storage/innodb_plugin/ha/ha0ha.c +++ b/storage/innodb_plugin/ha/ha0ha.c @@ -106,7 +106,7 @@ ha_insert_for_fold_func( #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG buf_block_t* block, /*!< in: buffer block containing the data */ #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ - const rec_t* data) /*!< in: data, must not be NULL */ + rec_t* data) /*!< in: data, must not be NULL */ { hash_cell_t* cell; ha_node_t* node; @@ -238,11 +238,11 @@ ha_search_and_update_if_found_func( /*===============================*/ hash_table_t* table, /*!< in/out: hash table */ ulint fold, /*!< in: folded value of the searched data */ - const rec_t* data, /*!< in: pointer to the data */ + rec_t* data, /*!< in: pointer to the data */ #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG buf_block_t* new_block,/*!< in: block containing new_data */ #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ - const rec_t* new_data)/*!< in: new pointer to the data */ + rec_t* new_data)/*!< in: new pointer to the data */ { ha_node_t* node; diff --git a/storage/innodb_plugin/include/ha0ha.h b/storage/innodb_plugin/include/ha0ha.h index 8bba564d153..83a7394123f 100644 --- a/storage/innodb_plugin/include/ha0ha.h +++ b/storage/innodb_plugin/include/ha0ha.h @@ -38,7 +38,7 @@ Looks for an element in a hash table. @return pointer to the data of the first hash table node in chain having the fold number, NULL if not found */ UNIV_INLINE -const rec_t* +rec_t* ha_search_and_get_data( /*===================*/ hash_table_t* table, /*!< in: hash table */ @@ -52,11 +52,11 @@ ha_search_and_update_if_found_func( /*===============================*/ hash_table_t* table, /*!< in/out: hash table */ ulint fold, /*!< in: folded value of the searched data */ - const rec_t* data, /*!< in: pointer to the data */ + rec_t* data, /*!< in: pointer to the data */ #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG buf_block_t* new_block,/*!< in: block containing new_data */ #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ - const rec_t* new_data);/*!< in: new pointer to the data */ + rec_t* new_data);/*!< in: new pointer to the data */ #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG /** Looks for an element when we know the pointer to the data and @@ -131,7 +131,7 @@ ha_insert_for_fold_func( #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG buf_block_t* block, /*!< in: buffer block containing the data */ #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ - const rec_t* data); /*!< in: data, must not be NULL */ + rec_t* data); /*!< in: data, must not be NULL */ #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG /** @@ -210,7 +210,7 @@ struct ha_node_struct { #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG buf_block_t* block; /*!< buffer block containing the data, or NULL */ #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ - const rec_t* data; /*!< pointer to the data */ + rec_t* data; /*!< pointer to the data */ ulint fold; /*!< fold value for the data */ }; diff --git a/storage/innodb_plugin/include/ha0ha.ic b/storage/innodb_plugin/include/ha0ha.ic index 5656e9b7eba..aec28398b5d 100644 --- a/storage/innodb_plugin/include/ha0ha.ic +++ b/storage/innodb_plugin/include/ha0ha.ic @@ -58,7 +58,7 @@ ha_node_set_data_func( #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG buf_block_t* block, /*!< in: buffer block containing the data */ #endif /* UNIV_AHI_DEBUG || UNIV_DEBUG */ - const rec_t* data) /*!< in: pointer to the data */ + rec_t* data) /*!< in: pointer to the data */ { #if defined UNIV_AHI_DEBUG || defined UNIV_DEBUG node->block = block; @@ -111,7 +111,7 @@ Looks for an element in a hash table. @return pointer to the data of the first hash table node in chain having the fold number, NULL if not found */ UNIV_INLINE -const rec_t* +rec_t* ha_search_and_get_data( /*===================*/ hash_table_t* table, /*!< in: hash table */