From 8ab1830f9a4cca12420e2cd9756983707bca9af2 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 2 Jun 2007 23:17:46 +0400 Subject: Bug#28494: Grouping by Item_func_set_user_var produces incorrect result. This is an additional fix. Item::val_xxx methods are supposed to use original data source and Item::val_xxx_result methods to use the item's result field. But for the Item_func_set_user_var class val_xxx_result methods were mapped to val_xxx methods. This leads, in particular, to producing bad sort keys and thus wrong order of the result set of queries with group by/order by clauses. The set of val_xxx_result methods is added to the Item_func_set_user_var class. It's the same as the val_xxx set of method but uses the result_field to return a value. mysql-test/t/user_var.test: Corrected test case for hte bug#28494. mysql-test/r/user_var.result: Corrected test case for hte bug#28494. sql/item_func.cc: Bug#28494: Grouping by Item_func_set_user_var produces incorrect result. The set of val_xxx_result methods is added to the Item_func_set_user_var class. It's the same as the val_xxx set of method but uses the result_field to return a value. sql/item_func.h: Bug#28494: Grouping by Item_func_set_user_var produces incorrect result. The set of val_xxx_result methods is added to the Item_func_set_user_var class. --- sql/item_func.cc | 34 ++++++++++++++++++++++++++++++++++ sql/item_func.h | 4 ++++ 2 files changed, 38 insertions(+) (limited to 'sql') diff --git a/sql/item_func.cc b/sql/item_func.cc index 95ff432ca5a..aa1d54b0ebd 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -4208,6 +4208,40 @@ my_decimal *Item_func_set_user_var::val_decimal(my_decimal *val) } +double Item_func_set_user_var::val_real_result() +{ + DBUG_ASSERT(fixed == 1); + check(TRUE); + update(); // Store expression + return entry->val_real(&null_value); +} + +longlong Item_func_set_user_var::val_int_result() +{ + DBUG_ASSERT(fixed == 1); + check(TRUE); + update(); // Store expression + return entry->val_int(&null_value); +} + +String *Item_func_set_user_var::val_str_result(String *str) +{ + DBUG_ASSERT(fixed == 1); + check(TRUE); + update(); // Store expression + return entry->val_str(&null_value, str, decimals); +} + + +my_decimal *Item_func_set_user_var::val_decimal_result(my_decimal *val) +{ + DBUG_ASSERT(fixed == 1); + check(TRUE); + update(); // Store expression + return entry->val_decimal(&null_value, val); +} + + void Item_func_set_user_var::print(String *str) { str->append(STRING_WITH_LEN("(@")); diff --git a/sql/item_func.h b/sql/item_func.h index 18cd87d2de4..c8ea79b9747 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -1208,6 +1208,10 @@ public: longlong val_int(); String *val_str(String *str); my_decimal *val_decimal(my_decimal *); + double val_real_result(); + longlong val_int_result(); + String *val_str_result(String *str); + my_decimal *val_decimal_result(my_decimal *); bool update_hash(void *ptr, uint length, enum Item_result type, CHARSET_INFO *cs, Derivation dv, bool unsigned_arg); bool send(Protocol *protocol, String *str_arg); -- cgit v1.2.1