Commit 1a536c8d authored by Igor Babaev's avatar Igor Babaev

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.
parent 472bc477
...@@ -1538,3 +1538,14 @@ a ...@@ -1538,3 +1538,14 @@ a
3 3
4 4
DROP TABLE t1,t2; 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;
...@@ -1185,3 +1185,18 @@ SELECT t1.a FROM t1 NATURAL STRAIGHT_JOIN t2 ORDER BY t1.a; ...@@ -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; SELECT t1.a FROM t1 NATURAL STRAIGHT_JOIN t2 ORDER BY t1.a;
DROP TABLE t1,t2; 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;
...@@ -7941,7 +7941,8 @@ static SEL_TREE *get_mm_tree(RANGE_OPT_PARAM *param,COND *cond) ...@@ -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; value= cond_func->arg_count > 1 ? cond_func->arguments()[1] : NULL;
if (value && value->is_expensive()) if (value && value->is_expensive())
DBUG_RETURN(0); 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 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) ...@@ -7966,7 +7967,8 @@ static SEL_TREE *get_mm_tree(RANGE_OPT_PARAM *param,COND *cond)
value= cond_func->arguments()[0]; value= cond_func->arguments()[0];
if (value && value->is_expensive()) if (value && value->is_expensive())
DBUG_RETURN(0); 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);
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment