summaryrefslogtreecommitdiff
path: root/sql/item_sum.h
diff options
context:
space:
mode:
authorMonty <monty@mariadb.org>2017-09-09 16:20:55 +0300
committerMonty <monty@mariadb.org>2017-12-03 13:58:35 +0200
commitda26d16dd1c07b34f46ba4b00527ebf76810d57d (patch)
tree387112d3d377201a9465b24e9dfa68d5f9340f31 /sql/item_sum.h
parent6f5a7e9227252512ecf2178b6d56c46318aef7d7 (diff)
downloadmariadb-git-da26d16dd1c07b34f46ba4b00527ebf76810d57d.tar.gz
Add direct aggregates
Spider patches 026 (MDEV-7723), 031 (MDEV-7727) and 058 (MDEV-12532) This allows the storage engine to internally compute sum and count operations. - Enhance sum items to be able to store the sum value directly. - return_record_by_parent() is enabled in spider as HANDLER_HAS_DIRECT_AGGREGATE is defined - Added spd_environ.h to spider. This is loaded first to ensure that all MariaDB specific defines that are used by include files are properly defined. - This code is tested by the existing spider tests direct_aggregate.test and direct_aggregate_part.test and also partition.test
Diffstat (limited to 'sql/item_sum.h')
-rw-r--r--sql/item_sum.h34
1 files changed, 27 insertions, 7 deletions
diff --git a/sql/item_sum.h b/sql/item_sum.h
index 9822f9e5430..d05fdbca5e1 100644
--- a/sql/item_sum.h
+++ b/sql/item_sum.h
@@ -521,6 +521,7 @@ public:
Item *get_arg(uint i) const { return args[i]; }
Item *set_arg(uint i, THD *thd, Item *new_val);
uint get_arg_count() const { return arg_count; }
+ virtual Item **get_args() { return fixed ? orig_args : args; }
/* Initialization of distinct related members */
void init_aggregator()
@@ -757,14 +758,20 @@ class Item_sum_sum :public Item_sum_num,
public Type_handler_hybrid_field_type
{
protected:
+ bool direct_added;
+ bool direct_reseted_field;
+ bool direct_sum_is_null;
+ double direct_sum_real;
double sum;
+ my_decimal direct_sum_decimal;
my_decimal dec_buffs[2];
uint curr_dec_buff;
void fix_length_and_dec();
public:
Item_sum_sum(THD *thd, Item *item_par, bool distinct):
- Item_sum_num(thd, item_par)
+ Item_sum_num(thd, item_par), direct_added(FALSE),
+ direct_reseted_field(FALSE)
{
set_distinct(distinct);
}
@@ -773,6 +780,9 @@ public:
{
return has_with_distinct() ? SUM_DISTINCT_FUNC : SUM_FUNC;
}
+ void cleanup();
+ void direct_add(my_decimal *add_sum_decimal);
+ void direct_add(double add_sum_real, bool add_sum_is_null);
void clear();
bool add();
double val_real();
@@ -808,6 +818,9 @@ private:
class Item_sum_count :public Item_sum_int
{
+ bool direct_counted;
+ bool direct_reseted_field;
+ longlong direct_count;
longlong count;
friend class Aggregator_distinct;
@@ -817,9 +830,10 @@ class Item_sum_count :public Item_sum_int
void cleanup();
void remove();
- public:
+public:
Item_sum_count(THD *thd, Item *item_par):
- Item_sum_int(thd, item_par), count(0)
+ Item_sum_int(thd, item_par), direct_counted(FALSE),
+ direct_reseted_field(FALSE), count(0)
{}
/**
@@ -831,12 +845,14 @@ class Item_sum_count :public Item_sum_int
*/
Item_sum_count(THD *thd, List<Item> &list):
- Item_sum_int(thd, list), count(0)
+ Item_sum_int(thd, list), direct_counted(FALSE),
+ direct_reseted_field(FALSE), count(0)
{
set_distinct(TRUE);
}
Item_sum_count(THD *thd, Item_sum_count *item):
- Item_sum_int(thd, item), count(item->count)
+ Item_sum_int(thd, item), direct_counted(FALSE),
+ direct_reseted_field(FALSE), count(item->count)
{}
enum Sumfunctype sum_func () const
{
@@ -851,6 +867,7 @@ class Item_sum_count :public Item_sum_int
longlong val_int();
void reset_field();
void update_field();
+ void direct_add(longlong add_count);
const char *func_name() const
{
return has_with_distinct() ? "count(distinct " : "count(";
@@ -1009,6 +1026,8 @@ class Item_cache;
class Item_sum_hybrid :public Item_sum, public Type_handler_hybrid_field_type
{
protected:
+ bool direct_added;
+ Item *direct_item;
Item_cache *value, *arg_cache;
Arg_comparator *cmp;
int cmp_sign;
@@ -1019,19 +1038,20 @@ protected:
Item_sum_hybrid(THD *thd, Item *item_par,int sign):
Item_sum(thd, item_par),
Type_handler_hybrid_field_type(&type_handler_longlong),
- value(0), arg_cache(0), cmp(0),
+ direct_added(FALSE), value(0), arg_cache(0), cmp(0),
cmp_sign(sign), was_values(TRUE)
{ collation.set(&my_charset_bin); }
Item_sum_hybrid(THD *thd, Item_sum_hybrid *item)
:Item_sum(thd, item),
Type_handler_hybrid_field_type(item),
- value(item->value), arg_cache(0),
+ direct_added(FALSE), value(item->value), arg_cache(0),
cmp_sign(item->cmp_sign), was_values(item->was_values)
{ }
bool fix_fields(THD *, Item **);
void fix_length_and_dec();
void setup_hybrid(THD *thd, Item *item, Item *value_arg);
void clear();
+ void direct_add(Item *item);
double val_real();
longlong val_int();
my_decimal *val_decimal(my_decimal *);