Loading mysql-test/r/group_min_max.result +6 −6 Original line number Diff line number Diff line Loading @@ -133,13 +133,13 @@ Table Op Msg_type Msg_text test.t3 analyze status Table is already up to date explain select a1, min(a2) from t1 group by a1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range NULL idx_t1_1 65 NULL 5 Using index for group-by 1 SIMPLE t1 range NULL idx_t1_1 130 NULL 5 Using index for group-by explain select a1, max(a2) from t1 group by a1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range NULL idx_t1_1 65 NULL 5 Using index for group-by explain select a1, min(a2), max(a2) from t1 group by a1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range NULL idx_t1_1 65 NULL 5 Using index for group-by 1 SIMPLE t1 range NULL idx_t1_1 130 NULL 5 Using index for group-by explain select a1, a2, b, min(c), max(c) from t1 group by a1,a2,b; 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 Loading @@ -151,13 +151,13 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range NULL idx_t2_1 # NULL # Using index for group-by explain select min(a2), a1, max(a2), min(a2), a1 from t1 group by a1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range NULL idx_t1_1 65 NULL 5 Using index for group-by 1 SIMPLE t1 range NULL idx_t1_1 130 NULL 5 Using index for group-by explain select a1, b, min(c), a1, max(c), b, a2, max(c), max(c) from t1 group by a1, a2, b; 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 explain select min(a2) from t1 group by a1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range NULL idx_t1_1 65 NULL 5 Using index for group-by 1 SIMPLE t1 range NULL idx_t1_1 130 NULL 5 Using index for group-by explain select a2, min(c), max(c) from t1 group by a1,a2,b; 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 Loading Loading @@ -1404,7 +1404,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by explain select a1,a2,b,min(c) from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 146 NULL # Using where; Using index for group-by 1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by select a1,a2,b,min(c),max(c) from t1 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b; a1 a2 b min(c) max(c) a a b e112 h112 Loading Loading @@ -1838,7 +1838,7 @@ 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 10 Using where; Using index for group-by explain select concat(ord(min(b)),ord(max(b))),min(b),max(b) from t1 group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range NULL idx_t1_1 130 NULL 9 Using index for group-by 1 SIMPLE t1 range NULL idx_t1_1 147 NULL 9 Using index for group-by select a1,a2,b, concat(min(c), max(c)) from t1 where a1 < 'd' group by a1,a2,b; a1 a2 b concat(min(c), max(c)) a a a a111d111 Loading sql/item_subselect.cc +9 −12 Original line number Diff line number Diff line Loading @@ -537,8 +537,6 @@ Item_exists_subselect::Item_exists_subselect(st_select_lex *select_lex): null_value= 0; //can't be NULL maybe_null= 0; //can't be NULL value= 0; // We need only 1 row to determinate existence select_lex->master_unit()->global_parameters->select_limit= 1; DBUG_VOID_RETURN; } Loading Loading @@ -605,6 +603,8 @@ void Item_exists_subselect::fix_length_and_dec() decimals= 0; max_length= 1; max_columns= engine->cols(); /* We need only 1 row to determinate existence */ unit->global_parameters->select_limit= 1; } double Item_exists_subselect::val_real() Loading Loading @@ -854,9 +854,6 @@ Item_in_subselect::single_value_transformer(JOIN *join, else { Item_maxmin_subselect *item; // remove LIMIT placed by ALL/ANY subquery select_lex->master_unit()->global_parameters->select_limit= HA_POS_ERROR; subs= item= new Item_maxmin_subselect(thd, this, select_lex, func->l_op()); if (upper_item) upper_item->set_sub_test(item); Loading Loading @@ -1286,13 +1283,10 @@ subselect_single_select_engine(st_select_lex *select, select_subselect *result, Item_subselect *item) :subselect_engine(item, result), prepared(0), optimized(0), executed(0), join(0) prepared(0), optimized(0), executed(0), select_lex(select), join(0) { select_lex= select; SELECT_LEX_UNIT *unit= select_lex->master_unit(); unit->set_limit(unit->global_parameters, select_lex); unit->item= item; this->select_lex= select_lex; select_lex->master_unit()->item= item; } Loading Loading @@ -1440,7 +1434,10 @@ int subselect_single_select_engine::exec() thd->lex->current_select= select_lex; if (!optimized) { SELECT_LEX_UNIT *unit= select_lex->master_unit(); optimized= 1; unit->set_limit(unit->global_parameters); if (join->optimize()) { thd->where= save_where; Loading sql/mysql_priv.h +1 −2 Original line number Diff line number Diff line Loading @@ -884,8 +884,7 @@ bool insert_fields(THD *thd,TABLE_LIST *tables, List_iterator<Item> *it, bool any_privileges, bool allocate_view_names); bool setup_tables(THD *thd, TABLE_LIST *tables, Item **conds, TABLE_LIST **leaves, bool refresh_only, bool select_insert); TABLE_LIST **leaves, bool select_insert); int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields, List<Item> *sum_func_list, uint wild_num); bool setup_fields(THD *thd, Item** ref_pointer_array, TABLE_LIST *tables, Loading sql/opt_range.cc +10 −1 Original line number Diff line number Diff line Loading @@ -7980,8 +7980,17 @@ void QUICK_GROUP_MIN_MAX_SELECT::update_key_stat() } } } else if (have_min && min_max_arg_part && min_max_arg_part->field->is_null()) else if (have_min && min_max_arg_part && min_max_arg_part->field->real_maybe_null()) { /* If a MIN/MAX argument value is NULL, we can quickly determine that we're in the beginning of the next group, because NULLs are always < any other value. This allows us to quickly determine the end of the current group and jump to the next group (see next_min()) and thus effectively increases the usable key length. */ max_used_key_length+= min_max_arg_len; ++used_key_parts; } Loading sql/sp.cc +1 −1 Original line number Diff line number Diff line Loading @@ -667,7 +667,7 @@ db_show_routine_status(THD *thd, int type, const char *wild) tables is not VIEW for sure => we can pass 0 as condition */ setup_tables(thd, &tables, 0, &leaves, FALSE, FALSE); setup_tables(thd, &tables, 0, &leaves, FALSE); for (used_field= &used_fields[0]; used_field->field_name; used_field++) Loading Loading
mysql-test/r/group_min_max.result +6 −6 Original line number Diff line number Diff line Loading @@ -133,13 +133,13 @@ Table Op Msg_type Msg_text test.t3 analyze status Table is already up to date explain select a1, min(a2) from t1 group by a1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range NULL idx_t1_1 65 NULL 5 Using index for group-by 1 SIMPLE t1 range NULL idx_t1_1 130 NULL 5 Using index for group-by explain select a1, max(a2) from t1 group by a1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range NULL idx_t1_1 65 NULL 5 Using index for group-by explain select a1, min(a2), max(a2) from t1 group by a1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range NULL idx_t1_1 65 NULL 5 Using index for group-by 1 SIMPLE t1 range NULL idx_t1_1 130 NULL 5 Using index for group-by explain select a1, a2, b, min(c), max(c) from t1 group by a1,a2,b; 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 Loading @@ -151,13 +151,13 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range NULL idx_t2_1 # NULL # Using index for group-by explain select min(a2), a1, max(a2), min(a2), a1 from t1 group by a1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range NULL idx_t1_1 65 NULL 5 Using index for group-by 1 SIMPLE t1 range NULL idx_t1_1 130 NULL 5 Using index for group-by explain select a1, b, min(c), a1, max(c), b, a2, max(c), max(c) from t1 group by a1, a2, b; 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 explain select min(a2) from t1 group by a1; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range NULL idx_t1_1 65 NULL 5 Using index for group-by 1 SIMPLE t1 range NULL idx_t1_1 130 NULL 5 Using index for group-by explain select a2, min(c), max(c) from t1 group by a1,a2,b; 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 Loading Loading @@ -1404,7 +1404,7 @@ id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by explain select a1,a2,b,min(c) from t2 where (a1 > 'a') and (a2 > 'a') and (b = 'c') group by a1,a2,b; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 146 NULL # Using where; Using index for group-by 1 SIMPLE t2 range idx_t2_0,idx_t2_1,idx_t2_2 idx_t2_1 163 NULL # Using where; Using index for group-by select a1,a2,b,min(c),max(c) from t1 where (a1 >= 'c' or a2 < 'b') and (b > 'a') group by a1,a2,b; a1 a2 b min(c) max(c) a a b e112 h112 Loading Loading @@ -1838,7 +1838,7 @@ 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 10 Using where; Using index for group-by explain select concat(ord(min(b)),ord(max(b))),min(b),max(b) from t1 group by a1,a2; id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 range NULL idx_t1_1 130 NULL 9 Using index for group-by 1 SIMPLE t1 range NULL idx_t1_1 147 NULL 9 Using index for group-by select a1,a2,b, concat(min(c), max(c)) from t1 where a1 < 'd' group by a1,a2,b; a1 a2 b concat(min(c), max(c)) a a a a111d111 Loading
sql/item_subselect.cc +9 −12 Original line number Diff line number Diff line Loading @@ -537,8 +537,6 @@ Item_exists_subselect::Item_exists_subselect(st_select_lex *select_lex): null_value= 0; //can't be NULL maybe_null= 0; //can't be NULL value= 0; // We need only 1 row to determinate existence select_lex->master_unit()->global_parameters->select_limit= 1; DBUG_VOID_RETURN; } Loading Loading @@ -605,6 +603,8 @@ void Item_exists_subselect::fix_length_and_dec() decimals= 0; max_length= 1; max_columns= engine->cols(); /* We need only 1 row to determinate existence */ unit->global_parameters->select_limit= 1; } double Item_exists_subselect::val_real() Loading Loading @@ -854,9 +854,6 @@ Item_in_subselect::single_value_transformer(JOIN *join, else { Item_maxmin_subselect *item; // remove LIMIT placed by ALL/ANY subquery select_lex->master_unit()->global_parameters->select_limit= HA_POS_ERROR; subs= item= new Item_maxmin_subselect(thd, this, select_lex, func->l_op()); if (upper_item) upper_item->set_sub_test(item); Loading Loading @@ -1286,13 +1283,10 @@ subselect_single_select_engine(st_select_lex *select, select_subselect *result, Item_subselect *item) :subselect_engine(item, result), prepared(0), optimized(0), executed(0), join(0) prepared(0), optimized(0), executed(0), select_lex(select), join(0) { select_lex= select; SELECT_LEX_UNIT *unit= select_lex->master_unit(); unit->set_limit(unit->global_parameters, select_lex); unit->item= item; this->select_lex= select_lex; select_lex->master_unit()->item= item; } Loading Loading @@ -1440,7 +1434,10 @@ int subselect_single_select_engine::exec() thd->lex->current_select= select_lex; if (!optimized) { SELECT_LEX_UNIT *unit= select_lex->master_unit(); optimized= 1; unit->set_limit(unit->global_parameters); if (join->optimize()) { thd->where= save_where; Loading
sql/mysql_priv.h +1 −2 Original line number Diff line number Diff line Loading @@ -884,8 +884,7 @@ bool insert_fields(THD *thd,TABLE_LIST *tables, List_iterator<Item> *it, bool any_privileges, bool allocate_view_names); bool setup_tables(THD *thd, TABLE_LIST *tables, Item **conds, TABLE_LIST **leaves, bool refresh_only, bool select_insert); TABLE_LIST **leaves, bool select_insert); int setup_wild(THD *thd, TABLE_LIST *tables, List<Item> &fields, List<Item> *sum_func_list, uint wild_num); bool setup_fields(THD *thd, Item** ref_pointer_array, TABLE_LIST *tables, Loading
sql/opt_range.cc +10 −1 Original line number Diff line number Diff line Loading @@ -7980,8 +7980,17 @@ void QUICK_GROUP_MIN_MAX_SELECT::update_key_stat() } } } else if (have_min && min_max_arg_part && min_max_arg_part->field->is_null()) else if (have_min && min_max_arg_part && min_max_arg_part->field->real_maybe_null()) { /* If a MIN/MAX argument value is NULL, we can quickly determine that we're in the beginning of the next group, because NULLs are always < any other value. This allows us to quickly determine the end of the current group and jump to the next group (see next_min()) and thus effectively increases the usable key length. */ max_used_key_length+= min_max_arg_len; ++used_key_parts; } Loading
sql/sp.cc +1 −1 Original line number Diff line number Diff line Loading @@ -667,7 +667,7 @@ db_show_routine_status(THD *thd, int type, const char *wild) tables is not VIEW for sure => we can pass 0 as condition */ setup_tables(thd, &tables, 0, &leaves, FALSE, FALSE); setup_tables(thd, &tables, 0, &leaves, FALSE); for (used_field= &used_fields[0]; used_field->field_name; used_field++) Loading