List:Internals« Previous MessageNext Message »
From:konstantin Date:April 15 2005 9:21pm
Subject:bk commit into 4.1 tree (konstantin:1.2188)
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 repository of kostja. When kostja 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.2188 05/04/15 14:21:34 konstantin@stripped +4 -0
  Implement SLEEP() function in SQL. This function is similar to RAND
  in the sense that it marks the query which uses it as uncacheable.
  Just like RAND it's evaluated for every result set row.
  The function tries to sleep given number of seconds and returns 0 if 
  the requested time has expired, or number of seconds left to sleep 
  otherwise. The implementation uses POSIX sleep() call.
  This is a request for review.

  sql/sql_yacc.yy
    1.382 05/04/15 14:21:30 konstantin@stripped +8 -0
    Parser support for Item_func_sleep

  sql/lex.h
    1.148 05/04/15 14:21:30 konstantin@stripped +1 -0
    Lexer support for SLEEP symbol

  sql/item_func.h
    1.122 05/04/15 14:21:30 konstantin@stripped +23 -0
    Declaration of class Item_func_sleep

  sql/item_func.cc
    1.239 05/04/15 14:21:30 konstantin@stripped +7 -0
    Implementation of Item_func_sleep::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:	konstantin
# Host:	dragonfly.local
# Root:	/media/sda1/mysql/mysql-4.1-func_sleep

--- 1.238/sql/item_func.cc	2005-03-28 01:01:53 -08:00
+++ 1.239/sql/item_func.cc	2005-04-15 14:21:30 -07:00
@@ -2287,6 +2287,13 @@
   return current_thd->insert_id();
 }
 
+
+longlong Item_func_sleep::val_int()
+{
+  DBUG_ASSERT(fixed == 1);
+  return (longlong) sleep(seconds);
+}
+
 /* This function is just used to test speed of different functions */
 
 longlong Item_func_benchmark::val_int()

--- 1.121/sql/item_func.h	2005-03-29 23:13:21 -08:00
+++ 1.122/sql/item_func.h	2005-04-15 14:21:30 -07:00
@@ -764,6 +764,29 @@
   void print(String *str);
 };
 
+/*
+  SLEEP(ulong_num) - sleep given number of seconds
+  Returns zero if requested time has elapsed, or the number of seconds
+  left to sleep.
+*/
+
+class Item_func_sleep: public Item_int_func
+{
+  uint seconds;
+public:
+  Item_func_sleep(uint seconds_arg, uint32 max_length_arg)
+    :seconds(seconds_arg)
+  {
+    max_length= max_length_arg;
+    maybe_null= 0;
+    used_tables_cache= RAND_TABLE_BIT;
+  }
+  void update_used_tables() { used_tables_cache= RAND_TABLE_BIT; }
+  const char *func_name() const { return "sleep"; }
+  bool const_item() const { return FALSE; }
+  longlong val_int();
+};
+
 
 #ifdef HAVE_DLOPEN
 

--- 1.147/sql/lex.h	2004-11-10 08:56:34 -08:00
+++ 1.148/sql/lex.h	2005-04-15 14:21:30 -07:00
@@ -653,6 +653,7 @@
   { "SIN",		F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sin)},
   { "SHA",              F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sha)},
   { "SHA1",             F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sha)},
+  { "SLEEP",            SYM(SLEEP_SYM)},
   { "SOUNDEX",		F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_soundex)},
   { "SPACE",		F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_space)},
   { "SQRT",		F_SYM(FUNC_ARG1),0,CREATE_FUNC(create_func_sqrt)},

--- 1.381/sql/sql_yacc.yy	2005-04-06 02:14:09 -07:00
+++ 1.382/sql/sql_yacc.yy	2005-04-15 14:21:30 -07:00
@@ -564,6 +564,7 @@
 %token	YEAR_SYM
 %token	YEARWEEK
 %token	BENCHMARK_SYM
+%token  SLEEP_SYM
 %token	END
 %token	THEN_SYM
 
@@ -3188,6 +3189,13 @@
 	| BENCHMARK_SYM '(' ULONG_NUM ',' expr ')'
 	  {
 	    $$=new Item_func_benchmark($3,$5);
+	    Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
+	  }
+	| SLEEP_SYM '(' NUM ')'
+	  {
+            int error;
+            uint seconds= (uint) my_strtoll10($3.str, (char**) 0, &error);
+	    $$= new Item_func_sleep(seconds, $3.length);
 	    Lex->uncacheable(UNCACHEABLE_SIDEEFFECT);
 	  }
 	| EXTRACT_SYM '(' interval FROM expr ')'
Thread
bk commit into 4.1 tree (konstantin:1.2188)konstantin15 Apr