diff options
-rw-r--r-- | mysql-test/r/user_var.result | 14 | ||||
-rw-r--r-- | mysql-test/t/user_var.test | 5 | ||||
-rw-r--r-- | sql/item_func.cc | 34 | ||||
-rw-r--r-- | sql/item_func.h | 4 |
4 files changed, 52 insertions, 5 deletions
diff --git a/mysql-test/r/user_var.result b/mysql-test/r/user_var.result index d8d7ddef122..1f9e1d63cfb 100644 --- a/mysql-test/r/user_var.result +++ b/mysql-test/r/user_var.result @@ -318,9 +318,17 @@ SHOW COUNT(*) ERRORS; @@session.error_count 1 create table t1(f1 int); -insert into t1 values(1),(1),(2); -select @a:=f1, count(f1) from t1 group by 1 order by 1; +insert into t1 values(1),(1),(2),(3),(4),(1),(3),(1); +select @a:=f1, count(f1) from t1 group by 1 desc; @a:=f1 count(f1) -1 2 +4 1 +3 2 2 1 +1 4 +select @a:=f1, count(f1) from t1 group by 1 asc; +@a:=f1 count(f1) +1 4 +2 1 +3 2 +4 1 drop table t1; diff --git a/mysql-test/t/user_var.test b/mysql-test/t/user_var.test index da4143bb0d3..3df949ae669 100644 --- a/mysql-test/t/user_var.test +++ b/mysql-test/t/user_var.test @@ -227,6 +227,7 @@ SHOW COUNT(*) ERRORS; # Bug#28494: Grouping by Item_func_set_user_var produces incorrect result. # create table t1(f1 int); -insert into t1 values(1),(1),(2); -select @a:=f1, count(f1) from t1 group by 1 order by 1; +insert into t1 values(1),(1),(2),(3),(4),(1),(3),(1); +select @a:=f1, count(f1) from t1 group by 1 desc; +select @a:=f1, count(f1) from t1 group by 1 asc; drop table t1; diff --git a/sql/item_func.cc b/sql/item_func.cc index 640ab3cac0c..c65477f3105 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -4179,6 +4179,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 8c761f605db..213e4298b39 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -1236,6 +1236,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); |