Commit ee9a19fb authored by Alexander Barkov's avatar Alexander Barkov

MDEV-21392 Cleanup redundant overriding in Item_sum_num

parent b21dc119
...@@ -1093,19 +1093,6 @@ void Aggregator_distinct::endup() ...@@ -1093,19 +1093,6 @@ void Aggregator_distinct::endup()
} }
String *
Item_sum_num::val_str(String *str)
{
return val_string_from_real(str);
}
my_decimal *Item_sum_num::val_decimal(my_decimal *decimal_value)
{
return val_decimal_from_real(decimal_value);
}
String * String *
Item_sum_int::val_str(String *str) Item_sum_int::val_str(String *str)
{ {
...@@ -2188,7 +2175,7 @@ static double variance_fp_recurrence_result(double s, ulonglong count, bool is_s ...@@ -2188,7 +2175,7 @@ static double variance_fp_recurrence_result(double s, ulonglong count, bool is_s
Item_sum_variance::Item_sum_variance(THD *thd, Item_sum_variance *item): Item_sum_variance::Item_sum_variance(THD *thd, Item_sum_variance *item):
Item_sum_num(thd, item), Item_sum_double(thd, item),
count(item->count), sample(item->sample), count(item->count), sample(item->sample),
prec_increment(item->prec_increment) prec_increment(item->prec_increment)
{ {
...@@ -2314,13 +2301,6 @@ double Item_sum_variance::val_real() ...@@ -2314,13 +2301,6 @@ double Item_sum_variance::val_real()
} }
my_decimal *Item_sum_variance::val_decimal(my_decimal *dec_buf)
{
DBUG_ASSERT(fixed == 1);
return val_decimal_from_real(dec_buf);
}
void Item_sum_variance::reset_field() void Item_sum_variance::reset_field()
{ {
double nr; double nr;
......
...@@ -578,6 +578,7 @@ class Item_sum :public Item_func_or_sum ...@@ -578,6 +578,7 @@ class Item_sum :public Item_func_or_sum
void mark_as_window_func_sum_expr() { window_func_sum_expr_flag= true; } void mark_as_window_func_sum_expr() { window_func_sum_expr_flag= true; }
bool is_window_func_sum_expr() { return window_func_sum_expr_flag; } bool is_window_func_sum_expr() { return window_func_sum_expr_flag; }
virtual void setup_caches(THD *thd) {}; virtual void setup_caches(THD *thd) {};
virtual void set_partition_row_count(ulonglong count) { DBUG_ASSERT(0); }
}; };
...@@ -713,33 +714,45 @@ class Aggregator_simple : public Aggregator ...@@ -713,33 +714,45 @@ class Aggregator_simple : public Aggregator
class Item_sum_num :public Item_sum class Item_sum_num :public Item_sum
{ {
protected:
/*
val_xxx() functions may be called several times during the execution of a
query. Derived classes that require extensive calculation in val_xxx()
maintain cache of aggregate value. This variable governs the validity of
that cache.
*/
bool is_evaluated;
public: public:
Item_sum_num(THD *thd): Item_sum(thd), is_evaluated(FALSE) {} Item_sum_num(THD *thd): Item_sum(thd) {}
Item_sum_num(THD *thd, Item *item_par): Item_sum_num(THD *thd, Item *item_par):
Item_sum(thd, item_par), is_evaluated(FALSE) {} Item_sum(thd, item_par) {}
Item_sum_num(THD *thd, Item *a, Item* b): Item_sum_num(THD *thd, Item *a, Item* b):
Item_sum(thd, a, b), is_evaluated(FALSE) {} Item_sum(thd, a, b) {}
Item_sum_num(THD *thd, List<Item> &list): Item_sum_num(THD *thd, List<Item> &list):
Item_sum(thd, list), is_evaluated(FALSE) {} Item_sum(thd, list) {}
Item_sum_num(THD *thd, Item_sum_num *item): Item_sum_num(THD *thd, Item_sum_num *item):
Item_sum(thd, item),is_evaluated(item->is_evaluated) {} Item_sum(thd, item) {}
bool fix_fields(THD *, Item **); bool fix_fields(THD *, Item **);
longlong val_int() { return val_int_from_real(); /* Real as default */ } void reset_field();
String *val_str(String*str); };
my_decimal *val_decimal(my_decimal *);
class Item_sum_double :public Item_sum_num
{
public:
Item_sum_double(THD *thd): Item_sum_num(thd) {}
Item_sum_double(THD *thd, Item *item_par): Item_sum_num(thd, item_par) {}
Item_sum_double(THD *thd, List<Item> &list): Item_sum_num(thd, list) {}
Item_sum_double(THD *thd, Item_sum_double *item) :Item_sum_num(thd, item) {}
longlong val_int()
{
return val_int_from_real();
}
String *val_str(String*str)
{
return val_string_from_real(str);
}
my_decimal *val_decimal(my_decimal *to)
{
return val_decimal_from_real(to);
}
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
{ {
return type_handler()->Item_get_date(this, ltime, fuzzydate); return get_date_from_real(ltime, fuzzydate);
} }
void reset_field(); const Type_handler *type_handler() const { return &type_handler_double; }
}; };
...@@ -753,6 +766,10 @@ class Item_sum_int :public Item_sum_num ...@@ -753,6 +766,10 @@ class Item_sum_int :public Item_sum_num
double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); } double val_real() { DBUG_ASSERT(fixed == 1); return (double) val_int(); }
String *val_str(String*str); String *val_str(String*str);
my_decimal *val_decimal(my_decimal *); my_decimal *val_decimal(my_decimal *);
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
{
return get_date_from_int(ltime, fuzzydate);
}
const Type_handler *type_handler() const { return &type_handler_longlong; } const Type_handler *type_handler() const { return &type_handler_longlong; }
bool fix_length_and_dec() bool fix_length_and_dec()
{ decimals=0; max_length=21; maybe_null=null_value=0; return FALSE; } { decimals=0; max_length=21; maybe_null=null_value=0; return FALSE; }
...@@ -794,6 +811,10 @@ class Item_sum_sum :public Item_sum_num, ...@@ -794,6 +811,10 @@ class Item_sum_sum :public Item_sum_num,
longlong val_int(); longlong val_int();
String *val_str(String*str); String *val_str(String*str);
my_decimal *val_decimal(my_decimal *); my_decimal *val_decimal(my_decimal *);
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
{
return type_handler()->Item_get_date(this, ltime, fuzzydate);
}
const Type_handler *type_handler() const const Type_handler *type_handler() const
{ return Type_handler_hybrid_field_type::type_handler(); } { return Type_handler_hybrid_field_type::type_handler(); }
void fix_length_and_dec_double(); void fix_length_and_dec_double();
...@@ -964,7 +985,7 @@ But, this falls prey to catastrophic cancellation. Instead, use the recurrence ...@@ -964,7 +985,7 @@ But, this falls prey to catastrophic cancellation. Instead, use the recurrence
*/ */
class Item_sum_variance : public Item_sum_num class Item_sum_variance : public Item_sum_double
{ {
bool fix_length_and_dec(); bool fix_length_and_dec();
...@@ -975,7 +996,7 @@ class Item_sum_variance : public Item_sum_num ...@@ -975,7 +996,7 @@ class Item_sum_variance : public Item_sum_num
uint prec_increment; uint prec_increment;
Item_sum_variance(THD *thd, Item *item_par, uint sample_arg): Item_sum_variance(THD *thd, Item *item_par, uint sample_arg):
Item_sum_num(thd, item_par), count(0), Item_sum_double(thd, item_par), count(0),
sample(sample_arg) sample(sample_arg)
{} {}
Item_sum_variance(THD *thd, Item_sum_variance *item); Item_sum_variance(THD *thd, Item_sum_variance *item);
...@@ -985,7 +1006,6 @@ class Item_sum_variance : public Item_sum_num ...@@ -985,7 +1006,6 @@ class Item_sum_variance : public Item_sum_num
void clear(); void clear();
bool add(); bool add();
double val_real(); double val_real();
my_decimal *val_decimal(my_decimal *);
void reset_field(); void reset_field();
void update_field(); void update_field();
Item *result_item(THD *thd, Field *field); Item *result_item(THD *thd, Field *field);
...@@ -994,11 +1014,10 @@ class Item_sum_variance : public Item_sum_num ...@@ -994,11 +1014,10 @@ class Item_sum_variance : public Item_sum_num
{ return sample ? "var_samp(" : "variance("; } { return sample ? "var_samp(" : "variance("; }
Item *copy_or_same(THD* thd); Item *copy_or_same(THD* thd);
Field *create_tmp_field(bool group, TABLE *table); Field *create_tmp_field(bool group, TABLE *table);
const Type_handler *type_handler() const { return &type_handler_double; }
void cleanup() void cleanup()
{ {
count= 0; count= 0;
Item_sum_num::cleanup(); Item_sum_double::cleanup();
} }
Item *get_copy(THD *thd) Item *get_copy(THD *thd)
{ return get_item_copy<Item_sum_variance>(thd, this); } { return get_item_copy<Item_sum_variance>(thd, this); }
...@@ -1679,15 +1698,15 @@ class Item_sum_udf_decimal :public Item_udf_sum ...@@ -1679,15 +1698,15 @@ class Item_sum_udf_decimal :public Item_udf_sum
#else /* Dummy functions to get sql_yacc.cc compiled */ #else /* Dummy functions to get sql_yacc.cc compiled */
class Item_sum_udf_float :public Item_sum_num class Item_sum_udf_float :public Item_sum_double
{ {
public: public:
Item_sum_udf_float(THD *thd, udf_func *udf_arg): Item_sum_udf_float(THD *thd, udf_func *udf_arg):
Item_sum_num(thd) {} Item_sum_double(thd) {}
Item_sum_udf_float(THD *thd, udf_func *udf_arg, List<Item> &list): Item_sum_udf_float(THD *thd, udf_func *udf_arg, List<Item> &list):
Item_sum_num(thd) {} Item_sum_double(thd) {}
Item_sum_udf_float(THD *thd, Item_sum_udf_float *item) Item_sum_udf_float(THD *thd, Item_sum_udf_float *item)
:Item_sum_num(thd, item) {} :Item_sum_double(thd, item) {}
enum Sumfunctype sum_func () const { return UDF_SUM_FUNC; } enum Sumfunctype sum_func () const { return UDF_SUM_FUNC; }
double val_real() { DBUG_ASSERT(fixed == 1); return 0.0; } double val_real() { DBUG_ASSERT(fixed == 1); return 0.0; }
void clear() {} void clear() {}
...@@ -1696,15 +1715,15 @@ class Item_sum_udf_float :public Item_sum_num ...@@ -1696,15 +1715,15 @@ class Item_sum_udf_float :public Item_sum_num
}; };
class Item_sum_udf_int :public Item_sum_num class Item_sum_udf_int :public Item_sum_double
{ {
public: public:
Item_sum_udf_int(THD *thd, udf_func *udf_arg): Item_sum_udf_int(THD *thd, udf_func *udf_arg):
Item_sum_num(thd) {} Item_sum_double(thd) {}
Item_sum_udf_int(THD *thd, udf_func *udf_arg, List<Item> &list): Item_sum_udf_int(THD *thd, udf_func *udf_arg, List<Item> &list):
Item_sum_num(thd) {} Item_sum_double(thd) {}
Item_sum_udf_int(THD *thd, Item_sum_udf_int *item) Item_sum_udf_int(THD *thd, Item_sum_udf_int *item)
:Item_sum_num(thd, item) {} :Item_sum_double(thd, item) {}
enum Sumfunctype sum_func () const { return UDF_SUM_FUNC; } enum Sumfunctype sum_func () const { return UDF_SUM_FUNC; }
longlong val_int() { DBUG_ASSERT(fixed == 1); return 0; } longlong val_int() { DBUG_ASSERT(fixed == 1); return 0; }
double val_real() { DBUG_ASSERT(fixed == 1); return 0; } double val_real() { DBUG_ASSERT(fixed == 1); return 0; }
...@@ -1714,15 +1733,15 @@ class Item_sum_udf_int :public Item_sum_num ...@@ -1714,15 +1733,15 @@ class Item_sum_udf_int :public Item_sum_num
}; };
class Item_sum_udf_decimal :public Item_sum_num class Item_sum_udf_decimal :public Item_sum_double
{ {
public: public:
Item_sum_udf_decimal(THD *thd, udf_func *udf_arg): Item_sum_udf_decimal(THD *thd, udf_func *udf_arg):
Item_sum_num(thd) {} Item_sum_double(thd) {}
Item_sum_udf_decimal(THD *thd, udf_func *udf_arg, List<Item> &list): Item_sum_udf_decimal(THD *thd, udf_func *udf_arg, List<Item> &list):
Item_sum_num(thd) {} Item_sum_double(thd) {}
Item_sum_udf_decimal(THD *thd, Item_sum_udf_float *item) Item_sum_udf_decimal(THD *thd, Item_sum_udf_float *item)
:Item_sum_num(thd, item) {} :Item_sum_double(thd, item) {}
enum Sumfunctype sum_func () const { return UDF_SUM_FUNC; } enum Sumfunctype sum_func () const { return UDF_SUM_FUNC; }
double val_real() { DBUG_ASSERT(fixed == 1); return 0.0; } double val_real() { DBUG_ASSERT(fixed == 1); return 0.0; }
my_decimal *val_decimal(my_decimal *) { DBUG_ASSERT(fixed == 1); return 0; } my_decimal *val_decimal(my_decimal *) { DBUG_ASSERT(fixed == 1); return 0; }
...@@ -1732,15 +1751,15 @@ class Item_sum_udf_decimal :public Item_sum_num ...@@ -1732,15 +1751,15 @@ class Item_sum_udf_decimal :public Item_sum_num
}; };
class Item_sum_udf_str :public Item_sum_num class Item_sum_udf_str :public Item_sum_double
{ {
public: public:
Item_sum_udf_str(THD *thd, udf_func *udf_arg): Item_sum_udf_str(THD *thd, udf_func *udf_arg):
Item_sum_num(thd) {} Item_sum_double(thd) {}
Item_sum_udf_str(THD *thd, udf_func *udf_arg, List<Item> &list): Item_sum_udf_str(THD *thd, udf_func *udf_arg, List<Item> &list):
Item_sum_num(thd) {} Item_sum_double(thd) {}
Item_sum_udf_str(THD *thd, Item_sum_udf_str *item) Item_sum_udf_str(THD *thd, Item_sum_udf_str *item)
:Item_sum_num(thd, item) {} :Item_sum_double(thd, item) {}
String *val_str(String *) String *val_str(String *)
{ DBUG_ASSERT(fixed == 1); null_value=1; return 0; } { DBUG_ASSERT(fixed == 1); null_value=1; return 0; }
double val_real() { DBUG_ASSERT(fixed == 1); null_value=1; return 0.0; } double val_real() { DBUG_ASSERT(fixed == 1); null_value=1; return 0.0; }
......
This diff is collapsed.
...@@ -1779,11 +1779,7 @@ class Frame_unbounded_following_set_count : public Frame_unbounded_following ...@@ -1779,11 +1779,7 @@ class Frame_unbounded_following_set_count : public Frame_unbounded_following
List_iterator_fast<Item_sum> it(sum_functions); List_iterator_fast<Item_sum> it(sum_functions);
Item_sum* item; Item_sum* item;
while ((item= it++)) while ((item= it++))
{ item->set_partition_row_count(num_rows_in_partition);
Item_sum_window_with_row_count* item_with_row_count =
static_cast<Item_sum_window_with_row_count *>(item);
item_with_row_count->set_row_count(num_rows_in_partition);
}
} }
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment