diff options
author | Varun Gupta <varun.gupta@mariadb.com> | 2019-12-31 11:00:15 +0530 |
---|---|---|
committer | Varun Gupta <varun.gupta@mariadb.com> | 2020-01-02 09:49:13 +0530 |
commit | faf2a6e5f03b9c7bd52d838b2a9b4860c3b65bee (patch) | |
tree | 2fea02ad183e5573c32a5a725ef0393f947b965b | |
parent | 359d91aaeec25825b51b0a00f52f272edad7d6cc (diff) | |
download | mariadb-git-faf2a6e5f03b9c7bd52d838b2a9b4860c3b65bee.tar.gz |
MDEV-20922: Adding an order by changes the query results
For Item_direct_view_ref , get value from val_* methods
instead of result* family
The val_* methods gets value from the item on which it is referred.
-rw-r--r-- | mysql-test/r/group_by.result | 16 | ||||
-rw-r--r-- | mysql-test/t/group_by.test | 14 | ||||
-rw-r--r-- | sql/item.cc | 40 | ||||
-rw-r--r-- | sql/item.h | 8 |
4 files changed, 78 insertions, 0 deletions
diff --git a/mysql-test/r/group_by.result b/mysql-test/r/group_by.result index eb730a8c954..9e50ba12db3 100644 --- a/mysql-test/r/group_by.result +++ b/mysql-test/r/group_by.result @@ -2792,3 +2792,19 @@ SELECT 1 IN ( SELECT COUNT( DISTINCT f2 ) FROM t1 WHERE f1 <= 4 ); 1 IN ( SELECT COUNT( DISTINCT f2 ) FROM t1 WHERE f1 <= 4 ) 0 drop table t1; +# +# MDEV-20922: Adding an order by changes the query results +# +CREATE TABLE t1(a int, b int); +INSERT INTO t1 values (1, 100), (2, 200), (3, 100), (4, 200); +create view v1 as select a, b+1 as x from t1; +SELECT x, COUNT(DISTINCT a) AS y FROM v1 GROUP BY x ORDER BY y; +x y +101 2 +201 2 +SELECT b+1 AS x, COUNT(DISTINCT a) AS y FROM t1 GROUP BY x ORDER BY y; +x y +101 2 +201 2 +drop view v1; +drop table t1; diff --git a/mysql-test/t/group_by.test b/mysql-test/t/group_by.test index 0401ad9780c..71e29d55303 100644 --- a/mysql-test/t/group_by.test +++ b/mysql-test/t/group_by.test @@ -1915,3 +1915,17 @@ INSERT INTO t1 VALUES (0,'foo'),(1,'bar'); SELECT 1 IN ( SELECT COUNT( DISTINCT f2 ) FROM t1 WHERE f1 <= 4 ); drop table t1; +--echo # +--echo # MDEV-20922: Adding an order by changes the query results +--echo # + +CREATE TABLE t1(a int, b int); +INSERT INTO t1 values (1, 100), (2, 200), (3, 100), (4, 200); + +create view v1 as select a, b+1 as x from t1; + +SELECT x, COUNT(DISTINCT a) AS y FROM v1 GROUP BY x ORDER BY y; +SELECT b+1 AS x, COUNT(DISTINCT a) AS y FROM t1 GROUP BY x ORDER BY y; + +drop view v1; +drop table t1; diff --git a/sql/item.cc b/sql/item.cc index 17eb570ad80..a05fafae3b2 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -8149,6 +8149,46 @@ Item *Item_direct_view_ref::replace_equal_field(THD *thd, uchar *arg) } +double Item_direct_view_ref::val_result() +{ + double tmp=(*ref)->val_result(); + null_value=(*ref)->null_value; + return tmp; +} + + +longlong Item_direct_view_ref::val_int_result() +{ + longlong tmp=(*ref)->val_int_result(); + null_value=(*ref)->null_value; + return tmp; +} + + +String *Item_direct_view_ref::str_result(String* tmp) +{ + tmp=(*ref)->str_result(tmp); + null_value=(*ref)->null_value; + return tmp; +} + + +my_decimal *Item_direct_view_ref::val_decimal_result(my_decimal *val) +{ + my_decimal *tmp= (*ref)->val_decimal_result(val); + null_value=(*ref)->null_value; + return tmp; +} + + +bool Item_direct_view_ref::val_bool_result() +{ + bool tmp= (*ref)->val_bool_result(); + null_value=(*ref)->null_value; + return tmp; +} + + bool Item_default_value::eq(const Item *item, bool binary_cmp) const { return item->type() == DEFAULT_VALUE_ITEM && diff --git a/sql/item.h b/sql/item.h index bea09620ef8..8a90d99db9d 100644 --- a/sql/item.h +++ b/sql/item.h @@ -4477,6 +4477,14 @@ public: item_equal= NULL; Item_direct_ref::cleanup(); } + /* + TODO move these val_*_result function to Item_dierct_ref (maybe) + */ + double val_result(); + longlong val_int_result(); + String *str_result(String* tmp); + my_decimal *val_decimal_result(my_decimal *val); + bool val_bool_result(); }; |