Description:
Incorrect results are obtained using the least() function in an interval statement where one of the values is a very large number,
mysql> select '2003-10-17 12:00:46' + interval least(3600, 9223372036854775808.0) second;
+----------------------------------------------------------------------------+
| '2003-10-17 12:00:46' + interval least(3600, 9223372036854775808.0) second |
+----------------------------------------------------------------------------+
| 2003-10-17 12:00:46 |
+----------------------------------------------------------------------------+
This query should return 2003-10-17 13:00:46.
How to repeat:
The simplified replication is in the description. The following starts with the query I'm really trying to execute, and simplifies it to the query listed in the description:
The following works correctly:
mysql> select '2003-10-17 12:00:46' + interval least(3600, power(2,62)) second;
+------------------------------------------------------------------+
| '2003-10-17 12:00:46' + interval least(3600, power(2,62)) second |
+------------------------------------------------------------------+
| 2003-10-17 13:00:46 |
+------------------------------------------------------------------+
1 row in set (0.02 sec)
but then I change to 63... and...
mysql> select '2003-10-17 12:00:46' + interval least(3600, power(2,63)) second;
+------------------------------------------------------------------+
| '2003-10-17 12:00:46' + interval least(3600, power(2,63)) second |
+------------------------------------------------------------------+
| 2003-10-17 12:00:46 |
+------------------------------------------------------------------+
1 row in set (0.03 sec)
it doesn't add anything to the time.
ok, break it down:
mysql> select least(3600, power(2,62));
+--------------------------+
| least(3600, power(2,62)) |
+--------------------------+
| 3600.000000 |
+--------------------------+
1 row in set (0.01 sec)
thats ok, try:
mysql> select least(3600, power(2,63));
+--------------------------+
| least(3600, power(2,63)) |
+--------------------------+
| 3600.000000 |
+--------------------------+
1 row in set (0.01 sec)
still ok. But as soon as I stick that least() into the interval, it fails to behave correctly. Including the output from power(2,63) into the least directly also fails to work properly.
I can only guess that there is some improper type conversion going on somewhere, but types and implicit type conversion in mysql doesn't appear to be well documented.