summaryrefslogtreecommitdiff
path: root/sql/sql_class.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_class.cc')
-rw-r--r--sql/sql_class.cc28
1 files changed, 25 insertions, 3 deletions
diff --git a/sql/sql_class.cc b/sql/sql_class.cc
index 7c0879af8c9..6b7c4442204 100644
--- a/sql/sql_class.cc
+++ b/sql/sql_class.cc
@@ -3654,7 +3654,7 @@ int select_max_min_finder_subselect::send_data(List<Item> &items)
if (!cache)
{
cache= val_item->get_cache(thd);
- switch (val_item->result_type()) {
+ switch (val_item->cmp_type()) {
case REAL_RESULT:
op= &select_max_min_finder_subselect::cmp_real;
break;
@@ -3667,8 +3667,13 @@ int select_max_min_finder_subselect::send_data(List<Item> &items)
case DECIMAL_RESULT:
op= &select_max_min_finder_subselect::cmp_decimal;
break;
- case ROW_RESULT:
case TIME_RESULT:
+ if (val_item->field_type() == MYSQL_TYPE_TIME)
+ op= &select_max_min_finder_subselect::cmp_time;
+ else
+ op= &select_max_min_finder_subselect::cmp_str;
+ break;
+ case ROW_RESULT:
// This case should never be chosen
DBUG_ASSERT(0);
op= 0;
@@ -3713,6 +3718,23 @@ bool select_max_min_finder_subselect::cmp_int()
return (val1 < val2);
}
+bool select_max_min_finder_subselect::cmp_time()
+{
+ Item *maxmin= ((Item_singlerow_subselect *)item)->element_index(0);
+ THD *thd= current_thd;
+ auto val1= cache->val_time_packed(thd), val2= maxmin->val_time_packed(thd);
+
+ /* Ignore NULLs for ANY and keep them for ALL subqueries */
+ if (cache->null_value)
+ return (is_all && !maxmin->null_value) || (!is_all && maxmin->null_value);
+ if (maxmin->null_value)
+ return !is_all;
+
+ if (fmax)
+ return(val1 > val2);
+ return (val1 < val2);
+}
+
bool select_max_min_finder_subselect::cmp_decimal()
{
Item *maxmin= ((Item_singlerow_subselect *)item)->element_index(0);
@@ -3736,7 +3758,7 @@ bool select_max_min_finder_subselect::cmp_str()
but added for safety
*/
val1= cache->val_str(&buf1);
- val2= maxmin->val_str(&buf1);
+ val2= maxmin->val_str(&buf2);
/* Ignore NULLs for ANY and keep them for ALL subqueries */
if (cache->null_value)