diff options
author | Vicențiu Ciorbaru <vicentiu@mariadb.org> | 2016-03-16 01:57:59 +0200 |
---|---|---|
committer | Vicențiu Ciorbaru <vicentiu@mariadb.org> | 2016-03-16 01:57:59 +0200 |
commit | 21651541ce0b2cc0e777988f1e35040b4badfce1 (patch) | |
tree | 12439f836abeb6658987e3aea41d9bd0c3df37f0 /sql/item_sum.cc | |
parent | aa74fef25e854741bd58e6cc3afc68ae2091e447 (diff) | |
download | mariadb-git-21651541ce0b2cc0e777988f1e35040b4badfce1.tar.gz |
Implemented avg() window function.
It is based on the sum() function, thus much of the logic is shared.
Considering that there are 2 counters stored within the function, one
that handles the null value, while the other that handles the divisor
for the avg computation, it is possible to remove the counter from the
Item_sum_avg. I have not removed it in this patch as we may choose to
refactor the whole code into a separate class.
This remains to be dicussed.
Diffstat (limited to 'sql/item_sum.cc')
-rw-r--r-- | sql/item_sum.cc | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/sql/item_sum.cc b/sql/item_sum.cc index b7490d02233..4b4ed0225d3 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -1681,6 +1681,16 @@ bool Item_sum_avg::add() return FALSE; } +void Item_sum_avg::remove() +{ + Item_sum_sum::remove(); + if (!aggr->arg_is_null(true)) + { + DBUG_ASSERT(count > 0); + count--; + } +} + double Item_sum_avg::val_real() { DBUG_ASSERT(fixed == 1); |