Commit 3fa4121c authored by Sergey Petrunya's avatar Sergey Petrunya

Merge: BUG#716293: "Range checked for each record" is not used if condition...

Merge: BUG#716293: "Range checked for each record" is not used if condition refers to outside of subquery
parents 173edbfd 5991ca2a
...@@ -51,7 +51,7 @@ FROM t3 WHERE 1 = 0 GROUP BY 1; ...@@ -51,7 +51,7 @@ FROM t3 WHERE 1 = 0 GROUP BY 1;
id select_type table type possible_keys key key_len ref rows Extra id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE 1 PRIMARY NULL NULL NULL NULL NULL NULL NULL Impossible WHERE
2 DEPENDENT SUBQUERY t1 index NULL PRIMARY 4 NULL 2 Using index 2 DEPENDENT SUBQUERY t1 index NULL PRIMARY 4 NULL 2 Using index
2 DEPENDENT SUBQUERY t2 index b b 5 NULL 2 Using where; Using index; Using join buffer (flat, BNL join) 2 DEPENDENT SUBQUERY t2 ALL b NULL NULL NULL 2 Range checked for each record (index map: 0x2)
# should return 0 rows # should return 0 rows
SELECT SELECT
(SELECT 1 FROM t1,t2 WHERE t2.b > t3.b) (SELECT 1 FROM t1,t2 WHERE t2.b > t3.b)
...@@ -671,3 +671,21 @@ DEALLOCATE PREPARE stmt; ...@@ -671,3 +671,21 @@ DEALLOCATE PREPARE stmt;
SET SESSION optimizer_switch = @old_optimizer_switch; SET SESSION optimizer_switch = @old_optimizer_switch;
SET SESSION join_cache_level = @old_join_cache_level; SET SESSION join_cache_level = @old_join_cache_level;
DROP TABLE t1, t2, t3; DROP TABLE t1, t2, t3;
#
# BUG#716293: "Range checked for each record" is not used if condition refers to outside of subquery
#
create table t1 (a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2 (a int, b int, `filler` char(200), key(a), key (b));
insert into t2
select A.a + 10*B.a + 100 * C.a, A.a + 10*B.a + 100 * C.a, 'filler' from t1 A, t1 B, t1 C;
# The following must use "Range checked for each record" for table B
explain
select a,
(select sum(X.a+B.b) from t1 X, t2 B where B.a=A.a or B.b=A.a)
from t1 A;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY A ALL NULL NULL NULL NULL 10
2 DEPENDENT SUBQUERY X ALL NULL NULL NULL NULL 10
2 DEPENDENT SUBQUERY B ALL a,b NULL NULL NULL 1000 Range checked for each record (index map: 0x3)
drop table t1, t2;
...@@ -602,3 +602,20 @@ SET SESSION join_cache_level = @old_join_cache_level; ...@@ -602,3 +602,20 @@ SET SESSION join_cache_level = @old_join_cache_level;
DROP TABLE t1, t2, t3; DROP TABLE t1, t2, t3;
--echo #
--echo # BUG#716293: "Range checked for each record" is not used if condition refers to outside of subquery
--echo #
create table t1 (a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
create table t2 (a int, b int, `filler` char(200), key(a), key (b));
insert into t2
select A.a + 10*B.a + 100 * C.a, A.a + 10*B.a + 100 * C.a, 'filler' from t1 A, t1 B, t1 C;
--echo # The following must use "Range checked for each record" for table B
explain
select a,
(select sum(X.a+B.b) from t1 X, t2 B where B.a=A.a or B.b=A.a)
from t1 A;
drop table t1, t2;
...@@ -7330,7 +7330,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond) ...@@ -7330,7 +7330,7 @@ make_join_select(JOIN *join,SQL_SELECT *select,COND *cond)
sel->cond->quick_fix_field(); sel->cond->quick_fix_field();
if (sel->test_quick_select(thd, tab->keys, if (sel->test_quick_select(thd, tab->keys,
used_tables & ~ current_map, (used_tables & ~ current_map) | OUTER_REF_TABLE_BIT,
(join->select_options & (join->select_options &
OPTION_FOUND_ROWS ? OPTION_FOUND_ROWS ?
HA_POS_ERROR : HA_POS_ERROR :
......
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