From bd414485de627818a8fd28fc00887d919d4e0ae1 Mon Sep 17 00:00:00 2001 From: Ramil Kalimullin Date: Tue, 24 Feb 2009 18:47:12 +0400 Subject: Fix for bug#42009: SELECT into variable gives different results to direct SELECT Problem: storing "SELECT ... INTO @var ..." results in variables we used val_xxx() methods which returned results of the current row. So, in some cases (e.g. SELECT DISTINCT, GROUP BY or HAVING) we got data from the first row of a new group (where we evaluate a clause) instead of data from the last row of the previous group. Fix: use val_xxx_result() counterparts to get proper results. mysql-test/r/distinct.result: Fix for bug#42009: SELECT into variable gives different results to direct SELECT - results adjusted. mysql-test/r/user_var.result: Fix for bug#42009: SELECT into variable gives different results to direct SELECT - test result. mysql-test/t/user_var.test: Fix for bug#42009: SELECT into variable gives different results to direct SELECT - test case. sql/item_func.cc: Fix for bug#42009: SELECT into variable gives different results to direct SELECT - Item_func_set_user_var::save_item_result() added to evaluate and store an item's result into a user variable. sql/item_func.h: Fix for bug#42009: SELECT into variable gives different results to direct SELECT - Item_func_set_user_var::save_item_result() added to evaluate and store an item's result into a user variable. sql/sql_class.cc: Fix for bug#42009: SELECT into variable gives different results to direct SELECT - use Item_func_set_user_var::save_item_result() to store results into user variables. --- mysql-test/t/user_var.test | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'mysql-test/t/user_var.test') diff --git a/mysql-test/t/user_var.test b/mysql-test/t/user_var.test index 3a3e8f88f83..d39b49a0e87 100644 --- a/mysql-test/t/user_var.test +++ b/mysql-test/t/user_var.test @@ -237,3 +237,15 @@ select @a:=f2, count(f2) from t1 group by 1 desc; select @a:=f3, count(f3) from t1 group by 1 desc; select @a:=f4, count(f4) from t1 group by 1 desc; drop table t1; + +# +# Bug#42009: SELECT into variable gives different results to direct SELECT +# +CREATE TABLE t1(a INT, b INT); +INSERT INTO t1 VALUES (0, 0), (2, 1), (2, 3), (1, 1), (30, 20); +SELECT a, b INTO @a, @b FROM t1 WHERE a=2 AND b=3 GROUP BY a, b; +SELECT @a, @b; +SELECT a, b FROM t1 WHERE a=2 AND b=3 GROUP BY a, b; +DROP TABLE t1; + +--echo End of 5.0 tests -- cgit v1.2.1