Skip to content

Commit 3e471bf

Browse files
author
Alexander Barkov
committed
MDEV-9215 Detect cmp_type() and result_type() from field_type()
Part2: deriving Item_sum_sum from Type_handler_hybrid_field_type, removing "Item_result Item_sum_sum::hybrid_type".
1 parent 607ef78 commit 3e471bf

File tree

4 files changed

+33
-48
lines changed

4 files changed

+33
-48
lines changed

sql/item.cc

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5350,22 +5350,6 @@ void Item_empty_string::make_field(THD *thd, Send_field *tmp_field)
53505350
}
53515351

53525352

5353-
enum_field_types Item::field_type_by_result_type() const
5354-
{
5355-
switch (result_type()) {
5356-
case STRING_RESULT: return string_field_type();
5357-
case INT_RESULT: return MYSQL_TYPE_LONGLONG;
5358-
case DECIMAL_RESULT: return MYSQL_TYPE_NEWDECIMAL;
5359-
case REAL_RESULT: return MYSQL_TYPE_DOUBLE;
5360-
case ROW_RESULT:
5361-
case TIME_RESULT:
5362-
DBUG_ASSERT(0);
5363-
return MYSQL_TYPE_VARCHAR;
5364-
}
5365-
return MYSQL_TYPE_VARCHAR;
5366-
}
5367-
5368-
53695353
/**
53705354
Verifies that the input string is well-formed according to its character set.
53715355
@param send_error If true, call my_error if string is not well-formed.

sql/item.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,6 @@ class Item: public Value_source,
768768
{
769769
return Type_handler::string_type_handler(max_length)->field_type();
770770
}
771-
enum_field_types field_type_by_result_type() const;
772771
virtual enum Type type() const =0;
773772
/*
774773
real_type() is the type of base item. This is same as type() for

sql/item_sum.cc

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,11 +1318,12 @@ Field *Item_sum_hybrid::create_tmp_field(bool group, TABLE *table,
13181318
check if the following assignments are really needed
13191319
*/
13201320
Item_sum_sum::Item_sum_sum(THD *thd, Item_sum_sum *item)
1321-
:Item_sum_num(thd, item), hybrid_type(item->hybrid_type),
1321+
:Item_sum_num(thd, item),
1322+
Type_handler_hybrid_field_type(item),
13221323
curr_dec_buff(item->curr_dec_buff)
13231324
{
13241325
/* TODO: check if the following assignments are really needed */
1325-
if (hybrid_type == DECIMAL_RESULT)
1326+
if (Item_sum_sum::result_type() == DECIMAL_RESULT)
13261327
{
13271328
my_decimal2decimal(item->dec_buffs, dec_buffs);
13281329
my_decimal2decimal(item->dec_buffs + 1, dec_buffs + 1);
@@ -1341,7 +1342,7 @@ void Item_sum_sum::clear()
13411342
{
13421343
DBUG_ENTER("Item_sum_sum::clear");
13431344
null_value=1;
1344-
if (hybrid_type == DECIMAL_RESULT)
1345+
if (Item_sum_sum::result_type() == DECIMAL_RESULT)
13451346
{
13461347
curr_dec_buff= 0;
13471348
my_decimal_set_zero(dec_buffs);
@@ -1360,7 +1361,7 @@ void Item_sum_sum::fix_length_and_dec()
13601361
switch (args[0]->cast_to_int_type()) {
13611362
case REAL_RESULT:
13621363
case STRING_RESULT:
1363-
hybrid_type= REAL_RESULT;
1364+
set_handler_by_field_type(MYSQL_TYPE_DOUBLE);
13641365
sum= 0.0;
13651366
break;
13661367
case INT_RESULT:
@@ -1373,17 +1374,17 @@ void Item_sum_sum::fix_length_and_dec()
13731374
decimals,
13741375
unsigned_flag);
13751376
curr_dec_buff= 0;
1376-
hybrid_type= DECIMAL_RESULT;
1377+
set_handler_by_field_type(MYSQL_TYPE_NEWDECIMAL);
13771378
my_decimal_set_zero(dec_buffs);
13781379
break;
13791380
}
13801381
case ROW_RESULT:
13811382
DBUG_ASSERT(0);
13821383
}
13831384
DBUG_PRINT("info", ("Type: %s (%d, %d)",
1384-
(hybrid_type == REAL_RESULT ? "REAL_RESULT" :
1385-
hybrid_type == DECIMAL_RESULT ? "DECIMAL_RESULT" :
1386-
hybrid_type == INT_RESULT ? "INT_RESULT" :
1385+
(result_type() == REAL_RESULT ? "REAL_RESULT" :
1386+
result_type() == DECIMAL_RESULT ? "DECIMAL_RESULT" :
1387+
result_type() == INT_RESULT ? "INT_RESULT" :
13871388
"--ILLEGAL!!!--"),
13881389
max_length,
13891390
(int)decimals));
@@ -1394,7 +1395,7 @@ void Item_sum_sum::fix_length_and_dec()
13941395
bool Item_sum_sum::add()
13951396
{
13961397
DBUG_ENTER("Item_sum_sum::add");
1397-
if (hybrid_type == DECIMAL_RESULT)
1398+
if (Item_sum_sum::result_type() == DECIMAL_RESULT)
13981399
{
13991400
my_decimal value;
14001401
const my_decimal *val= aggr->arg_val_decimal(&value);
@@ -1421,7 +1422,7 @@ longlong Item_sum_sum::val_int()
14211422
DBUG_ASSERT(fixed == 1);
14221423
if (aggr)
14231424
aggr->endup();
1424-
if (hybrid_type == DECIMAL_RESULT)
1425+
if (Item_sum_sum::result_type() == DECIMAL_RESULT)
14251426
{
14261427
longlong result;
14271428
my_decimal2int(E_DEC_FATAL_ERROR, dec_buffs + curr_dec_buff, unsigned_flag,
@@ -1437,7 +1438,7 @@ double Item_sum_sum::val_real()
14371438
DBUG_ASSERT(fixed == 1);
14381439
if (aggr)
14391440
aggr->endup();
1440-
if (hybrid_type == DECIMAL_RESULT)
1441+
if (Item_sum_sum::result_type() == DECIMAL_RESULT)
14411442
my_decimal2double(E_DEC_FATAL_ERROR, dec_buffs + curr_dec_buff, &sum);
14421443
return sum;
14431444
}
@@ -1447,7 +1448,7 @@ String *Item_sum_sum::val_str(String *str)
14471448
{
14481449
if (aggr)
14491450
aggr->endup();
1450-
if (hybrid_type == DECIMAL_RESULT)
1451+
if (Item_sum_sum::result_type() == DECIMAL_RESULT)
14511452
return val_string_from_decimal(str);
14521453
return val_string_from_real(str);
14531454
}
@@ -1457,7 +1458,7 @@ my_decimal *Item_sum_sum::val_decimal(my_decimal *val)
14571458
{
14581459
if (aggr)
14591460
aggr->endup();
1460-
if (hybrid_type == DECIMAL_RESULT)
1461+
if (Item_sum_sum::result_type() == DECIMAL_RESULT)
14611462
return (dec_buffs + curr_dec_buff);
14621463
return val_decimal_from_real(val);
14631464
}
@@ -1633,7 +1634,7 @@ void Item_sum_avg::fix_length_and_dec()
16331634
Item_sum_sum::fix_length_and_dec();
16341635
maybe_null=null_value=1;
16351636
prec_increment= current_thd->variables.div_precincrement;
1636-
if (hybrid_type == DECIMAL_RESULT)
1637+
if (Item_sum_avg::result_type() == DECIMAL_RESULT)
16371638
{
16381639
int precision= args[0]->decimal_precision() + prec_increment;
16391640
decimals= MY_MIN(args[0]->decimals + prec_increment, DECIMAL_MAX_SCALE);
@@ -1672,11 +1673,11 @@ Field *Item_sum_avg::create_tmp_field(bool group, TABLE *table,
16721673
and unpack on access.
16731674
*/
16741675
field= new (mem_root)
1675-
Field_string(((hybrid_type == DECIMAL_RESULT) ?
1676+
Field_string(((Item_sum_avg::result_type() == DECIMAL_RESULT) ?
16761677
dec_bin_size : sizeof(double)) + sizeof(longlong),
16771678
0, name, &my_charset_bin);
16781679
}
1679-
else if (hybrid_type == DECIMAL_RESULT)
1680+
else if (Item_sum_avg::result_type() == DECIMAL_RESULT)
16801681
field= Field_new_decimal::create_from_item(mem_root, this);
16811682
else
16821683
field= new (mem_root) Field_double(max_length, maybe_null, name, decimals,
@@ -1731,10 +1732,10 @@ my_decimal *Item_sum_avg::val_decimal(my_decimal *val)
17311732
}
17321733

17331734
/*
1734-
For non-DECIMAL hybrid_type the division will be done in
1735+
For non-DECIMAL result_type() the division will be done in
17351736
Item_sum_avg::val_real().
17361737
*/
1737-
if (hybrid_type != DECIMAL_RESULT)
1738+
if (Item_sum_avg::result_type() != DECIMAL_RESULT)
17381739
return val_decimal_from_real(val);
17391740

17401741
sum_dec= dec_buffs + curr_dec_buff;
@@ -1748,7 +1749,7 @@ String *Item_sum_avg::val_str(String *str)
17481749
{
17491750
if (aggr)
17501751
aggr->endup();
1751-
if (hybrid_type == DECIMAL_RESULT)
1752+
if (Item_sum_avg::result_type() == DECIMAL_RESULT)
17521753
return val_string_from_decimal(str);
17531754
return val_string_from_real(str);
17541755
}
@@ -2316,7 +2317,7 @@ void Item_sum_hybrid::reset_field()
23162317
void Item_sum_sum::reset_field()
23172318
{
23182319
DBUG_ASSERT (aggr->Aggrtype() != Aggregator::DISTINCT_AGGREGATOR);
2319-
if (hybrid_type == DECIMAL_RESULT)
2320+
if (Item_sum_sum::result_type() == DECIMAL_RESULT)
23202321
{
23212322
my_decimal value, *arg_val= args[0]->val_decimal(&value);
23222323
if (!arg_val) // Null
@@ -2325,7 +2326,7 @@ void Item_sum_sum::reset_field()
23252326
}
23262327
else
23272328
{
2328-
DBUG_ASSERT(hybrid_type == REAL_RESULT);
2329+
DBUG_ASSERT(result_type() == REAL_RESULT);
23292330
double nr= args[0]->val_real(); // Nulls also return 0
23302331
float8store(result_field->ptr, nr);
23312332
}
@@ -2352,7 +2353,7 @@ void Item_sum_avg::reset_field()
23522353
{
23532354
uchar *res=result_field->ptr;
23542355
DBUG_ASSERT (aggr->Aggrtype() != Aggregator::DISTINCT_AGGREGATOR);
2355-
if (hybrid_type == DECIMAL_RESULT)
2356+
if (Item_sum_avg::result_type() == DECIMAL_RESULT)
23562357
{
23572358
longlong tmp;
23582359
my_decimal value, *arg_dec= args[0]->val_decimal(&value);
@@ -2406,7 +2407,7 @@ void Item_sum_bit::update_field()
24062407
void Item_sum_sum::update_field()
24072408
{
24082409
DBUG_ASSERT (aggr->Aggrtype() != Aggregator::DISTINCT_AGGREGATOR);
2409-
if (hybrid_type == DECIMAL_RESULT)
2410+
if (Item_sum_sum::result_type() == DECIMAL_RESULT)
24102411
{
24112412
my_decimal value, *arg_val= args[0]->val_decimal(&value);
24122413
if (!args[0]->null_value)
@@ -2461,7 +2462,7 @@ void Item_sum_avg::update_field()
24612462

24622463
DBUG_ASSERT (aggr->Aggrtype() != Aggregator::DISTINCT_AGGREGATOR);
24632464

2464-
if (hybrid_type == DECIMAL_RESULT)
2465+
if (Item_sum_avg::result_type() == DECIMAL_RESULT)
24652466
{
24662467
my_decimal value, *arg_val= args[0]->val_decimal(&value);
24672468
if (!args[0]->null_value)
@@ -2500,7 +2501,7 @@ void Item_sum_avg::update_field()
25002501
Item *Item_sum_avg::result_item(THD *thd, Field *field)
25012502
{
25022503
return
2503-
hybrid_type == DECIMAL_RESULT ?
2504+
Item_sum_avg::result_type() == DECIMAL_RESULT ?
25042505
(Item_avg_field*) new (thd->mem_root) Item_avg_field_decimal(thd, this) :
25052506
(Item_avg_field*) new (thd->mem_root) Item_avg_field_double(thd, this);
25062507
}

sql/item_sum.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -721,10 +721,10 @@ class Item_sum_int :public Item_sum_num
721721
};
722722

723723

724-
class Item_sum_sum :public Item_sum_num
724+
class Item_sum_sum :public Item_sum_num,
725+
public Type_handler_hybrid_field_type
725726
{
726727
protected:
727-
Item_result hybrid_type;
728728
double sum;
729729
my_decimal dec_buffs[2];
730730
uint curr_dec_buff;
@@ -747,11 +747,12 @@ class Item_sum_sum :public Item_sum_num
747747
longlong val_int();
748748
String *val_str(String*str);
749749
my_decimal *val_decimal(my_decimal *);
750-
enum Item_result result_type () const { return hybrid_type; }
751750
enum_field_types field_type() const
752-
{
753-
return field_type_by_result_type();
754-
}
751+
{ return Type_handler_hybrid_field_type::field_type(); }
752+
enum Item_result result_type () const
753+
{ return Type_handler_hybrid_field_type::result_type(); }
754+
enum Item_result cmp_type () const
755+
{ return Type_handler_hybrid_field_type::cmp_type(); }
755756
void reset_field();
756757
void update_field();
757758
void no_rows_in_result() {}

0 commit comments

Comments
 (0)