List:Commits« Previous MessageNext Message »
From:Ignacio Galarza Date:July 25 2006 8:19pm
Subject:bk commit into 5.0 tree (iggy:1.2238) BUG#19792
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of iggy. When iggy 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@stripped, 2006-07-25 16:19:32-04:00, iggy@stripped +5 -0
  Bug #19792 With ORDER BY RAND() updated variable values are not visible in query results.
  
  When a user variable is set within a select statement, that variable is now considered to be non-const through the entire statement.

  mysql-test/r/user_var.result@stripped, 2006-07-25 16:19:25-04:00, iggy@stripped +62 -2
    Added results and corrected incorrect results.

  mysql-test/t/user_var.test@stripped, 2006-07-25 16:19:25-04:00, iggy@stripped +22 -0
    Added test.

  sql/item_func.cc@stripped, 2006-07-25 16:19:25-04:00, iggy@stripped +18 -1
    Added constructor and destructor to the Item_func_set_user_var object to control the user_var_entry->midupdate flag.
    Changed the const_item() criteria to use the new midupdate flag.

  sql/item_func.h@stripped, 2006-07-25 16:19:25-04:00, iggy@stripped +2 -3
    Added constructor and desctructor.

  sql/sql_class.h@stripped, 2006-07-25 16:19:25-04:00, iggy@stripped +2 -1
    Added mid_update attribute to the user_var_entry object.  This flag will be used but the Item_func_set_user_var object to make all instances of that user_var non-const.

# 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:	iggy
# Host:	rolltop.ignatz42.dyndns.org
# Root:	/mnt/storeage/mysql-5.0-maint_bug19792

--- 1.294/sql/item_func.cc	2006-07-25 16:19:38 -04:00
+++ 1.295/sql/item_func.cc	2006-07-25 16:19:38 -04:00
@@ -3429,6 +3429,23 @@
   return entry;
 }
 
+Item_func_set_user_var::
+Item_func_set_user_var(LEX_STRING a, Item *b)
+  :Item_func(b), cached_result_type(INT_RESULT), name(a)
+{
+  THD *thd= current_thd;
+  if (entry= get_variable(&current_thd->user_vars, name, 0))
+      entry->mid_update= 1;
+}
+
+Item_func_set_user_var::
+~Item_func_set_user_var()
+{
+  THD *thd= current_thd;
+  if (entry= get_variable(&current_thd->user_vars, name, 0))
+      entry->mid_update= 0;
+}
+
 /*
   When a user variable is updated (in a SET command or a query like
   SELECT @a:= ).
@@ -4090,7 +4107,7 @@
 
 bool Item_func_get_user_var::const_item() const
 {
-  return (!var_entry || current_thd->query_id != var_entry->update_query_id);
+  return (!var_entry || (!var_entry->mid_update && current_thd->query_id != var_entry->update_query_id));
 }
 
 

--- 1.143/sql/item_func.h	2006-07-25 16:19:38 -04:00
+++ 1.144/sql/item_func.h	2006-07-25 16:19:38 -04:00
@@ -1160,9 +1160,8 @@
 
 public:
   LEX_STRING name; // keep it public
-  Item_func_set_user_var(LEX_STRING a,Item *b)
-    :Item_func(b), cached_result_type(INT_RESULT), name(a)
-  {}
+  Item_func_set_user_var(LEX_STRING a, Item *b);
+  ~Item_func_set_user_var();
   double val_real();
   longlong val_int();
   String *val_str(String *str);

--- 1.290/sql/sql_class.h	2006-07-25 16:19:38 -04:00
+++ 1.291/sql/sql_class.h	2006-07-25 16:19:38 -04:00
@@ -1995,13 +1995,14 @@
 class user_var_entry
 {
  public:
-  user_var_entry() {}                         /* Remove gcc warning */
+  user_var_entry():mid_update(0) {}            /* Remove gcc warning */
   LEX_STRING name;
   char *value;
   ulong length;
   query_id_t update_query_id, used_query_id;
   Item_result type;
   bool unsigned_flag;
+  bool mid_update;                             /* Used to declare changing items non-const */
 
   double val_real(my_bool *null_value);
   longlong val_int(my_bool *null_value);

--- 1.39/mysql-test/r/user_var.result	2006-07-25 16:19:38 -04:00
+++ 1.40/mysql-test/r/user_var.result	2006-07-25 16:19:38 -04:00
@@ -121,8 +121,8 @@
 select @a+0, @a:=@a+0+count(*), count(*), @a+0 from t1 group by i;
 @a+0	@a:=@a+0+count(*)	count(*)	@a+0
 0	1	1	0
-1	3	2	0
-3	6	3	0
+0	2	2	0
+0	3	3	0
 set @a=0;
 select @a,@a:="hello",@a,@a:=3,@a,@a:="hello again" from t1 group by i;
 @a	@a:="hello"	@a	@a:=3	@a	@a:="hello again"
@@ -292,3 +292,63 @@
 @a
 18446744071710965857
 drop table bigfailure;
