Merge 5.2->5.3

This commit is contained in:
unknown 2012-05-11 11:40:23 +03:00
commit e10fecc02f
15 changed files with 342 additions and 33 deletions

View file

@ -247,6 +247,7 @@ public:
{}
bool fix_fields(THD *, Item **);
bool fix_left(THD *thd, Item **ref);
table_map not_null_tables() const { return 0; }
bool is_null();
longlong val_int();
void cleanup();
@ -498,6 +499,7 @@ public:
{}
virtual void top_level_item() { abort_on_null= 1; }
bool is_top_level_item() { return abort_on_null; }
table_map not_null_tables() const { return 0; }
longlong val_int();
enum Functype functype() const { return NOT_ALL_FUNC; }
const char *func_name() const { return "<not>"; }

View file

@ -13121,7 +13121,7 @@ int QUICK_GROUP_MIN_MAX_SELECT::next_min()
if (min_max_arg_part && min_max_arg_part->field->is_null())
{
/* Find the first subsequent record without NULL in the MIN/MAX field. */
key_copy(tmp_record, record, index_info, 0);
key_copy(tmp_record, record, index_info, max_used_key_length);
result= file->ha_index_read_map(record, tmp_record,
make_keypart_map(real_key_parts),
HA_READ_AFTER_KEY);

View file

@ -416,7 +416,7 @@ int opt_sum_query(THD *thd,
}
removed_tables|= table->map;
}
else if (!expr->const_item() || !is_exact_count)
else if (!expr->const_item() || !is_exact_count || conds)
{
/*
The optimization is not applicable in both cases:
@ -426,6 +426,8 @@ int opt_sum_query(THD *thd,
NULL if the query does not return any rows. Thus, if we are not
able to determine if the query returns any rows, we can't apply
the optimization and replace MIN/MAX with a constant.
(c) there is a WHERE clause. The WHERE conditions may result in
an empty result, but the clause cannot be taken into account here.
*/
const_result= 0;
break;

View file

@ -1487,7 +1487,6 @@ JOIN::optimize()
simple_order=1;
select_distinct= 0; // No need in distinct for 1 row
group_optimized_away= 1;
implicit_grouping= TRUE;
}
calc_group_buffer(this, group_list);
@ -7880,7 +7879,31 @@ JOIN::make_simple_join(JOIN *parent, TABLE *temp_table)
tmp_table_param.copy_field= tmp_table_param.copy_field_end=0;
first_record= sort_and_group=0;
send_records= (ha_rows) 0;
group= 0;
if (group_optimized_away && !tmp_table_param.precomputed_group_by)
{
/*
If grouping has been optimized away, a temporary table is
normally not needed unless we're explicitly requested to create
one (e.g. due to a SQL_BUFFER_RESULT hint or INSERT ... SELECT).
In this case (grouping was optimized away), temp_table was
created without a grouping expression and JOIN::exec() will not
perform the necessary grouping (by the use of end_send_group()
or end_write_group()) if JOIN::group is set to false.
There is one exception: if the loose index scan access method is
used to read into the temporary table, grouping and aggregate
functions are handled.
*/
// the temporary table was explicitly requested
DBUG_ASSERT(test(select_options & OPTION_BUFFER_RESULT));
// the temporary table does not have a grouping expression
DBUG_ASSERT(!temp_table->group);
}
else
group= false;
row_limit= unit->select_limit_cnt;
do_send_rows= row_limit ? 1 : 0;