MySQL Lists are EOL. Please join:

List:Internals« Previous MessageNext Message »
From:Jim Winstead Date:August 19 2005 10:51pm
Subject:bk commit into 5.0 tree (jimw:1.2001) BUG#12689
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of jimw. When jimw 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
  1.2001 05/08/19 15:51:40 jimw@stripped +4 -0
  Fix cases where SLEEP() calls would get optimized away or cached. (Bug #12689)

  sql/item_func.h
    1.127 05/08/19 15:51:36 jimw@stripped +6 -0
    Flag SLEEP() as not constant, and set RAND_TABLE_BIT so that it is
    always evaluated.

  sql/item_create.cc
    1.56 05/08/19 15:51:35 jimw@stripped +1 -0
    When SLEEP() is used, mark the statement as uncacheable.

  mysql-test/t/func_misc.test
    1.15 05/08/19 15:51:35 jimw@stripped +23 -0
    Add new regression test.

  mysql-test/r/func_misc.result
    1.20 05/08/19 15:51:35 jimw@stripped +24 -0
    Add new results

# 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:	jimw
# Host:	rama.(none)
# Root:	/home/jimw/my/mysql-5.0-12689

--- 1.55/sql/item_create.cc	2005-08-11 18:58:18 -07:00
+++ 1.56/sql/item_create.cc	2005-08-19 15:51:35 -07:00
@@ -356,6 +356,7 @@
 
 Item *create_func_sleep(Item* a)
 {
+  current_thd->lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
   return new Item_func_sleep(a);
 }
 

--- 1.126/sql/item_func.h	2005-08-11 18:58:18 -07:00
+++ 1.127/sql/item_func.h	2005-08-19 15:51:36 -07:00
@@ -893,7 +893,13 @@
 {
 public:
   Item_func_sleep(Item *a) :Item_int_func(a) {}
+  bool const_item() const { return 0; }
   const char *func_name() const { return "sleep"; }
+  void update_used_tables()
+  {
+    Item_int_func::update_used_tables();
+    used_tables_cache|= RAND_TABLE_BIT;
+  }
   longlong val_int();
 };
 

--- 1.19/mysql-test/r/func_misc.result	2005-08-11 18:58:18 -07:00
+++ 1.20/mysql-test/r/func_misc.result	2005-08-19 15:51:35 -07:00
@@ -70,3 +70,27 @@
 timediff(b, a) >= '00:00:03'
 1
 drop table t1;
+set global query_cache_size=1355776;
+create table t1 (a int);
+insert into t1 values (1),(1),(1);
+create table t2 (a datetime default null, b datetime default null);
+insert into t2 set a = now();
+select a from t1 where sleep(1);
+a
+update t2 set b = now() where b is null;
+insert into t2 set a = now();
+select a from t1 where sleep(a);
+a
+update t2 set b = now() where b is null;
+insert into t2 set a = now();
+select a from t1 where sleep(1);
+a
+update t2 set b = now() where b is null;
+select timediff(b, a) >= '00:00:03' from t2;
+timediff(b, a) >= '00:00:03'
+1
+1
+1
+drop table t2;
+drop table t1;
+set global query_cache_size=default;

--- 1.14/mysql-test/t/func_misc.test	2005-08-11 18:58:18 -07:00
+++ 1.15/mysql-test/t/func_misc.test	2005-08-19 15:51:35 -07:00
@@ -55,3 +55,26 @@
 update t1 set b = now();
 select timediff(b, a) >= '00:00:03' from t1;
 drop table t1;
+
+#
+# Bug #12689: SLEEP() gets incorrectly cached/optimized-away
+#
+set global query_cache_size=1355776;
+create table t1 (a int);
+insert into t1 values (1),(1),(1);
+create table t2 (a datetime default null, b datetime default null);
+insert into t2 set a = now();
+select a from t1 where sleep(1);
+update t2 set b = now() where b is null;
+insert into t2 set a = now();
+select a from t1 where sleep(a);
+update t2 set b = now() where b is null;
+insert into t2 set a = now();
+select a from t1 where sleep(1);
+update t2 set b = now() where b is null;
+select timediff(b, a) >= '00:00:03' from t2;
+drop table t2;
+drop table t1;
+set global query_cache_size=default;
+
+# End of 5.0 tests
Thread
bk commit into 5.0 tree (jimw:1.2001) BUG#12689Jim Winstead20 Aug