diff --git a/mysql-test/r/group_min_max.result b/mysql-test/r/group_min_max.result index e97d8d63579..c291599b078 100644 --- a/mysql-test/r/group_min_max.result +++ b/mysql-test/r/group_min_max.result @@ -1354,6 +1354,18 @@ c a a b311 d311 c a b e312 h312 d a a b411 d411 d a b e412 h412 +explain select a1,a2,b,min(c),max(c) from t1 +where exists ( select * from t2 where t2.c = t1.c ) +group by a1,a2,b; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 index NULL idx_t1_1 163 NULL 128 Using where; Using index +2 DEPENDENT SUBQUERY t2 index NULL idx_t2_1 163 NULL 164 Using where; Using index +explain select a1,a2,b,min(c),max(c) from t1 +where exists ( select * from t2 where t2.c > 'b1' ) +group by a1,a2,b; +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 range NULL idx_t1_1 147 NULL 17 Using index for group-by +2 SUBQUERY t2 index NULL idx_t2_1 163 NULL 164 Using index explain select a1,a2,b,min(c),max(c) from t1 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range idx_t1_0,idx_t1_1,idx_t1_2 idx_t1_1 147 NULL 17 Using where; Using index for group-by @@ -1637,6 +1649,14 @@ a1 a2 b select distinct b from t2 where (a2 >= 'b') and (b = 'a'); b a +select distinct t_00.a1 +from t1 t_00 +where exists ( select * from t2 where a1 = t_00.a1 ); +a1 +a +b +c +d explain select distinct a1,a2,b from t1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range NULL idx_t1_1 147 NULL 17 Using index for group-by diff --git a/mysql-test/t/group_min_max.test b/mysql-test/t/group_min_max.test index 5b48f89470d..0eb6fc49990 100644 --- a/mysql-test/t/group_min_max.test +++ b/mysql-test/t/group_min_max.test @@ -372,15 +372,15 @@ select a1,a2,b,min(c),max(c) from t2 where (c > 'b111') and (c <= 'g112') group select a1,a2,b,min(c),max(c) from t2 where (c < 'c5') or (c = 'g412') or (c = 'k421') group by a1,a2,b; select a1,a2,b,min(c),max(c) from t2 where ((c > 'b111') and (c <= 'g112')) or ((c > 'd000') and (c <= 'i110')) group by a1,a2,b; -#-- analyze the sub-select -#explain select a1,a2,b,min(c),max(c) from t1 -#where exists ( select * from t2 where t2.c = t1.c ) -#group by a1,a2,b; +-- analyze the sub-select +explain select a1,a2,b,min(c),max(c) from t1 +where exists ( select * from t2 where t2.c = t1.c ) +group by a1,a2,b; -#-- the sub-select is unrelated to MIN/MAX -#explain select a1,a2,b,min(c),max(c) from t1 -#where exists ( select * from t2 where t2.c > 'b1' ) -#group by a1,a2,b; +-- the sub-select is unrelated to MIN/MAX +explain select a1,a2,b,min(c),max(c) from t1 +where exists ( select * from t2 where t2.c > 'b1' ) +group by a1,a2,b; -- A,B,C) Predicates referencing mixed classes of attributes @@ -474,10 +474,10 @@ select distinct a1,a2,b,c from t2 where (a2 >= 'b') and (b = 'a') and (c = 'i121 select distinct a1,a2,b from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c'); select distinct b from t2 where (a2 >= 'b') and (b = 'a'); -#-- BUG 6303 -#select distinct t_00.a1 -#from t1 t_00 -#where exists ( select * from t2 where a1 = t_00.a1 ); +-- BUG 6303 +select distinct t_00.a1 +from t1 t_00 +where exists ( select * from t2 where a1 = t_00.a1 ); -- diff --git a/sql/opt_range.cc b/sql/opt_range.cc index 8f7e713e33d..48f48797a60 100644 --- a/sql/opt_range.cc +++ b/sql/opt_range.cc @@ -6965,8 +6965,9 @@ check_group_min_max_predicates(COND *cond, Item_field *min_max_arg_item, if (cur_arg->type() == Item::FIELD_ITEM) { if (min_max_arg_item->eq(cur_arg, 1)) - {/* - If pred references the MIN/MAX argument check whether pred is a range + { + /* + If pred references the MIN/MAX argument, check whether pred is a range condition that compares the MIN/MAX argument with a constant. */ Item_func::Functype pred_type= pred->functype();