List:Internals« Previous MessageNext Message »
From:sasha Date:August 16 2001 6:01pm
Subject:bk commit into 3.23 tree
View as plain text  
Below is the list of changes that have just been commited into a local
3.23. repository of sasha. When sasha does a push, they will be
propogaged to the main repository and within 24 hours after the push into
the public repository. For information on how to access
the public repository see
http://www.mysql.com/doc/I/n/Installing_source_tree.html

ChangeSet@stripped, 2001-08-16 12:01:35-06:00, sasha@stripped
  fixed bug in Item_func_div::val_int() that broke all functions that
  do val_int() on their arguments before starting the computation. 
  Similar fixes are need for +-* and probably several other but I want
  to make sure Monty is fine with my fix approach before changing a lot
  of code. 
  
  Amazingly,
  this bug is not as critical as you would expect since very few functions do val_int()
  on their arguments ( from_unixtime(), sec_to_time()), and those not
  very frequently perform a computation on their floating point arguments.
  which is probably why no one has yet reported this bug. Another 
  possibility is that the result is usually wrong by no more than 5%,
  which makes it hard to catch it. I found it when trying to compute mile
  splits for 30:47 10K - it told me 5:07, and I knew it was wrong because
  5:00 mile gives you 31:08. However, if I had not run as many 10K races,
  I would have easily believed that 30:47 10K is a 5:07 mile pace and 
  would not have noticed the bug.

  mysql-test/r/func_time.result
    1.7 01/08/16 12:01:34 sasha@stripped +2 -2
    another test for sec_to_time that exposes a long outstanding bug

  mysql-test/t/func_time.test
    1.7 01/08/16 12:01:34 sasha@stripped +2 -1
    another test for sec_to_time that exposes a long outstanding bug

  sql/item_func.cc
    1.38 01/08/16 12:01:34 sasha@stripped +8 -5
    fixed bug in Item_func_div::val_int() 

# 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:	sasha
# Host:	mysql.sashanet.com
# Root:	/home/sasha/src/bk/mysql

--- 1.37/sql/item_func.cc	Fri Aug  3 15:09:21 2001
+++ 1.38/sql/item_func.cc	Thu Aug 16 12:01:34 2001
@@ -309,11 +309,14 @@
 
 longlong Item_func_div::val_int()
 {
-  longlong value=args[0]->val_int();
-  longlong val2=args[1]->val_int();
-  if ((null_value= val2 == 0 || args[0]->null_value || args[1]->null_value))
-    return 0;
-  return value/val2;
+  // the integer result of division of two arguments needs to be computed
+  // as a type-cast division of val(), not as diviion of val_int() of each
+  // argument. For example, val_int(41.5/3.4) = val_int(12.206) = 12, but
+  // if you do val_int(41.5)/val_int(3.4), as in the old code, we get 42/3=
+  // 14, which is wrong. This would break sec_to_time(a/b),
+  // from_unixtime(a/b), and
+  // all functions that do val_int() on their arguments
+  return (longlong)val();
 }
 
 void Item_func_div::fix_length_and_dec()

--- 1.6/mysql-test/r/func_time.result	Tue May 22 17:32:52 2001
+++ 1.7/mysql-test/r/func_time.result	Thu Aug 16 12:01:34 2001
@@ -6,8 +6,8 @@
 0	0	0
 from_unixtime(unix_timestamp("1994-03-02 10:11:12"))	from_unixtime(unix_timestamp("1994-03-02 10:11:12"),"%Y-%m-%d %h:%i:%s")	from_unixtime(unix_timestamp("1994-03-02 10:11:12"))+0
 1994-03-02 10:11:12	1994-03-02 10:11:12	19940302101112
-sec_to_time(9001)	sec_to_time(9001)+0	time_to_sec("15:12:22")
-02:30:01	23001	54742
+sec_to_time(9001)	sec_to_time(9001)+0	time_to_sec("15:12:22")	sec_to_time(time_to_sec("0:30:47")/6.21)
+02:30:01	23001	54742	00:04:57
 now()-curdate()*1000000-curtime()
 0
 strcmp(current_timestamp(),concat(current_date()," ",current_time()))

--- 1.6/mysql-test/t/func_time.test	Tue May 22 17:32:52 2001
+++ 1.7/mysql-test/t/func_time.test	Thu Aug 16 12:01:34 2001
@@ -7,7 +7,8 @@
 select period_add("9602",-12),period_diff(199505,"9404") ;
 select now()-now(),weekday(curdate())-weekday(now()),unix_timestamp()-unix_timestamp(now());
 select from_unixtime(unix_timestamp("1994-03-02 10:11:12")),from_unixtime(unix_timestamp("1994-03-02 10:11:12"),"%Y-%m-%d %h:%i:%s"),from_unixtime(unix_timestamp("1994-03-02 10:11:12"))+0;
-select sec_to_time(9001),sec_to_time(9001)+0,time_to_sec("15:12:22");
+select sec_to_time(9001),sec_to_time(9001)+0,time_to_sec("15:12:22"),
+  sec_to_time(time_to_sec("0:30:47")/6.21);
 select now()-curdate()*1000000-curtime();
 select strcmp(current_timestamp(),concat(current_date()," ",current_time()));
 select date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w");
Thread
bk commit into 3.23 treesasha16 Aug