summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2015-10-06 00:48:46 +0400
committerAlexander Barkov <bar@mariadb.org>2015-10-06 00:48:46 +0400
commit3c47809bc27486984bc56712b3db019d0720f30a (patch)
tree778e81c1f7077102b7681b3f924440c599448489
parent56cd7d0cd02c5fd97a0db5f7e879dc05d44c6ea4 (diff)
downloadmariadb-git-3c47809bc27486984bc56712b3db019d0720f30a.tar.gz
Clean-up: changing switch(result_type()) followed by a test for temporal types
in case of STRING_RESULT to switch(cmp_type()).
-rw-r--r--sql/item_func.cc120
-rw-r--r--sql/sql_select.cc20
2 files changed, 66 insertions, 74 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc
index a6360477149..de718b738e4 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -871,7 +871,7 @@ void Item_func_num1::fix_length_and_dec()
String *Item_func_hybrid_field_type::val_str(String *str)
{
DBUG_ASSERT(fixed == 1);
- switch (Item_func_hybrid_field_type::result_type()) {
+ switch (Item_func_hybrid_field_type::cmp_type()) {
case DECIMAL_RESULT:
{
my_decimal decimal_value, *val;
@@ -898,24 +898,23 @@ String *Item_func_hybrid_field_type::val_str(String *str)
str->set_real(nr, decimals, collation.collation);
break;
}
- case STRING_RESULT:
- if (is_temporal_type(field_type()))
+ case TIME_RESULT:
+ {
+ 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;
- if (date_op(&ltime,
- 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;
+ 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;
+ }
+ case STRING_RESULT:
return str_op(&str_value);
- case TIME_RESULT:
case ROW_RESULT:
DBUG_ASSERT(0);
}
@@ -926,7 +925,7 @@ String *Item_func_hybrid_field_type::val_str(String *str)
double Item_func_hybrid_field_type::val_real()
{
DBUG_ASSERT(fixed == 1);
- switch (Item_func_hybrid_field_type::result_type()) {
+ switch (Item_func_hybrid_field_type::cmp_type()) {
case DECIMAL_RESULT:
{
my_decimal decimal_value, *val;
@@ -943,24 +942,23 @@ double Item_func_hybrid_field_type::val_real()
}
case REAL_RESULT:
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;
- if (date_op(&ltime,
- 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);
+ null_value= 1;
+ return 0;
}
+ ltime.time_type= mysql_type_to_time_type(field_type());
+ return TIME_to_double(&ltime);
+ }
+ case STRING_RESULT:
+ {
String *res= str_op(&str_value);
return res ? double_from_string_with_check(res) : 0.0;
}
- case TIME_RESULT:
case ROW_RESULT:
DBUG_ASSERT(0);
}
@@ -971,7 +969,7 @@ double Item_func_hybrid_field_type::val_real()
longlong Item_func_hybrid_field_type::val_int()
{
DBUG_ASSERT(fixed == 1);
- switch (Item_func_hybrid_field_type::result_type()) {
+ switch (Item_func_hybrid_field_type::cmp_type()) {
case DECIMAL_RESULT:
{
my_decimal decimal_value, *val;
@@ -985,24 +983,23 @@ longlong Item_func_hybrid_field_type::val_int()
return int_op();
case REAL_RESULT:
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;
- if (date_op(&ltime,
- 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);
+ null_value= 1;
+ return 0;
}
+ ltime.time_type= mysql_type_to_time_type(field_type());
+ return TIME_to_ulonglong(&ltime);
+ }
+ case STRING_RESULT:
+ {
String *res= str_op(&str_value);
return res ? longlong_from_string_with_check(res) : 0;
}
- case TIME_RESULT:
case ROW_RESULT:
DBUG_ASSERT(0);
}
@@ -1014,7 +1011,7 @@ my_decimal *Item_func_hybrid_field_type::val_decimal(my_decimal *decimal_value)
{
my_decimal *val= decimal_value;
DBUG_ASSERT(fixed == 1);
- switch (Item_func_hybrid_field_type::result_type()) {
+ switch (Item_func_hybrid_field_type::cmp_type()) {
case DECIMAL_RESULT:
val= decimal_op(decimal_value);
break;
@@ -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);
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;
- if (date_op(&ltime,
- field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 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);
+ 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);
+ }
+ case STRING_RESULT:
+ {
String *res= str_op(&str_value);
return res ? decimal_from_string_with_check(decimal_value, res) : 0;
}
case ROW_RESULT:
- case TIME_RESULT:
DBUG_ASSERT(0);
}
return val;
@@ -1060,7 +1056,7 @@ bool Item_func_hybrid_field_type::get_date(MYSQL_TIME *ltime,
ulonglong fuzzydate)
{
DBUG_ASSERT(fixed == 1);
- switch (Item_func_hybrid_field_type::result_type()) {
+ switch (Item_func_hybrid_field_type::cmp_type()) {
case DECIMAL_RESULT:
{
my_decimal value, *res;
@@ -1088,12 +1084,12 @@ bool Item_func_hybrid_field_type::get_date(MYSQL_TIME *ltime,
goto err;
break;
}
+ case TIME_RESULT:
+ return date_op(ltime,
+ fuzzydate |
+ (field_type() == MYSQL_TYPE_TIME ? TIME_TIME_ONLY : 0));
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];
String tmp(buff,sizeof(buff), &my_charset_bin),*res;
if (!(res= str_op(&tmp)) ||
@@ -1101,10 +1097,8 @@ bool Item_func_hybrid_field_type::get_date(MYSQL_TIME *ltime,
ltime, fuzzydate))
goto err;
break;
- break;
}
case ROW_RESULT:
- case TIME_RESULT:
DBUG_ASSERT(0);
}
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index d1912ac3e46..53ca3c32f14 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -22410,7 +22410,7 @@ calc_group_buffer(JOIN *join,ORDER *group)
}
else
{
- switch (group_item->result_type()) {
+ switch (group_item->cmp_type()) {
case REAL_RESULT:
key_length+= sizeof(double);
break;
@@ -22422,22 +22422,20 @@ calc_group_buffer(JOIN *join,ORDER *group)
(group_item->decimals ? 1 : 0),
group_item->decimals);
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
have STRING_RESULT result type, we increase the length
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;
- }
- else if (type == MYSQL_TYPE_BLOB)
+ key_length+= 8;
+ break;
+ }
+ 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
else
{