summaryrefslogtreecommitdiff
path: root/sql/item_func.h
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.org>2018-02-21 08:18:44 +0400
committerAlexander Barkov <bar@mariadb.org>2018-02-21 08:18:44 +0400
commit5417002dae7a9f15ad77c58fae93eada80699b4b (patch)
tree39234567a658b0b9124e339941b129250b9fa6e5 /sql/item_func.h
parentaef530bb6955d8c13a1ff9c5624c74fefa68943c (diff)
downloadmariadb-git-5417002dae7a9f15ad77c58fae93eada80699b4b.tar.gz
A cleanup for MDEV-15340 + fix MDEV-15363 Wrong result for CAST(LAST_DAY(TIME'00:00:00') AS TIME)
The change N7 in MDEV-15340 (see the commit message) introduced a regression in how CAST(AS TIME), HOUR(), TIME_TO_SEC() treat datetimes '0000-00-DD mm:hh:ss' (i.e. with zero YYYYMM part and a non-zero day). These functions historically do not mix days to hours on datetime-to-time conversion. Implementations of the underlying methods used get_arg0_time() to fetch MYSQL_TIME. After MDEV-15340, get_arg0_time() went through the Time() constructor, which always adds '0000-00-DD' to hours automatically (as in all other places in the code we do mix days to hours). Changes: 1. Extending Time() to make it possible to choose a desired way of treating '0000-00-DD' (ignore or mix to hours) on datetime-to-time conversion. Adding a helper class Time::Options for this, which now describes two aspects of Time() creation: 1. Flags for get_date() 2. Days/hours mixing behavior. 2. Removing Item_func::get_arg0_time(). Using Time() directly in all affected classes. Forcing Time() to ignore (rather than mix) '0000-00-DD' in these affected classes by passing a suitable Options value. 3. Adding Time::to_seconds(), to reuse the code between Item_func_time_to_sec::decimal_op() and Item_func_time_to_sec::int_op(). 4. Item_func::get_arg0_date() now returns only a datetime value, with automatic time-to-datetime conversion if needed. An assert was added to catch attempts to pass TIME_TIME_ONLY to get_arg0_date(). All callers were checked not to pass TIME_TIME_ONLY, this revealed a bug MDEV-15363. 5. Changing Item_func_last_day::get_date() to remove the TIME_TIME_ONLY flag before calling get_arg0_date(). This fixes MDEV-15363.
Diffstat (limited to 'sql/item_func.h')
-rw-r--r--sql/item_func.h10
1 files changed, 1 insertions, 9 deletions
diff --git a/sql/item_func.h b/sql/item_func.h
index 063a80de737..7d7cd61f474 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -160,18 +160,10 @@ public:
void print_args(String *str, uint from, enum_query_type query_type);
inline bool get_arg0_date(MYSQL_TIME *ltime, ulonglong fuzzy_date)
{
- return fuzzy_date & TIME_TIME_ONLY ? get_arg0_time(ltime) :
- get_arg0_datetime(ltime, fuzzy_date);
- }
- inline bool get_arg0_datetime(MYSQL_TIME *ltime, ulonglong fuzzy_date)
- {
+ DBUG_ASSERT(!(fuzzy_date & TIME_TIME_ONLY));
Datetime dt(current_thd, args[0], fuzzy_date);
return (null_value= dt.copy_to_mysql_time(ltime));
}
- inline bool get_arg0_time(MYSQL_TIME *ltime)
- {
- return (null_value= Time(args[0]).copy_to_mysql_time(ltime));
- }
bool is_null() {
update_null_value();
return null_value;