Bug #8871 current_time returns incorrect value if called from a stored function
Submitted: 1 Mar 2005 18:12 Modified: 7 Sep 2005 19:14
Reporter: Sergei Golubchik Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.3 OS:
Assigned to: Assigned Account CPU Architecture:Any

[1 Mar 2005 18:12] Sergei Golubchik
Description:
current_time returns incorrect value if called from a stored function

How to repeat:
create table t1 (a int); insert t1 values (1),(1);
create function sub3() returns timestamp return current_timestamp();
select benchmark(100, sha1(repeat(rand(), 10000))), current_timestamp,sub3() from t1;
[7 Mar 2005 7:32] Sergei Golubchik
Hmm, or is the behaviour correct ?
After all,"'RETURNS" above is "intervening <SQL procedure statement>"
[7 Sep 2005 15:16] Alexander Nozdrin
mysql> select benchmark(100, sha1(repeat(rand(), 10000))), current_timestamp,sub3() from t1;
+---------------------------------------------+---------------------+---------------------+
| benchmark(100, sha1(repeat(rand(), 10000))) | current_timestamp   | sub3()              |
+---------------------------------------------+---------------------+---------------------+
|                                           0 | 2005-09-07 15:20:55 | 2005-09-07 15:20:55 |
|                                           0 | 2005-09-07 15:20:55 | 2005-09-07 15:20:55 |
+---------------------------------------------+---------------------+---------------------+
2 rows in set (1.59 sec)

Should this output be considered as wrong? I.e. should timestamps be different?
[7 Sep 2005 19:13] Alexander Nozdrin
This bug is related to Bug#12480: NOW() is not constant in a trigger.
According to ANSI SQL NOW() in a trigger and all functions the triggers calls
needs to evaluate to the start time of the statement that caused the trigger to
invoke.
[7 Sep 2005 19:16] Alexander Nozdrin
Also, Bug#12481 is related.