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,8 +898,7 @@ String *Item_func_hybrid_field_type::val_str(String *str) ...@@ -898,8 +898,7 @@ 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; MYSQL_TIME ltime;
if (date_op(&ltime, if (date_op(&ltime,
...@@ -914,8 +913,8 @@ String *Item_func_hybrid_field_type::val_str(String *str) ...@@ -914,8 +913,8 @@ String *Item_func_hybrid_field_type::val_str(String *str)
str->set_charset(&my_charset_bin); str->set_charset(&my_charset_bin);
return str; 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,9 +942,7 @@ double Item_func_hybrid_field_type::val_real() ...@@ -943,9 +942,7 @@ 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; MYSQL_TIME ltime;
if (date_op(&ltime, if (date_op(&ltime,
...@@ -957,10 +954,11 @@ double Item_func_hybrid_field_type::val_real() ...@@ -957,10 +954,11 @@ double Item_func_hybrid_field_type::val_real()
ltime.time_type= mysql_type_to_time_type(field_type()); ltime.time_type= mysql_type_to_time_type(field_type());
return TIME_to_double(&ltime); 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,9 +983,7 @@ longlong Item_func_hybrid_field_type::val_int() ...@@ -985,9 +983,7 @@ 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; MYSQL_TIME ltime;
if (date_op(&ltime, if (date_op(&ltime,
...@@ -999,10 +995,11 @@ longlong Item_func_hybrid_field_type::val_int() ...@@ -999,10 +995,11 @@ longlong Item_func_hybrid_field_type::val_int()
ltime.time_type= mysql_type_to_time_type(field_type()); ltime.time_type= mysql_type_to_time_type(field_type());
return TIME_to_ulonglong(&ltime); 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,9 +1027,7 @@ my_decimal *Item_func_hybrid_field_type::val_decimal(my_decimal *decimal_value) ...@@ -1030,9 +1027,7 @@ 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; MYSQL_TIME ltime;
if (date_op(&ltime, if (date_op(&ltime,
...@@ -1045,11 +1040,12 @@ my_decimal *Item_func_hybrid_field_type::val_decimal(my_decimal *decimal_value) ...@@ -1045,11 +1040,12 @@ my_decimal *Item_func_hybrid_field_type::val_decimal(my_decimal *decimal_value)
ltime.time_type= mysql_type_to_time_type(field_type()); ltime.time_type= mysql_type_to_time_type(field_type());
return date2my_decimal(&ltime, decimal_value); 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 STRING_RESULT: case TIME_RESULT:
{
if (is_temporal_type(field_type()))
return date_op(ltime, return date_op(ltime,
fuzzydate | fuzzydate |
(field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0)); (field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0));
case STRING_RESULT:
{
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 ||
type == MYSQL_TYPE_DATE ||
type == MYSQL_TYPE_DATETIME ||
type == MYSQL_TYPE_TIMESTAMP)
{
key_length+= 8; key_length+= 8;
break;
} }
else if (type == MYSQL_TYPE_BLOB) case STRING_RESULT:
{
enum enum_field_types type= group_item->field_type();
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