summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorGeorgi Kodinov <Georgi.Kodinov@Oracle.com>2010-12-08 14:28:06 +0200
committerGeorgi Kodinov <Georgi.Kodinov@Oracle.com>2010-12-08 14:28:06 +0200
commit352ce1b596758403ab9d439b06267fec4d191a58 (patch)
tree843cd564016bb7ea84119c7bbc818afe1b4cd412 /sql
parent9588e1ba53fa91463c4ad5695c46f821aa2ade7b (diff)
downloadmariadb-git-352ce1b596758403ab9d439b06267fec4d191a58.tar.gz
Bug #57954: BIT_AND function returns incorrect results
when semijoin=on When setting the aggregate function as having no rows to report the function no_rows_in_result() was calling Item_sum::reset(). However this function in addition to cleaning up the aggregate value by calling aggregator_clear() was also adding the current value to the aggregate value by calling aggregator_add(). Fixed by making no_rows_in_result() to call aggregator_clear() directly. Renamed Item_sum::reset to Item_sum::reset_and_add() to and added a comment to avoid misinterpretation of what the function does.
Diffstat (limited to 'sql')
-rw-r--r--sql/item_sum.cc2
-rw-r--r--sql/item_sum.h20
-rw-r--r--sql/opt_range.cc4
-rw-r--r--sql/opt_sum.cc2
-rw-r--r--sql/sql_select.cc2
5 files changed, 19 insertions, 11 deletions
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index cf95fc3969f..7aff7940c4d 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -2235,7 +2235,7 @@ void Item_sum_avg::reset_field()
void Item_sum_bit::reset_field()
{
- reset();
+ reset_and_add();
int8store(result_field->ptr, bits);
}
diff --git a/sql/item_sum.h b/sql/item_sum.h
index c7159568c40..3ea79fb8cee 100644
--- a/sql/item_sum.h
+++ b/sql/item_sum.h
@@ -406,14 +406,22 @@ public:
Item_sum(THD *thd, Item_sum *item);
enum Type type() const { return SUM_FUNC_ITEM; }
virtual enum Sumfunctype sum_func () const=0;
- inline bool reset() { aggregator_clear(); return aggregator_add(); };
+ /**
+ Resets the aggregate value to its default and aggregates the current
+ value of its attribute(s).
+ */
+ inline bool reset_and_add()
+ {
+ aggregator_clear();
+ return aggregator_add();
+ };
/*
Called when new group is started and results are being saved in
- a temporary table. Similar to reset(), but must also store value in
- result_field. Like reset() it is supposed to reset start value to
- default.
- This set of methods (reult_field(), reset_field, update_field()) of
+ a temporary table. Similarly to reset_and_add() it resets the
+ value to its default and aggregates the value of its
+ attribute(s), but must also store it in result_field.
+ This set of methods (result_item(), reset_field, update_field()) of
Item_sum is used only if quick_group is not null. Otherwise
copy_or_same() is used to obtain a copy of this item.
*/
@@ -456,7 +464,7 @@ public:
set_aggregator(with_distinct ?
Aggregator::DISTINCT_AGGREGATOR :
Aggregator::SIMPLE_AGGREGATOR);
- reset();
+ aggregator_clear();
}
virtual void make_unique() { force_copy_fields= TRUE; }
Item *get_tmp_table_item(THD *thd);
diff --git a/sql/opt_range.cc b/sql/opt_range.cc
index 2ac860d25e3..f39037e9db9 100644
--- a/sql/opt_range.cc
+++ b/sql/opt_range.cc
@@ -11391,7 +11391,7 @@ void QUICK_GROUP_MIN_MAX_SELECT::update_min_result()
min_functions_it->rewind();
while ((min_func= (*min_functions_it)++))
- min_func->reset();
+ min_func->reset_and_add();
}
@@ -11423,7 +11423,7 @@ void QUICK_GROUP_MIN_MAX_SELECT::update_max_result()
max_functions_it->rewind();
while ((max_func= (*max_functions_it)++))
- max_func->reset();
+ max_func->reset_and_add();
}
diff --git a/sql/opt_sum.cc b/sql/opt_sum.cc
index e020c94a3bd..a2f8b9c4447 100644
--- a/sql/opt_sum.cc
+++ b/sql/opt_sum.cc
@@ -424,7 +424,7 @@ int opt_sum_query(TABLE_LIST *tables, List<Item> &all_fields,COND *conds)
item_sum->aggregator_clear();
}
else
- item_sum->reset();
+ item_sum->reset_and_add();
item_sum->make_const();
recalc_const_item= 1;
break;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index ef2dd1d76e1..e4772bf3fb2 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -15850,7 +15850,7 @@ init_sum_functions(Item_sum **func_ptr, Item_sum **end_ptr)
{
for (; func_ptr != end_ptr ;func_ptr++)
{
- if ((*func_ptr)->reset())
+ if ((*func_ptr)->reset_and_add())
return 1;
}
/* If rollup, calculate the upper sum levels */