MySQL Lists are EOL. Please join:

List:Commits« Previous MessageNext Message »
From:eugene Date:March 6 2006 2:08pm
Subject:bk commit into 5.0 tree (evgen:1.2050) BUG#13575
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of evgen. When evgen 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.2050 06/03/06 17:08:20 evgen@stripped +3 -0
  Fixed bug#13575: SP funcs in select with distinct/group and order by can
  produce wrong data
  
  By default Item_sp_func::val_str() returns string from it's result_field 
  internal buffer. When grouping is present Item_copy_string is used to 
  store SP function result, but it doesn't additionally buffer the result.
  When the next record is read, internal buffer is overwritten, due to
  this Item_copy_string::val_str() will have wrong data. Thus producing
  weird query result.
  
  The Item_func_sp::val_str() now makes a copy of returned value to prevent
  occasional corruption.

  mysql-test/r/sp.result
    1.186 06/03/06 17:05:52 evgen@stripped +16 -0
    Added test case for bug#13575: SP funcs in select with distinct/group and
    order by can produce wrong data

  mysql-test/t/sp.test
    1.175 06/03/06 17:05:42 evgen@stripped +16 -0
    Added test case for bug#13575: SP funcs in select with distinct/group and order by can produce wrong data

  sql/item_func.h
    1.136 06/03/06 17:03:37 evgen@stripped +10 -1
    Fixed bug#13575: SP funcs in select with distinct/group and order by can
    produce wrong data
    The Item_func_sp::val_str() now makes a copy of returned value to prevent
    occasinal corruption.

# 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:	evgen
# Host:	moonbone.local
# Root:	/work/13575-bug-5.0-mysql

--- 1.135/sql/item_func.h	2006-02-07 14:29:59 +03:00
+++ 1.136/sql/item_func.h	2006-03-06 17:03:37 +03:00
@@ -1421,9 +1421,18 @@
 
   String *val_str(String *str)
   {
+    String buf;
     if (execute(&result_field))
       return NULL;
-    return result_field->val_str(str);
+    /*
+      result_field will set buf pointing to internal buffer
+      of the resul_field. Due to this it will change any time
+      when SP is executed. In order to prevent occasional
+      corruption of returned value, we make here a copy.
+    */
+    result_field->val_str(&buf);
+    str->copy(buf);
+    return str;
   }
 
   virtual bool change_context_processor(byte *cntx)

--- 1.185/mysql-test/r/sp.result	2006-02-06 16:09:07 +03:00
+++ 1.186/mysql-test/r/sp.result	2006-03-06 17:05:52 +03:00
@@ -4519,4 +4519,20 @@
 Inner
 drop procedure bug15011|
 drop table t3|
+create table t3 (f1 int, f2 varchar(3), primary key(f1)) engine=innodb|
+insert into t3 values (1,'aaa'),(2,'bbb'),(3,'ccc')|
+CREATE FUNCTION bug13575 ( p1 integer ) 
+returns varchar(3) 
+BEGIN 
+DECLARE v1 VARCHAR(10) DEFAULT null;
+SELECT f2 INTO v1 FROM t3 WHERE f1 = p1; 
+RETURN v1;
+END|
+select distinct f1, bug13575(f1) from t3 order by f1|
+f1	bug13575(f1)
+1	aaa
+2	bbb
+3	ccc
+drop function bug13575;
+drop table t3|
 drop table t1,t2;

--- 1.174/mysql-test/t/sp.test	2006-02-06 16:09:07 +03:00
+++ 1.175/mysql-test/t/sp.test	2006-03-06 17:05:42 +03:00
@@ -5310,6 +5310,22 @@
 drop procedure bug15011|
 drop table t3|
 
+#
+# Bug#13575 SP funcs in select with distinct/group and order by can
+#           produce bad data
+#
+create table t3 (f1 int, f2 varchar(3), primary key(f1)) engine=innodb|
+insert into t3 values (1,'aaa'),(2,'bbb'),(3,'ccc')|
+CREATE FUNCTION bug13575 ( p1 integer ) 
+returns varchar(3) 
+BEGIN 
+DECLARE v1 VARCHAR(10) DEFAULT null;
+SELECT f2 INTO v1 FROM t3 WHERE f1 = p1; 
+RETURN v1;
+END|
+select distinct f1, bug13575(f1) from t3 order by f1|
+drop function bug13575;
+drop table t3|
 
 #
 # BUG#NNNN: New bug synopsis
Thread
bk commit into 5.0 tree (evgen:1.2050) BUG#13575eugene6 Mar