From c397f97407157c8be05f86a6365826674a921993 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Tue, 25 Feb 2014 19:25:49 +0400 Subject: [PATCH 1/7] MDEV-5732: Valgrind warning for index_merge and extended_keys - Make is_key_scan_ror() take into account the existence of extended keys. --- sql/opt_range.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 6c1ddab9710..51a4f2ed16b 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -10603,8 +10603,13 @@ static bool is_key_scan_ror(PARAM *param, uint keynr, uint8 nparts) if (param->table->field[fieldnr]->key_length() != kp->length) return FALSE; } - - if (key_part == key_part_end) + + /* + If there are equalities for all key parts, it is a ROR scan. If there are + equalities all keyparts and even some of key parts from "Extended Key" + index suffix, it is a ROR-scan, too. + */ + if (key_part >= key_part_end) return TRUE; key_part= table_key->key_part + nparts; From d7081b25242ee975f0e7e448045cef7a7dbb4016 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Thu, 27 Feb 2014 13:40:40 +0400 Subject: [PATCH 2/7] Update test results after fix for MDEV-5732 --- mysql-test/r/innodb_ext_key.result | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mysql-test/r/innodb_ext_key.result b/mysql-test/r/innodb_ext_key.result index df681f21f3b..f3a18d09198 100644 --- a/mysql-test/r/innodb_ext_key.result +++ b/mysql-test/r/innodb_ext_key.result @@ -327,7 +327,7 @@ from lineitem use index (i_l_shipdate, i_l_receiptdate) where l_shipdate='1992-07-01' and l_orderkey=130 or l_receiptdate='1992-07-01' and l_orderkey=5603; id select_type table type possible_keys key key_len ref rows Extra -1 SIMPLE lineitem index_merge i_l_shipdate,i_l_receiptdate i_l_shipdate,i_l_receiptdate 8,8 NULL 2 Using sort_union(i_l_shipdate,i_l_receiptdate); Using where +1 SIMPLE lineitem index_merge i_l_shipdate,i_l_receiptdate i_l_shipdate,i_l_receiptdate 8,8 NULL 2 Using union(i_l_shipdate,i_l_receiptdate); Using where flush status; select l_orderkey, l_linenumber from lineitem use index (i_l_shipdate, i_l_receiptdate) From 1a536c8daf7beabc1f08bfb4f614c8cc7d3aa8e5 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Thu, 27 Feb 2014 13:54:05 -0800 Subject: [PATCH 3/7] Fixed bug mdev-5635. After constant row substitution some field items become constant items. The range analyzer should take into account this fact when looking for ranges. --- mysql-test/r/join.result | 11 +++++++++++ mysql-test/t/join.test | 15 +++++++++++++++ sql/opt_range.cc | 6 ++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/mysql-test/r/join.result b/mysql-test/r/join.result index 0f798f7ba1a..e7292e8ddce 100644 --- a/mysql-test/r/join.result +++ b/mysql-test/r/join.result @@ -1538,3 +1538,14 @@ a 3 4 DROP TABLE t1,t2; +# +# MDEV-5635: join of a const table with non-const tables +# +CREATE TABLE t1 (a varchar(3) NOT NULL) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('foo'); +CREATE TABLE t2 (b varchar(3), c varchar(3), INDEX(b)) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('bar', 'bar'),( 'qux', 'qux'); +SELECT STRAIGHT_JOIN * FROM t1, t2 AS t2_1, t2 AS t2_2 +WHERE t2_2.c = t2_1.c AND t2_2.b = t2_1.b AND ( a IS NULL OR t2_1.c = a ); +a b c b c +DROP TABLE t1,t2; diff --git a/mysql-test/t/join.test b/mysql-test/t/join.test index 54b2a3c82ea..e07a3665920 100644 --- a/mysql-test/t/join.test +++ b/mysql-test/t/join.test @@ -1185,3 +1185,18 @@ SELECT t1.a FROM t1 NATURAL STRAIGHT_JOIN t2 ORDER BY t1.a; SELECT t1.a FROM t1 NATURAL STRAIGHT_JOIN t2 ORDER BY t1.a; DROP TABLE t1,t2; + +--echo # +--echo # MDEV-5635: join of a const table with non-const tables +--echo # + +CREATE TABLE t1 (a varchar(3) NOT NULL) ENGINE=MyISAM; +INSERT INTO t1 VALUES ('foo'); + +CREATE TABLE t2 (b varchar(3), c varchar(3), INDEX(b)) ENGINE=MyISAM; +INSERT INTO t2 VALUES ('bar', 'bar'),( 'qux', 'qux'); + +SELECT STRAIGHT_JOIN * FROM t1, t2 AS t2_1, t2 AS t2_2 + WHERE t2_2.c = t2_1.c AND t2_2.b = t2_1.b AND ( a IS NULL OR t2_1.c = a ); + +DROP TABLE t1,t2; diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 51a4f2ed16b..806f0466fe5 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -7941,7 +7941,8 @@ static SEL_TREE *get_mm_tree(RANGE_OPT_PARAM *param,COND *cond) value= cond_func->arg_count > 1 ? cond_func->arguments()[1] : NULL; if (value && value->is_expensive()) DBUG_RETURN(0); - ftree= get_full_func_mm_tree(param, cond_func, field_item, value, inv); + if (!cond_func->arguments()[0]->real_item()->const_item()) + ftree= get_full_func_mm_tree(param, cond_func, field_item, value, inv); } /* Even if get_full_func_mm_tree() was executed above and did not @@ -7966,7 +7967,8 @@ static SEL_TREE *get_mm_tree(RANGE_OPT_PARAM *param,COND *cond) value= cond_func->arguments()[0]; if (value && value->is_expensive()) DBUG_RETURN(0); - ftree= get_full_func_mm_tree(param, cond_func, field_item, value, inv); + if (!cond_func->arguments()[1]->real_item()->const_item()) + ftree= get_full_func_mm_tree(param, cond_func, field_item, value, inv); } } From 24d9bf822746ca138b449677d984536e9addfebc Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Tue, 4 Mar 2014 00:41:50 +0400 Subject: [PATCH 4/7] MDEV-5778: Valgrind failure in innodb_ext_keys.test - Fix valgrind failure: make test_if_order_by_key() account for extended keys feature. --- sql/sql_select.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 93e67c484e3..8f982a9212e 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -19492,7 +19492,7 @@ static int test_if_order_by_key(ORDER *order, TABLE *table, uint idx, for (; const_key_parts & 1 ; const_key_parts>>= 1) key_part++; - if (key_part == key_part_end) + if (key_part >= key_part_end) { /* We are at the end of the key. Check if the engine has the primary From 64649e3393e1506cd62670c0329cb70e0fe524fa Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Tue, 4 Mar 2014 15:14:40 +0400 Subject: [PATCH 5/7] MDEV-5723: mysqldump -uroot unusable for multi-database operations, checks all databases - Make do_fill_table() use join_tab->cache_select->cond if it is present. When join_tab->cache_select->cond is present, join_tab->select_cond doesn't have any conditions that are usable for I_S optimizations. --- mysql-test/r/information_schema.result | 42 +++++++++++++++++++ mysql-test/t/information_schema.test | 56 ++++++++++++++++++++++++++ sql/sql_show.cc | 18 +++++++-- 3 files changed, 113 insertions(+), 3 deletions(-) diff --git a/mysql-test/r/information_schema.result b/mysql-test/r/information_schema.result index 4ccf3ba1ca4..ec260dfc990 100644 --- a/mysql-test/r/information_schema.result +++ b/mysql-test/r/information_schema.result @@ -1972,3 +1972,45 @@ drop database mysqltest; # # End of 5.5 tests # +# +# MDEV-5723: mysqldump -uroot unusable for multi-database operations, checks all databases +# +drop database if exists db1; +create database db1; +use db1; +create table t1 (a int); +create table t2 (a int); +create table t3 (a int); +create database mysqltest; +use mysqltest; +create table t1 (a int); +create table t2 (a int); +create table t3 (a int); +flush tables; +flush status; +SELECT +LOGFILE_GROUP_NAME, FILE_NAME, TOTAL_EXTENTS, INITIAL_SIZE, ENGINE, EXTRA +FROM +INFORMATION_SCHEMA.FILES +WHERE +FILE_TYPE = 'UNDO LOG' AND FILE_NAME IS NOT NULL AND +LOGFILE_GROUP_NAME IN (SELECT DISTINCT LOGFILE_GROUP_NAME +FROM INFORMATION_SCHEMA.FILES +WHERE +FILE_TYPE = 'DATAFILE' AND +TABLESPACE_NAME IN (SELECT DISTINCT TABLESPACE_NAME +FROM INFORMATION_SCHEMA.PARTITIONS +WHERE TABLE_SCHEMA IN ('db1') +) +) +GROUP BY +LOGFILE_GROUP_NAME, FILE_NAME, ENGINE +ORDER BY +LOGFILE_GROUP_NAME; +LOGFILE_GROUP_NAME FILE_NAME TOTAL_EXTENTS INITIAL_SIZE ENGINE EXTRA +# This must have Opened_tables=3, not 6. +show status like 'Opened_tables'; +Variable_name Value +Opened_tables 3 +drop database mysqltest; +drop database db1; diff --git a/mysql-test/t/information_schema.test b/mysql-test/t/information_schema.test index 8c88be5c603..f6422a0aae7 100644 --- a/mysql-test/t/information_schema.test +++ b/mysql-test/t/information_schema.test @@ -1816,5 +1816,61 @@ drop database mysqltest; --echo # End of 5.5 tests --echo # +--echo # +--echo # MDEV-5723: mysqldump -uroot unusable for multi-database operations, checks all databases +--echo # + +--disable_warnings +drop database if exists db1; +--enable_warnings + +connect (con1,localhost,root,,); +connection con1; + +create database db1; +use db1; +create table t1 (a int); +create table t2 (a int); +create table t3 (a int); + +create database mysqltest; +use mysqltest; +create table t1 (a int); +create table t2 (a int); +create table t3 (a int); + +flush tables; +flush status; + +SELECT + LOGFILE_GROUP_NAME, FILE_NAME, TOTAL_EXTENTS, INITIAL_SIZE, ENGINE, EXTRA +FROM + INFORMATION_SCHEMA.FILES +WHERE + FILE_TYPE = 'UNDO LOG' AND FILE_NAME IS NOT NULL AND + LOGFILE_GROUP_NAME IN (SELECT DISTINCT LOGFILE_GROUP_NAME + FROM INFORMATION_SCHEMA.FILES + WHERE + FILE_TYPE = 'DATAFILE' AND + TABLESPACE_NAME IN (SELECT DISTINCT TABLESPACE_NAME + FROM INFORMATION_SCHEMA.PARTITIONS + WHERE TABLE_SCHEMA IN ('db1') + ) + ) +GROUP BY + LOGFILE_GROUP_NAME, FILE_NAME, ENGINE +ORDER BY + LOGFILE_GROUP_NAME; + +--echo # This must have Opened_tables=3, not 6. +show status like 'Opened_tables'; + +drop database mysqltest; +drop database db1; + +connection default; +disconnect con1; + # Wait till all disconnects are completed --source include/wait_until_count_sessions.inc + diff --git a/sql/sql_show.cc b/sql/sql_show.cc index 27fe535a3ab..19a5a84b274 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -8021,9 +8021,21 @@ static bool do_fill_table(THD *thd, Warning_info *wi_saved= thd->warning_info; thd->warning_info= &wi; - - bool res= table_list->schema_table->fill_table( - thd, table_list, join_table->select_cond); + + Item *item= join_table->select_cond; + if (join_table->cache_select && + join_table->cache_select->cond) + { + /* + If join buffering is used, we should use the condition that is attached + to the join cache. Cache condition has a part of WHERE that can be + checked when we're populating this table. + join_tab->select_cond is of no interest, because it only has conditions + that depend on both this table and previous tables in the join order. + */ + item= join_table->cache_select->cond; + } + bool res= table_list->schema_table->fill_table(thd, table_list, item); thd->warning_info= wi_saved; From cfc2eb9dd20f5101eb11fff3b2896cd05700548c Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 4 Mar 2014 14:37:09 +0100 Subject: [PATCH 6/7] MDEV-5703: [PATCH] Slave disconnects and fails to reconnect on Error_code: 1159 Patch from Tomas Matejicek Add missing error code to is_networ_error(), to allow slave to automatically attempt reconnection also in this case. --- sql/slave.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/sql/slave.cc b/sql/slave.cc index 5aec8d70bad..5275578295b 100644 --- a/sql/slave.cc +++ b/sql/slave.cc @@ -1339,6 +1339,7 @@ bool is_network_error(uint errorno) errorno == ER_CON_COUNT_ERROR || errorno == ER_CONNECTION_KILLED || errorno == ER_NEW_ABORTING_CONNECTION || + errorno == ER_NET_READ_INTERRUPTED || errorno == ER_SERVER_SHUTDOWN) return TRUE; From 23af77d26e3ff336e415a5d8bf3f4c4a7bc84a18 Mon Sep 17 00:00:00 2001 From: Sergey Petrunya Date: Wed, 5 Mar 2014 02:10:06 +0400 Subject: [PATCH 7/7] MDEV-5723: mysqldump -uroot unusable for multi-database operations, checks all databases - MariaDB-5.5 part of the fix: since we can't easily fix query optimization for I_S tables, run the affected-tablespaces query with semijoin=off. It happens to have a good query plan with that setting. [This is a forward-port to MariaDB 10.0] --- client/mysqldump.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/client/mysqldump.c b/client/mysqldump.c index cf42b161f8a..e445fb96d59 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -3991,7 +3991,13 @@ static int dump_tablespaces(char* ts_where) char *ubs; char *endsemi; DBUG_ENTER("dump_tablespaces"); - + + /* + Try to turn off semi-join optimization (if that fails, this is a + pre-optimizer_switch server, and the old query plan is ok for us. + */ + mysql_query(mysql, "set optimizer_switch='semijoin=off'"); + init_dynamic_string_checked(&sqlbuf, "SELECT LOGFILE_GROUP_NAME," " FILE_NAME," @@ -4151,6 +4157,8 @@ static int dump_tablespaces(char* ts_where) mysql_free_result(tableres); dynstr_free(&sqlbuf); + mysql_query(mysql, "set optimizer_switch=default"); + DBUG_RETURN(0); }