Skip to content
Permalink
Browse files

MDEV-20273 Add class Item_sum_min_max

  • Loading branch information...
abarkov committed Aug 7, 2019
1 parent a8def12 commit e978efd96b9a8146ba2c80a1f3aea755568ac73a
Showing with 108 additions and 95 deletions.
  1. +2 −2 sql/item_cmpfunc.h
  2. +1 −1 sql/item_subselect.cc
  3. +38 −38 sql/item_sum.cc
  4. +34 −16 sql/item_sum.h
  5. +5 −10 sql/item_windowfunc.h
  6. +15 −15 sql/sql_type.cc
  7. +11 −11 sql/sql_type.h
  8. +2 −2 storage/spider/spd_db_conn.cc
@@ -654,7 +654,7 @@ class Item_func_trig_cond: public Item_bool_func
class Item_func_not_all :public Item_func_not
{
/* allow to check presence of values in max/min optimization */
Item_sum_hybrid *test_sum_item;
Item_sum_min_max *test_sum_item;
Item_maxmin_subselect *test_sub_item;

public:
@@ -670,7 +670,7 @@ class Item_func_not_all :public Item_func_not
bool fix_fields(THD *thd, Item **ref)
{return Item_func::fix_fields(thd, ref);}
virtual void print(String *str, enum_query_type query_type);
void set_sum_test(Item_sum_hybrid *item) { test_sum_item= item; test_sub_item= 0; };
void set_sum_test(Item_sum_min_max *item) { test_sum_item= item; test_sub_item= 0; };
void set_sub_test(Item_maxmin_subselect *item) { test_sub_item= item; test_sum_item= 0;};
bool empty_underlying_subquery();
Item *neg_transformer(THD *thd);
@@ -1966,7 +1966,7 @@ bool Item_allany_subselect::transform_into_max_min(JOIN *join)
(!select_lex->ref_pointer_array[0]->maybe_null || /*4*/
substype() != Item_subselect::ALL_SUBS)) /*4*/
{
Item_sum_hybrid *item;
Item_sum_min_max *item;
nesting_map save_allow_sum_func;
if (func->l_op())
{
@@ -1152,9 +1152,9 @@ Item_sum_num::fix_fields(THD *thd, Item **ref)


bool
Item_sum_hybrid::fix_fields(THD *thd, Item **ref)
Item_sum_min_max::fix_fields(THD *thd, Item **ref)
{
DBUG_ENTER("Item_sum_hybrid::fix_fields");
DBUG_ENTER("Item_sum_min_max::fix_fields");
DBUG_ASSERT(fixed == 0);

if (init_sum_func_check(thd))
@@ -1184,11 +1184,11 @@ Item_sum_hybrid::fix_fields(THD *thd, Item **ref)
}


bool Item_sum_hybrid::fix_length_and_dec()
bool Item_sum_min_max::fix_length_and_dec()
{
DBUG_ASSERT(args[0]->field_type() == args[0]->real_item()->field_type());
DBUG_ASSERT(args[0]->result_type() == args[0]->real_item()->result_type());
return args[0]->type_handler()->Item_sum_hybrid_fix_length_and_dec(this);
return args[0]->type_handler()->Item_sum_min_max_fix_length_and_dec(this);
}


@@ -1209,9 +1209,9 @@ bool Item_sum_hybrid::fix_length_and_dec()
and Item_sum_min::add() to use different values!
*/

void Item_sum_hybrid::setup_hybrid(THD *thd, Item *item, Item *value_arg)
void Item_sum_min_max::setup_hybrid(THD *thd, Item *item, Item *value_arg)
{
DBUG_ENTER("Item_sum_hybrid::setup_hybrid");
DBUG_ENTER("Item_sum_min_max::setup_hybrid");
if (!(value= item->get_cache(thd)))
DBUG_VOID_RETURN;
value->setup(thd, item);
@@ -1232,9 +1232,9 @@ void Item_sum_hybrid::setup_hybrid(THD *thd, Item *item, Item *value_arg)
}


Field *Item_sum_hybrid::create_tmp_field(bool group, TABLE *table)
Field *Item_sum_min_max::create_tmp_field(bool group, TABLE *table)
{
DBUG_ENTER("Item_sum_hybrid::create_tmp_field");
DBUG_ENTER("Item_sum_min_max::create_tmp_field");

if (args[0]->type() == Item::FIELD_ITEM)
{
@@ -2314,17 +2314,17 @@ Item *Item_sum_variance::result_item(THD *thd, Field *field)

/* min & max */

void Item_sum_hybrid::clear()
void Item_sum_min_max::clear()
{
DBUG_ENTER("Item_sum_hybrid::clear");
DBUG_ENTER("Item_sum_min_max::clear");
value->clear();
null_value= 1;
DBUG_VOID_RETURN;
}


bool
Item_sum_hybrid::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
Item_sum_min_max::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
{
DBUG_ASSERT(fixed == 1);
if (null_value)
@@ -2336,19 +2336,19 @@ Item_sum_hybrid::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate)
}


void Item_sum_hybrid::direct_add(Item *item)
void Item_sum_min_max::direct_add(Item *item)
{
DBUG_ENTER("Item_sum_hybrid::direct_add");
DBUG_ENTER("Item_sum_min_max::direct_add");
DBUG_PRINT("info", ("item: %p", item));
direct_added= TRUE;
direct_item= item;
DBUG_VOID_RETURN;
}


double Item_sum_hybrid::val_real()
double Item_sum_min_max::val_real()
{
DBUG_ENTER("Item_sum_hybrid::val_real");
DBUG_ENTER("Item_sum_min_max::val_real");
DBUG_ASSERT(fixed == 1);
if (null_value)
DBUG_RETURN(0.0);
@@ -2358,9 +2358,9 @@ double Item_sum_hybrid::val_real()
DBUG_RETURN(retval);
}

longlong Item_sum_hybrid::val_int()
longlong Item_sum_min_max::val_int()
{
DBUG_ENTER("Item_sum_hybrid::val_int");
DBUG_ENTER("Item_sum_min_max::val_int");
DBUG_ASSERT(fixed == 1);
if (null_value)
DBUG_RETURN(0);
@@ -2371,9 +2371,9 @@ longlong Item_sum_hybrid::val_int()
}


my_decimal *Item_sum_hybrid::val_decimal(my_decimal *val)
my_decimal *Item_sum_min_max::val_decimal(my_decimal *val)
{
DBUG_ENTER("Item_sum_hybrid::val_decimal");
DBUG_ENTER("Item_sum_min_max::val_decimal");
DBUG_ASSERT(fixed == 1);
if (null_value)
DBUG_RETURN(0);
@@ -2385,9 +2385,9 @@ my_decimal *Item_sum_hybrid::val_decimal(my_decimal *val)


String *
Item_sum_hybrid::val_str(String *str)
Item_sum_min_max::val_str(String *str)
{
DBUG_ENTER("Item_sum_hybrid::val_str");
DBUG_ENTER("Item_sum_min_max::val_str");
DBUG_ASSERT(fixed == 1);
if (null_value)
DBUG_RETURN(0);
@@ -2398,9 +2398,9 @@ Item_sum_hybrid::val_str(String *str)
}


void Item_sum_hybrid::cleanup()
void Item_sum_min_max::cleanup()
{
DBUG_ENTER("Item_sum_hybrid::cleanup");
DBUG_ENTER("Item_sum_min_max::cleanup");
Item_sum::cleanup();
if (cmp)
delete cmp;
@@ -2416,9 +2416,9 @@ void Item_sum_hybrid::cleanup()
DBUG_VOID_RETURN;
}

void Item_sum_hybrid::no_rows_in_result()
void Item_sum_min_max::no_rows_in_result()
{
DBUG_ENTER("Item_sum_hybrid::no_rows_in_result");
DBUG_ENTER("Item_sum_min_max::no_rows_in_result");
/* We may be called here twice in case of ref field in function */
if (was_values)
{
@@ -2429,7 +2429,7 @@ void Item_sum_hybrid::no_rows_in_result()
DBUG_VOID_RETURN;
}

void Item_sum_hybrid::restore_to_before_no_rows_in_result()
void Item_sum_min_max::restore_to_before_no_rows_in_result()
{
if (!was_values)
{
@@ -2693,10 +2693,10 @@ void Item_sum_num::reset_field()
}


void Item_sum_hybrid::reset_field()
void Item_sum_min_max::reset_field()
{
Item *UNINIT_VAR(tmp_item), *arg0;
DBUG_ENTER("Item_sum_hybrid::reset_field");
DBUG_ENTER("Item_sum_min_max::reset_field");

arg0= args[0];
if (unlikely(direct_added))
@@ -3049,9 +3049,9 @@ Item *Item_sum_avg::result_item(THD *thd, Field *field)
}


void Item_sum_hybrid::update_field()
void Item_sum_min_max::update_field()
{
DBUG_ENTER("Item_sum_hybrid::update_field");
DBUG_ENTER("Item_sum_min_max::update_field");
Item *UNINIT_VAR(tmp_item);
if (unlikely(direct_added))
{
@@ -3081,9 +3081,9 @@ void Item_sum_hybrid::update_field()


void
Item_sum_hybrid::min_max_update_str_field()
Item_sum_min_max::min_max_update_str_field()
{
DBUG_ENTER("Item_sum_hybrid::min_max_update_str_field");
DBUG_ENTER("Item_sum_min_max::min_max_update_str_field");
DBUG_ASSERT(cmp);
String *res_str=args[0]->val_str(&cmp->value1);

@@ -3104,11 +3104,11 @@ Item_sum_hybrid::min_max_update_str_field()


void
Item_sum_hybrid::min_max_update_real_field()
Item_sum_min_max::min_max_update_real_field()
{
double nr,old_nr;

DBUG_ENTER("Item_sum_hybrid::min_max_update_real_field");
DBUG_ENTER("Item_sum_min_max::min_max_update_real_field");
old_nr=result_field->val_real();
nr= args[0]->val_real();
if (!args[0]->null_value)
@@ -3126,11 +3126,11 @@ Item_sum_hybrid::min_max_update_real_field()


void
Item_sum_hybrid::min_max_update_int_field()
Item_sum_min_max::min_max_update_int_field()
{
longlong nr,old_nr;

DBUG_ENTER("Item_sum_hybrid::min_max_update_int_field");
DBUG_ENTER("Item_sum_min_max::min_max_update_int_field");
old_nr=result_field->val_int();
nr=args[0]->val_int();
if (!args[0]->null_value)
@@ -3161,9 +3161,9 @@ Item_sum_hybrid::min_max_update_int_field()
optimize: do not get result_field in case of args[0] is NULL
*/
void
Item_sum_hybrid::min_max_update_decimal_field()
Item_sum_min_max::min_max_update_decimal_field()
{
DBUG_ENTER("Item_sum_hybrid::min_max_update_decimal_field");
DBUG_ENTER("Item_sum_min_max::min_max_update_decimal_field");
my_decimal old_val, nr_val;
const my_decimal *old_nr;
const my_decimal *nr= args[0]->val_decimal(&nr_val);
@@ -1025,10 +1025,32 @@ class Item_sum_std :public Item_sum_variance
{ return get_item_copy<Item_sum_std>(thd, this); }
};


class Item_sum_hybrid: public Item_sum,
public Type_handler_hybrid_field_type
{
public:
Item_sum_hybrid(THD *thd, Item *item_par):
Item_sum(thd, item_par),
Type_handler_hybrid_field_type(&type_handler_longlong)
{ collation.set(&my_charset_bin); }
Item_sum_hybrid(THD *thd, Item *a, Item *b):
Item_sum(thd, a, b),
Type_handler_hybrid_field_type(&type_handler_longlong)
{ collation.set(&my_charset_bin); }
Item_sum_hybrid(THD *thd, Item_sum_hybrid *item)
:Item_sum(thd, item),
Type_handler_hybrid_field_type(item)
{ }
const Type_handler *type_handler() const
{ return Type_handler_hybrid_field_type::type_handler(); }
};


// This class is a string or number function depending on num_func
class Arg_comparator;
class Item_cache;
class Item_sum_hybrid :public Item_sum, public Type_handler_hybrid_field_type
class Item_sum_min_max :public Item_sum_hybrid
{
protected:
bool direct_added;
@@ -1039,16 +1061,14 @@ class Item_sum_hybrid :public Item_sum, public Type_handler_hybrid_field_type
bool was_values; // Set if we have found at least one row (for max/min only)
bool was_null_value;

public:
Item_sum_hybrid(THD *thd, Item *item_par,int sign):
Item_sum(thd, item_par),
Type_handler_hybrid_field_type(&type_handler_longlong),
public:
Item_sum_min_max(THD *thd, Item *item_par,int sign):
Item_sum_hybrid(thd, item_par),
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),
Item_sum_min_max(THD *thd, Item_sum_min_max *item)
:Item_sum_hybrid(thd, item),
direct_added(FALSE), value(item->value), arg_cache(0),
cmp_sign(item->cmp_sign), was_values(item->was_values)
{ }
@@ -1067,8 +1087,6 @@ class Item_sum_hybrid :public Item_sum, public Type_handler_hybrid_field_type
{
return get_arg(0)->real_type_handler();
}
const Type_handler *type_handler() const
{ return Type_handler_hybrid_field_type::type_handler(); }
TYPELIB *get_typelib() const { return args[0]->get_typelib(); }
void update_field();
void min_max_update_str_field();
@@ -1084,11 +1102,11 @@ class Item_sum_hybrid :public Item_sum, public Type_handler_hybrid_field_type
};


class Item_sum_min :public Item_sum_hybrid
class Item_sum_min :public Item_sum_min_max
{
public:
Item_sum_min(THD *thd, Item *item_par): Item_sum_hybrid(thd, item_par, 1) {}
Item_sum_min(THD *thd, Item_sum_min *item) :Item_sum_hybrid(thd, item) {}
Item_sum_min(THD *thd, Item *item_par): Item_sum_min_max(thd, item_par, 1) {}
Item_sum_min(THD *thd, Item_sum_min *item) :Item_sum_min_max(thd, item) {}
enum Sumfunctype sum_func () const {return MIN_FUNC;}

bool add();
@@ -1099,11 +1117,11 @@ class Item_sum_min :public Item_sum_hybrid
};


class Item_sum_max :public Item_sum_hybrid
class Item_sum_max :public Item_sum_min_max
{
public:
Item_sum_max(THD *thd, Item *item_par): Item_sum_hybrid(thd, item_par, -1) {}
Item_sum_max(THD *thd, Item_sum_max *item) :Item_sum_hybrid(thd, item) {}
Item_sum_max(THD *thd, Item *item_par): Item_sum_min_max(thd, item_par, -1) {}
Item_sum_max(THD *thd, Item_sum_max *item) :Item_sum_min_max(thd, item) {}
enum Sumfunctype sum_func () const {return MAX_FUNC;}

bool add();
@@ -292,21 +292,18 @@ class Item_sum_dense_rank: public Item_sum_int
{ return get_item_copy<Item_sum_dense_rank>(thd, this); }
};

class Item_sum_hybrid_simple : public Item_sum,
public Type_handler_hybrid_field_type
class Item_sum_hybrid_simple : public Item_sum_hybrid
{
public:
Item_sum_hybrid_simple(THD *thd, Item *arg):
Item_sum(thd, arg),
Type_handler_hybrid_field_type(&type_handler_longlong),
Item_sum_hybrid(thd, arg),
value(NULL)
{ collation.set(&my_charset_bin); }
{ }

Item_sum_hybrid_simple(THD *thd, Item *arg1, Item *arg2):
Item_sum(thd, arg1, arg2),
Type_handler_hybrid_field_type(&type_handler_longlong),
Item_sum_hybrid(thd, arg1, arg2),
value(NULL)
{ collation.set(&my_charset_bin); }
{ }

bool add();
bool fix_fields(THD *, Item **);
@@ -317,8 +314,6 @@ class Item_sum_hybrid_simple : public Item_sum,
void reset_field();
String *val_str(String *);
bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate);
const Type_handler *type_handler() const
{ return Type_handler_hybrid_field_type::type_handler(); }
void update_field();
Field *create_tmp_field(bool group, TABLE *table);
void clear()

0 comments on commit e978efd

Please sign in to comment.
You can’t perform that action at this time.