summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <sanja@montyprogram.com>2012-05-11 11:40:23 +0300
committerunknown <sanja@montyprogram.com>2012-05-11 11:40:23 +0300
commite10fecc02f57980ddc27bafb9d1f620e8533f4a3 (patch)
tree393865dac63fb0c44cd7c6d166c97a4617b1a313 /sql
parentfe0a0bdb143696c54206cd5f908dac94996aab42 (diff)
parentf2cbc014d98a927ed7038f55a25c3d288de10f51 (diff)
downloadmariadb-git-e10fecc02f57980ddc27bafb9d1f620e8533f4a3.tar.gz
Merge 5.2->5.3
Diffstat (limited to 'sql')
-rw-r--r--sql/item_cmpfunc.h2
-rw-r--r--sql/opt_range.cc2
-rw-r--r--sql/opt_sum.cc4
-rw-r--r--sql/sql_select.cc27
4 files changed, 31 insertions, 4 deletions
diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h
index 189b83b7efc..45a0976fae1 100644
--- a/sql/item_cmpfunc.h
+++ b/sql/item_cmpfunc.h
@@ -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>"; }
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 4b973b8500e..4ffe184ca03 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -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);
diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc
index 9e097af1e6e..b6aca56f047 100644
--- a/sql/opt_sum.cc
+++ b/sql/opt_sum.cc
@@ -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;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index fccd94ec3cd..50d1ffbb19c 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -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;