Skip to content

Commit 3c47809

Browse files
author
Alexander Barkov
committed
Clean-up: changing switch(result_type()) followed by a test for temporal types
in case of STRING_RESULT to switch(cmp_type()).
1 parent 56cd7d0 commit 3c47809

File tree

2 files changed

+66
-74
lines changed

2 files changed

+66
-74
lines changed

sql/item_func.cc

Lines changed: 57 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ void Item_func_num1::fix_length_and_dec()
871871
String *Item_func_hybrid_field_type::val_str(String *str)
872872
{
873873
DBUG_ASSERT(fixed == 1);
874-
switch (Item_func_hybrid_field_type::result_type()) {
874+
switch (Item_func_hybrid_field_type::cmp_type()) {
875875
case DECIMAL_RESULT:
876876
{
877877
my_decimal decimal_value, *val;
@@ -898,24 +898,23 @@ String *Item_func_hybrid_field_type::val_str(String *str)
898898
str->set_real(nr, decimals, collation.collation);
899899
break;
900900
}
901-
case STRING_RESULT:
902-
if (is_temporal_type(field_type()))
901+
case TIME_RESULT:
902+
{
903+
MYSQL_TIME ltime;
904+
if (date_op(&ltime,
905+
field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0) ||
906+
str->alloc(MAX_DATE_STRING_REP_LENGTH))
903907
{
904-
MYSQL_TIME ltime;
905-
if (date_op(&ltime,
906-
field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0) ||
907-
str->alloc(MAX_DATE_STRING_REP_LENGTH))
908-
{
909-
null_value= 1;
910-
return (String *) 0;
911-
}
912-
ltime.time_type= mysql_type_to_time_type(field_type());
913-
str->length(my_TIME_to_str(&ltime, const_cast<char*>(str->ptr()), decimals));
914-
str->set_charset(&my_charset_bin);
915-
return str;
908+
null_value= 1;
909+
return (String *) 0;
916910
}
911+
ltime.time_type= mysql_type_to_time_type(field_type());
912+
str->length(my_TIME_to_str(&ltime, const_cast<char*>(str->ptr()), decimals));
913+
str->set_charset(&my_charset_bin);
914+
return str;
915+
}
916+
case STRING_RESULT:
917917
return str_op(&str_value);
918-
case TIME_RESULT:
919918
case ROW_RESULT:
920919
DBUG_ASSERT(0);
921920
}
@@ -926,7 +925,7 @@ String *Item_func_hybrid_field_type::val_str(String *str)
926925
double Item_func_hybrid_field_type::val_real()
927926
{
928927
DBUG_ASSERT(fixed == 1);
929-
switch (Item_func_hybrid_field_type::result_type()) {
928+
switch (Item_func_hybrid_field_type::cmp_type()) {
930929
case DECIMAL_RESULT:
931930
{
932931
my_decimal decimal_value, *val;
@@ -943,24 +942,23 @@ double Item_func_hybrid_field_type::val_real()
943942
}
944943
case REAL_RESULT:
945944
return real_op();
946-
case STRING_RESULT:
945+
case TIME_RESULT:
947946
{
948-
if (is_temporal_type(field_type()))
947+
MYSQL_TIME ltime;
948+
if (date_op(&ltime,
949+
field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0 ))
949950
{
950-
MYSQL_TIME ltime;
951-
if (date_op(&ltime,
952-
field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0 ))
953-
{
954-
null_value= 1;
955-
return 0;
956-
}
957-
ltime.time_type= mysql_type_to_time_type(field_type());
958-
return TIME_to_double(&ltime);
951+
null_value= 1;
952+
return 0;
959953
}
954+
ltime.time_type= mysql_type_to_time_type(field_type());
955+
return TIME_to_double(&ltime);
956+
}
957+
case STRING_RESULT:
958+
{
960959
String *res= str_op(&str_value);
961960
return res ? double_from_string_with_check(res) : 0.0;
962961
}
963-
case TIME_RESULT:
964962
case ROW_RESULT:
965963
DBUG_ASSERT(0);
966964
}
@@ -971,7 +969,7 @@ double Item_func_hybrid_field_type::val_real()
971969
longlong Item_func_hybrid_field_type::val_int()
972970
{
973971
DBUG_ASSERT(fixed == 1);
974-
switch (Item_func_hybrid_field_type::result_type()) {
972+
switch (Item_func_hybrid_field_type::cmp_type()) {
975973
case DECIMAL_RESULT:
976974
{
977975
my_decimal decimal_value, *val;
@@ -985,24 +983,23 @@ longlong Item_func_hybrid_field_type::val_int()
985983
return int_op();
986984
case REAL_RESULT:
987985
return (longlong) rint(real_op());
988-
case STRING_RESULT:
986+
case TIME_RESULT:
989987
{
990-
if (is_temporal_type(field_type()))
988+
MYSQL_TIME ltime;
989+
if (date_op(&ltime,
990+
field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0))
991991
{
992-
MYSQL_TIME ltime;
993-
if (date_op(&ltime,
994-
field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0))
995-
{
996-
null_value= 1;
997-
return 0;
998-
}
999-
ltime.time_type= mysql_type_to_time_type(field_type());
1000-
return TIME_to_ulonglong(&ltime);
992+
null_value= 1;
993+
return 0;
1001994
}
995+
ltime.time_type= mysql_type_to_time_type(field_type());
996+
return TIME_to_ulonglong(&ltime);
997+
}
998+
case STRING_RESULT:
999+
{
10021000
String *res= str_op(&str_value);
10031001
return res ? longlong_from_string_with_check(res) : 0;
10041002
}
1005-
case TIME_RESULT:
10061003
case ROW_RESULT:
10071004
DBUG_ASSERT(0);
10081005
}
@@ -1014,7 +1011,7 @@ my_decimal *Item_func_hybrid_field_type::val_decimal(my_decimal *decimal_value)
10141011
{
10151012
my_decimal *val= decimal_value;
10161013
DBUG_ASSERT(fixed == 1);
1017-
switch (Item_func_hybrid_field_type::result_type()) {
1014+
switch (Item_func_hybrid_field_type::cmp_type()) {
10181015
case DECIMAL_RESULT:
10191016
val= decimal_op(decimal_value);
10201017
break;
@@ -1030,26 +1027,25 @@ my_decimal *Item_func_hybrid_field_type::val_decimal(my_decimal *decimal_value)
10301027
double2my_decimal(E_DEC_FATAL_ERROR, result, decimal_value);
10311028
break;
10321029
}
1033-
case STRING_RESULT:
1030+
case TIME_RESULT:
10341031
{
1035-
if (is_temporal_type(field_type()))
1032+
MYSQL_TIME ltime;
1033+
if (date_op(&ltime,
1034+
field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0))
10361035
{
1037-
MYSQL_TIME ltime;
1038-
if (date_op(&ltime,
1039-
field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0))
1040-
{
1041-
my_decimal_set_zero(decimal_value);
1042-
null_value= 1;
1043-
return 0;
1044-
}
1045-
ltime.time_type= mysql_type_to_time_type(field_type());
1046-
return date2my_decimal(&ltime, decimal_value);
1036+
my_decimal_set_zero(decimal_value);
1037+
null_value= 1;
1038+
return 0;
10471039
}
1040+
ltime.time_type= mysql_type_to_time_type(field_type());
1041+
return date2my_decimal(&ltime, decimal_value);
1042+
}
1043+
case STRING_RESULT:
1044+
{
10481045
String *res= str_op(&str_value);
10491046
return res ? decimal_from_string_with_check(decimal_value, res) : 0;
10501047
}
10511048
case ROW_RESULT:
1052-
case TIME_RESULT:
10531049
DBUG_ASSERT(0);
10541050
}
10551051
return val;
@@ -1060,7 +1056,7 @@ bool Item_func_hybrid_field_type::get_date(MYSQL_TIME *ltime,
10601056
ulonglong fuzzydate)
10611057
{
10621058
DBUG_ASSERT(fixed == 1);
1063-
switch (Item_func_hybrid_field_type::result_type()) {
1059+
switch (Item_func_hybrid_field_type::cmp_type()) {
10641060
case DECIMAL_RESULT:
10651061
{
10661062
my_decimal value, *res;
@@ -1088,23 +1084,21 @@ bool Item_func_hybrid_field_type::get_date(MYSQL_TIME *ltime,
10881084
goto err;
10891085
break;
10901086
}
1087+
case TIME_RESULT:
1088+
return date_op(ltime,
1089+
fuzzydate |
1090+
(field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0));
10911091
case STRING_RESULT:
10921092
{
1093-
if (is_temporal_type(field_type()))
1094-
return date_op(ltime,
1095-
fuzzydate |
1096-
(field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0));
10971093
char buff[40];
10981094
String tmp(buff,sizeof(buff), &my_charset_bin),*res;
10991095
if (!(res= str_op(&tmp)) ||
11001096
str_to_datetime_with_warn(res->charset(), res->ptr(), res->length(),
11011097
ltime, fuzzydate))
11021098
goto err;
11031099
break;
1104-
break;
11051100
}
11061101
case ROW_RESULT:
1107-
case TIME_RESULT:
11081102
DBUG_ASSERT(0);
11091103
}
11101104

sql/sql_select.cc

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22410,7 +22410,7 @@ calc_group_buffer(JOIN *join,ORDER *group)
2241022410
}
2241122411
else
2241222412
{
22413-
switch (group_item->result_type()) {
22413+
switch (group_item->cmp_type()) {
2241422414
case REAL_RESULT:
2241522415
key_length+= sizeof(double);
2241622416
break;
@@ -22422,22 +22422,20 @@ calc_group_buffer(JOIN *join,ORDER *group)
2242222422
(group_item->decimals ? 1 : 0),
2242322423
group_item->decimals);
2242422424
break;
22425-
case STRING_RESULT:
22425+
case TIME_RESULT:
2242622426
{
22427-
enum enum_field_types type= group_item->field_type();
2242822427
/*
2242922428
As items represented as DATE/TIME fields in the group buffer
2243022429
have STRING_RESULT result type, we increase the length
2243122430
by 8 as maximum pack length of such fields.
2243222431
*/
22433-
if (type == MYSQL_TYPE_TIME ||
22434-
type == MYSQL_TYPE_DATE ||
22435-
type == MYSQL_TYPE_DATETIME ||
22436-
type == MYSQL_TYPE_TIMESTAMP)
22437-
{
22438-
key_length+= 8;
22439-
}
22440-
else if (type == MYSQL_TYPE_BLOB)
22432+
key_length+= 8;
22433+
break;
22434+
}
22435+
case STRING_RESULT:
22436+
{
22437+
enum enum_field_types type= group_item->field_type();
22438+
if (type == MYSQL_TYPE_BLOB)
2244122439
key_length+= MAX_BLOB_WIDTH; // Can't be used as a key
2244222440
else
2244322441
{

0 commit comments

Comments
 (0)