summaryrefslogtreecommitdiff
path: root/sql/item_func.cc
diff options
context:
space:
mode:
authorRamil Kalimullin <ramil@mysql.com>2009-02-24 18:47:12 +0400
committerRamil Kalimullin <ramil@mysql.com>2009-02-24 18:47:12 +0400
commitbd414485de627818a8fd28fc00887d919d4e0ae1 (patch)
tree098b599994037a5e7609851889db9e3952582d54 /sql/item_func.cc
parentfb20a7d6d0b21d69ff0941f3c0c57c1ae24fbbef (diff)
downloadmariadb-git-bd414485de627818a8fd28fc00887d919d4e0ae1.tar.gz
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.
Diffstat (limited to 'sql/item_func.cc')
-rw-r--r--sql/item_func.cc35
1 files changed, 35 insertions, 0 deletions
diff --git a/sql/item_func.cc b/sql/item_func.cc
index 55324923fe2..519b476ccf8 100644
--- a/sql/item_func.cc
+++ b/sql/item_func.cc
@@ -4147,6 +4147,41 @@ Item_func_set_user_var::check(bool use_result_field)
}
+/**
+ @brief Evaluate and store item's result.
+ This function is invoked on "SELECT ... INTO @var ...".
+
+ @param item An item to get value from.
+*/
+
+void Item_func_set_user_var::save_item_result(Item *item)
+{
+ DBUG_ENTER("Item_func_set_user_var::save_item_result");
+
+ switch (cached_result_type) {
+ case REAL_RESULT:
+ save_result.vreal= item->val_result();
+ break;
+ case INT_RESULT:
+ save_result.vint= item->val_int_result();
+ unsigned_flag= item->unsigned_flag;
+ break;
+ case STRING_RESULT:
+ save_result.vstr= item->str_result(&value);
+ break;
+ case DECIMAL_RESULT:
+ save_result.vdec= item->val_decimal_result(&decimal_buff);
+ break;
+ case ROW_RESULT:
+ default:
+ // Should never happen
+ DBUG_ASSERT(0);
+ break;
+ }
+ DBUG_VOID_RETURN;
+}
+
+
/*
This functions is invoked on SET @variable or @variable:= expression.