summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorMattias Jonsson <mattias.jonsson@sun.com>2009-10-19 13:40:08 +0200
committerMattias Jonsson <mattias.jonsson@sun.com>2009-10-19 13:40:08 +0200
commitec7c4fb442842b46029f28355ece7d0104ea63ac (patch)
treeb7dbc78e60afcd1709cf9da42404e948ae3a9909 /sql
parent93e02adcfab140265d3baf2062057826b3a28bc2 (diff)
downloadmariadb-git-ec7c4fb442842b46029f28355ece7d0104ea63ac.tar.gz
port of fixes for bug-20577 and 46362 for TO_SECONDS
Diffstat (limited to 'sql')
-rw-r--r--sql/item_timefunc.cc38
1 files changed, 29 insertions, 9 deletions
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 29fab2a38a2..fd05737728e 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -944,8 +944,29 @@ longlong Item_func_to_days::val_int()
longlong Item_func_to_seconds::val_int_endpoint(bool left_endp,
bool *incl_endp)
{
- longlong res= val_int();
- return null_value ? LONGLONG_MIN : res;
+ DBUG_ASSERT(fixed == 1);
+ MYSQL_TIME ltime;
+ longlong seconds;
+ longlong days;
+ int dummy; /* unused */
+ if (get_arg0_date(&ltime, TIME_FUZZY_DATE))
+ {
+ /* got NULL, leave the incl_endp intact */
+ return LONGLONG_MIN;
+ }
+ seconds= ltime.hour * 3600L + ltime.minute * 60 + ltime.second;
+ seconds= ltime.neg ? -seconds : seconds;
+ days= (longlong) calc_daynr(ltime.year, ltime.month, ltime.day);
+ seconds+= days * 24L * 3600L;
+ /* Set to NULL if invalid date, but keep the value */
+ null_value= check_date(&ltime,
+ (ltime.year || ltime.month || ltime.day),
+ (TIME_NO_ZERO_IN_DATE | TIME_NO_ZERO_DATE),
+ &dummy);
+ /*
+ Even if the evaluation return NULL, seconds is useful for pruning
+ */
+ return seconds;
}
longlong Item_func_to_seconds::val_int()
@@ -956,10 +977,10 @@ longlong Item_func_to_seconds::val_int()
longlong days;
if (get_arg0_date(&ltime, TIME_NO_ZERO_DATE))
return 0;
- seconds=ltime.hour*3600L+ltime.minute*60+ltime.second;
+ seconds= ltime.hour * 3600L + ltime.minute * 60 + ltime.second;
seconds=ltime.neg ? -seconds : seconds;
- days= (longlong) calc_daynr(ltime.year,ltime.month,ltime.day);
- return (seconds + days * (24L * 3600L));
+ days= (longlong) calc_daynr(ltime.year, ltime.month, ltime.day);
+ return seconds + days * 24L * 3600L;
}
/*
@@ -992,10 +1013,9 @@ enum_monotonicity_info Item_func_to_seconds::get_monotonicity_info() const
{
if (args[0]->type() == Item::FIELD_ITEM)
{
- if (args[0]->field_type() == MYSQL_TYPE_DATE)
- return MONOTONIC_STRICT_INCREASING;
- if (args[0]->field_type() == MYSQL_TYPE_DATETIME)
- return MONOTONIC_INCREASING;
+ if (args[0]->field_type() == MYSQL_TYPE_DATE ||
+ args[0]->field_type() == MYSQL_TYPE_DATETIME)
+ return MONOTONIC_STRICT_INCREASING_NOT_NULL;
}
return NON_MONOTONIC;
}