From: Date: May 25 2006 11:24pm Subject: bk commit into 4.1 tree (evgen:1.2485) BUG#16716 List-Archive: http://lists.mysql.com/commits/6892 X-Bug: 16716 Message-Id: <20060525212419.3A56522D147@moonbone.moonbone.local> Below is the list of changes that have just been committed into a local 4.1 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.2485 06/05/26 01:24:14 evgen@stripped +3 -0 Fixed bug#16716: subselect in concat() may lead to a wrong result. The Item_func_concat::val_str() function tries to make as less re-allocations as possible. This results in appending strings returned by 2nd and next arguments to the string returned by 1st argument if the buffer for the first argument has enough free space. A constant subselect is evaluated only once and its result is stored in an Item_cache_str. In the case when the first argument of the concat() function is such a subselect Item_cache_str returns the stored value and Item_func_concat::val_str() append values of other arguments to it. But for the next row the value in the Item_cache_str isn't restored because the subselect is a constant one and it isn't evaluated second time. This results in appending string values of 2nd and next arguments to the result of the previous Item_func_concat::val_str() call. The Item_func_concat::val_str() function now checks whether the first argument is a constant one and if so it doesn't append values of 2nd and next arguments to the string value returned by it. sql/item_strfunc.cc 1.242 06/05/26 01:23:02 evgen@stripped +4 -1 Fixed bug#16716: subselect in concat() may lead to a wrong result. The Item_func_concat::val_str() function now checks whether the first argument is a constant one and if so it doesn't append values of 2nd and next arguments to the string value returned by it. mysql-test/r/func_concat.result 1.8 06/05/26 01:22:52 evgen@stripped +7 -0 Added test case for bug#16716: subselect in concat() may lead to a wrong result. mysql-test/t/func_concat.test 1.9 06/05/26 01:22:03 evgen@stripped +7 -0 Added test case for bug#16716: subselect in concat() may lead to a wrong result. # 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/16716-bug-4.1-mysql --- 1.241/sql/item_strfunc.cc 2006-05-08 05:39:19 +04:00 +++ 1.242/sql/item_strfunc.cc 2006-05-26 01:23:02 +04:00 @@ -252,11 +252,13 @@ DBUG_ASSERT(fixed == 1); String *res,*res2,*use_as_buff; uint i; + bool is_const= 0; null_value=0; if (!(res=args[0]->val_str(str))) goto null; use_as_buff= &tmp_value; + is_const= args[0]->const_item(); for (i=1 ; i < arg_count ; i++) { if (res->length() == 0) @@ -279,7 +281,7 @@ current_thd->variables.max_allowed_packet); goto null; } - if (res->alloced_length() >= res->length()+res2->length()) + if (!is_const && res->alloced_length() >= res->length()+res2->length()) { // Use old buffer res->append(*res2); } @@ -334,6 +336,7 @@ res= &tmp_value; use_as_buff=str; } + is_const= 0; } } res->set_charset(collation.collation); --- 1.7/mysql-test/r/func_concat.result 2004-12-30 14:56:02 +03:00 +++ 1.8/mysql-test/r/func_concat.result 2006-05-26 01:22:52 +04:00 @@ -64,3 +64,10 @@ a a good +select concat((select x from (select 'a' as x) as t1 ), +(select y from (select 'b' as y) as t2 )) from (select 1 union select 2 ) +as t3; +concat((select x from (select 'a' as x) as t1 ), +(select y from (select 'b' as y) as t2 )) +ab +ab --- 1.8/mysql-test/t/func_concat.test 2005-09-15 18:17:12 +04:00 +++ 1.9/mysql-test/t/func_concat.test 2006-05-26 01:22:03 +04:00 @@ -50,4 +50,11 @@ --replace_result 'a-0.0' good 'a0.0' good select 'a' union select concat('a', -0.0); +# +# Bug#16716: subselect in concat() may lead to a wrong result +# +select concat((select x from (select 'a' as x) as t1 ), + (select y from (select 'b' as y) as t2 )) from (select 1 union select 2 ) + as t3; + # End of 4.1 tests