Commit 3c47809b authored by Alexander Barkov's avatar Alexander Barkov

Clean-up: changing switch(result_type()) followed by a test for temporal types

in case of STRING_RESULT to switch(cmp_type()).
parent 56cd7d0c
...@@ -871,7 +871,7 @@ void Item_func_num1::fix_length_and_dec() ...@@ -871,7 +871,7 @@ void Item_func_num1::fix_length_and_dec()
String *Item_func_hybrid_field_type::val_str(String *str) String *Item_func_hybrid_field_type::val_str(String *str)
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
switch (Item_func_hybrid_field_type::result_type()) { switch (Item_func_hybrid_field_type::cmp_type()) {
case DECIMAL_RESULT: case DECIMAL_RESULT:
{ {
my_decimal decimal_value, *val; my_decimal decimal_value, *val;
...@@ -898,24 +898,23 @@ String *Item_func_hybrid_field_type::val_str(String *str) ...@@ -898,24 +898,23 @@ String *Item_func_hybrid_field_type::val_str(String *str)
str->set_real(nr, decimals, collation.collation); str->set_real(nr, decimals, collation.collation);
break; break;
} }
case STRING_RESULT: case TIME_RESULT:
if (is_temporal_type(field_type())) {
MYSQL_TIME ltime;
if (date_op(&ltime,
field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0) ||
str->alloc(MAX_DATE_STRING_REP_LENGTH))
{ {
MYSQL_TIME ltime; null_value= 1;
if (date_op(&ltime, return (String *) 0;
field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0) ||
str->alloc(MAX_DATE_STRING_REP_LENGTH))
{
null_value= 1;
return (String *) 0;
}
ltime.time_type= mysql_type_to_time_type(field_type());
str->length(my_TIME_to_str(&ltime, const_cast<char*>(str->ptr()), decimals));
str->set_charset(&my_charset_bin);
return str;
} }
ltime.time_type= mysql_type_to_time_type(field_type());
str->length(my_TIME_to_str(&ltime, const_cast<char*>(str->ptr()), decimals));
str->set_charset(&my_charset_bin);
return str;
}
case STRING_RESULT:
return str_op(&str_value); return str_op(&str_value);
case TIME_RESULT:
case ROW_RESULT: case ROW_RESULT:
DBUG_ASSERT(0); DBUG_ASSERT(0);
} }
...@@ -926,7 +925,7 @@ String *Item_func_hybrid_field_type::val_str(String *str) ...@@ -926,7 +925,7 @@ String *Item_func_hybrid_field_type::val_str(String *str)
double Item_func_hybrid_field_type::val_real() double Item_func_hybrid_field_type::val_real()
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
switch (Item_func_hybrid_field_type::result_type()) { switch (Item_func_hybrid_field_type::cmp_type()) {
case DECIMAL_RESULT: case DECIMAL_RESULT:
{ {
my_decimal decimal_value, *val; my_decimal decimal_value, *val;
...@@ -943,24 +942,23 @@ double Item_func_hybrid_field_type::val_real() ...@@ -943,24 +942,23 @@ double Item_func_hybrid_field_type::val_real()
} }
case REAL_RESULT: case REAL_RESULT:
return real_op(); return real_op();
case STRING_RESULT: case TIME_RESULT:
{ {
if (is_temporal_type(field_type())) MYSQL_TIME ltime;
if (date_op(&ltime,
field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0 ))
{ {
MYSQL_TIME ltime; null_value= 1;
if (date_op(&ltime, return 0;
field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0 ))
{
null_value= 1;
return 0;
}
ltime.time_type= mysql_type_to_time_type(field_type());
return TIME_to_double(&ltime);
} }
ltime.time_type= mysql_type_to_time_type(field_type());
return TIME_to_double(&ltime);
}
case STRING_RESULT:
{
String *res= str_op(&str_value); String *res= str_op(&str_value);
return res ? double_from_string_with_check(res) : 0.0; return res ? double_from_string_with_check(res) : 0.0;
} }
case TIME_RESULT:
case ROW_RESULT: case ROW_RESULT:
DBUG_ASSERT(0); DBUG_ASSERT(0);
} }
...@@ -971,7 +969,7 @@ double Item_func_hybrid_field_type::val_real() ...@@ -971,7 +969,7 @@ double Item_func_hybrid_field_type::val_real()
longlong Item_func_hybrid_field_type::val_int() longlong Item_func_hybrid_field_type::val_int()
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
switch (Item_func_hybrid_field_type::result_type()) { switch (Item_func_hybrid_field_type::cmp_type()) {
case DECIMAL_RESULT: case DECIMAL_RESULT:
{ {
my_decimal decimal_value, *val; my_decimal decimal_value, *val;
...@@ -985,24 +983,23 @@ longlong Item_func_hybrid_field_type::val_int() ...@@ -985,24 +983,23 @@ longlong Item_func_hybrid_field_type::val_int()
return int_op(); return int_op();
case REAL_RESULT: case REAL_RESULT:
return (longlong) rint(real_op()); return (longlong) rint(real_op());
case STRING_RESULT: case TIME_RESULT:
{ {
if (is_temporal_type(field_type())) MYSQL_TIME ltime;
if (date_op(&ltime,
field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0))
{ {
MYSQL_TIME ltime; null_value= 1;
if (date_op(&ltime, return 0;
field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0))
{
null_value= 1;
return 0;
}
ltime.time_type= mysql_type_to_time_type(field_type());
return TIME_to_ulonglong(&ltime);
} }
ltime.time_type= mysql_type_to_time_type(field_type());
return TIME_to_ulonglong(&ltime);
}
case STRING_RESULT:
{
String *res= str_op(&str_value); String *res= str_op(&str_value);
return res ? longlong_from_string_with_check(res) : 0; return res ? longlong_from_string_with_check(res) : 0;
} }
case TIME_RESULT:
case ROW_RESULT: case ROW_RESULT:
DBUG_ASSERT(0); DBUG_ASSERT(0);
} }
...@@ -1014,7 +1011,7 @@ my_decimal *Item_func_hybrid_field_type::val_decimal(my_decimal *decimal_value) ...@@ -1014,7 +1011,7 @@ my_decimal *Item_func_hybrid_field_type::val_decimal(my_decimal *decimal_value)
{ {
my_decimal *val= decimal_value; my_decimal *val= decimal_value;
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
switch (Item_func_hybrid_field_type::result_type()) { switch (Item_func_hybrid_field_type::cmp_type()) {
case DECIMAL_RESULT: case DECIMAL_RESULT:
val= decimal_op(decimal_value); val= decimal_op(decimal_value);
break; break;
...@@ -1030,26 +1027,25 @@ my_decimal *Item_func_hybrid_field_type::val_decimal(my_decimal *decimal_value) ...@@ -1030,26 +1027,25 @@ my_decimal *Item_func_hybrid_field_type::val_decimal(my_decimal *decimal_value)
double2my_decimal(E_DEC_FATAL_ERROR, result, decimal_value); double2my_decimal(E_DEC_FATAL_ERROR, result, decimal_value);
break; break;
} }
case STRING_RESULT: case TIME_RESULT:
{ {
if (is_temporal_type(field_type())) MYSQL_TIME ltime;
if (date_op(&ltime,
field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0))
{ {
MYSQL_TIME ltime; my_decimal_set_zero(decimal_value);
if (date_op(&ltime, null_value= 1;
field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0)) return 0;
{
my_decimal_set_zero(decimal_value);
null_value= 1;
return 0;
}
ltime.time_type= mysql_type_to_time_type(field_type());
return date2my_decimal(&ltime, decimal_value);
} }
ltime.time_type= mysql_type_to_time_type(field_type());
return date2my_decimal(&ltime, decimal_value);
}
case STRING_RESULT:
{
String *res= str_op(&str_value); String *res= str_op(&str_value);
return res ? decimal_from_string_with_check(decimal_value, res) : 0; return res ? decimal_from_string_with_check(decimal_value, res) : 0;
} }
case ROW_RESULT: case ROW_RESULT:
case TIME_RESULT:
DBUG_ASSERT(0); DBUG_ASSERT(0);
} }
return val; return val;
...@@ -1060,7 +1056,7 @@ bool Item_func_hybrid_field_type::get_date(MYSQL_TIME *ltime, ...@@ -1060,7 +1056,7 @@ bool Item_func_hybrid_field_type::get_date(MYSQL_TIME *ltime,
ulonglong fuzzydate) ulonglong fuzzydate)
{ {
DBUG_ASSERT(fixed == 1); DBUG_ASSERT(fixed == 1);
switch (Item_func_hybrid_field_type::result_type()) { switch (Item_func_hybrid_field_type::cmp_type()) {
case DECIMAL_RESULT: case DECIMAL_RESULT:
{ {
my_decimal value, *res; my_decimal value, *res;
...@@ -1088,12 +1084,12 @@ bool Item_func_hybrid_field_type::get_date(MYSQL_TIME *ltime, ...@@ -1088,12 +1084,12 @@ bool Item_func_hybrid_field_type::get_date(MYSQL_TIME *ltime,
goto err; goto err;
break; break;
} }
case TIME_RESULT:
return date_op(ltime,
fuzzydate |
(field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0));
case STRING_RESULT: case STRING_RESULT:
{ {
if (is_temporal_type(field_type()))
return date_op(ltime,
fuzzydate |
(field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0));
char buff[40]; char buff[40];
String tmp(buff,sizeof(buff), &my_charset_bin),*res; String tmp(buff,sizeof(buff), &my_charset_bin),*res;
if (!(res= str_op(&tmp)) || if (!(res= str_op(&tmp)) ||
...@@ -1101,10 +1097,8 @@ bool Item_func_hybrid_field_type::get_date(MYSQL_TIME *ltime, ...@@ -1101,10 +1097,8 @@ bool Item_func_hybrid_field_type::get_date(MYSQL_TIME *ltime,
ltime, fuzzydate)) ltime, fuzzydate))
goto err; goto err;
break; break;
break;
} }
case ROW_RESULT: case ROW_RESULT:
case TIME_RESULT:
DBUG_ASSERT(0); DBUG_ASSERT(0);
} }
......
...@@ -22410,7 +22410,7 @@ calc_group_buffer(JOIN *join,ORDER *group) ...@@ -22410,7 +22410,7 @@ calc_group_buffer(JOIN *join,ORDER *group)
} }
else else
{ {
switch (group_item->result_type()) { switch (group_item->cmp_type()) {
case REAL_RESULT: case REAL_RESULT:
key_length+= sizeof(double); key_length+= sizeof(double);
break; break;
...@@ -22422,22 +22422,20 @@ calc_group_buffer(JOIN *join,ORDER *group) ...@@ -22422,22 +22422,20 @@ calc_group_buffer(JOIN *join,ORDER *group)
(group_item->decimals ? 1 : 0), (group_item->decimals ? 1 : 0),
group_item->decimals); group_item->decimals);
break; break;
case STRING_RESULT: case TIME_RESULT:
{ {
enum enum_field_types type= group_item->field_type();
/* /*
As items represented as DATE/TIME fields in the group buffer As items represented as DATE/TIME fields in the group buffer
have STRING_RESULT result type, we increase the length have STRING_RESULT result type, we increase the length
by 8 as maximum pack length of such fields. by 8 as maximum pack length of such fields.
*/ */
if (type == MYSQL_TYPE_TIME || key_length+= 8;
type == MYSQL_TYPE_DATE || break;
type == MYSQL_TYPE_DATETIME || }
type == MYSQL_TYPE_TIMESTAMP) case STRING_RESULT:
{ {
key_length+= 8; enum enum_field_types type= group_item->field_type();
} if (type == MYSQL_TYPE_BLOB)
else if (type == MYSQL_TYPE_BLOB)
key_length+= MAX_BLOB_WIDTH; // Can't be used as a key key_length+= MAX_BLOB_WIDTH; // Can't be used as a key
else else
{ {
......
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