@@ -1318,11 +1318,12 @@ Field *Item_sum_hybrid::create_tmp_field(bool group, TABLE *table,
1318
1318
check if the following assignments are really needed
1319
1319
*/
1320
1320
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),
1322
1323
curr_dec_buff(item->curr_dec_buff)
1323
1324
{
1324
1325
/* TODO: check if the following assignments are really needed */
1325
- if (hybrid_type == DECIMAL_RESULT)
1326
+ if (Item_sum_sum::result_type () == DECIMAL_RESULT)
1326
1327
{
1327
1328
my_decimal2decimal (item->dec_buffs , dec_buffs);
1328
1329
my_decimal2decimal (item->dec_buffs + 1 , dec_buffs + 1 );
@@ -1341,7 +1342,7 @@ void Item_sum_sum::clear()
1341
1342
{
1342
1343
DBUG_ENTER (" Item_sum_sum::clear" );
1343
1344
null_value=1 ;
1344
- if (hybrid_type == DECIMAL_RESULT)
1345
+ if (Item_sum_sum::result_type () == DECIMAL_RESULT)
1345
1346
{
1346
1347
curr_dec_buff= 0 ;
1347
1348
my_decimal_set_zero (dec_buffs);
@@ -1360,7 +1361,7 @@ void Item_sum_sum::fix_length_and_dec()
1360
1361
switch (args[0 ]->cast_to_int_type ()) {
1361
1362
case REAL_RESULT:
1362
1363
case STRING_RESULT:
1363
- hybrid_type= REAL_RESULT ;
1364
+ set_handler_by_field_type (MYSQL_TYPE_DOUBLE) ;
1364
1365
sum= 0.0 ;
1365
1366
break ;
1366
1367
case INT_RESULT:
@@ -1373,17 +1374,17 @@ void Item_sum_sum::fix_length_and_dec()
1373
1374
decimals,
1374
1375
unsigned_flag);
1375
1376
curr_dec_buff= 0 ;
1376
- hybrid_type= DECIMAL_RESULT ;
1377
+ set_handler_by_field_type (MYSQL_TYPE_NEWDECIMAL) ;
1377
1378
my_decimal_set_zero (dec_buffs);
1378
1379
break ;
1379
1380
}
1380
1381
case ROW_RESULT:
1381
1382
DBUG_ASSERT (0 );
1382
1383
}
1383
1384
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" :
1387
1388
" --ILLEGAL!!!--" ),
1388
1389
max_length,
1389
1390
(int )decimals));
@@ -1394,7 +1395,7 @@ void Item_sum_sum::fix_length_and_dec()
1394
1395
bool Item_sum_sum::add ()
1395
1396
{
1396
1397
DBUG_ENTER (" Item_sum_sum::add" );
1397
- if (hybrid_type == DECIMAL_RESULT)
1398
+ if (Item_sum_sum::result_type () == DECIMAL_RESULT)
1398
1399
{
1399
1400
my_decimal value;
1400
1401
const my_decimal *val= aggr->arg_val_decimal (&value);
@@ -1421,7 +1422,7 @@ longlong Item_sum_sum::val_int()
1421
1422
DBUG_ASSERT (fixed == 1 );
1422
1423
if (aggr)
1423
1424
aggr->endup ();
1424
- if (hybrid_type == DECIMAL_RESULT)
1425
+ if (Item_sum_sum::result_type () == DECIMAL_RESULT)
1425
1426
{
1426
1427
longlong result;
1427
1428
my_decimal2int (E_DEC_FATAL_ERROR, dec_buffs + curr_dec_buff, unsigned_flag,
@@ -1437,7 +1438,7 @@ double Item_sum_sum::val_real()
1437
1438
DBUG_ASSERT (fixed == 1 );
1438
1439
if (aggr)
1439
1440
aggr->endup ();
1440
- if (hybrid_type == DECIMAL_RESULT)
1441
+ if (Item_sum_sum::result_type () == DECIMAL_RESULT)
1441
1442
my_decimal2double (E_DEC_FATAL_ERROR, dec_buffs + curr_dec_buff, &sum);
1442
1443
return sum;
1443
1444
}
@@ -1447,7 +1448,7 @@ String *Item_sum_sum::val_str(String *str)
1447
1448
{
1448
1449
if (aggr)
1449
1450
aggr->endup ();
1450
- if (hybrid_type == DECIMAL_RESULT)
1451
+ if (Item_sum_sum::result_type () == DECIMAL_RESULT)
1451
1452
return val_string_from_decimal (str);
1452
1453
return val_string_from_real (str);
1453
1454
}
@@ -1457,7 +1458,7 @@ my_decimal *Item_sum_sum::val_decimal(my_decimal *val)
1457
1458
{
1458
1459
if (aggr)
1459
1460
aggr->endup ();
1460
- if (hybrid_type == DECIMAL_RESULT)
1461
+ if (Item_sum_sum::result_type () == DECIMAL_RESULT)
1461
1462
return (dec_buffs + curr_dec_buff);
1462
1463
return val_decimal_from_real (val);
1463
1464
}
@@ -1633,7 +1634,7 @@ void Item_sum_avg::fix_length_and_dec()
1633
1634
Item_sum_sum::fix_length_and_dec ();
1634
1635
maybe_null=null_value=1 ;
1635
1636
prec_increment= current_thd->variables .div_precincrement ;
1636
- if (hybrid_type == DECIMAL_RESULT)
1637
+ if (Item_sum_avg::result_type () == DECIMAL_RESULT)
1637
1638
{
1638
1639
int precision= args[0 ]->decimal_precision () + prec_increment;
1639
1640
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,
1672
1673
and unpack on access.
1673
1674
*/
1674
1675
field= new (mem_root)
1675
- Field_string (((hybrid_type == DECIMAL_RESULT) ?
1676
+ Field_string (((Item_sum_avg::result_type () == DECIMAL_RESULT) ?
1676
1677
dec_bin_size : sizeof (double )) + sizeof (longlong),
1677
1678
0 , name, &my_charset_bin);
1678
1679
}
1679
- else if (hybrid_type == DECIMAL_RESULT)
1680
+ else if (Item_sum_avg::result_type () == DECIMAL_RESULT)
1680
1681
field= Field_new_decimal::create_from_item (mem_root, this );
1681
1682
else
1682
1683
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)
1731
1732
}
1732
1733
1733
1734
/*
1734
- For non-DECIMAL hybrid_type the division will be done in
1735
+ For non-DECIMAL result_type() the division will be done in
1735
1736
Item_sum_avg::val_real().
1736
1737
*/
1737
- if (hybrid_type != DECIMAL_RESULT)
1738
+ if (Item_sum_avg::result_type () != DECIMAL_RESULT)
1738
1739
return val_decimal_from_real (val);
1739
1740
1740
1741
sum_dec= dec_buffs + curr_dec_buff;
@@ -1748,7 +1749,7 @@ String *Item_sum_avg::val_str(String *str)
1748
1749
{
1749
1750
if (aggr)
1750
1751
aggr->endup ();
1751
- if (hybrid_type == DECIMAL_RESULT)
1752
+ if (Item_sum_avg::result_type () == DECIMAL_RESULT)
1752
1753
return val_string_from_decimal (str);
1753
1754
return val_string_from_real (str);
1754
1755
}
@@ -2316,7 +2317,7 @@ void Item_sum_hybrid::reset_field()
2316
2317
void Item_sum_sum::reset_field ()
2317
2318
{
2318
2319
DBUG_ASSERT (aggr->Aggrtype () != Aggregator::DISTINCT_AGGREGATOR);
2319
- if (hybrid_type == DECIMAL_RESULT)
2320
+ if (Item_sum_sum::result_type () == DECIMAL_RESULT)
2320
2321
{
2321
2322
my_decimal value, *arg_val= args[0 ]->val_decimal (&value);
2322
2323
if (!arg_val) // Null
@@ -2325,7 +2326,7 @@ void Item_sum_sum::reset_field()
2325
2326
}
2326
2327
else
2327
2328
{
2328
- DBUG_ASSERT (hybrid_type == REAL_RESULT);
2329
+ DBUG_ASSERT (result_type () == REAL_RESULT);
2329
2330
double nr= args[0 ]->val_real (); // Nulls also return 0
2330
2331
float8store (result_field->ptr , nr);
2331
2332
}
@@ -2352,7 +2353,7 @@ void Item_sum_avg::reset_field()
2352
2353
{
2353
2354
uchar *res=result_field->ptr ;
2354
2355
DBUG_ASSERT (aggr->Aggrtype () != Aggregator::DISTINCT_AGGREGATOR);
2355
- if (hybrid_type == DECIMAL_RESULT)
2356
+ if (Item_sum_avg::result_type () == DECIMAL_RESULT)
2356
2357
{
2357
2358
longlong tmp;
2358
2359
my_decimal value, *arg_dec= args[0 ]->val_decimal (&value);
@@ -2406,7 +2407,7 @@ void Item_sum_bit::update_field()
2406
2407
void Item_sum_sum::update_field ()
2407
2408
{
2408
2409
DBUG_ASSERT (aggr->Aggrtype () != Aggregator::DISTINCT_AGGREGATOR);
2409
- if (hybrid_type == DECIMAL_RESULT)
2410
+ if (Item_sum_sum::result_type () == DECIMAL_RESULT)
2410
2411
{
2411
2412
my_decimal value, *arg_val= args[0 ]->val_decimal (&value);
2412
2413
if (!args[0 ]->null_value )
@@ -2461,7 +2462,7 @@ void Item_sum_avg::update_field()
2461
2462
2462
2463
DBUG_ASSERT (aggr->Aggrtype () != Aggregator::DISTINCT_AGGREGATOR);
2463
2464
2464
- if (hybrid_type == DECIMAL_RESULT)
2465
+ if (Item_sum_avg::result_type () == DECIMAL_RESULT)
2465
2466
{
2466
2467
my_decimal value, *arg_val= args[0 ]->val_decimal (&value);
2467
2468
if (!args[0 ]->null_value )
@@ -2500,7 +2501,7 @@ void Item_sum_avg::update_field()
2500
2501
Item *Item_sum_avg::result_item (THD *thd, Field *field)
2501
2502
{
2502
2503
return
2503
- hybrid_type == DECIMAL_RESULT ?
2504
+ Item_sum_avg::result_type () == DECIMAL_RESULT ?
2504
2505
(Item_avg_field*) new (thd->mem_root ) Item_avg_field_decimal (thd, this ) :
2505
2506
(Item_avg_field*) new (thd->mem_root ) Item_avg_field_double (thd, this );
2506
2507
}
0 commit comments