summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorVicențiu Ciorbaru <vicentiu@mariadb.org>2016-03-14 19:11:03 +0200
committerVicențiu Ciorbaru <vicentiu@mariadb.org>2016-03-14 19:12:27 +0200
commit93f2371020039f943a28e314412ff6605315ff27 (patch)
treef88bfbf9553167dff5ab5aa1d5e5067e23796f19 /sql
parente261c14456fdc92844a76688c08e1f4a6cc2c8bb (diff)
downloadmariadb-git-93f2371020039f943a28e314412ff6605315ff27.tar.gz
Implemented a counter within Item_sum_sum
The counter keeps track of the number of items added to the sum function. It is increased when we add a value to the sum function and decreased when it is removed.
Diffstat (limited to 'sql')
-rw-r--r--sql/item_sum.cc26
-rw-r--r--sql/item_sum.h1
-rw-r--r--sql/sql_window.cc7
3 files changed, 31 insertions, 3 deletions
diff --git a/sql/item_sum.cc b/sql/item_sum.cc
index 3f4853a4e1f..b7490d02233 100644
--- a/sql/item_sum.cc
+++ b/sql/item_sum.cc
@@ -1243,7 +1243,8 @@ Field *Item_sum_hybrid::create_tmp_field(bool group, TABLE *table,
Item_sum_sum::Item_sum_sum(THD *thd, Item_sum_sum *item)
:Item_sum_num(thd, item),
Type_handler_hybrid_field_type(item),
- curr_dec_buff(item->curr_dec_buff)
+ curr_dec_buff(item->curr_dec_buff),
+ count(item->count)
{
/* TODO: check if the following assignments are really needed */
if (Item_sum_sum::result_type() == DECIMAL_RESULT)
@@ -1265,6 +1266,7 @@ void Item_sum_sum::clear()
{
DBUG_ENTER("Item_sum_sum::clear");
null_value=1;
+ count= 0;
if (Item_sum_sum::result_type() == DECIMAL_RESULT)
{
curr_dec_buff= 0;
@@ -1325,6 +1327,7 @@ bool Item_sum_sum::add()
void Item_sum_sum::add_helper(bool perform_removal)
{
DBUG_ENTER("Item_sum_sum::add_helper");
+
if (Item_sum_sum::result_type() == DECIMAL_RESULT)
{
my_decimal value;
@@ -1332,13 +1335,20 @@ void Item_sum_sum::add_helper(bool perform_removal)
if (!aggr->arg_is_null(true))
{
if (perform_removal)
+ {
+ DBUG_ASSERT(count > 0);
my_decimal_sub(E_DEC_FATAL_ERROR, dec_buffs + (curr_dec_buff ^ 1),
dec_buffs + curr_dec_buff, val);
+ count--;
+ }
else
+ {
+ count++;
my_decimal_add(E_DEC_FATAL_ERROR, dec_buffs + (curr_dec_buff ^ 1),
val, dec_buffs + curr_dec_buff);
+ }
curr_dec_buff^= 1;
- null_value= 0;
+ null_value= (count > 0) ? 0 : 1;
}
}
else
@@ -1348,7 +1358,17 @@ void Item_sum_sum::add_helper(bool perform_removal)
else
sum+= aggr->arg_val_real();
if (!aggr->arg_is_null(true))
- null_value= 0;
+ {
+ if (perform_removal)
+ {
+ DBUG_ASSERT(count > 0);
+ count--;
+ }
+ else
+ count++;
+
+ null_value= (count > 0) ? 0 : 1;
+ }
}
DBUG_VOID_RETURN;
}
diff --git a/sql/item_sum.h b/sql/item_sum.h
index 24dfd9b91ad..6698a1b2169 100644
--- a/sql/item_sum.h
+++ b/sql/item_sum.h
@@ -777,6 +777,7 @@ public:
private:
void add_helper(bool perform_removal);
+ ulonglong count;
};
diff --git a/sql/sql_window.cc b/sql/sql_window.cc
index f0d74b15e7c..e41207f7e4e 100644
--- a/sql/sql_window.cc
+++ b/sql/sql_window.cc
@@ -1261,6 +1261,13 @@ bool compute_window_func_with_frames(Item_window_func *item_win,
*/
tbl->file->ha_rnd_pos(tbl->record[0], rowid_buf);
store_record(tbl,record[1]);
+ // TODO-cvicentiu
+ // Save in field does not make use of the null value for the sum function.
+ // If we do however set the null value to be the same as the one that
+ // the current sum function has, via say
+ // item_win->null_value = sum_func->null_value; we get an assertion failure
+ // during the sending of data within Item::send, in the case of DECIMAL_RESULT.
+ // How do we force saving of NULL values in the table?
item_win->save_in_field(item_win->result_field, true);
err= tbl->file->ha_update_row(tbl->record[1], tbl->record[0]);
if (err && err != HA_ERR_RECORD_IS_THE_SAME)