From: Date: March 10 2006 11:53am Subject: bk commit into 5.0 tree (evgen:1.2085) BUG#13575 List-Archive: http://lists.mysql.com/commits/3692 X-Bug: 13575 Message-Id: <20060310105305.3802E241B3@moonbone.moonbone.local> 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.2085 06/03/10 13:53:00 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. sql/item_func.h 1.136 06/03/10 13:52:00 evgen@stripped +13 -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. mysql-test/r/sp.result 1.192 06/03/10 13:51:25 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.180 06/03/10 13:50:29 evgen@stripped +16 -0 Added test case for bug#13575: SP funcs in select with distinct/group and order by can produce wrong data # 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-10 13:52:00 +03:00 @@ -1421,9 +1421,21 @@ String *val_str(String *str) { + String buf; + char buff[20]; + buf.set(buff, 20, str->charset()); + buf.length(0); 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.191/mysql-test/r/sp.result 2006-03-09 15:11:33 +03:00 +++ 1.192/mysql-test/r/sp.result 2006-03-10 13:51:25 +03:00 @@ -4786,4 +4786,20 @@ 0 drop table t3| drop procedure bug16887| +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.179/mysql-test/t/sp.test 2006-03-09 15:11:33 +03:00 +++ 1.180/mysql-test/t/sp.test 2006-03-10 13:50:29 +03:00 @@ -5630,6 +5630,22 @@ drop table t3| drop procedure bug16887| +# +# 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