List:Commits« Previous MessageNext Message »
From:eugene Date:May 4 2007 7:38pm
Subject:bk commit into 5.0 tree (evgen:1.2475)
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of evgen. When evgen does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet@stripped, 2007-05-04 21:38:05+04:00, evgen@stripped +1 -0
  Merge epotemkin@stripped:/home/bk/mysql-5.0-opt
  into  moonbone.local:/mnt/gentoo64/work/27759-bug-5.0-opt-mysql
  MERGE: 1.2469.2.1

  sql/item_func.cc@stripped, 2007-05-04 21:38:03+04:00, evgen@stripped +0 -0
    Auto merged
    MERGE: 1.334.1.1

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	evgen
# Host:	moonbone.local
# Root:	/mnt/gentoo64/work/27759-bug-5.0-opt-mysql/RESYNC

--- 1.335/sql/item_func.cc	2007-05-04 12:27:20.000000000 +0400
+++ 1.336/sql/item_func.cc	2007-05-04 21:38:03.000000000 +0400
@@ -2122,6 +2122,7 @@
 void Item_func_min_max::fix_length_and_dec()
 {
   int max_int_part=0;
+  bool datetime_found= FALSE;
   decimals=0;
   max_length=0;
   maybe_null=0;
@@ -2135,18 +2136,88 @@
     if (args[i]->maybe_null)
       maybe_null=1;
     cmp_type=item_cmp_type(cmp_type,args[i]->result_type());
+    if (args[i]->result_type() != ROW_RESULT && args[i]->is_datetime())
+    {
+      datetime_found= TRUE;
+      if (!datetime_item || args[i]->field_type() == MYSQL_TYPE_DATETIME)
+        datetime_item= args[i];
+    }
   }
   if (cmp_type == STRING_RESULT)
+  {
     agg_arg_charsets(collation, args, arg_count, MY_COLL_CMP_CONV, 1);
+    if (datetime_found)
+    {
+      thd= current_thd;
+      compare_as_dates= TRUE;
+    }
+  }
   else if ((cmp_type == DECIMAL_RESULT) || (cmp_type == INT_RESULT))
     max_length= my_decimal_precision_to_length(max_int_part+decimals, decimals,
                                             unsigned_flag);
 }
 
 
+/*
+  Compare item arguments in the DATETIME context.
+
+  SYNOPSIS
+    cmp_datetimes()
+    value [out]   found least/greatest DATE/DATETIME value
+
+  DESCRIPTION
+    Compare item arguments as DATETIME values and return the index of the
+    least/greatest argument in the arguments array.
+    The correct integer DATE/DATETIME value of the found argument is
+    stored to the value pointer, if latter is provided.
+
+  RETURN
+   0	If one of arguments is NULL
+   #	index of the least/greatest argument
+*/
+
+uint Item_func_min_max::cmp_datetimes(ulonglong *value)
+{
+  ulonglong min_max;
+  uint min_max_idx= 0;
+  LINT_INIT(min_max);
+
+  for (uint i=0; i < arg_count ; i++)
+  {
+    Item **arg= args + i;
+    bool is_null;
+    ulonglong res= get_datetime_value(thd, &arg, 0, datetime_item, &is_null);
+    if ((null_value= args[i]->null_value))
+      return 0;
+    if (i == 0 || (res < min_max ? cmp_sign : -cmp_sign) > 0)
+    {
+      min_max= res;
+      min_max_idx= i;
+    }
+  }
+  if (value)
+  {
+    *value= min_max;
+    if (datetime_item->field_type() == MYSQL_TYPE_DATE)
+      *value/= 1000000L;
+  }
+  return min_max_idx;
+}
+
+
 String *Item_func_min_max::val_str(String *str)
 {
   DBUG_ASSERT(fixed == 1);
+  if (compare_as_dates)
+  {
+    String *str_res;
+    uint min_max_idx= cmp_datetimes(NULL);
+    if (null_value)
+      return 0;
+    str_res= args[min_max_idx]->val_str(str);
+    str_res->set_charset(collation.collation);
+    return str_res;
+  }
   switch (cmp_type) {
   case INT_RESULT:
   {
@@ -2214,6 +2285,12 @@
 {
   DBUG_ASSERT(fixed == 1);
   double value=0.0;
+  if (compare_as_dates)
+  {
+    ulonglong result;
+    (void)cmp_datetimes(&result);
+    return (double)result;
+  }
   for (uint i=0; i < arg_count ; i++)
   {
     if (i == 0)
@@ -2235,6 +2312,12 @@
 {
   DBUG_ASSERT(fixed == 1);
   longlong value=0;
+  if (compare_as_dates)
+  {
+    ulonglong result;
+    (void)cmp_datetimes(&result);
+    return (longlong)result;
+  }
   for (uint i=0; i < arg_count ; i++)
   {
     if (i == 0)
@@ -2258,6 +2341,13 @@
   my_decimal tmp_buf, *tmp, *res;
   LINT_INIT(res);
 
+  if (compare_as_dates)
+  {
+    ulonglong value;
+    (void)cmp_datetimes(&value);
+    ulonglong2decimal(value, dec);
+    return dec;
+  }
   for (uint i=0; i < arg_count ; i++)
   {
     if (i == 0)
Thread
bk commit into 5.0 tree (evgen:1.2475)eugene4 May