+DROP TABLE IF EXISTS t1;
+CREATE TABLE t1 (field1 INT);
+INSERT INTO t1 VALUES (2),(3),(5),(7),(11);
+"First 'mysqltest':"
+SET @varA = 1;
+SET @varB = 1;
+SELECT @varA AS f1, @varA := @varA + 1 AS f2, @varA := @varA + 2 AS f3, @varB := @varB + 2 AS s1, @varB := @varB + 4 AS s2, @varB := @varB + 6 AS s3 FROM t1;
+f1	f2	f3	s1	s2	s3
+1	2	4	3	7	13
+4	5	7	15	19	25
+7	8	10	27	31	37
+10	11	13	39	43	49
+13	14	16	51	55	61
+SET @varA = 1;
+SET @varB = 1;
+SELECT @varA AS f1, @varA := @varA + 1 AS f2, @varA := @varA + 2 AS f3, @varB := @varB + 2 AS s1, @varB := @varB + 4 AS s2, @varB := @varB + 6 AS s3 FROM t1 ORDER BY field1;
+f1	f2	f3	s1	s2	s3
+1	2	4	3	7	13
+4	5	7	15	19	25
+7	8	10	27	31	37
+10	11	13	39	43	49
+13	14	16	51	55	61
+SET @varA = 1;
+SET @varB = 1;
+SELECT @varA AS f1, @varA := @varA + 1 AS f2, @varA := @varA + 2 AS f3, @varB := @varB + 2 AS s1, @varB := @varB + 4 AS s2, @varB := @varB + 6 AS s3 FROM t1 ORDER BY RAND(1);
+f1	f2	f3	s1	s2	s3
+13	14	16	51	55	61
+10	11	13	39	43	49
+7	8	10	27	31	37
+1	2	4	3	7	13
+4	5	7	15	19	25
+Now 'mysql':
++------+------+------+------+------+------+
+| f1   | f2   | f3   | s1   | s2   | s3   |
++------+------+------+------+------+------+
+| 1    |    2 |    4 |    3 |    7 |   13 | 
+| 4    |    5 |    7 |   15 |   19 |   25 | 
+| 7    |    8 |   10 |   27 |   31 |   37 | 
+| 10   |   11 |   13 |   39 |   43 |   49 | 
+| 13   |   14 |   16 |   51 |   55 |   61 | 
++------+------+------+------+------+------+
++------+------+------+------+------+------+
+| f1   | f2   | f3   | s1   | s2   | s3   |
++------+------+------+------+------+------+
+| 1    |    2 |    4 |    3 |    7 |   13 | 
+| 4    |    5 |    7 |   15 |   19 |   25 | 
+| 7    |    8 |   10 |   27 |   31 |   37 | 
+| 10   |   11 |   13 |   39 |   43 |   49 | 
+| 13   |   14 |   16 |   51 |   55 |   61 | 
++------+------+------+------+------+------+
++------+------+------+------+------+------+
+| f1   | f2   | f3   | s1   | s2   | s3   |
++------+------+------+------+------+------+
+|   13 |   14 |   16 |   51 |   55 |   61 | 
+|   10 |   11 |   13 |   39 |   43 |   49 | 
+|    7 |    8 |   10 |   27 |   31 |   37 | 
+|    1 |    2 |    4 |    3 |    7 |   13 | 
+|    4 |    5 |    7 |   15 |   19 |   25 | 
++------+------+------+------+------+------+
+DROP TABLE t1;

--- 1.34/mysql-test/t/user_var.test	2006-07-25 16:19:38 -04:00
+++ 1.35/mysql-test/t/user_var.test	2006-07-25 16:19:38 -04:00
@@ -202,3 +202,25 @@
 SELECT @a;
 
 drop table bigfailure;
+
+#
+# Bug#19792: Sorting on a rand() column... unexpected results
+#
+--disable_warnings
+DROP TABLE IF EXISTS t1;
+--enable_warnings
+
+CREATE TABLE t1 (field1 INT);
+INSERT INTO t1 VALUES (2),(3),(5),(7),(11);
+
+echo "First 'mysqltest':";
+SET @varA = 1; SET @varB = 1; SELECT @varA AS f1, @varA := @varA + 1 AS f2, @varA := @varA + 2 AS f3, @varB := @varB + 2 AS s1, @varB := @varB + 4 AS s2, @varB := @varB + 6 AS s3 FROM t1;
+SET @varA = 1; SET @varB = 1; SELECT @varA AS f1, @varA := @varA + 1 AS f2, @varA := @varA + 2 AS f3, @varB := @varB + 2 AS s1, @varB := @varB + 4 AS s2, @varB := @varB + 6 AS s3 FROM t1 ORDER BY field1;
+SET @varA = 1; SET @varB = 1; SELECT @varA AS f1, @varA := @varA + 1 AS f2, @varA := @varA + 2 AS f3, @varB := @varB + 2 AS s1, @varB := @varB + 4 AS s2, @varB := @varB + 6 AS s3 FROM t1 ORDER BY RAND(1);
+
+--exec echo "Now 'mysql':"
+--exec $MYSQL test -t -e 'SET @varA = 1; SET @varB = 1; SELECT @varA AS f1, @varA := @varA + 1 AS f2, @varA := @varA + 2 AS f3, @varB := @varB + 2 AS s1, @varB := @varB + 4 AS s2, @varB := @varB + 6 AS s3 FROM t1;'
+--exec $MYSQL test -t -e 'SET @varA = 1; SET @varB = 1; SELECT @varA AS f1, @varA := @varA + 1 AS f2, @varA := @varA + 2 AS f3, @varB := @varB + 2 AS s1, @varB := @varB + 4 AS s2, @varB := @varB + 6 AS s3 FROM t1 ORDER BY field1;'
+--exec $MYSQL test -t -e 'SET @varA = 1; SET @varB = 1; SELECT @varA AS f1, @varA := @varA + 1 AS f2, @varA := @varA + 2 AS f3, @varB := @varB + 2 AS s1, @varB := @varB + 4 AS s2, @varB := @varB + 6 AS s3 FROM t1 ORDER BY RAND(1);'
+
+DROP TABLE t1;
Thread
bk commit into 5.0 tree (iggy:1.2238) BUG#19792Ignacio Galarza25 Jul