Commit 948bb77d authored by unknown's avatar unknown
Browse files

Fixed BUG#6857: current_time() in STORED PROCEDURES

  Have to thd->set_time() before each substatement execution, to make
  current_time() et al return different times within the same procedure.


mysql-test/r/sp.result:
  New test case for BUG#6857: current_time() in STORED PROCEDURES.
  Note: The actual call is disable, to save time when running with slow debugging tools.
mysql-test/t/sp.test:
  New test case for BUG#6857: current_time() in STORED PROCEDURES.
  Note: The actual call is disable, to save time when running with slow debugging tools.
sql/sp_head.cc:
  Make current_time() et all work in stored procedures.
parent f46729c2
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -2158,6 +2158,22 @@ call bug8116(42)|
userid
drop procedure bug8116|
drop table t3|
drop procedure if exists bug6857|
create procedure bug6857(counter int)
begin
declare t0, t1 int;
declare plus bool default 0;
set t0 = current_time();
while counter > 0 do
set counter = counter - 1;
end while;
set t1 = current_time();
if t1 > t0 then
set plus = 1;
end if;
select plus;
end|
drop procedure bug6857|
drop table if exists fac|
create table fac (n int unsigned not null primary key, f bigint unsigned)|
drop procedure if exists ifac|
+31 −0
Original line number Diff line number Diff line
@@ -2645,6 +2645,37 @@ call bug8116(42)|
drop procedure bug8116|
drop table t3|

#
# BUG#6857: current_time() in STORED PROCEDURES
#
--disable_warnings
drop procedure if exists bug6857|
--enable_warnings
create procedure bug6857(counter int)
begin
  declare t0, t1 int;
  declare plus bool default 0;

  set t0 = current_time();
  while counter > 0 do
    set counter = counter - 1;
  end while;
  set t1 = current_time();
  if t1 > t0 then
    set plus = 1;
  end if;
  select plus;
end|

# QQ: This is currently disabled. Not only does it slow down a normal test
#     run, it makes running with valgrind (or similar tools) extremely
#     painful.
# Make sure this takes at least one second on all machines in all builds.
# 30000 makes it about 3 seconds on an old 1.1GHz linux.
#call bug6857(300000)|

drop procedure bug6857|


#
# Some "real" examples
+1 −0
Original line number Diff line number Diff line
@@ -503,6 +503,7 @@ sp_head::execute(THD *thd)
    if (i == NULL)
      break;
    DBUG_PRINT("execute", ("Instruction %u", ip));
    thd->set_time();		// Make current_time() et al work
    ret= i->execute(thd, &ip);
    thd->rollback_item_tree_changes();
    if (i->free_list)