From 1a536c8daf7beabc1f08bfb4f614c8cc7d3aa8e5 Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Thu, 27 Feb 2014 13:54:05 -0800 Subject: [PATCH] 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); } }